2018-06-26 10:31:06 -04:00
|
|
|
import _ from 'lodash'
|
|
|
|
|
import postcss from 'postcss'
|
2018-06-22 12:43:24 -04:00
|
|
|
import escapeClassName from './escapeClassName'
|
|
|
|
|
|
|
|
|
|
export default function generateVariantFunction(generator) {
|
|
|
|
|
return (container, config) => {
|
2018-06-26 10:31:06 -04:00
|
|
|
const cloned = postcss.root({ nodes: container.clone().nodes })
|
2018-06-22 12:43:24 -04:00
|
|
|
|
2018-06-26 10:31:06 -04:00
|
|
|
container.before(
|
|
|
|
|
_.defaultTo(
|
|
|
|
|
generator({
|
|
|
|
|
container: cloned,
|
2019-01-18 09:15:12 -05:00
|
|
|
separator: escapeClassName(config.separator),
|
2018-06-26 10:31:06 -04:00
|
|
|
modifySelectors: modifierFunction => {
|
|
|
|
|
cloned.walkRules(rule => {
|
2018-09-15 11:38:58 +10:00
|
|
|
rule.selectors = rule.selectors.map(selector =>
|
|
|
|
|
modifierFunction({
|
|
|
|
|
className: selector.slice(1),
|
2018-09-15 13:07:29 +10:00
|
|
|
selector,
|
2018-09-15 11:38:58 +10:00
|
|
|
})
|
|
|
|
|
)
|
2018-06-26 10:31:06 -04:00
|
|
|
})
|
|
|
|
|
return cloned
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
cloned
|
|
|
|
|
).nodes
|
|
|
|
|
)
|
2018-06-22 12:43:24 -04:00
|
|
|
}
|
|
|
|
|
}
|