-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelao-design-system.js
206 lines (193 loc) Β· 6.87 KB
/
elao-design-system.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
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
const colors = require('tailwindcss/colors');
const defaultTheme = require('tailwindcss/defaultTheme');
/**
* Elao Design System default config.
*
* @type {import('tailwindcss').Config}
*
* @see https://tailwindcss.com/docs/theme
* @see defaults https://github.com/tailwindlabs/tailwindcss/blob/master/stubs/config.full.js
*/
const ds = {
theme: {
extend: {
/**
* Control the background color of an element using the bg-{color} utilities.
*
* @see https://tailwindcss.com/docs/background-color
*/
backgroundColor: {
DEFAULT: 'var(--background)',
base: 'var(--background)', // To use the `bg-base` utility
dark: 'var(--background--dark)',
},
/**
* Control the border color of an element using the border-{color} utilities.
*
* @see https://tailwindcss.com/docs/border-color
*/
borderColor: {
// https://tailwindcss.com/docs/customizing-colors#using-css-variables
DEFAULT: 'var(--border)',
base: 'var(--border)', // To use the `border-base` utility
dark: 'var(--border--dark)',
},
/**
* Add primary and common colors, with some automatic shades.
* By default, these colors will be made available everywhere in the framework where you use colors,
* like the text color utilities, border color utilities, background color utilities, and more.
*
* @see https://tailwindcss.com/docs/customizing-colors#adding-additional-colors
*/
colors: {
// Custom colors, from CSS variables:
// https://tailwindcss.com/docs/customizing-colors#using-css-variables
primary: {
...generateColorGradients('primary'),
dark: `var(--color-primary-dark, ${generateColorGradients('primary')['800']})`,
},
...mainColor('success', colors.green),
...mainColor('success', colors.green),
...mainColor('warning', colors.amber),
...mainColor('danger', colors.red),
...mainColor('info', colors.sky),
'accessibility-highlight': 'rgb(var(--color-accessibility-highlight) / <alpha-value>)',
},
/**
* You can control the typeface of text using the font-{family} utilities.
*
* @see https://tailwindcss.com/docs/font-family
*/
fontFamily: {
primary: ['var(--primary-font, "Worker Sans")', ...defaultTheme.fontFamily.sans],
sans: ['var(--primary-font, "Worker Sans")', ...defaultTheme.fontFamily.sans],
icons: ['base-icons'],
},
/**
* Add some common font sizes.
* Controls the font size of an element using the text-{size} utilities.
*
* @see https://tailwindcss.com/docs/font-size
*/
fontSize: {
h1: defaultTheme.fontSize['4xl'],
h2: defaultTheme.fontSize['3xl'],
h3: defaultTheme.fontSize['2xl'],
h4: defaultTheme.fontSize['xl'],
h5: defaultTheme.fontSize['lg'],
h6: defaultTheme.fontSize['base'],
},
/**
* Add some common text colors.
* Control the text color of an element using the text-{color} utilities.
*
* @see https://tailwindcss.com/docs/text-color
*/
textColor: {
/**
* Uses "main" as identifier instead of base, not to be confounded with text-base from font-size:
* https://tailwindcss.com/docs/font-size#setting-the-font-size
*/
main: `var(--text, ${colors.slate['500']})`,
dark: `var(--text--dark, ${colors.slate['600']})`,
light: `var(--text--light, ${colors.slate['400']})`,
lighter: `var(--text--lighter, ${colors.slate['300']})`,
},
/**
* Set the maximum width of an element using the max-w-{size} utilities.
*
* @see https://tailwindcss.com/docs/max-width
*/
maxWidth: {
'main-content': '1900px', // Max content size for the main content area
}
},
},
plugins: [],
};
module.exports = {
ds,
/**
* Customize the default config.
*
* @param {import('tailwindcss').Config} custom
*
* @return {import('tailwindcss').Config}
*/
customize(custom) {
return {
...ds,
...custom,
theme: {
...ds.theme,
...custom.theme,
extend: {
...ds.theme?.extend,
...custom.theme?.extend,
...mergedThemeConfig('backgroundColor', custom, ds),
...mergedThemeConfig('borderColor', custom, ds),
colors: {
...mergedThemeConfig('colors', custom, ds).colors,
primary: mergedColorDefinition('primary', custom, ds),
success: mergedColorDefinition('success', custom, ds),
warning: mergedColorDefinition('warning', custom, ds),
danger: mergedColorDefinition('danger', custom, ds),
info: mergedColorDefinition('info', custom, ds),
},
...mergedThemeConfig('fontFamily', custom, ds),
...mergedThemeConfig('fontSize', custom, ds),
...mergedThemeConfig('maxWidth', custom, ds),
...mergedThemeConfig('spacing', custom, ds),
...mergedThemeConfig('textColor', custom, ds),
},
},
}
}
}
function mainColor(colorName, defaultPalette) {
return {
[colorName]: {
...defaultPalette,
DEFAULT: `rgb(var(--color-${colorName}) / <alpha-value>)`
},
}
}
function mergedThemeConfig(configName, custom, ds) {
return {
[configName]: {
...ds.theme?.extend?.[configName],
...custom.theme?.extend?.[configName],
}
};
}
function mergedColorDefinition(colorName, custom, ds) {
const defaultValue = stringOrNull(custom.theme?.extend?.colors?.[colorName]);
return {
...ds.theme?.extend?.colors?.[colorName],
...custom.theme?.extend?.colors?.[colorName],
...(defaultValue ? { DEFAULT: defaultValue } : {})
};
}
/**
* Generate a color gradients from a color hue.
*
* @see https://blog.logrocket.com/building-color-palette-css/ for inspiration.
*/
function generateColorGradients(colorName) {
return {
DEFAULT: `hsl(var(--color-${colorName}), <alpha-value>)`,
'50': `hsl(var(--color-${colorName}-hue), 55%, 90%, <alpha-value>)`,
'100': `hsl(var(--color-${colorName}-hue), 55%, 85%, <alpha-value>)`,
'200': `hsl(var(--color-${colorName}-hue), 55%, 80%, <alpha-value>)`,
'300': `hsl(var(--color-${colorName}-hue), 55%, 75%, <alpha-value>)`,
'400': `hsl(var(--color-${colorName}-hue), 65%, 65%, <alpha-value>)`,
'500': `hsl(var(--color-${colorName}-hue), 65%, 55%, <alpha-value>)`,
'600': `hsl(var(--color-${colorName}-hue), 75%, 45%, <alpha-value>)`,
'700': `hsl(var(--color-${colorName}-hue), 75%, 40%, <alpha-value>)`,
'800': `hsl(var(--color-${colorName}-hue), 75%, 35%, <alpha-value>)`,
'900': `hsl(var(--color-${colorName}-hue), 75%, 25%, <alpha-value>)`,
};
}
function stringOrNull(value) {
return typeof value === 'string' ? value : null;
}