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

useStyles.tsx

623 lines16.2 KB

1import * as goober from 'goober'
2import { createSignal, useContext } from 'solid-js'
3import { tokens } from './tokens'
4import { ShadowDomTargetContext } from './context'
5import type { Accessor } from 'solid-js'
6​
7const stylesFactory = (shadowDOMTarget?: ShadowRoot) => {
8 const { colors, font, size, alpha, shadow, border } = tokens
9 const { fontFamily, lineHeight, size: fontSize } = font
10 const css = shadowDOMTarget
11 ? goober.css.bind({ target: shadowDOMTarget })
12 : goober.css
13​
14 return {
15 devtoolsPanelContainer: css`
16 direction: ltr;
17 position: fixed;
18 bottom: 0;
19 right: 0;
20 z-index: 99999;
21 width: 100%;
22 max-height: 90%;
23 border-top: 1px solid ${colors.gray[700]};
24 transform-origin: top;
25 `,
26 devtoolsPanelContainerVisibility: (isOpen: boolean) => {
27 return css`
28 visibility: ${isOpen ? 'visible' : 'hidden'};
29 `
30 },
31 devtoolsPanelContainerResizing: (isResizing: Accessor<boolean>) => {
32 if (isResizing()) {
33 return css`
34 transition: none;
35 `
36 }
37​
38 return css`
39 transition: all 0.4s ease;
40 `
41 },
42 devtoolsPanelContainerAnimation: (isOpen: boolean, height: number) => {
43 if (isOpen) {
44 return css`
45 pointer-events: auto;
46 transform: translateY(0);
47 `
48 }
49 return css`
50 pointer-events: none;
51 transform: translateY(${height}px);
52 `
53 },
54 logo: css`
55 cursor: pointer;
56 display: flex;
57 flex-direction: column;
58 background-color: transparent;
59 border: none;
60 font-family: ${fontFamily.sans};
61 gap: ${tokens.size[0.5]};
62 padding: 0px;
63 &:hover {
64 opacity: 0.7;
65 }
66 &:focus-visible {
67 outline-offset: 4px;
68 border-radius: ${border.radius.xs};
69 outline: 2px solid ${colors.blue[800]};
70 }
71 `,
72 tanstackLogo: css`
73 font-size: ${font.size.md};
74 font-weight: ${font.weight.bold};
75 line-height: ${font.lineHeight.xs};
76 white-space: nowrap;
77 color: ${colors.gray[300]};
78 `,
79 routerLogo: css`
80 font-weight: ${font.weight.semibold};
81 font-size: ${font.size.xs};
82 background: linear-gradient(to right, #84cc16, #10b981);
83 background-clip: text;
84 -webkit-background-clip: text;
85 line-height: 1;
86 -webkit-text-fill-color: transparent;
87 white-space: nowrap;
88 `,
89 devtoolsPanel: css`
90 display: flex;
91 font-size: ${fontSize.sm};
92 font-family: ${fontFamily.sans};
93 background-color: ${colors.darkGray[700]};
94 color: ${colors.gray[300]};
95​
96 @media (max-width: 700px) {
97 flex-direction: column;
98 }
99 @media (max-width: 600px) {
100 font-size: ${fontSize.xs};
101 }
102 `,
103 dragHandle: css`
104 position: absolute;
105 left: 0;
106 top: 0;
107 width: 100%;
108 height: 4px;
109 cursor: row-resize;
110 z-index: 100000;
111 &:hover {
112 background-color: ${colors.purple[400]}${alpha[90]};
113 }
114 `,
115 firstContainer: css`
116 flex: 1 1 500px;
117 min-height: 40%;
118 max-height: 100%;
119 overflow: auto;
120 border-right: 1px solid ${colors.gray[700]};
121 display: flex;
122 flex-direction: column;
123 `,
124 routerExplorerContainer: css`
125 overflow-y: auto;
126 flex: 1;
127 `,
128 routerExplorer: css`
129 padding: ${tokens.size[2]};
130 `,
131 row: css`
132 display: flex;
133 align-items: center;
134 padding: ${tokens.size[2]} ${tokens.size[2.5]};
135 gap: ${tokens.size[2.5]};
136 border-bottom: ${colors.darkGray[500]} 1px solid;
137 align-items: center;
138 `,
139 detailsHeader: css`
140 font-family: ui-sans-serif, Inter, system-ui, sans-serif, sans-serif;
141 position: sticky;
142 top: 0;
143 z-index: 2;
144 background-color: ${colors.darkGray[600]};
145 padding: 0px ${tokens.size[2]};
146 font-weight: ${font.weight.medium};
147 font-size: ${font.size.xs};
148 min-height: ${tokens.size[8]};
149 line-height: ${font.lineHeight.xs};
150 text-align: left;
151 display: flex;
152 align-items: center;
153 `,
154 maskedBadge: css`
155 background: ${colors.yellow[900]}${alpha[70]};
156 color: ${colors.yellow[300]};
157 display: inline-block;
158 padding: ${tokens.size[0]} ${tokens.size[2.5]};
159 border-radius: ${border.radius.full};
160 font-size: ${font.size.xs};
161 font-weight: ${font.weight.normal};
162 border: 1px solid ${colors.yellow[300]};
163 `,
164 maskedLocation: css`
165 color: ${colors.yellow[300]};
166 `,
167 detailsContent: css`
168 padding: ${tokens.size[1.5]} ${tokens.size[2]};
169 display: flex;
170 align-items: center;
171 justify-content: space-between;
172 font-size: ${font.size.xs};
173 `,
174 routeMatchesToggle: css`
175 display: flex;
176 align-items: center;
177 border: 1px solid ${colors.gray[500]};
178 border-radius: ${border.radius.sm};
179 overflow: hidden;
180 `,
181 routeMatchesToggleBtn: (active: boolean, showBorder: boolean) => {
182 const base = css`
183 appearance: none;
184 border: none;
185 font-size: 12px;
186 padding: 4px 8px;
187 background: transparent;
188 cursor: pointer;
189 font-family: ${fontFamily.sans};
190 font-weight: ${font.weight.medium};
191 `
192 const classes = [base]
193​
194 if (active) {
195 const activeStyles = css`
196 background: ${colors.darkGray[400]};
197 color: ${colors.gray[300]};
198 `
199 classes.push(activeStyles)
200 } else {
201 const inactiveStyles = css`
202 color: ${colors.gray[500]};
203 background: ${colors.darkGray[800]}${alpha[20]};
204 `
205 classes.push(inactiveStyles)
206 }
207​
208 if (showBorder) {
209 classes.push(css`
210 border-right: 1px solid ${tokens.colors.gray[500]};
211 `)
212 }
213​
214 return classes
215 },
216 detailsHeaderInfo: css`
217 flex: 1;
218 justify-content: flex-end;
219 display: flex;
220 align-items: center;
221 font-weight: ${font.weight.normal};
222 color: ${colors.gray[400]};
223 `,
224 matchRow: (active: boolean) => {
225 const base = css`
226 display: flex;
227 border-bottom: 1px solid ${colors.darkGray[400]};
228 cursor: pointer;
229 align-items: center;
230 padding: ${size[1]} ${size[2]};
231 gap: ${size[2]};
232 font-size: ${fontSize.xs};
233 color: ${colors.gray[300]};
234 `
235 const classes = [base]
236​
237 if (active) {
238 const activeStyles = css`
239 background: ${colors.darkGray[500]};
240 `
241 classes.push(activeStyles)
242 }
243​
244 return classes
245 },
246 matchIndicator: (
247 color: 'green' | 'red' | 'yellow' | 'gray' | 'blue' | 'purple',
248 ) => {
249 const base = css`
250 flex: 0 0 auto;
251 width: ${size[3]};
252 height: ${size[3]};
253 background: ${colors[color][900]};
254 border: 1px solid ${colors[color][500]};
255 border-radius: ${border.radius.full};
256 transition: all 0.25s ease-out;
257 box-sizing: border-box;
258 `
259 const classes = [base]
260​
261 if (color === 'gray') {
262 const grayStyles = css`
263 background: ${colors.gray[700]};
264 border-color: ${colors.gray[400]};
265 `
266 classes.push(grayStyles)
267 }
268​
269 return classes
270 },
271 matchID: css`
272 flex: 1;
273 line-height: ${lineHeight['xs']};
274 `,
275 ageTicker: (showWarning: boolean) => {
276 const base = css`
277 display: flex;
278 gap: ${size[1]};
279 font-size: ${fontSize.xs};
280 color: ${colors.gray[400]};
281 font-variant-numeric: tabular-nums;
282 line-height: ${lineHeight['xs']};
283 `
284​
285 const classes = [base]
286​
287 if (showWarning) {
288 const warningStyles = css`
289 color: ${colors.yellow[400]};
290 `
291 classes.push(warningStyles)
292 }
293​
294 return classes
295 },
296 secondContainer: css`
297 flex: 1 1 500px;
298 min-height: 40%;
299 max-height: 100%;
300 overflow: auto;
301 border-right: 1px solid ${colors.gray[700]};
302 display: flex;
303 flex-direction: column;
304 `,
305 thirdContainer: css`
306 flex: 1 1 500px;
307 overflow: auto;
308 display: flex;
309 flex-direction: column;
310 height: 100%;
311 border-right: 1px solid ${colors.gray[700]};
312​
313 @media (max-width: 700px) {
314 border-top: 2px solid ${colors.gray[700]};
315 }
316 `,
317 fourthContainer: css`
318 flex: 1 1 500px;
319 min-height: 40%;
320 max-height: 100%;
321 overflow: auto;
322 display: flex;
323 flex-direction: column;
324 `,
325 routesContainer: css`
326 overflow-x: auto;
327 overflow-y: visible;
328 `,
329 routesRowContainer: (active: boolean, isMatch: boolean) => {
330 const base = css`
331 display: flex;
332 border-bottom: 1px solid ${colors.darkGray[400]};
333 align-items: center;
334 padding: ${size[1]} ${size[2]};
335 gap: ${size[2]};
336 font-size: ${fontSize.xs};
337 color: ${colors.gray[300]};
338 cursor: ${isMatch ? 'pointer' : 'default'};
339 line-height: ${lineHeight['xs']};
340 `
341 const classes = [base]
342​
343 if (active) {
344 const activeStyles = css`
345 background: ${colors.darkGray[500]};
346 `
347 classes.push(activeStyles)
348 }
349​
350 return classes
351 },
352 routesRow: (isMatch: boolean) => {
353 const base = css`
354 flex: 1 0 auto;
355 display: flex;
356 justify-content: space-between;
357 align-items: center;
358 font-size: ${fontSize.xs};
359 line-height: ${lineHeight['xs']};
360 `
361​
362 const classes = [base]
363​
364 if (!isMatch) {
365 const matchStyles = css`
366 color: ${colors.gray[400]};
367 `
368 classes.push(matchStyles)
369 }
370​
371 return classes
372 },
373 routesRowInner: css`
374 display: 'flex';
375 align-items: 'center';
376 flex-grow: 1;
377 min-width: 0;
378 `,
379 routeParamInfo: css`
380 color: ${colors.gray[400]};
381 font-size: ${fontSize.xs};
382 line-height: ${lineHeight['xs']};
383 `,
384 nestedRouteRow: (isRoot: boolean) => {
385 const base = css`
386 margin-left: ${isRoot ? 0 : size[3.5]};
387 border-left: ${isRoot ? '' : `solid 1px ${colors.gray[700]}`};
388 `
389 return base
390 },
391 code: css`
392 font-size: ${fontSize.xs};
393 line-height: ${lineHeight['xs']};
394 white-space: nowrap;
395 overflow: hidden;
396 text-overflow: ellipsis;
397 `,
398 matchesContainer: css`
399 flex: 1 1 auto;
400 overflow-y: auto;
401 `,
402 cachedMatchesContainer: css`
403 flex: 1 1 auto;
404 overflow-y: auto;
405 max-height: 50%;
406 `,
407 historyContainer: css`
408 display: flex;
409 flex: 1 1 auto;
410 overflow-y: auto;
411 max-height: 50%;
412 `,
413 historyOverflowContainer: css`
414 padding: ${size[1]} ${size[2]};
415 font-size: ${tokens.font.size.xs};
416 `,
417 maskedBadgeContainer: css`
418 flex: 1;
419 justify-content: flex-end;
420 display: flex;
421 `,
422 matchDetails: css`
423 display: flex;
424 flex-direction: column;
425 padding: ${tokens.size[2]};
426 font-size: ${tokens.font.size.xs};
427 color: ${tokens.colors.gray[300]};
428 line-height: ${tokens.font.lineHeight.sm};
429 `,
430 matchStatus: (
431 status: 'pending' | 'success' | 'error' | 'notFound',
432 isFetching: false | 'beforeLoad' | 'loader',
433 ) => {
434 const colorMap = {
435 pending: 'yellow',
436 success: 'green',
437 error: 'red',
438 notFound: 'purple',
439 } as const
440​
441 const color =
442 isFetching && status === 'success'
443 ? isFetching === 'beforeLoad'
444 ? 'purple'
445 : 'blue'
446 : colorMap[status]
447​
448 return css`
449 display: flex;
450 justify-content: center;
451 align-items: center;
452 height: 40px;
453 border-radius: ${tokens.border.radius.sm};
454 font-weight: ${tokens.font.weight.normal};
455 background-color: ${tokens.colors[color][900]}${tokens.alpha[90]};
456 color: ${tokens.colors[color][300]};
457 border: 1px solid ${tokens.colors[color][600]};
458 margin-bottom: ${tokens.size[2]};
459 transition: all 0.25s ease-out;
460 `
461 },
462 matchDetailsInfo: css`
463 display: flex;
464 justify-content: flex-end;
465 flex: 1;
466 `,
467 matchDetailsInfoLabel: css`
468 display: flex;
469 `,
470 mainCloseBtn: css`
471 background: ${colors.darkGray[700]};
472 padding: ${size[1]} ${size[2]} ${size[1]} ${size[1.5]};
473 border-radius: ${border.radius.md};
474 position: fixed;
475 z-index: 99999;
476 display: inline-flex;
477 width: fit-content;
478 cursor: pointer;
479 appearance: none;
480 border: 0;
481 gap: 8px;
482 align-items: center;
483 border: 1px solid ${colors.gray[500]};
484 font-size: ${font.size.xs};
485 cursor: pointer;
486 transition: all 0.25s ease-out;
487​
488 &:hover {
489 background: ${colors.darkGray[500]};
490 }
491 `,
492 mainCloseBtnPosition: (
493 position: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right',
494 ) => {
495 const base = css`
496 ${position === 'top-left' ? `top: ${size[2]}; left: ${size[2]};` : ''}
497 ${position === 'top-right' ? `top: ${size[2]}; right: ${size[2]};` : ''}
498 ${position === 'bottom-left'
499 ? `bottom: ${size[2]}; left: ${size[2]};`
500 : ''}
501 ${position === 'bottom-right'
502 ? `bottom: ${size[2]}; right: ${size[2]};`
503 : ''}
504 `
505 return base
506 },
507 mainCloseBtnAnimation: (isOpen: boolean) => {
508 if (!isOpen) {
509 return css`
510 opacity: 1;
511 pointer-events: auto;
512 visibility: visible;
513 `
514 }
515 return css`
516 opacity: 0;
517 pointer-events: none;
518 visibility: hidden;
519 `
520 },
521 routerLogoCloseButton: css`
522 font-weight: ${font.weight.semibold};
523 font-size: ${font.size.xs};
524 background: linear-gradient(to right, #98f30c, #00f4a3);
525 background-clip: text;
526 -webkit-background-clip: text;
527 line-height: 1;
528 -webkit-text-fill-color: transparent;
529 white-space: nowrap;
530 `,
531 mainCloseBtnDivider: css`
532 width: 1px;
533 background: ${tokens.colors.gray[600]};
534 height: 100%;
535 border-radius: 999999px;
536 color: transparent;
537 `,
538 mainCloseBtnIconContainer: css`
539 position: relative;
540 width: ${size[5]};
541 height: ${size[5]};
542 background: pink;
543 border-radius: 999999px;
544 overflow: hidden;
545 `,
546 mainCloseBtnIconOuter: css`
547 width: ${size[5]};
548 height: ${size[5]};
549 position: absolute;
550 top: 50%;
551 left: 50%;
552 transform: translate(-50%, -50%);
553 filter: blur(3px) saturate(1.8) contrast(2);
554 `,
555 mainCloseBtnIconInner: css`
556 width: ${size[4]};
557 height: ${size[4]};
558 position: absolute;
559 top: 50%;
560 left: 50%;
561 transform: translate(-50%, -50%);
562 `,
563 panelCloseBtn: css`
564 position: absolute;
565 cursor: pointer;
566 z-index: 100001;
567 display: flex;
568 align-items: center;
569 justify-content: center;
570 outline: none;
571 background-color: ${colors.darkGray[700]};
572 &:hover {
573 background-color: ${colors.darkGray[500]};
574 }
575​
576 top: 0;
577 right: ${size[2]};
578 transform: translate(0, -100%);
579 border-right: ${colors.darkGray[300]} 1px solid;
580 border-left: ${colors.darkGray[300]} 1px solid;
581 border-top: ${colors.darkGray[300]} 1px solid;
582 border-bottom: none;
583 border-radius: ${border.radius.sm} ${border.radius.sm} 0px 0px;
584 padding: ${size[1]} ${size[1.5]} ${size[0.5]} ${size[1.5]};
585​
586 &::after {
587 content: ' ';
588 position: absolute;
589 top: 100%;
590 left: -${size[2.5]};
591 height: ${size[1.5]};
592 width: calc(100% + ${size[5]});
593 }
594 `,
595 panelCloseBtnIcon: css`
596 color: ${colors.gray[400]};
597 width: ${size[2]};
598 height: ${size[2]};
599 `,
600 navigateButton: css`
601 background: none;
602 border: none;
603 padding: 0 0 0 4px;
604 margin: 0;
605 color: ${colors.gray[400]};
606 font-size: ${fontSize.md};
607 cursor: pointer;
608 line-height: 1;
609 vertical-align: middle;
610 margin-right: 0.5ch;
611 flex-shrink: 0;
612 &:hover {
613 color: ${colors.blue[300]};
614 }
615 `,
616 }
618​
619export function useStyles() {
620 const shadowDomTarget = useContext(ShadowDomTargetContext)
621 const [_styles] = createSignal(stylesFactory(shadowDomTarget))
622 return _styles