-
-
Save vjeux/8e27dd06c64dc566bfee705e1b19cb18 to your computer and use it in GitHub Desktop.
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
// Solution #1: Generic Override (like CSS) | |
var ButtonGroup = React.createClass({ | |
render() { | |
return <div>{this.props.buttons.map((btn, i) => | |
<Button style={{ | |
...(i !== 0 && {marginLeft: 0}) | |
...(i !== this.props.buttons.length - 1 && {marginRight: 0}) | |
}} /> | |
)}</div>; | |
} | |
}); | |
var Button = React.createClass({ | |
render() { | |
return <div style={{ | |
...styles.button, | |
...this.props.style, | |
}} />; | |
} | |
}); | |
// Solution #2: Encapsulated behavior | |
var ButtonGroup = React.createClass({ | |
render() { | |
return <div>{this.props.buttons.map((btn, i) => | |
<Button | |
hasLeftSibling={i !== 0} | |
hasRightSibling={i !== this.props.buttons.length - 1} | |
/> | |
)}</div>; | |
} | |
}); | |
var Button = React.createClass({ | |
render() { | |
return <div style={{ | |
...styles.button, | |
...(hasLeftSibling && {marginLeft: 0}), | |
...(hasRightSibling && {marginRight: 0}), | |
}} />; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
here's a take on the above with glamor -