Last active
November 15, 2016 00:53
-
-
Save chrisui/8283c716520c74556b30927449d8e688 to your computer and use it in GitHub Desktop.
example component
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 cx from 'classnames'; | |
import styles from './styles.css' | |
// heading implements all the styling logic | |
export function Heading({size, weight, ...props}) { | |
const Component = `H${size}`; | |
return ( | |
<Component | |
className={cx({ | |
[`size-${size}`]: true, | |
[`weight-${weight}`]: true | |
})} | |
{...props} | |
/> | |
); | |
} | |
// make composable components for easier styleguide-conformant usage | |
export function H1(props) { | |
return ( | |
<Heading size={1} weight="bold" {...props} /> | |
); | |
} | |
// recompose library is great for this | |
export const H2 = Recompose.withProps({size: 2, weight: 'semi-bold'})(Heading); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment