-
Notifications
You must be signed in to change notification settings - Fork 0
/
createTheme.tsx
47 lines (41 loc) · 1.54 KB
/
createTheme.tsx
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
import { theme } from 'antd';
import type { ThemeConfig as AntdThemeConfig } from 'antd/lib/config-provider/context';
import tokens from '@eduzz/ui-tokens';
export type BrandColor = keyof typeof tokens.brands;
export default function createTheme(
primaryColor: BrandColor | `#${string}`,
mode: 'dark' | 'light',
motion: boolean
): AntdThemeConfig {
const token = removeUndef({
...theme.defaultSeed,
motion,
colorPrimary: primaryColor.startsWith('#') ? primaryColor : tokens.brands[primaryColor as BrandColor].primary.pure,
colorBgLayout: mode === 'light' ? tokens.base.light.surface.subtle : tokens.base.dark.surface.subtle,
colorBgTextHover: mode === 'light' ? 'rgba(0, 0, 0, 0.03)' : 'rgba(255, 255, 255, 0.06)',
fontFamily: tokens.font.family.base,
fontSize: 16,
borderRadius: 0,
colorTextLightSolid: mode === 'light' ? '#fff' : '#000'
});
const customDarkAlgorithm = () => {
const currentDarkAlgorithm = theme.darkAlgorithm(token as any);
currentDarkAlgorithm.colorPrimary = primaryColor.startsWith('#')
? primaryColor
: tokens.brands[primaryColor as BrandColor].primary.pure;
return currentDarkAlgorithm;
};
return {
algorithm: mode === 'dark' ? [customDarkAlgorithm] : [],
token
};
}
function removeUndef(theme: NonNullable<AntdThemeConfig['token']>): AntdThemeConfig['token'] {
return Object.keys(theme).reduce(
(acc, key) => {
if ((theme as any)[key] === undefined) return acc;
return { ...acc, [key]: (theme as any)[key] };
},
{} as typeof theme
);
}