Skip to content
Source
Sign inSign up
TanStack/form
Open History to see the last commit

use-styles.ts

362 lines10.4 KB

1import * as goober from 'goober'
2import { createEffect, createSignal } from 'solid-js'
3import { useTheme } from '@tanstack/devtools-ui'
4import { tokens } from './tokens'
5​
6const stylesFactory = (theme: 'light' | 'dark') => {
7 const { colors, font, size, alpha, border } = tokens
8 const { fontFamily, size: fontSize } = font
9 const css = goober.css
10 const t = (light: string, dark: string) => (theme === 'light' ? light : dark)
11​
12 return {
13 mainContainer: css`
14 display: flex;
15 flex: 1;
16 min-height: 80%;
17 overflow: hidden;
18 padding: ${size[2]};
19 `,
20 dragHandle: css`
21 width: 8px;
22 background: ${t(colors.gray[300], colors.darkGray[600])};
23 cursor: col-resize;
24 position: relative;
25 transition: all 0.2s ease;
26 user-select: none;
27 pointer-events: all;
28 margin: 0 ${size[1]};
29 border-radius: 2px;
30​
31 &:hover {
32 background: ${t(colors.blue[600], colors.blue[500])};
33 margin: 0 ${size[1]};
34 }
35​
36 &.dragging {
37 background: ${t(colors.blue[700], colors.blue[600])};
38 margin: 0 ${size[1]};
39 }
40​
41 &::after {
42 content: '';
43 position: absolute;
44 top: 50%;
45 left: 50%;
46 transform: translate(-50%, -50%);
47 width: 2px;
48 height: 20px;
49 background: ${t(colors.gray[400], colors.darkGray[400])};
50 border-radius: 1px;
51 pointer-events: none;
52 }
53​
54 &:hover::after,
55 &.dragging::after {
56 background: ${t(colors.blue[500], colors.blue[300])};
57 }
58 `,
59 leftPanel: css`
60 background: ${t(colors.gray[100], colors.darkGray[800])};
61 border-radius: ${border.radius.lg};
62 border: 1px solid ${t(colors.gray[200], colors.darkGray[700])};
63 display: flex;
64 flex-direction: column;
65 overflow: hidden;
66 min-height: 0;
67 flex-shrink: 0;
68 `,
69 rightPanel: css`
70 background: ${t(colors.gray[100], colors.darkGray[800])};
71 border-radius: ${border.radius.lg};
72 border: 1px solid ${t(colors.gray[200], colors.darkGray[700])};
73 display: flex;
74 flex-direction: column;
75 overflow: hidden;
76 min-height: 0;
77 flex: 1;
78 `,
79 panelHeader: css`
80 font-size: ${fontSize.md};
81 font-weight: ${font.weight.bold};
82 color: ${t(colors.blue[700], colors.blue[400])};
83 padding: ${size[2]};
84 border-bottom: 1px solid ${t(colors.gray[200], colors.darkGray[700])};
85 background: ${t(colors.gray[100], colors.darkGray[800])};
86 flex-shrink: 0;
87 `,
88 utilList: css`
89 flex: 1;
90 overflow-y: auto;
91 padding: ${size[1]};
92 min-height: 0;
93 `,
94 utilGroup: css`
95 margin-bottom: ${size[2]};
96 `,
97 utilGroupHeader: css`
98 font-size: ${fontSize.xs};
99 font-weight: ${font.weight.semibold};
100 color: ${t(colors.gray[600], colors.gray[400])};
101 text-transform: uppercase;
102 letter-spacing: 0.05em;
103 margin-bottom: ${size[1]};
104 padding: ${size[1]} ${size[2]};
105 background: ${t(colors.gray[200], colors.darkGray[700])};
106 border-radius: ${border.radius.md};
107 `,
108 utilRow: css`
109 display: flex;
110 justify-content: space-between;
111 align-items: center;
112 padding: ${size[2]};
113 margin-bottom: ${size[1]};
114 background: ${t(colors.gray[200], colors.darkGray[700])};
115 border-radius: ${border.radius.md};
116 cursor: pointer;
117 transition: all 0.2s ease;
118 border: 1px solid transparent;
119​
120 &:hover {
121 background: ${t(colors.gray[300], colors.darkGray[600])};
122 border-color: ${t(colors.gray[400], colors.darkGray[500])};
123 }
124 `,
125 utilRowSelected: css`
126 background: ${t(colors.blue[100], colors.blue[900] + alpha[20])};
127 border-color: ${t(colors.blue[600], colors.blue[500])};
128 box-shadow: 0 0 0 1px
129 ${t(colors.blue[600] + alpha[30], colors.blue[500] + alpha[30])};
130 `,
131 utilKey: css`
132 font-family: ${fontFamily.mono};
133 font-size: ${fontSize.xs};
134 color: ${t(colors.gray[900], colors.gray[100])};
135 flex: 1;
136 overflow: hidden;
137 text-overflow: ellipsis;
138 white-space: nowrap;
139 `,
140 utilStatus: css`
141 font-size: ${fontSize.xs};
142 color: ${t(colors.gray[600], colors.gray[400])};
143 text-transform: uppercase;
144 letter-spacing: 0.05em;
145 padding: ${size[1]} ${size[1]};
146 background: ${t(colors.gray[300], colors.darkGray[600])};
147 border-radius: ${border.radius.sm};
148 margin-left: ${size[1]};
149 `,
150 stateDetails: css`
151 flex: 1;
152 overflow-y: auto;
153 padding: ${size[2]};
154 min-height: 0;
155 `,
156 stateHeader: css`
157 margin-bottom: ${size[2]};
158 padding-bottom: ${size[2]};
159 border-bottom: 1px solid ${t(colors.gray[200], colors.darkGray[700])};
160 `,
161 stateTitle: css`
162 font-size: ${fontSize.md};
163 font-weight: ${font.weight.bold};
164 color: ${t(colors.blue[700], colors.blue[400])};
165 margin-bottom: ${size[1]};
166 `,
167 stateKey: css`
168 font-family: ${fontFamily.mono};
169 font-size: ${fontSize.xs};
170 color: ${t(colors.gray[600], colors.gray[400])};
171 word-break: break-all;
172 `,
173 stateContent: css`
174 background: ${t(colors.gray[100], colors.darkGray[700])};
175 border-radius: ${border.radius.md};
176 padding: ${size[2]};
177 border: 1px solid ${t(colors.gray[300], colors.darkGray[600])};
178 `,
179 detailsGrid: css`
180 display: grid;
181 grid-template-columns: 1fr;
182 gap: ${size[2]};
183 align-items: start;
184 `,
185 detailSection: css`
186 background: ${t(colors.white, colors.darkGray[700])};
187 border: 1px solid ${t(colors.gray[300], colors.darkGray[600])};
188 border-radius: ${border.radius.md};
189 padding: ${size[2]};
190 `,
191 detailSectionHeader: css`
192 font-size: ${fontSize.sm};
193 font-weight: ${font.weight.bold};
194 color: ${t(colors.gray[800], colors.gray[200])};
195 margin-bottom: ${size[1]};
196 text-transform: uppercase;
197 letter-spacing: 0.04em;
198 `,
199 actionsRow: css`
200 display: flex;
201 flex-wrap: wrap;
202 gap: ${size[2]};
203 `,
204 actionButton: css`
205 display: inline-flex;
206 align-items: center;
207 gap: ${size[1]};
208 padding: ${size[1]} ${size[2]};
209 border-radius: ${border.radius.md};
210 border: 1px solid ${t(colors.gray[300], colors.darkGray[500])};
211 background: ${t(colors.gray[200], colors.darkGray[600])};
212 color: ${t(colors.gray[900], colors.gray[100])};
213 font-size: ${fontSize.xs};
214 cursor: pointer;
215 user-select: none;
216 transition:
217 background 0.15s,
218 border-color 0.15s;
219 &:hover {
220 background: ${t(colors.gray[300], colors.darkGray[500])};
221 border-color: ${t(colors.gray[400], colors.darkGray[400])};
222 }
223 &:disabled {
224 opacity: 0.5;
225 cursor: not-allowed;
226 &:hover {
227 background: ${t(colors.gray[200], colors.darkGray[600])};
228 border-color: ${t(colors.gray[300], colors.darkGray[500])};
229 }
230 }
231 `,
232 actionDotBlue: css`
233 width: 6px;
234 height: 6px;
235 border-radius: 9999px;
236 background: ${colors.blue[400]};
237 `,
238 actionDotGreen: css`
239 width: 6px;
240 height: 6px;
241 border-radius: 9999px;
242 background: ${colors.green[400]};
243 `,
244 actionDotRed: css`
245 width: 6px;
246 height: 6px;
247 border-radius: 9999px;
248 background: ${colors.red[400]};
249 `,
250 actionDotYellow: css`
251 width: 6px;
252 height: 6px;
253 border-radius: 9999px;
254 background: ${colors.yellow[400]};
255 `,
256 actionDotOrange: css`
257 width: 6px;
258 height: 6px;
259 border-radius: 9999px;
260 background: ${colors.pink[400]};
261 `,
262 actionDotPurple: css`
263 width: 6px;
264 height: 6px;
265 border-radius: 9999px;
266 background: ${colors.purple[400]};
267 `,
268 infoGrid: css`
269 display: grid;
270 grid-template-columns: auto 1fr;
271 gap: ${size[1]};
272 row-gap: ${size[1]};
273 align-items: center;
274 `,
275 infoLabel: css`
276 color: ${t(colors.gray[600], colors.gray[400])};
277 font-size: ${fontSize.xs};
278 text-transform: uppercase;
279 letter-spacing: 0.05em;
280 `,
281 infoValueMono: css`
282 font-family: ${fontFamily.mono};
283 font-size: ${fontSize.xs};
284 color: ${t(colors.gray[900], colors.gray[100])};
285 word-break: break-all;
286 `,
287 noSelection: css`
288 flex: 1;
289 display: flex;
290 align-items: center;
291 justify-content: center;
292 color: ${t(colors.gray[500], colors.gray[500])};
293 font-style: italic;
294 text-align: center;
295 padding: ${size[4]};
296 `,
297 // Keep existing styles for backward compatibility
298 sectionContainer: css`
299 display: flex;
300 flex-wrap: wrap;
301 gap: ${size[4]};
302 `,
303 section: css`
304 background: ${t(colors.gray[100], colors.darkGray[800])};
305 border-radius: ${border.radius.lg};
306 box-shadow: ${tokens.shadow.md(
307 t(colors.gray[400] + alpha[80], colors.black + alpha[80]),
308 )};
309 padding: ${size[4]};
310 margin-bottom: ${size[4]};
311 border: 1px solid ${t(colors.gray[200], colors.darkGray[700])};
312 min-width: 0;
313 max-width: 33%;
314 max-height: fit-content;
315 `,
316 sectionHeader: css`
317 font-size: ${fontSize.lg};
318 font-weight: ${font.weight.bold};
319 margin-bottom: ${size[2]};
320 color: ${t(colors.blue[600], colors.blue[400])};
321 letter-spacing: 0.01em;
322 display: flex;
323 align-items: center;
324 gap: ${size[2]};
325 `,
326 sectionEmpty: css`
327 color: ${t(colors.gray[500], colors.gray[500])};
328 font-size: ${fontSize.sm};
329 font-style: italic;
330 margin: ${size[2]} 0;
331 `,
332 instanceList: css`
333 display: flex;
334 flex-direction: column;
335 gap: ${size[2]};
336 background: ${t(colors.gray[200], colors.darkGray[700])};
337 border: 1px solid ${t(colors.gray[300], colors.darkGray[600])};
338 `,
339 instanceCard: css`
340 background: ${t(colors.gray[200], colors.darkGray[700])};
341 border-radius: ${border.radius.md};
342 padding: ${size[3]};
343 border: 1px solid ${t(colors.gray[300], colors.darkGray[600])};
344 font-size: ${fontSize.sm};
345 color: ${t(colors.gray[900], colors.gray[100])};
346 font-family: ${fontFamily.mono};
347 overflow-x: auto;
348 transition:
349 box-shadow 0.3s,
350 background 0.3s;
351 `,
352 }
354​
355export function useStyles() {
356 const { theme } = useTheme()
357 const [styles, setStyles] = createSignal(stylesFactory(theme()))
358 createEffect(() => {
359 setStyles(stylesFactory(theme()))
360 })
361 return styles