-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtailwind.config.ts
62 lines (56 loc) · 1.67 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
import _ from 'lodash';
import type { Config } from 'tailwindcss';
import { fontFamily } from 'tailwindcss/defaultTheme';
import type { PluginAPI } from 'tailwindcss/types/config';
import { colorsRaw } from './utils/theme/colors';
import { ThemeVariables, lightTheme, darkTheme } from './utils/theme/themeDefs';
const toRGB = (hex: string) => {
const hexNum = parseInt(hex.replace('#', ''), 16);
const r = (hexNum >> 16) & 255;
const g = (hexNum >> 8) & 255;
const b = hexNum & 255;
return `${r} ${g} ${b}`;
};
const themeToRGB = (theme: ThemeVariables) =>
Object.fromEntries(
Object.entries(theme).map(([key, value]) => [key, toRGB(value)]),
);
export const themeDefsPlugin = ({ addUtilities, e }: PluginAPI) => {
addUtilities([
{
[`.${e('index-theme-light')}`]: themeToRGB(lightTheme),
[`.${e('index-theme-dark')}`]: themeToRGB(darkTheme),
},
]);
};
const colorPalette = <Key extends keyof typeof colorsRaw>(key: Key) =>
_.mapValues(colorsRaw[key], (value) => {
return `rgba(${value} / <alpha-value>)`;
}) as (typeof colorsRaw)[Key];
export default {
content: ['./pages/**/*.tsx', './components/**/*.tsx'],
theme: {
colors: {
...colorPalette('primitives'),
},
fontFamily: {
raleway: ['var(--font-raleway)', ...fontFamily.sans],
mont: ['var(--font-montserrat)', ...fontFamily.sans],
},
extend: {
backgroundColor: {
...colorPalette('background'),
},
borderColor: {
...colorPalette('border'),
},
textColor: {
...colorPalette('text'),
},
fill: {
...colorPalette('text'),
},
},
},
plugins: [themeDefsPlugin],
} satisfies Config;