threepointone / glamor
- четверг, 27 октября 2016 г. в 03:17:32
JavaScript
inline css for react et al
css for component systems
npm install glamor --save
usage
import { style, merge } from 'glamor'
// make css rules
let rule = style({
color: 'red',
':hover': {
color: 'pink'
},
'@media(min-width: 300px)': {
color: 'green',
':hover': {
color: 'yellow'
}
}
})
// add as data attributes
<div {...rule} {...another}>
zomg
</div>
// or as classes
<div className={`${rule} ${another}`}>
zomg
</div>
// compose rules for great justice
let mono = style({
fontFamily: 'monospace'
})
let bolder = style({
fontWeight: 'bolder'
})
<div {...merge(mono, bolder)}>
bold code!
</div>
This expands on ideas from @vjeux's 2014 css-in-js talk. We introduce an api to annotate arbitrary dom nodes with style definitions ("rules") for, um, the greater good.
@media
queries@font-face
/ @keyframes
:hover
, etc(thanks to BrowserStack for providing the infrastructure that allows us to run our build in real browsers.)
glamor/reset
- include a css resetglamor/react
- helpers for themes, inline 'css' prop, @vars
glamor/jsxstyle
- react integration, à la jsxstyleglamor/aphrodite
- shim for aphrodite stylesheetsglamor/utils
- a port of postcss-utilitiesglamor/ous
- a port of the skeleton css frameworkwhile glamor shares most common attributes of other inline style / css-in-js systems, here are some key differences -
simulate
helper. very useful, especially when combined when hot-loading and/or editing directly in devtools.I get it