Skip to content

Instantly share code, notes, and snippets.

@callmephil
Created January 20, 2019 17:41
Show Gist options
  • Save callmephil/ad13f24b2c59493143ab5d92d96cb345 to your computer and use it in GitHub Desktop.
Save callmephil/ad13f24b2c59493143ab5d92d96cb345 to your computer and use it in GitHub Desktop.
Sidebar-React
@import url(//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css);
@import url(https://fonts.googleapis.com/css?family=Titillium+Web:300);
.fa-2x {
font-size: 2em;
}
.fa {
position: relative;
display: table-cell;
width: 60px;
height: 36px;
text-align: center;
vertical-align: middle;
font-size: 20px;
}
.main-menu-expand-color {
color: rgb(255, 115, 0) !important;
background-color: rgb(30, 30, 30) !important;
}
.main-menu-expand-color > span {
color: #999;
}
.main-menu-expand-color:hover,
.main-menu-expand-color:hover>span,
.main-menu-expand-color:focus,
.main-menu-expand-color:focus>span,
.main-menu-expand-color:active,
.main-menu-expand-color:active>span {
color: #fff !important;
background-color: rgb(255, 115, 0) !important;
}
.main-menu-expand {
width: 250px !important;
}
.main-menu {
background: rgb(30, 30, 30);
border-right: 1px solid #e5e5e5;
position: absolute;
top: 0;
bottom: 0;
height: 100%;
left: 0;
width: 60px;
overflow: hidden;
-webkit-transition: width .05s linear;
transition: width .05s linear;
z-index: 1000;
}
.main-menu>ul {
margin: 7px 0;
}
.main-menu li {
position: relative;
display: block;
width: 250px;
}
.main-menu li>a {
position: relative;
display: table;
border-collapse: collapse;
border-spacing: 0;
color: #999;
font-family: arial;
font-size: 14px;
text-decoration: none;
-webkit-transition: all .1s linear;
transition: all .1s linear;
}
.main-menu .nav-icon {
position: relative;
display: table-cell;
width: 60px;
height: 36px;
text-align: center;
vertical-align: middle;
font-size: 18px;
}
.main-menu .nav-text {
position: relative;
display: table-cell;
vertical-align: middle;
width: 190px;
font-family: 'Titillium Web', sans-serif;
}
.main-menu>ul.logout {
position: absolute;
left: 0;
bottom: 0;
}
.no-touch .scrollable.hover {
overflow-y: hidden;
}
.no-touch .scrollable.hover:hover {
overflow-y: auto;
overflow: visible;
}
a:hover,
a:focus {
text-decoration: none;
}
nav {
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
-o-user-select: none;
user-select: none;
}
nav ul,
nav li {
outline: 0;
margin: 0;
padding: 0;
}
.main-menu li:hover>a,
nav.main-menu li.active>a,
.dropdown-menu>li>a:hover,
.dropdown-menu>li>a:focus,
.dropdown-menu>.active>a,
.dropdown-menu>.active>a:hover,
.dropdown-menu>.active>a:focus,
.no-touch .dashboard-page nav.dashboard-menu ul li:hover a,
.dashboard-page nav.dashboard-menu ul li.active a {
color: #fff;
background-color: #5fa2db;
}
.area {
float: left;
background: #e2e2e2;
width: 100%;
height: 100%;
}
@font-face {
font-family: 'Titillium Web';
font-style: normal;
font-weight: 300;
src: local('Titillium WebLight'), local('TitilliumWeb-Light'), url(http://themes.googleusercontent.com/static/fonts/titilliumweb/v2/anMUvcNT0H1YN4FII8wpr24bNCNEoFTpS2BTjF6FB5E.woff) format('woff');
}
@media only screen and (max-width: 200px) {
/* For mobile phones: */
.main-menu-expand {
width: 60px !important;
overflow: hidden !important;
}
/* ! TODO */
.main-menu-expand-color {
color: rgb(201, 201, 201) !important;
background-color: rgb(30, 30, 30) !important;
}
.main-menu-expand-color {
color: rgb(30, 30, 30) !important;
}
}
input,
textarea,
button,
select,
a {
-webkit-tap-highlight-color: rgba(0,0,0,0);
}
.w3-container {
padding: 0.01em 16px;
}
*, ::before, ::after {
box-sizing: inherit;
}
import React, { Component } from "react";
import { NavLink } from 'react-router-dom'
import './Sidebar.css';
export default class Sidebar extends Component {
constructor(props) {
super(props);
this.state = {
isCollasped: false
};
this.toggleCollapse = this.toggleCollapse.bind(this);
}
toggleCollapse() {
const collapse = !this.state.isCollasped;
this.setState({ isCollasped: collapse });
}
render() {
let toggleClassName = !this.state.isCollasped ? "main-menu" : "main-menu main-menu-expand";
const Links = [
{
link:"/home",
icon:"fa fa-2x fa-home",
text:"Home",
position: ""
},
{
link:"/hey",
icon:"fa fa-2x fa-home",
text:"Test 3",
position: ""
},
{
link:"/#",
icon:"fa fa-2x fa-power-off",
text:"Logout",
position: "logout"
},
];
return (
<div>
<div className="area">
<nav className={toggleClassName}>
<div>
<li>
<a className="main-menu-expand-color" onClick={this.toggleCollapse}>
<i className="fa fa-2x">☰</i>
<span className="nav-text">
Collapase menu
</span>
</a>
</li>
</div>
{Links.map((x, i) => (
<ul className={x.position} key={i}>
<li>
<NavLink to={x.link} activeStyle={{ color: "red" }}>
<i className={x.icon} />
<span className="nav-text">
{x.text}
</span>
</NavLink>
</li>
</ul>
))}
</nav>
</div>
<div Style="margin-left:70px">
<div className="w3-container">
<h2>Sidebar Icons</h2>
<p>Finally Responsive. How do we do active menu ?</p>
</div>
</div>
</div>
)
}
}
@callmephil
Copy link
Author

Require : React-router-dom (Unfinished)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment