Open History to see the last commit
1import * as goober from 'goober'
2import { createEffect, createSignal } from 'solid-js'
3import { createTheme } from '../components/theme'
4import { tokens } from './tokens'
5β
6import type { TanStackDevtoolsTheme } from '../components/theme'
7import type { ButtonVariant } from '../components/button'
8β
9const buttonVariantColors: Record<
10 ButtonVariant,
11 {
12 bg: { light: string; dark: string }
13 hover: { light: string; dark: string }
14 active: { light: string; dark: string }
15 text: { light: string; dark: string }
16 border: { light: string; dark: string }
17 outline: { light: string; dark: string }
18 outlineHover: { light: string; dark: string }
19 }
20> = {
21 primary: {
22 bg: { light: tokens.colors.gray[900], dark: tokens.colors.gray[100] },
23 hover: { light: tokens.colors.gray[800], dark: tokens.colors.gray[200] },
24 active: { light: tokens.colors.gray[700], dark: tokens.colors.gray[300] },
25 text: { light: '#fff', dark: tokens.colors.gray[900] },
26 border: { light: tokens.colors.gray[800], dark: tokens.colors.gray[200] },
27 outline: {
28 light: tokens.colors.gray[900],
29 dark: tokens.colors.gray[100],
30 },
31 outlineHover: {
32 light: tokens.colors.gray[800],
33 dark: tokens.colors.gray[200],
34 },
35 },
36 secondary: {
37 bg: { light: tokens.colors.gray[100], dark: tokens.colors.gray[100] },
38 hover: { light: tokens.colors.gray[200], dark: tokens.colors.gray[200] },
39 active: { light: tokens.colors.gray[300], dark: tokens.colors.gray[300] },
40 text: { light: tokens.colors.gray[900], dark: tokens.colors.gray[900] },
41 border: { light: tokens.colors.gray[300], dark: tokens.colors.gray[300] },
42 outline: {
43 light: tokens.colors.gray[700],
44 dark: tokens.colors.gray[300],
45 },
46 outlineHover: {
47 light: tokens.colors.gray[800],
48 dark: tokens.colors.gray[200],
49 },
50 },
51 info: {
52 bg: { light: tokens.colors.blue[500], dark: tokens.colors.blue[500] },
53 hover: { light: tokens.colors.blue[600], dark: tokens.colors.blue[600] },
54 active: { light: tokens.colors.blue[700], dark: tokens.colors.blue[700] },
55 text: { light: '#fff', dark: '#fff' },
56 border: { light: tokens.colors.blue[500], dark: tokens.colors.blue[500] },
57 outline: {
58 light: tokens.colors.blue[700],
59 dark: tokens.colors.blue[300],
60 },
61 outlineHover: {
62 light: tokens.colors.blue[600],
63 dark: tokens.colors.blue[200],
64 },
65 },
66 warning: {
67 bg: { light: tokens.colors.yellow[500], dark: tokens.colors.yellow[500] },
68 hover: {
69 light: tokens.colors.yellow[600],
70 dark: tokens.colors.yellow[600],
71 },
72 active: {
73 light: tokens.colors.yellow[700],
74 dark: tokens.colors.yellow[700],
75 },
76 text: { light: '#fff', dark: '#fff' },
77 border: {
78 light: tokens.colors.yellow[500],
79 dark: tokens.colors.yellow[500],
80 },
81 outline: {
82 light: tokens.colors.yellow[700],
83 dark: tokens.colors.yellow[300],
84 },
85 outlineHover: {
86 light: tokens.colors.yellow[600],
87 dark: tokens.colors.yellow[200],
88 },
89 },
90 danger: {
91 bg: { light: tokens.colors.red[500], dark: tokens.colors.red[500] },
92 hover: { light: tokens.colors.red[600], dark: tokens.colors.red[600] },
93 active: { light: tokens.colors.red[700], dark: tokens.colors.red[700] },
94 text: { light: '#fff', dark: '#fff' },
95 border: { light: tokens.colors.red[500], dark: tokens.colors.red[500] },
96 outline: {
97 light: tokens.colors.red[700],
98 dark: tokens.colors.red[300],
99 },
100 outlineHover: {
101 light: tokens.colors.red[600],
102 dark: tokens.colors.red[200],
103 },
104 },
105 success: {
106 bg: { light: tokens.colors.green[500], dark: tokens.colors.green[500] },
107 hover: { light: tokens.colors.green[600], dark: tokens.colors.green[600] },
108 active: { light: tokens.colors.green[700], dark: tokens.colors.green[700] },
109 text: { light: '#fff', dark: '#fff' },
110 border: { light: tokens.colors.green[500], dark: tokens.colors.green[500] },
111 outline: {
112 light: tokens.colors.green[700],
113 dark: tokens.colors.green[300],
114 },
115 outlineHover: {
116 light: tokens.colors.green[600],
117 dark: tokens.colors.green[200],
118 },
119 },
120}
121export const css = goober.css
122const stylesFactory = (theme: TanStackDevtoolsTheme) => {
123 const { colors, font, size, border } = tokens
124 const { fontFamily } = font
125β
126 const t = (light: string, dark: string) => (theme === 'light' ? light : dark)
127 const buildButtonVariant = (variant: ButtonVariant) => {
128 const v = buttonVariantColors[variant]
129 const outlineColor = t(v.outline.light, v.outline.dark)
130 const outlineHoverColor = t(v.outlineHover.light, v.outlineHover.dark)
131 const solidBg = t(v.bg.light, v.bg.dark)
132 const solidHover = t(v.hover.light, v.hover.dark)
133 const solidActive = t(v.active.light, v.active.dark)
134 const solidText = t(v.text.light, v.text.dark)
135 const solidBorder = t(v.border.light, v.border.dark)
136β
137 return {
138 ghost: css`
139 background: transparent;
140 color: ${outlineColor};
141 border-color: transparent;
142 &:hover {
143 background: ${t(colors.gray[100], colors.darkGray[800])};
144 color: ${outlineHoverColor};
145 }
146 &:active {
147 background: ${t(colors.gray[200], colors.darkGray[700])};
148 color: ${outlineHoverColor};
149 }
150 `,
151 outline: css`
152 background: transparent;
153 color: ${outlineColor};
154 border-color: ${outlineColor};
155 &:hover {
156 background: ${t(colors.gray[50], colors.darkGray[800])};
157 color: ${outlineHoverColor};
158 border-color: ${outlineHoverColor};
159 }
160 &:active {
161 background: ${t(colors.gray[100], colors.darkGray[700])};
162 color: ${outlineHoverColor};
163 border-color: ${outlineHoverColor};
164 }
165 `,
166 solid: css`
167 background: ${solidBg};
168 color: ${solidText};
169 border-color: ${solidBorder};
170 &:hover {
171 background: ${solidHover};
172 border-color: ${solidHover};
173 box-shadow: ${t(
174 tokens.shadow.xs('rgb(0 0 0 / 0.12)'),
175 tokens.shadow.xs('rgb(0 0 0 / 0.5)'),
176 )};
177 }
178 &:active {
179 background: ${solidActive};
180 border-color: ${solidActive};
181 box-shadow: ${t(
182 tokens.shadow.inner('rgb(0 0 0 / 0.2)'),
183 tokens.shadow.inner('rgb(0 0 0 / 0.6)'),
184 )};
185 }
186 `,
187 }
188 }
189 const buttonVariants: Record<
190 ButtonVariant,
191 { ghost: string; outline: string; solid: string }
192 > = {
193 primary: buildButtonVariant('primary'),
194 secondary: buildButtonVariant('secondary'),
195 info: buildButtonVariant('info'),
196 warning: buildButtonVariant('warning'),
197 danger: buildButtonVariant('danger'),
198 success: buildButtonVariant('success'),
199 }
200β
201 const wrapperSize = 320
202β
203 return {
204 logo: css`
205 cursor: pointer;
206 display: flex;
207 flex-direction: column;
208 background-color: transparent;
209 border: none;
210 width: ${size[12]};
211 height: ${size[12]};
212 font-family: ${fontFamily.sans};
213 gap: ${tokens.size[0.5]};
214 padding: 0;
215 &:hover {
216 opacity: 0.7;
217 }
218 `,
219β
220 selectWrapper: css`
221 width: 100%;
222 max-width: ${wrapperSize}px;
223 display: flex;
224 flex-direction: column;
225 gap: 0.375rem;
226 `,
227 selectContainer: css`
228 width: 100%;
229 `,
230 selectLabel: css`
231 font-size: 0.875rem;
232 font-weight: 500;
233 color: ${t(colors.gray[900], colors.gray[100])};
234 text-align: left;
235 `,
236 selectDescription: css`
237 font-size: 0.8rem;
238 color: ${t(colors.gray[500], colors.gray[400])};
239 margin: 0;
240 line-height: 1.3;
241 text-align: left;
242 `,
243 select: css`
244 appearance: none;
245 width: 100%;
246 padding: 0.5rem 3rem 0.5rem 0.75rem;
247 border-radius: 0.375rem;
248 background-color: ${t(colors.gray[50], colors.darkGray[800])};
249 color: ${t(colors.gray[900], colors.gray[100])};
250 border: 1px solid ${t(colors.gray[200], colors.gray[800])};
251 font-size: 0.875rem;
252 transition: all 0.15s ease;
253 cursor: pointer;
254β
255 /* Custom arrow */
256 background-image: url("data:image/svg+xml;utf8,<svg fill='%236b7280' height='20' viewBox='0 0 24 24' width='20' xmlns='http://www.w3.org/2000/svg'><path d='M7 10l5 5 5-5z'/></svg>");
257 background-repeat: no-repeat;
258 background-position: right 0.75rem center;
259 background-size: 1.25rem;
260β
261 &:hover {
262 border-color: ${t(colors.gray[300], colors.gray[700])};
263 }
264β
265 &:focus {
266 outline: none;
267 border-color: ${colors.gray[400]};
268 box-shadow: 0 0 0 3px ${t(colors.gray[200], colors.gray[800])};
269 }
270 `,
271 inputWrapper: css`
272 width: 100%;
273 max-width: ${wrapperSize}px;
274 display: flex;
275 flex-direction: column;
276 gap: 0.375rem;
277 `,
278 inputContainer: css`
279 width: 100%;
280 `,
281 inputLabel: css`
282 font-size: 0.875rem;
283 font-weight: 500;
284 color: ${t(colors.gray[900], colors.gray[100])};
285 text-align: left;
286 `,
287 inputDescription: css`
288 font-size: 0.8rem;
289 color: ${t(colors.gray[500], colors.gray[400])};
290 margin: 0;
291 line-height: 1.3;
292 text-align: left;
293 `,
294 input: css`
295 appearance: none;
296 box-sizing: border-box;
297 width: 100%;
298 padding: 0.5rem 0.75rem;
299 border-radius: 0.375rem;
300 background-color: ${t(colors.gray[50], colors.darkGray[800])};
301 color: ${t(colors.gray[900], colors.gray[100])};
302 border: 1px solid ${t(colors.gray[200], colors.gray[800])};
303 font-size: 0.875rem;
304 font-family: ${fontFamily.mono};
305 transition: all 0.15s ease;
306β
307 &::placeholder {
308 color: ${t(colors.gray[400], colors.gray[500])};
309 }
310β
311 &:hover {
312 border-color: ${t(colors.gray[300], colors.gray[700])};
313 }
314β
315 &:focus {
316 outline: none;
317 border-color: ${t(colors.gray[400], colors.gray[600])};
318 box-shadow: 0 0 0 3px ${t(colors.gray[200], colors.gray[800])};
319 }
320 `,
321 checkboxWrapper: css`
322 display: flex;
323 align-items: flex-start;
324 gap: 0.75rem;
325 cursor: pointer;
326 user-select: none;
327 padding: 0.375rem;
328 border-radius: 0.375rem;
329 transition: background-color 0.15s ease;
330β
331 &:hover {
332 background-color: ${t(colors.gray[50], colors.darkGray[900])};
333 }
334 `,
335 checkboxContainer: css`
336 width: 100%;
337 `,
338 checkboxLabelContainer: css`
339 display: flex;
340 flex-direction: column;
341 gap: 0.25rem;
342 flex: 1;
343 `,
344 checkbox: css`
345 appearance: none;
346 width: 1.25rem;
347 height: 1.25rem;
348 border: 2px solid ${t(colors.gray[300], colors.gray[700])};
349 border-radius: 0.25rem;
350 background-color: ${t(colors.gray[50], colors.darkGray[800])};
351 display: grid;
352 place-items: center;
353 transition: all 0.15s ease;
354 flex-shrink: 0;
355 margin-top: 0.125rem;
356β
357 &:hover {
358 border-color: ${t(colors.gray[400], colors.gray[600])};
359 }
360β
361 &:checked {
362 background-color: ${t(colors.gray[900], colors.gray[100])};
363 border-color: ${t(colors.gray[900], colors.gray[100])};
364 }
365β
366 &:checked::after {
367 content: '';
368 width: 0.4rem;
369 height: 0.6rem;
370 border: solid ${t('#fff', colors.gray[900])};
371 border-width: 0 2px 2px 0;
372 transform: rotate(45deg);
373 margin-top: -3px;
374 }
375 `,
376 checkboxLabel: css`
377 color: ${t(colors.gray[900], colors.gray[100])};
378 font-size: 0.875rem;
379 font-weight: 500;
380 line-height: 1.4;
381 text-align: left;
382 `,
383 checkboxDescription: css`
384 color: ${t(colors.gray[500], colors.gray[400])};
385 font-size: 0.8rem;
386 line-height: 1.3;
387 text-align: left;
388 `,
389 button: {
390 base: css`
391 display: inline-flex;
392 align-items: center;
393 justify-content: center;
394 font-family: ${tokens.font.fontFamily.sans};
395 font-size: 0.8rem;
396 font-weight: 500;
397 border-radius: 0.375rem;
398 padding: 0.375rem 0.75rem;
399 cursor: pointer;
400 transition:
401 background 0.15s,
402 color 0.15s,
403 border 0.15s,
404 box-shadow 0.15s;
405 outline: none;
406 border-width: 1px;
407 border-style: solid;
408 `,
409 variant(variant: ButtonVariant, outline?: boolean, ghost?: boolean) {
410 const v = buttonVariants[variant]
411 if (ghost) {
412 return v.ghost
413 }
414 if (outline) {
415 return v.outline
416 }
417 return v.solid
418 },
419 },
420 tag: {
421 dot: (color: keyof typeof tokens.colors) => css`
422 width: ${tokens.size[1.5]};
423 height: ${tokens.size[1.5]};
424 border-radius: ${tokens.border.radius.full};
425 background-color: ${t(
426 tokens.colors[color][500],
427 tokens.colors[color][500],
428 )};
429 `,
430 base: css`
431 display: flex;
432 gap: ${tokens.size[1.5]};
433 box-sizing: border-box;
434 height: ${tokens.size[6.5]};
435 background: ${t(colors.gray[50], colors.darkGray[500])};
436 color: ${t(colors.gray[700], colors.gray[300])};
437 border-radius: ${tokens.border.radius.sm};
438 font-size: ${font.size.sm};
439 padding: ${tokens.size[1]};
440 padding-left: ${tokens.size[1.5]};
441 align-items: center;
442 font-weight: ${font.weight.medium};
443 border: ${t('1px solid ' + colors.gray[300], '1px solid transparent')};
444 user-select: none;
445 position: relative;
446 &:focus-visible {
447 outline-offset: 2px;
448 outline: 2px solid ${t(colors.blue[700], colors.blue[800])};
449 }
450 `,
451 label: css`
452 font-size: ${font.size.xs};
453 `,
454 count: css`
455 font-size: ${font.size.xs};
456 padding: 0 5px;
457 display: flex;
458 align-items: center;
459 justify-content: center;
460 color: ${t(colors.gray[500], colors.gray[400])};
461 background-color: ${t(colors.gray[200], colors.darkGray[300])};
462 border-radius: 2px;
463 font-variant-numeric: tabular-nums;
464 height: ${tokens.size[4.5]};
465 `,
466 },
467 tree: {
468 info: css`
469 color: ${t(colors.gray[500], colors.gray[500])};
470 font-size: ${font.size.xs};
471 margin-right: ${size[1]};
472 `,
473 actionButton: css`
474 background-color: transparent;
475 color: ${t(colors.gray[500], colors.gray[500])};
476 border: none;
477 display: inline-flex;
478 padding: 0;
479 align-items: center;
480 justify-content: center;
481 cursor: pointer;
482 width: ${size[3]};
483 height: ${size[3]};
484 position: relative;
485 z-index: 1;
486β
487 &:hover svg {
488 color: ${t(colors.gray[600], colors.gray[400])};
489 }
490β
491 &:focus-visible {
492 border-radius: ${border.radius.xs};
493 outline: 2px solid ${t(colors.blue[700], colors.blue[800])};
494 outline-offset: 2px;
495 }
496 `,
497 expanderContainer: css`
498 position: relative;
499 `,
500 expander: css`
501 position: absolute;
502 cursor: pointer;
503 left: -16px;
504 top: 3px;
505 & path {
506 stroke: ${t(colors.blue[400], colors.blue[300])};
507 }
508 & svg {
509 width: ${size[3]};
510 height: ${size[3]};
511 }
512β
513 display: inline-flex;
514 align-items: center;
515 transition: all 0.1s ease;
516 `,
517 expandedLine: (hasBorder: boolean) => css`
518 display: block;
519 padding-left: 0.75rem;
520 margin-left: -0.7rem;
521 ${hasBorder
522 ? `border-left: 1px solid ${t(colors.blue[400], colors.blue[300])};`
523 : ''}
524 `,
525 collapsible: css`
526 cursor: pointer;
527 transition: all 0.2s ease;
528 &:hover {
529 background-color: ${t(colors.gray[100], colors.darkGray[700])};
530 border-radius: ${tokens.border.radius.sm};
531 padding: 0 ${tokens.size[1]};
532 }
533 `,
534 actions: css`
535 display: inline-flex;
536 margin-left: ${size[2]};
537 gap: ${size[2]};
538 align-items: center;
539 & svg {
540 height: 12px;
541 width: 12px;
542 }
543 `,
544 valueCollapsed: css`
545 color: ${t(colors.gray[500], colors.gray[400])};
546 `,
547 valueFunction: css`
548 color: ${t(colors.cyan[500], colors.cyan[400])};
549 `,
550 valueString: css`
551 color: ${t(colors.green[500], colors.green[400])};
552 `,
553 valueNumber: css`
554 color: ${t(colors.yellow[500], colors.yellow[400])};
555 `,
556 valueBoolean: css`
557 color: ${t(colors.pink[500], colors.pink[400])};
558 `,
559 valueNull: css`
560 color: ${t(colors.gray[500], colors.gray[400])};
561 font-style: italic;
562 `,
563 valueKey: css`
564 color: ${t(colors.blue[400], colors.blue[300])};
565 `,
566 valueBraces: css`
567 color: ${colors.gray[500]};
568 `,
569 valueContainer: (isRoot: boolean) => css`
570 display: block;
571 margin-left: ${isRoot ? '0' : '1rem'};
572β
573 &:not(:hover) .actions {
574 display: none;
575 }
576β
577 &:hover .actions {
578 display: inline-flex;
579 }
580 `,
581 },
582 header: {
583 row: css`
584 display: flex;
585 justify-content: space-between;
586 align-items: center;
587 padding: ${tokens.size[2]} ${tokens.size[2.5]};
588 gap: ${tokens.size[2.5]};
589 border-bottom: ${t(colors.gray[300], colors.darkGray[500])} 1px solid;
590 align-items: center;
591 `,
592 logoAndToggleContainer: css`
593 display: flex;
594 gap: ${tokens.size[3]};
595 align-items: center;
596 & > button {
597 padding: 0;
598 background: transparent;
599 border: none;
600 display: flex;
601 gap: ${size[0.5]};
602 flex-direction: column;
603 }
604 `,
605 logo: css`
606 cursor: pointer;
607 display: flex;
608 flex-direction: column;
609 background-color: transparent;
610 border: none;
611 gap: ${tokens.size[0.5]};
612 padding: 0;
613 &:hover {
614 opacity: 0.7;
615 }
616 &:focus-visible {
617 outline-offset: 4px;
618 border-radius: ${border.radius.xs};
619 outline: 2px solid ${colors.blue[800]};
620 }
621 `,
622 tanstackLogo: css`
623 font-size: ${font.size.md};
624 font-weight: ${font.weight.bold};
625 line-height: ${font.lineHeight.xs};
626 white-space: nowrap;
627 color: ${t(colors.gray[700], colors.gray[300])};
628 `,
629 flavorLogo: (flavorLight: string, flavorDark: string) => css`
630 font-weight: ${font.weight.semibold};
631 font-size: ${font.size.xs};
632 background: linear-gradient(to right, ${t(flavorLight, flavorDark)});
633 background-clip: text;
634 -webkit-background-clip: text;
635 line-height: 1;
636 -webkit-text-fill-color: transparent;
637 white-space: nowrap;
638 `,
639 },
640 section: {
641 main: css`
642 margin-bottom: 1.5rem;
643 padding: 1rem;
644 background-color: ${t(colors.gray[50], colors.darkGray[800])};
645 border: 1px solid ${t(colors.gray[200], colors.gray[800])};
646 border-radius: 0.5rem;
647 box-shadow: none;
648 `,
649 title: css`
650 font-size: 1rem;
651 font-weight: 600;
652 color: ${t(colors.gray[900], colors.gray[100])};
653 margin: 0 0 0.75rem 0;
654 padding-bottom: 0.5rem;
655 border-bottom: 1px solid ${t(colors.gray[200], colors.gray[800])};
656 display: flex;
657 align-items: center;
658 gap: 0.5rem;
659 text-align: left;
660 `,
661 icon: css`
662 height: 18px;
663 width: 18px;
664 & > svg {
665 height: 100%;
666 width: 100%;
667 }
668 color: ${t(colors.gray[700], colors.gray[400])};
669 `,
670 description: css`
671 color: ${t(colors.gray[500], colors.gray[400])};
672 font-size: 0.8rem;
673 margin: 0 0 1rem 0;
674 line-height: 1.4;
675 text-align: left;
676 `,
677 },
678 mainPanel: {
679 panel: (withPadding: boolean) => css`
680 padding: ${withPadding ? tokens.size[3] : 0};
681 background: ${t(colors.gray[50], colors.darkGray[700])};
682 overflow-y: auto;
683 height: 100%;
684 `,
685 },
686 }
687}
688β
689export function createStyles() {
690 const { theme } = createTheme()
691 const [styles, setStyles] = createSignal(stylesFactory(theme()))
692 createEffect(() => {
693 setStyles(stylesFactory(theme()))
694 })
695 return styles
696}