generated from apav-dev/pages-latest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tailwindPlugin.ts
37 lines (31 loc) · 1.24 KB
/
tailwindPlugin.ts
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
import plugin from "tailwindcss/plugin";
// Plugin to generate tailwind components from the buttons, links, and headings keys in tailwind.config.cjs
// Components will be available as tailwind class ex: <button className="Button Button--primary">
function styleguidePlugin() {
return plugin(({ addComponents, theme }) => {
const components: any = Object.assign(
{},
{ ".Button": JSON.parse(JSON.stringify(theme("buttons") || {})) },
{ ".Link": JSON.parse(JSON.stringify(theme("links") || {})) },
{ ".Heading": JSON.parse(JSON.stringify(theme("headings") || {})) }
);
delete components[".Button"].variants;
for (const [variant, styles] of Object.entries(
theme("buttons")?.variants
)) {
components[`.Button--${variant}`] = styles;
}
// delete components[".Link"].variants;
// for (const [variant, styles] of Object.entries(theme("links")?.variants)) {
// components[`.Link--${variant}`] = styles;
// }
// delete components[".Heading"].variants;
// for (const [variant, styles] of Object.entries(
// theme("headings")?.variants
// )) {
// components[`.Heading--${variant}`] = styles;
// }
addComponents(components);
});
}
export { styleguidePlugin };