-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
62 lines (55 loc) · 1.89 KB
/
index.js
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const selectorParser = require("postcss-selector-parser");
const plugin = require("tailwindcss/plugin");
module.exports = plugin(({ theme, addVariant, prefix, e }) => {
const namedGroups = theme("namedGroups") || [];
addVariant(`group-hover`, ({ modifySelectors, separator }) => {
return modifySelectors(({ selector }) => {
return selectorParser((root) => {
root.walkClasses((node) => {
// Regular group
const value = node.value;
node.value = `group-hover${separator}${value}`;
node.parent.insertBefore(
node,
selectorParser().astSync(prefix(`.group:hover `))
);
// Named groups
namedGroups.forEach((namedGroup) => {
node.parent.parent.insertAfter(
node.parent,
selectorParser().astSync(
prefix(`.group-${namedGroup}:hover .`) +
e(`group-${namedGroup}-hover${separator}${value}`)
)
);
});
});
}).processSync(selector);
});
});
addVariant(`group-focus`, ({ modifySelectors, separator }) => {
return modifySelectors(({ selector }) => {
return selectorParser((root) => {
root.walkClasses((node) => {
// Regular group
const value = node.value;
node.value = `group-focus${separator}${value}`;
node.parent.insertBefore(
node,
selectorParser().astSync(prefix(`.group:focus `))
);
// Named groups
namedGroups.forEach((namedGroup) => {
node.parent.parent.insertAfter(
node.parent,
selectorParser().astSync(
prefix(`.group-${namedGroup}:focus .`) +
e(`group-${namedGroup}-focus${separator}${value}`)
)
);
});
});
}).processSync(selector);
});
});
});