Last active
August 29, 2015 14:17
-
-
Save axross/8c5e2d30dd742d47c8f6 to your computer and use it in GitHub Desktop.
ReactでBEMなclassNameを書きやすくするBemmerというライブラリを作った
This file contains 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
.exButton { | |
color: black; | |
&--isOdd { color: red; } | |
&--isEven { color: blue; } | |
} |
This file contains 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 Bemmer from 'bemmer'; | |
var ExButton = React.createClass({ | |
getInitialState() { | |
return { count: 0 }; | |
}, | |
_onClick() { | |
this.setState({ count: this.state.count + 1 }); | |
} | |
render() { | |
var bemmer = new Bemmer('exButton', this.props.className); | |
var isOdd = () => this.state.count % === 1; | |
return ( | |
<a | |
className={bemmer.mo('isOdd', isOdd()).mo('isEven', !isOdd()).out()} | |
onClick={this._onClick} | |
> | |
push me!! | |
</a> | |
); | |
}, | |
}); |
This file contains 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/addons'; | |
var ExButton = React.createClass({ | |
getInitialState() { | |
return { count: 0 }; | |
}, | |
_onClick() { | |
this.setState({ count: this.state.count + 1 }); | |
} | |
render() { | |
var isOdd = () => this.state.count % === 1; | |
var className = React.addons.classSet({ | |
'exButton': true, | |
'exButton--isOdd': isOdd(), | |
'exButton--isEven': !isOdd(), | |
}); | |
return ( | |
<a | |
className={className} | |
onClick={this._onClick} | |
> | |
push me!! | |
</a> | |
); | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment