Skip to content

Instantly share code, notes, and snippets.

@ajmalafif
Forked from mxstbr/Component.js
Created October 24, 2018 04:42
Show Gist options
  • Select an option

  • Save ajmalafif/86dfdedc492acc277c16b5ad9a075d61 to your computer and use it in GitHub Desktop.

Select an option

Save ajmalafif/86dfdedc492acc277c16b5ad9a075d61 to your computer and use it in GitHub Desktop.
styled-components ❤ tachyons
// There's two ways to use Tachyons together with styled-components
// Both are valid, which one you use depends if you want to always apply a tachyons class when a certain component
// is rendered or if you want to apply it for specific instances.
// 1. Use .attrs to define classNames that should always be applied to a styled component
// Whenever you use <Component /> now it'll have both the styled-components as well as the Tachyons class
// See the docs for more info: https://www.styled-components.com/docs/basics#attaching-additional-props
const Component = styled.div.attrs({
className: 'bw0-l',
})`
color: blue;
`
<Component /> // has bw0-1 class applied!
// 2. Use the Tachyons className in the JSX
// styled-components doesn't force you to not use any classes so this works like with any other component
const Component = styled.div`
color: blue;
`
// Add the Tachyons class when you render the component
<Component className="bw0-1" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment