11import { TinyColor } from '@ctrl/tinycolor'
2+ import { generate , presetPalettes , presetDarkPalettes } from '@ant-design/colors'
23
34export const getAlphaColor = ( baseColor : string , alpha : number ) =>
45 new TinyColor ( baseColor ) . setAlpha ( alpha ) . toRgbString ( )
@@ -16,12 +17,65 @@ export const getShadeColor = (baseColor: string, shadeNumber: number) => {
1617 return new TinyColor ( baseColor ) . shade ( shadeNumber ) . toString ( )
1718}
1819
19- export const getCssVarColor = ( baseColor : string ) => {
20+ export const getLightNeutralColor = ( ) => {
2021 return {
22+ '--neutral-color' : '#000000e0' ,
23+ '--neutral-secondary' : '#000000a6' ,
24+ '--neutral-disabled' : '#00000040' ,
25+ '--neutral-disabled-bg' : '#0000000a' ,
26+ '--neutral-border' : '#d9d9d9' ,
27+ '--neutral-separator' : '#0505050f' ,
28+ '--neutral-bg' : '#f5f5f5' ,
29+ }
30+ }
31+
32+ export const getDarkNeutralColor = ( ) => {
33+ return {
34+ '--neutral-color' : '#FFFFFFD9' ,
35+ '--neutral-secondary' : '#FFFFFFA6' ,
36+ '--neutral-disabled' : '#FFFFFF40' ,
37+ '--neutral-disabled-bg' : 'rgba(255, 255, 255, 0.08)' ,
38+ '--neutral-border' : '#424242' ,
39+ '--neutral-separator' : '#FDFDFD1F' ,
40+ '--neutral-bg' : '#000000' ,
41+ }
42+ }
43+
44+ export const getCssVarColor = (
45+ baseColor : string ,
46+ opts ?: { appearance : 'light' | 'dark' ; backgroundColor : string } ,
47+ ) => {
48+ const { appearance = 'light' , backgroundColor = '#141414' } = opts || { }
49+ const color = new TinyColor ( baseColor )
50+ const preset = appearance === 'dark' ? presetDarkPalettes : presetPalettes
51+ const colors =
52+ preset [ baseColor ] ||
53+ generate (
54+ color . toHexString ( ) ,
55+ appearance === 'dark' ? { theme : appearance , backgroundColor } : undefined ,
56+ )
57+ const accentColor = colors [ 5 ]
58+ return {
59+ '--accent-color-1' : colors [ 0 ] ,
60+ '--accent-color-2' : colors [ 1 ] ,
61+ '--accent-color-3' : colors [ 2 ] ,
62+ '--accent-color-4' : colors [ 3 ] ,
63+ '--accent-color-5' : colors [ 4 ] ,
64+ '--accent-color-6' : colors [ 5 ] ,
65+ '--accent-color-7' : colors [ 6 ] ,
66+ '--accent-color-8' : colors [ 7 ] ,
67+ '--accent-color-9' : colors [ 8 ] ,
68+ '--accent-color-10' : colors [ 9 ] ,
69+ '--accent-color' : accentColor ,
70+ '--accent-color-hover' : colors [ 4 ] ,
71+ '--accent-color-active' : colors [ 5 ] ,
72+ '--accent-color-content' : '#ffffff' ,
73+ ...( appearance === 'dark' ? getDarkNeutralColor ( ) : getLightNeutralColor ( ) ) ,
2174 '--bg-color' : baseColor ,
2275 '--bg-color-hover' : getTintColor ( baseColor , 10 ) ,
2376 '--bg-color-active' : getTintColor ( baseColor , 20 ) ,
2477 '--bg-color-content' : '#ffffff' ,
78+
2579 '--border-color' : baseColor ,
2680 '--border-color-hover' : getTintColor ( baseColor , 10 ) ,
2781 '--border-color-active' : getTintColor ( baseColor , 20 ) ,
0 commit comments