Skip to content

Instantly share code, notes, and snippets.

@chrisui
Last active November 15, 2016 00:53
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisui/8283c716520c74556b30927449d8e688 to your computer and use it in GitHub Desktop.
Save chrisui/8283c716520c74556b30927449d8e688 to your computer and use it in GitHub Desktop.
example component
// all of our components are in their own directories with local css
// so we use index.js (node resolution paradigm) so we can write:
// `import Button from 'components/button'`
// rather than:
// `import Button from 'components/button/button'`
//
// eg. dir structure
// /components/button
// /components/button/index.js
// /components/button/button.js
// /components/button/button.css
export {default as default} from './button';
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