-
Notifications
You must be signed in to change notification settings - Fork 0
/
tailwind.config.ts
86 lines (74 loc) · 2.13 KB
/
tailwind.config.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
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
import { semanticColorCssVars, styledTheme } from '@pluralsh/design-system'
import { kebabCase, mapKeys, mapValues } from 'lodash-es'
import { type Config } from 'tailwindcss'
import plugin from 'tailwindcss/plugin'
import { breakpoints } from './src/breakpoints'
const spacing = {
...mapValues(styledTheme.spacing, (space) =>
typeof space === 'number' ? `${space}px` : space
),
'0': '0',
}
const colors = {
...styledTheme.colors,
...semanticColorCssVars,
}
const borderRadius = {
none: '0',
medium: `${styledTheme.borderRadiuses.medium}px`,
large: `${styledTheme.borderRadiuses.large}px`,
}
const screens = mapKeys(
mapValues(breakpoints, (bp) => `${bp}px`),
(_, key) => key
)
/**
* Deep sorts the keys of an object alphabetically while putting members that
* are objects at the end
*
* @param obj - The object to sort
*/
function sortStyleKeys<T extends Record<string, any>>(obj: T): T {
const keys = Object.keys(obj).sort((a, b) => {
if (typeof obj[a] === 'object' && typeof obj[b] !== 'object') {
return 1
}
if (typeof obj[b] === 'object' && typeof obj[a] !== 'object') {
return -1
}
return a.localeCompare(b, 'en')
})
return Object.fromEntries(
keys.map((key) => {
if (typeof obj[key] === 'object') {
return [key, sortStyleKeys(obj[key])]
}
return [key, obj[key]]
})
) as T
}
// Sorting the keys makes the generated tailwind classes easier to read
const textStyles = Object.fromEntries([
...Object.entries(sortStyleKeys(styledTheme.partials.text)).map(
([selector, styles]) => [`${kebabCase(selector)}`, styles]
),
...Object.entries(sortStyleKeys(styledTheme.partials.marketingText)).map(
([selector, styles]) => [`mktg-${kebabCase(selector)}`, styles]
),
])
export const textStyleKeys = Object.keys(textStyles)
export default {
content: ['./src/components/**/*.{jsx,tsx}', './pages/**/*.{jsx,tsx}'],
theme: {
screens,
colors,
spacing,
borderRadius,
extend: {},
},
plugins: [
plugin(({ addComponents }) => {
addComponents(mapKeys(textStyles, (_, key) => `.txt-${key}`) as any)
}),
],
} satisfies Config