Skip to content

Instantly share code, notes, and snippets.

@jaketrent
Created August 7, 2017 19:14
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 jaketrent/d7001b870952a5616a85543b1c207ebd to your computer and use it in GitHub Desktop.
Save jaketrent/d7001b870952a5616a85543b1c207ebd to your computer and use it in GitHub Desktop.
glamorous glamor.css as className
<P className={glamor.css({ color: 'blue' })}>wow</P>
import glamorous from 'glamorous'
import React from 'react'
const P = glamorous.p({
color: 'red',
})
export default props => <P {...props} className={`${props.className}`} />
// works!
import glamorous from 'glamorous'
import React from 'react'
const P = glamorous.p({
color: 'red',
})
export default props => <P {...props} />
// errors with:
// VM128 preview.bundle.js:830 Warning: Failed prop type: Invalid prop `className` of type `object` supplied to `glamorous(p)`, expected `string`.
// in glamorous(p)
// in Unknown (created by BackgroundDecorator)
// in div (created by BackgroundDecorator)
// in BackgroundDecorator
// also errors:
// export default props => <P {...props} className={props.className} />
@jaketrent
Copy link
Author

Examples seem to always cast this way:

const myCustomGlamorStyles = glamor.css({fontSize: 2})
<MyStyledDiv className={`${myCustomGlamorStyles} custom-class`} />
// styles applied:
// {margin: 1, fontSize: 2, padding: 1}
// as well as any styles custom-class applies

https://glamorous.rocks/basics/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment