Skip to content

Instantly share code, notes, and snippets.

@jxnblk
Created July 17, 2018 02:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jxnblk/0de110c211f68fdea230f42f9d0a06cf to your computer and use it in GitHub Desktop.
Save jxnblk/0de110c211f68fdea230f42f9d0a06cf to your computer and use it in GitHub Desktop.
import React from 'react'
import styled, { ThemeProvider } from 'styled-components'
export const Base = ({
value,
children,
...props
}) =>
<React.Fragment>
{React.Children.toArray(children)
.map(child => typeof child === 'string' ? (
<div {...props}>{child}</div>
) : (
React.cloneElement(child, props)
)
)}
</React.Fragment>
export const create = prop => styled(Base)([],
props => props.value ? ({
[prop]: props.value
}) : null
)
export const FontSize = create('fontSize')
export const Color = create('color')
export const BackgroundColor = create('backgroundColor')
export const Margin = create('margin')
export const Padding = create('padding')
export default props =>
<BackgroundColor value='black'>
<Color value='tomato'>
<Padding value='32px'>
<FontSize value='32px'>
Hi
</FontSize>
</Padding>
</Color>
</BackgroundColor>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment