Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork25
PostCSS for React Inline Styles, Free Style and other CSS-in-JS
License
postcss/postcss-js
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
PostCSS for CSS-in-JS and styles in JS objects.
For example, to useStylelint orRTLCSS plugins in your workflow.
constpostcssJs=require('postcss-js')constautoprefixer=require('autoprefixer')constprefixer=postcssJs.sync([autoprefixer])conststyle=prefixer({userSelect:'none'})style//=> {// WebkitUserSelect: 'none',// MozUserSelect: 'none',// msUserSelect: 'none',// userSelect: 'none'// }
constpostcss=require('postcss')constpostcssJs=require('postcss-js')conststyle={top:10,'&:hover':{top:5}};postcss().process(style,{parser:postcssJs}).then((result)=>{result.css//=> top: 10px;// &:hover { top: 5px; }})
constpostcss=require('postcss')constpostcssJs=require('postcss-js')constcss='--text-color: #DD3A0A; @media screen { z-index: 1; color: var(--text-color) }'constroot=postcss.parse(css)postcssJs.objectify(root)//=> {// '--text-color': '#DD3A0A',// '@media screen': {// zIndex: '1',// color: 'var(--text-color)'// }// }
Create PostCSS processor with simple API, but with only sync PostCSS pluginssupport.
Processor is just a function, which takes one style object and return other.
Same assync, but also support async plugins.
Returned processor will return Promise.
Parse CSS-in-JS style object to PostCSSRoot instance.
It converts numbers to pixels and parses[Free Style] like selectors and at-rules:
{'@media screen':{'&:hover':{top:10}}}
This methods use Custom Syntax name convention, so you can use it like this:
postcss().process(obj,{parser:postcssJs})
Convert PostCSSRoot instance to CSS-in-JS style object.
Webpack may need some extra config for some PostCSS plugins.
Autoprefixer and some other pluginsneed ajson-loader to import data.
So, please install this loader and add to webpack config:
loaders:[{test:/\.json$/,loader:"json-loader"}]
About
PostCSS for React Inline Styles, Free Style and other CSS-in-JS
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Contributors13
Uh oh!
There was an error while loading.Please reload this page.