-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
49 lines (45 loc) · 1.35 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
const plugin = require("tailwindcss/plugin");
module.exports = plugin(
function ({ e, theme, addVariant }) {
const {
numberOfSpacings,
baseSpacing,
generateNegative,
spacings: configSpacings,
} = theme("paddedRadius");
const spacings =
configSpacings ??
[...Array(numberOfSpacings).keys()].reduce((obj, spacing, idx) => {
obj[idx + 1] = `${spacing + 1} * ${baseSpacing}`;
return obj;
}, {});
const generate = (container, rule, name, spacing, negative) => {
const newRule = rule.clone();
newRule.selector = `.${e(
`${rule.selector.slice(1)}-${negative ? "-" : ""}${name}`
)}`;
newRule.walkDecls((decl) => {
decl.value = `calc(${decl.value} ${negative ? "-" : "+"} ${spacing})`;
});
container.prepend(newRule);
};
addVariant("paddedRadius", ({ container }) => {
container.walkRules((rule) => {
Object.entries(spacings).map(([name, spacing]) => {
generate(container, rule, name, spacing, false);
generateNegative && generate(container, rule, name, spacing, true);
});
});
});
},
{
theme: {
paddedRadius: (theme) => ({
baseSpacing: theme("spacing")["1"],
numberOfSpacings: 64,
spacings: undefined,
generateNegative: false,
}),
},
}
);