|
| 1 | +import { darken, lighten } from '../color/color.models'; |
1 | 2 | import { defineThemes } from '../theme/theme.models'; |
2 | 3 | import { appThemes } from '../theme/themes'; |
3 | 4 |
|
4 | | -export const { useTheme } = defineThemes({ |
5 | | - dark: { |
6 | | - basic: { |
7 | | - default: { |
8 | | - textColor: appThemes.dark.text.baseColor, |
9 | | - backgroundColor: 'rgba(255, 255, 255, 0.08)', |
10 | | - |
11 | | - hover: { |
12 | | - textColor: appThemes.dark.text.baseColor, |
13 | | - backgroundColor: 'rgba(255, 255, 255, 0.12)', |
14 | | - }, |
15 | | - |
16 | | - pressed: { |
17 | | - textColor: appThemes.dark.text.baseColor, |
18 | | - backgroundColor: 'rgba(255, 255, 255, 0.24)', |
19 | | - }, |
20 | | - |
21 | | - outline: { |
22 | | - color: appThemes.dark.primary.color, |
23 | | - }, |
24 | | - }, |
25 | | - |
26 | | - primary: { |
27 | | - textColor: appThemes.dark.text.baseColor, |
28 | | - backgroundColor: appThemes.dark.primary.color, |
29 | | - |
30 | | - hover: { |
31 | | - textColor: appThemes.dark.text.baseColor, |
32 | | - backgroundColor: appThemes.dark.primary.colorHover, |
33 | | - }, |
34 | | - |
35 | | - pressed: { |
36 | | - textColor: appThemes.dark.text.baseColor, |
37 | | - backgroundColor: appThemes.dark.primary.colorPressed, |
38 | | - }, |
39 | | - |
40 | | - outline: { |
41 | | - color: appThemes.dark.primary.color, |
42 | | - }, |
43 | | - }, |
44 | | - |
45 | | - warning: { |
46 | | - textColor: appThemes.dark.text.baseColor, |
47 | | - backgroundColor: appThemes.dark.warning.color, |
48 | | - |
49 | | - hover: { |
50 | | - textColor: appThemes.dark.text.baseColor, |
51 | | - backgroundColor: appThemes.dark.warning.colorHover, |
52 | | - }, |
53 | | - |
54 | | - pressed: { |
55 | | - textColor: appThemes.dark.text.baseColor, |
56 | | - backgroundColor: appThemes.dark.warning.colorPressed, |
57 | | - }, |
58 | | - |
59 | | - outline: { |
60 | | - color: appThemes.dark.warning.color, |
61 | | - }, |
62 | | - }, |
63 | | - }, |
64 | | - |
65 | | - text: { |
66 | | - default: { |
67 | | - textColor: appThemes.dark.text.baseColor, |
68 | | - backgroundColor: 'transparent', |
69 | | - |
70 | | - hover: { |
71 | | - textColor: appThemes.dark.text.baseColor, |
72 | | - backgroundColor: 'rgba(255, 255, 255, 0.12)', |
73 | | - }, |
74 | | - |
75 | | - pressed: { |
76 | | - textColor: appThemes.dark.text.baseColor, |
77 | | - backgroundColor: 'rgba(255, 255, 255, 0.82)', |
78 | | - }, |
79 | | - |
80 | | - outline: { |
81 | | - color: appThemes.dark.primary.color, |
82 | | - }, |
83 | | - }, |
84 | | - |
85 | | - primary: { |
86 | | - textColor: appThemes.dark.text.baseColor, |
87 | | - backgroundColor: appThemes.dark.primary.color, |
88 | | - |
89 | | - hover: { |
90 | | - textColor: appThemes.dark.text.baseColor, |
91 | | - backgroundColor: appThemes.dark.primary.colorHover, |
92 | | - }, |
93 | | - |
94 | | - pressed: { |
95 | | - textColor: appThemes.dark.text.baseColor, |
96 | | - backgroundColor: appThemes.dark.primary.colorPressed, |
97 | | - }, |
98 | | - |
99 | | - outline: { |
100 | | - color: appThemes.dark.primary.color, |
101 | | - }, |
102 | | - }, |
103 | | - |
104 | | - warning: { |
105 | | - textColor: appThemes.dark.text.baseColor, |
106 | | - backgroundColor: appThemes.dark.warning.color, |
107 | | - |
108 | | - hover: { |
109 | | - textColor: appThemes.dark.text.baseColor, |
110 | | - backgroundColor: appThemes.dark.warning.colorHover, |
111 | | - }, |
| 5 | +const createState = ({ |
| 6 | + textColor, |
| 7 | + backgroundColor, |
| 8 | + hoverBackground, |
| 9 | + hoveredTextColor = textColor, |
| 10 | + pressedBackground, |
| 11 | + pressedTextColor = textColor, |
| 12 | +}: { |
| 13 | + textColor: string; |
| 14 | + backgroundColor: string; |
| 15 | + hoverBackground: string; |
| 16 | + hoveredTextColor?: string; |
| 17 | + pressedBackground: string; |
| 18 | + pressedTextColor?: string; |
| 19 | +}) => ({ |
| 20 | + textColor, |
| 21 | + backgroundColor, |
| 22 | + hover: { textColor: hoveredTextColor, backgroundColor: hoverBackground }, |
| 23 | + pressed: { textColor: pressedTextColor, backgroundColor: pressedBackground }, |
| 24 | +}); |
112 | 25 |
|
113 | | - pressed: { |
114 | | - textColor: appThemes.dark.text.baseColor, |
115 | | - backgroundColor: appThemes.dark.warning.colorPressed, |
116 | | - }, |
| 26 | +const createTheme = ({ style }: { style: 'light' | 'dark' }) => { |
| 27 | + const theme = appThemes[style]; |
117 | 28 |
|
118 | | - outline: { |
119 | | - color: appThemes.dark.warning.color, |
120 | | - }, |
121 | | - }, |
122 | | - }, |
123 | | - }, |
124 | | - light: { |
| 29 | + return { |
125 | 30 | basic: { |
126 | | - default: { |
127 | | - textColor: appThemes.light.text.baseColor, |
128 | | - backgroundColor: 'rgba(46, 51, 56, 0.05)', |
129 | | - |
130 | | - hover: { |
131 | | - textColor: appThemes.light.text.baseColor, |
132 | | - backgroundColor: 'rgba(46, 51, 56, 0.09)', |
133 | | - }, |
134 | | - |
135 | | - pressed: { |
136 | | - textColor: appThemes.light.text.baseColor, |
137 | | - backgroundColor: 'rgba(46, 51, 56, 0.22)', |
138 | | - }, |
139 | | - |
140 | | - outline: { |
141 | | - color: appThemes.light.primary.color, |
142 | | - }, |
143 | | - }, |
144 | | - |
145 | | - primary: { |
146 | | - textColor: appThemes.dark.text.baseColor, |
147 | | - backgroundColor: appThemes.light.primary.color, |
148 | | - |
149 | | - hover: { |
150 | | - textColor: appThemes.dark.text.baseColor, |
151 | | - backgroundColor: appThemes.light.primary.colorHover, |
152 | | - }, |
153 | | - |
154 | | - pressed: { |
155 | | - textColor: appThemes.dark.text.baseColor, |
156 | | - backgroundColor: appThemes.light.primary.colorPressed, |
157 | | - }, |
158 | | - |
159 | | - outline: { |
160 | | - color: appThemes.light.primary.color, |
161 | | - }, |
162 | | - }, |
163 | | - |
164 | | - warning: { |
165 | | - textColor: appThemes.dark.text.baseColor, |
166 | | - backgroundColor: appThemes.light.warning.color, |
167 | | - |
168 | | - hover: { |
169 | | - textColor: appThemes.dark.text.baseColor, |
170 | | - backgroundColor: appThemes.light.warning.colorHover, |
171 | | - }, |
172 | | - |
173 | | - pressed: { |
174 | | - textColor: appThemes.dark.text.baseColor, |
175 | | - backgroundColor: appThemes.light.warning.colorPressed, |
176 | | - }, |
177 | | - |
178 | | - outline: { |
179 | | - color: appThemes.light.warning.color, |
180 | | - }, |
181 | | - }, |
| 31 | + default: createState({ |
| 32 | + textColor: theme.text.baseColor, |
| 33 | + backgroundColor: theme.default.color, |
| 34 | + hoverBackground: theme.default.colorHover, |
| 35 | + pressedBackground: theme.default.colorPressed, |
| 36 | + }), |
| 37 | + primary: createState({ |
| 38 | + textColor: theme.primary.color, |
| 39 | + backgroundColor: theme.primary.colorFaded, |
| 40 | + hoverBackground: lighten(theme.primary.colorFaded, 30), |
| 41 | + pressedBackground: darken(theme.primary.colorFaded, 30), |
| 42 | + }), |
| 43 | + warning: createState({ |
| 44 | + textColor: theme.text.baseColor, |
| 45 | + backgroundColor: theme.warning.color, |
| 46 | + hoverBackground: theme.warning.colorHover, |
| 47 | + pressedBackground: theme.warning.colorPressed, |
| 48 | + }), |
182 | 49 | }, |
183 | 50 | text: { |
184 | | - default: { |
185 | | - textColor: appThemes.light.text.baseColor, |
| 51 | + default: createState({ |
| 52 | + textColor: theme.text.baseColor, |
186 | 53 | backgroundColor: 'transparent', |
187 | | - |
188 | | - hover: { |
189 | | - textColor: appThemes.light.text.baseColor, |
190 | | - backgroundColor: 'rgba(46, 51, 56, 0.09)', |
191 | | - }, |
192 | | - |
193 | | - pressed: { |
194 | | - textColor: appThemes.light.text.baseColor, |
195 | | - backgroundColor: 'rgba(46, 51, 56, 0.13)', |
196 | | - }, |
197 | | - |
198 | | - outline: { |
199 | | - color: appThemes.light.primary.color, |
200 | | - }, |
201 | | - }, |
202 | | - primary: { |
203 | | - textColor: appThemes.light.primary.color, |
204 | | - backgroundColor: 'transparent', |
205 | | - |
206 | | - hover: { |
207 | | - textColor: appThemes.light.primary.colorHover, |
208 | | - backgroundColor: 'rgba(46, 51, 56, 0.09)', |
209 | | - }, |
210 | | - |
211 | | - pressed: { |
212 | | - textColor: appThemes.light.primary.colorPressed, |
213 | | - backgroundColor: 'rgba(46, 51, 56, 0.13)', |
214 | | - }, |
215 | | - |
216 | | - outline: { |
217 | | - color: appThemes.light.primary.color, |
218 | | - }, |
219 | | - }, |
220 | | - warning: { |
221 | | - textColor: appThemes.light.warning.color, |
| 54 | + hoverBackground: theme.default.colorHover, |
| 55 | + pressedBackground: theme.default.colorPressed, |
| 56 | + }), |
| 57 | + primary: createState({ |
| 58 | + textColor: theme.primary.color, |
222 | 59 | backgroundColor: 'transparent', |
223 | | - |
224 | | - hover: { |
225 | | - textColor: appThemes.light.warning.colorHover, |
226 | | - backgroundColor: 'rgba(46, 51, 56, 0.09)', |
227 | | - }, |
228 | | - |
229 | | - pressed: { |
230 | | - textColor: appThemes.light.warning.colorPressed, |
231 | | - backgroundColor: 'rgba(46, 51, 56, 0.13)', |
232 | | - }, |
233 | | - |
234 | | - outline: { |
235 | | - color: appThemes.light.warning.color, |
236 | | - }, |
237 | | - }, |
| 60 | + hoverBackground: theme.primary.colorFaded, |
| 61 | + pressedBackground: darken(theme.primary.colorFaded, 30), |
| 62 | + }), |
| 63 | + warning: createState({ |
| 64 | + textColor: theme.text.baseColor, |
| 65 | + backgroundColor: theme.warning.color, |
| 66 | + hoverBackground: theme.warning.colorHover, |
| 67 | + pressedBackground: theme.warning.colorPressed, |
| 68 | + }), |
238 | 69 | }, |
239 | | - }, |
| 70 | + }; |
| 71 | +}; |
| 72 | + |
| 73 | +export const { useTheme } = defineThemes({ |
| 74 | + dark: createTheme({ style: 'dark' }), |
| 75 | + light: createTheme({ style: 'light' }), |
240 | 76 | }); |
0 commit comments