Last active
June 22, 2018 17:29
-
-
Save amazingandyyy/f65ed8d40fde74355f8585ce0d77845b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import 'style.scss'; | |
const NavButton = (props) => <div className='container'><div classname={`nav-btn ${props.active}`}><i>Click Me</i></div><div> | |
export default NavButton; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$brand-color: red; | |
.nav-btn { | |
border: 1px solid black; | |
border-radius: 5px; | |
background: white; | |
&.true { | |
background: $brand-color; | |
} | |
} | |
.container { | |
... | |
} |
<div className={`nav-btn ${props.active}`}></div>
{props.avtive?<div className='nav-btn true'></div>:<div className='navbar-btn'></div>}
<div className={props.active ? 'nav-btn true': 'navbar-btn'}></div>
CSS-Modules
NavButton.js
import React from 'react';
import cx from 'classnames';
import s from './styles.css';
const NavButton = ({ active, className, ...props }) => <div className={cx(className, s.nbtn, active && s.active)} {...props} />
styles.css
@value brand-color: red;
.nbtn {
border: 1px solid black;
border-radius: 5px;
background: white;
}
.active {
background: $brand-color;
}
JSS
NavButton.js
import React from 'react';
import cx from 'classnames';
import { withStyles } from '@material-ui/core';
import styles from './styles.js';
const NavButton = withStyles(styles)(({ active, classes, className, ...props }) => (
<div className={cx(className, classes.nbtn, { [classes.active]: active })} {...props} />
))
styles.js
const styles = (theme) => ({
active: {
background: theme.brandColor,
},
nbtn: {
border: '1px solid black',
borderRadius: 5,
background: 'white',
}
});
export default styles;
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Styled Components
NavButton.js
Usage: