-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtailwind.config.mjs
131 lines (119 loc) · 3.98 KB
/
tailwind.config.mjs
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
const defaultColors = require("tailwindcss/colors");
const defaultTheme = require("tailwindcss/defaultTheme");
const plugin = require("tailwindcss/plugin");
// https://noumenal.es/notes/tailwind/django-integration/
// Resolve path to directory containing manage.py file.
// This is the root of the project.
// Then assumed layout of <main-app>/static/css/tailwind.config.js, so up 3 levels.
// Adjust for your needs.
const path = require("path");
const projectRoot = path.resolve(__dirname);
const { spawnSync } = require("child_process");
// Function to execute the Django management command and capture its output
const getTemplateFiles = () => {
const command = "python"; // Requires virtualenv to be activated.
const args = ["manage.py", "tailwind", "list_templates"]; // Requires cwd to be set.
const options = { cwd: projectRoot };
const result = spawnSync(command, args, options);
if (result.error) {
throw result.error;
}
if (result.status !== 0) {
console.log(result.stdout.toString(), result.stderr.toString());
}
return result.stdout
.toString()
.split("\n")
.map((file) => file.trim())
.filter(function (e) {
return e;
});
};
/** @type {import('tailwindcss').Config} */
export default {
content: ["./core/markdown.py", "./templates/**/*.svg"].concat(
getTemplateFiles(),
),
theme: {
extend: {
colors: {
gray: defaultColors.neutral,
primary: defaultColors.indigo,
secondary: defaultColors.gray,
tertiary: defaultColors.green,
aspect: defaultColors.orange,
danger: defaultColors.red,
},
fontFamily: {
brico: ["BricolageGrotesque", ...defaultTheme.fontFamily.sans],
mono: ["MonoLisa", ...defaultTheme.fontFamily.mono],
sans: ["InterVariable", ...defaultTheme.fontFamily.sans],
},
screens: {
xs: "425px",
},
},
},
plugins: [
require("@tailwindcss/aspect-ratio"),
require("@tailwindcss/container-queries"),
require("@tailwindcss/forms"),
require("@tailwindcss/typography"),
require("tailwindcss-debug-screens"),
plugin(function ({ addVariant }) {
addVariant("htmx-settling", ["&.htmx-settling", ".htmx-settling &"]);
addVariant("htmx-request", ["&.htmx-request", ".htmx-request &"]);
addVariant("htmx-swapping", ["&.htmx-swapping", ".htmx-swapping &"]);
addVariant("htmx-added", ["&.htmx-added", ".htmx-added &"]);
}),
plugin(function ({ addUtilities, theme }) {
const widths = theme("maxWidth");
const gridUtilities = {};
Object.keys(widths).forEach((scale) => {
gridUtilities[`.hg-grid-${scale}`] = {
display: "grid",
gridTemplateColumns: `1fr min(${widths[scale]}, 100%) 1fr`,
};
gridUtilities[`.hg-grid-${scale} > *`] = {
gridColumn: "2",
};
});
const newUtilities = {
".hg-grid": {
display: "grid",
gridTemplateColumns: "1fr min(65ch, 100%) 1fr",
},
".hg-grid > *": {
gridColumn: "2",
},
...gridUtilities,
};
Object.keys(widths).forEach((size) => {
newUtilities[`.stretch-to-${size}`] = {
width: "100%",
gridColumn: "1 / 4",
maxWidth: widths[size],
marginLeft: "auto",
marginRight: "auto",
};
});
addUtilities(newUtilities, ["responsive"]);
}),
plugin(function ({ addBase, theme }) {
const colors = theme("colors");
const colorVariables = {};
Object.keys(colors).forEach((colorKey) => {
const color = colors[colorKey];
if (typeof color === "object") {
Object.keys(color).forEach((shade) => {
colorVariables[`--tw-color-${colorKey}-${shade}`] = color[shade];
});
colorVariables[`--tw-color-${colorKey}`] = color[500];
} else {
colorVariables[`--tw-color-${colorKey}`] = color;
}
});
addBase({ ":root": colorVariables });
}),
],
};