forked from tailwindlabs/tailwindcss
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerateVariantFunction.js
More file actions
38 lines (34 loc) · 1.05 KB
/
generateVariantFunction.js
File metadata and controls
38 lines (34 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import _ from 'lodash'
import postcss from 'postcss'
import selectorParser from 'postcss-selector-parser'
export default function generateVariantFunction(generator) {
return (container, config) => {
const cloned = postcss.root({ nodes: container.clone().nodes })
container.before(
_.defaultTo(
generator({
container: cloned,
separator: config.separator,
modifySelectors: modifierFunction => {
cloned.each(rule => {
if (rule.type !== 'rule') {
return
}
rule.selectors = rule.selectors.map(selector => {
const className = selectorParser(selectors => {
return selectors.first.filter(({ type }) => type === 'class').pop().value
}).transformSync(selector)
return modifierFunction({
className,
selector,
})
})
})
return cloned
},
}),
cloned
).nodes
)
}
}