Skip to content

Instantly share code, notes, and snippets.

@vdanchenkov
Created September 14, 2016 00:02
Show Gist options
  • Save vdanchenkov/6656dc3e62ce7815a3cfc767680a47f9 to your computer and use it in GitHub Desktop.
Save vdanchenkov/6656dc3e62ce7815a3cfc767680a47f9 to your computer and use it in GitHub Desktop.
Might be useful for glamor... Or not... https://github.com/threepointone/glamor
const doSomething = () => {}
const S = (...args) => {
const [ Component, css, defaultProps ] =
typeof args[0] === 'string' ? args : [ 'div', ...args ]
return (props) => <Component css={css} {...defaultProps} {...props}/>
}
const Label = S('label', { display: 'block' })
const Block = S({ margin: '1rem 0' })
const Checkbox = S('input', { color: 'red' }, { type: 'checkbox' })
const Component = () => (
<Block>
Text with
<Label>
<Checkbox onClick={doSomething}/>
checkbox
</Label>
</Block>
)
// vs
const label = { display: 'block' }
const block = { margin: '1rem 0' }
const checkbox = { color: 'red' }
const Component = () => (
<div css={block}>
Text with
<label css={label}>
<input css={checkbox} type="checkbox" onClick={doSomething}/>
checkbox
</label>
</div>
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment