Last active
August 28, 2015 18:22
-
-
Save djfarrelly/bd17a45195643210da98 to your computer and use it in GitHub Desktop.
style-guide
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 getValidProps from '../lib/utils'; | |
class Card extends React.Component { | |
render () { | |
return ( | |
<div className="Card" | |
{...getValidProps(this.props)}> | |
{this.props.children} | |
</div> | |
) | |
} | |
} | |
export default Card; |
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 {Card, Button} from 'buffer-style-guide'; | |
class MyApp extends React.Component { | |
handleClickJoin (e) { | |
alert('Welcome!'); | |
} | |
handleClickClose (e) { | |
window.close(); | |
} | |
render () { | |
return ( | |
<div className="my-app"> | |
<h1>This is my app</h1> | |
<Card> | |
<p>Would you like to join?</p> | |
<Button onClick={this.handleClickJoin} | |
primary={true}> | |
Yes! I really want to join | |
</Button> | |
<Button onClick={this.handleClickClose}> | |
No :( | |
</Button> | |
</Card> | |
</div> | |
) | |
} | |
} | |
export default MyApp; |
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
const VALID_PROPS = [ | |
'style', | |
'onClick', | |
'onHover', | |
'onSelect', | |
'onHover', | |
'onChange' | |
// etc... | |
]; | |
export function getValidProps(originalProps) { | |
return VALID_PROPS.reduce(function(props, validPropName) { | |
if (validPropName in originalProps) | |
props[validPropName] = originalProps[validPropName]; | |
return props; | |
}, {}); | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment