prejss
Version:
Get the power of PostCSS with plugins in your JSS styles. 🎨 Just put CSS into JS and get it as JSS object.
26 lines (23 loc) • 628 B
JavaScript
import guid from './utils/guid'
export default (chunks, ...variables) => {
let rawStyles
let expressions = {}
// Do we have expressions?
if (chunks.length === 1) {
rawStyles = chunks[0];
} else {
rawStyles = chunks.map((chunk, index) => {
const variable = variables[index]
if (typeof variable === 'function') {
const key = `$^var__${guid()}`
expressions[key] = variable
return chunk + key
} else if (typeof variable === 'string') {
return chunk + variable
} else {
return chunk
}
}).join('')
}
return { rawStyles, expressions }
}