@zeyolabs/ui 0.0.0-stage → 2026.11.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (143) hide show
  1. package/README.md +43 -2
  2. package/back-button/BackButton.svelte +26 -0
  3. package/badge/Badge.svelte +73 -0
  4. package/badge/PromoBadge.svelte +319 -0
  5. package/badge/color.ts +10 -0
  6. package/bar/Bar.svelte +63 -0
  7. package/base.css +47 -0
  8. package/boundary/Boundary.svelte +59 -0
  9. package/boundary/BoundaryFailed.svelte +40 -0
  10. package/boundary/PendingTracker.svelte +14 -0
  11. package/boundary/pending-context.ts +15 -0
  12. package/boundary/pending-flag.svelte.ts +33 -0
  13. package/boundary/report-boundary-error.ts +13 -0
  14. package/card/Card.svelte +239 -0
  15. package/card/CardBody.svelte +41 -0
  16. package/card/CardFooter.svelte +36 -0
  17. package/card/CardHeader.svelte +36 -0
  18. package/copy/CopyArea.svelte +37 -0
  19. package/copy/CopyButton.svelte +59 -0
  20. package/copy/copy-state.svelte.ts +23 -0
  21. package/copy/types.ts +1 -0
  22. package/dialog/ConfirmDialog.svelte +61 -0
  23. package/dialog/Dialog.svelte +31 -0
  24. package/dialog/DialogBody.svelte +88 -0
  25. package/dialog/DialogCloseButton.svelte +26 -0
  26. package/dialog/DialogFooter.svelte +23 -0
  27. package/dialog/DialogTrigger.svelte +15 -0
  28. package/distribution-bar/DistributionBar.svelte +37 -0
  29. package/drawer/Drawer.svelte +31 -0
  30. package/drawer/DrawerBody.svelte +61 -0
  31. package/empty-state/EmptyState.svelte +74 -0
  32. package/error/ErrorPage.svelte +54 -0
  33. package/eyebrow/Eyebrow.svelte +10 -0
  34. package/faq/FAQList.svelte +89 -0
  35. package/filter/FilterChipGroup.svelte +78 -0
  36. package/filter/FilterOptionList.svelte +188 -0
  37. package/filter/FilterPopover.svelte +122 -0
  38. package/filter/filter-draft.svelte.ts +25 -0
  39. package/form/Button.svelte +73 -0
  40. package/form/Field.svelte +111 -0
  41. package/form/FieldLabel.svelte +19 -0
  42. package/form/Form.svelte +133 -0
  43. package/form/PhoneField.svelte +214 -0
  44. package/form/UnsavedBar.svelte +22 -0
  45. package/form/field-view.svelte.ts +213 -0
  46. package/form/fields/CheckboxField.svelte +85 -0
  47. package/form/fields/Combobox.svelte +327 -0
  48. package/form/fields/ComboboxAction.svelte +16 -0
  49. package/form/fields/DateField.svelte +31 -0
  50. package/form/fields/DateRangeField.svelte +188 -0
  51. package/form/fields/DateRangePresetField.svelte +119 -0
  52. package/form/fields/EmailField.svelte +63 -0
  53. package/form/fields/FileField.svelte +145 -0
  54. package/form/fields/HexColorField.svelte +83 -0
  55. package/form/fields/IntervalField.svelte +100 -0
  56. package/form/fields/MessageField.svelte +99 -0
  57. package/form/fields/NumberField.svelte +64 -0
  58. package/form/fields/Option.svelte +48 -0
  59. package/form/fields/OptionRegistrar.svelte +15 -0
  60. package/form/fields/PasswordField.svelte +44 -0
  61. package/form/fields/RadioField.svelte +60 -0
  62. package/form/fields/RichTextField.svelte +221 -0
  63. package/form/fields/SelectField.svelte +216 -0
  64. package/form/fields/SliderField.svelte +182 -0
  65. package/form/fields/SwitchField.svelte +102 -0
  66. package/form/fields/TextField.svelte +72 -0
  67. package/form/fields/TimeField.svelte +31 -0
  68. package/form/fields/index.ts +19 -0
  69. package/form/fields/select-field-context.ts +21 -0
  70. package/form/index.ts +21 -0
  71. package/form/primitives/Checkbox.svelte +103 -0
  72. package/form/primitives/DateInput.svelte +51 -0
  73. package/form/primitives/IconInputWrapper.svelte +40 -0
  74. package/form/primitives/Input.svelte +47 -0
  75. package/form/primitives/SearchBar.svelte +37 -0
  76. package/form/primitives/Select.svelte +139 -0
  77. package/form/primitives/TextArea.svelte +51 -0
  78. package/form/primitives/index.ts +6 -0
  79. package/gallery/ImageGallery.svelte +133 -0
  80. package/gallery/flickity-fullscreen.d.ts +2 -0
  81. package/grouped-grid/GroupedGrid.svelte +143 -0
  82. package/grouped-grid/types.ts +25 -0
  83. package/layout/Cluster.svelte +92 -0
  84. package/layout/Container.svelte +9 -0
  85. package/layout/Grid.svelte +131 -0
  86. package/layout/Section.svelte +146 -0
  87. package/layout/Shell.svelte +32 -0
  88. package/layout/SplitShell.svelte +47 -0
  89. package/layout/Stack.svelte +78 -0
  90. package/list-row/ListRow.svelte +77 -0
  91. package/menu/MenuButton.svelte +101 -0
  92. package/mini-stat/MiniStat.svelte +13 -0
  93. package/package.json +171 -5
  94. package/page-hero/PageHero.svelte +35 -0
  95. package/pagination/Pagination.svelte +44 -0
  96. package/pagination/finder-pagination.svelte.ts +55 -0
  97. package/pagination/finder-search.svelte.ts +292 -0
  98. package/percentage-ring/PercentageRing.svelte +76 -0
  99. package/percentage-ring/types.ts +1 -0
  100. package/popover/InfoTip.svelte +36 -0
  101. package/popover/Popover.svelte +157 -0
  102. package/query-state/QueryState.svelte +42 -0
  103. package/schema.ts +20 -0
  104. package/sidebar/Sidebar.svelte +73 -0
  105. package/sidebar/SidebarBrand.svelte +32 -0
  106. package/sidebar/SidebarButton.svelte +31 -0
  107. package/sidebar/SidebarGroup.svelte +39 -0
  108. package/sidebar/SidebarItem.svelte +48 -0
  109. package/skeleton/Skeleton.svelte +86 -0
  110. package/skeleton/SkeletonButton.svelte +27 -0
  111. package/skeleton/SkeletonCard.svelte +49 -0
  112. package/skeleton/SkeletonCircle.svelte +25 -0
  113. package/skeleton/SkeletonField.svelte +19 -0
  114. package/skeleton/SkeletonRow.svelte +47 -0
  115. package/skeleton/SkeletonText.svelte +46 -0
  116. package/skeleton/TableSkeleton.svelte +60 -0
  117. package/spacing.css +32 -0
  118. package/stat/NextPayoutCountdown.svelte +52 -0
  119. package/stat/Stat.svelte +103 -0
  120. package/stat/ValueBox.svelte +38 -0
  121. package/status-row/StatusRow.svelte +176 -0
  122. package/status-row/types.ts +5 -0
  123. package/table/SelectAllCell.svelte +34 -0
  124. package/table/SelectAllTableCell.svelte +25 -0
  125. package/table/SelectRowCell.svelte +31 -0
  126. package/table/SelectRowTableCell.svelte +25 -0
  127. package/table/SelectionBar.svelte +68 -0
  128. package/table/SelectionOverlay.svelte +83 -0
  129. package/table/Table.svelte +64 -0
  130. package/table/TableCell.svelte +185 -0
  131. package/table/TableRow.svelte +86 -0
  132. package/table/index.ts +9 -0
  133. package/table/selection.svelte.ts +79 -0
  134. package/tabs/TabBlock.svelte +56 -0
  135. package/tabs/TabButton.svelte +33 -0
  136. package/template.css +1393 -0
  137. package/text/Span.svelte +83 -0
  138. package/text/Text.svelte +94 -0
  139. package/text/Title.svelte +75 -0
  140. package/text/color.ts +41 -0
  141. package/theme/theme.svelte.ts +33 -0
  142. package/tokens.css +62 -0
  143. package/typography.css +164 -0
@@ -0,0 +1,47 @@
1
+ <script lang="ts">
2
+ import Skeleton from './Skeleton.svelte';
3
+ import SkeletonCircle from './SkeletonCircle.svelte';
4
+
5
+ let {
6
+ avatar = true,
7
+ class: klass = '',
8
+ cols = 2,
9
+ variant = 'pulse',
10
+ }: {
11
+ /** Show a leading avatar/circle. */
12
+ avatar?: boolean;
13
+ class?: string;
14
+ /** Number of text columns after the avatar. */
15
+ cols?: number;
16
+ variant?: 'pulse' | 'shimmer';
17
+ } = $props();
18
+
19
+ // Decreasing widths so columns look like name / detail / value.
20
+ const WIDTHS = ['40%', '24%', '16%', '12%'];
21
+ </script>
22
+
23
+ <div class="sk-row {klass}">
24
+ {#if avatar}
25
+ <SkeletonCircle size="sm" {variant} />
26
+ {/if}
27
+ <div class="sk-row-cols">
28
+ {#each Array.from({ length: cols }) as _, i (i)}
29
+ <Skeleton h="0.75rem" radius="xs" {variant} w={WIDTHS[i] ?? '20%'} />
30
+ {/each}
31
+ </div>
32
+ </div>
33
+
34
+ <style>
35
+ .sk-row {
36
+ display: flex;
37
+ align-items: center;
38
+ gap: 0.75rem;
39
+ width: 100%;
40
+ }
41
+ .sk-row-cols {
42
+ display: flex;
43
+ align-items: center;
44
+ gap: 1rem;
45
+ flex: 1;
46
+ }
47
+ </style>
@@ -0,0 +1,46 @@
1
+ <script lang="ts">
2
+ import Skeleton from './Skeleton.svelte';
3
+
4
+ type Size = 'lg' | 'md' | 'sm';
5
+
6
+ let {
7
+ class: klass = '',
8
+ gap = '0.5rem',
9
+ lastLineWidth = '60%',
10
+ lines = 1,
11
+ size = 'md',
12
+ variant = 'pulse',
13
+ }: {
14
+ class?: string;
15
+ /** Vertical gap between lines. */
16
+ gap?: string;
17
+ /** Width of the final line (ragged-edge effect). Ignored when lines === 1. */
18
+ lastLineWidth?: string;
19
+ /** Number of text lines. */
20
+ lines?: number;
21
+ /** Line height preset. */
22
+ size?: Size;
23
+ variant?: 'pulse' | 'shimmer';
24
+ } = $props();
25
+
26
+ const HEIGHTS: Record<Size, string> = {
27
+ lg: '1.25rem',
28
+ md: '0.875rem',
29
+ sm: '0.625rem',
30
+ };
31
+ const h = $derived(HEIGHTS[size]);
32
+ </script>
33
+
34
+ <span style="gap: {gap};" class="sk-text {klass}">
35
+ {#each Array.from({ length: lines }) as _, i (i)}
36
+ <Skeleton {h} radius="xs" {variant} w={lines > 1 && i === lines - 1 ? lastLineWidth : '100%'} />
37
+ {/each}
38
+ </span>
39
+
40
+ <style>
41
+ .sk-text {
42
+ display: flex;
43
+ flex-direction: column;
44
+ width: 100%;
45
+ }
46
+ </style>
@@ -0,0 +1,60 @@
1
+ <script lang="ts">
2
+ import Skeleton from './Skeleton.svelte';
3
+
4
+ // Matches SelectAllTableCell/SelectRowTableCell's fixed column width.
5
+ const CHECKBOX_COL_WIDTH = '40px';
6
+
7
+ let {
8
+ checkbox = false,
9
+ cols = 2,
10
+ rows = 6,
11
+ variant = 'pulse',
12
+ }: {
13
+ /** Leading checkbox-shaped placeholder, for a table with a select column. Counts as one
14
+ * of `cols` — checkbox + cols=2 still shows 2 columns total, not 3. Always a fixed-width
15
+ * column, matching the real checkbox column it's standing in for. */
16
+ checkbox?: boolean;
17
+ /** Total number of columns per row, checkbox included. */
18
+ cols?: number;
19
+ rows?: number;
20
+ variant?: 'pulse' | 'shimmer';
21
+ } = $props();
22
+
23
+ const barCols = $derived(checkbox ? cols - 1 : cols);
24
+ </script>
25
+
26
+ <div class="flex flex-col">
27
+ <div
28
+ style="background: var(--sf);"
29
+ class="flex items-center gap-3 border-b border-(--bds) px-4 py-3.5"
30
+ >
31
+ {#if checkbox}
32
+ <div style:width={CHECKBOX_COL_WIDTH} class="flex shrink-0 justify-center"></div>
33
+ {/if}
34
+ <div
35
+ style:grid-template-columns="repeat({barCols}, 1fr)"
36
+ class="grid flex-1 items-center gap-4"
37
+ >
38
+ {#each Array.from({ length: barCols }) as _, j (j)}
39
+ <Skeleton h="0.5rem" radius="xs" {variant} w="40%" />
40
+ {/each}
41
+ </div>
42
+ </div>
43
+ {#each Array.from({ length: rows }) as _, i (i)}
44
+ <div class="flex items-center gap-3 border-b border-(--bds) px-4 py-3.5 last:border-b-0">
45
+ {#if checkbox}
46
+ <div style:width={CHECKBOX_COL_WIDTH} class="flex shrink-0 justify-center">
47
+ <Skeleton h="1rem" radius="xs" {variant} w="1rem" />
48
+ </div>
49
+ {/if}
50
+ <div
51
+ style:grid-template-columns="repeat({barCols}, 1fr)"
52
+ class="grid flex-1 items-center gap-4"
53
+ >
54
+ {#each Array.from({ length: barCols }) as _, j (j)}
55
+ <Skeleton h="0.75rem" radius="xs" {variant} />
56
+ {/each}
57
+ </div>
58
+ </div>
59
+ {/each}
60
+ </div>
package/spacing.css ADDED
@@ -0,0 +1,32 @@
1
+ /* Spacing scale, shared across every app: named steps on top of Tailwind v4's dynamic
2
+ --spacing multiplier, for the layout components' gap/spacing/padding props and Card's
3
+ padding prop, reached for before a new one-off arbitrary value (gap-3.5, px-4.5, etc).
4
+
5
+ Deliberately plain CSS custom properties, not a Tailwind @theme block: Tailwind's own
6
+ max-w-* / max-h-* utilities resolve named sizes (xs/sm/md/lg/xl/2xl/etc) through this
7
+ exact --spacing-* namespace ahead of their own --container-* scale whenever a matching
8
+ key exists. Registering these under @theme silently shrank every max-w-md (etc) in the
9
+ app to this scale's tiny values instead of Tailwind's real ~448px default. Plain :root
10
+ custom properties are still fully readable via var(--spacing-md) everywhere, including
11
+ inside @theme-registered component CSS, they just do not participate in Tailwind's own
12
+ utility generation/resolution. Do not move this back into @theme without re-checking
13
+ that collision. */
14
+ :root {
15
+ --spacing-xs: calc(var(--spacing) * 2); /* 8px */
16
+ --spacing-sm: calc(var(--spacing) * 3); /* 12px */
17
+ --spacing-md: calc(var(--spacing) * 5); /* 20px */
18
+ --spacing-lg: calc(var(--spacing) * 8); /* 32px */
19
+ --spacing-xl: calc(var(--spacing) * 12); /* 48px */
20
+ /* Section-band tier — page-level bands (a colored full-bleed section's own vertical
21
+ padding) need a bigger range than component-internal gaps ever do. */
22
+ --spacing-2xl: calc(var(--spacing) * 16); /* 64px */
23
+ --spacing-3xl: calc(var(--spacing) * 24); /* 96px */
24
+ --spacing-4xl: calc(var(--spacing) * 32); /* 128px */
25
+ }
26
+
27
+ /* Sidebar width — the fixed sidebar and every app's matching margin-left read these.
28
+ v2-parity: v2 measures 240px expanded / ~58px collapsed (was 256px / 56px). */
29
+ :root {
30
+ --sidebar-width-expanded: 15rem; /* 240px */
31
+ --sidebar-width-collapsed: 3.625rem; /* 58px */
32
+ }
@@ -0,0 +1,52 @@
1
+ <script lang="ts">
2
+ import {
3
+ getLocalTimeZone,
4
+ now,
5
+ today,
6
+ toZoned,
7
+ type ZonedDateTime,
8
+ } from '@internationalized/date';
9
+ // The next affiliate payout run — the 1st of next month, at midnight in the viewer's own
10
+ // timezone. Shared by apps/affiliate's payments page and apps/admin's affiliate drawer so
11
+ // admins see the same clock affiliates do.
12
+ import { Datetime } from '@zeyolabs/kit/utils/datetime';
13
+
14
+ import ValueBox from './ValueBox.svelte';
15
+
16
+ let nextPayoutDate = $state<null | ZonedDateTime>(null);
17
+ let payoutCountdownMs = $state(0);
18
+
19
+ // $effect (not top-level script) because getLocalTimeZone() reads the runtime's zone; running
20
+ // this during SSR would compute the server's zone instead of the browser's.
21
+ $effect(() => {
22
+ const zone = getLocalTimeZone();
23
+ const firstOfThisMonth = today(zone).set({ day: 1 });
24
+ const target = toZoned(firstOfThisMonth.add({ months: 1 }), zone);
25
+ nextPayoutDate = target;
26
+
27
+ const tick = () => {
28
+ payoutCountdownMs = Math.max(0, target.compare(now(zone)));
29
+ };
30
+ tick();
31
+ const interval = setInterval(tick, 1000);
32
+ return () => clearInterval(interval);
33
+ });
34
+
35
+ const payoutCountdownText = $derived.by(() => {
36
+ const totalSeconds = Math.floor(payoutCountdownMs / 1000);
37
+ const pad = (n: number) => String(n).padStart(2, '0');
38
+ return [
39
+ Math.floor(totalSeconds / 3600),
40
+ Math.floor((totalSeconds % 3600) / 60),
41
+ totalSeconds % 60,
42
+ ]
43
+ .map(pad)
44
+ .join(':');
45
+ });
46
+ </script>
47
+
48
+ <ValueBox
49
+ label="Next payout date"
50
+ value={nextPayoutDate ? Datetime.formatLocalDateNum(nextPayoutDate) : '—'}
51
+ />
52
+ <ValueBox label="Time remaining" value={payoutCountdownText} />
@@ -0,0 +1,103 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from 'svelte';
3
+
4
+ import Card from '@zeyolabs/ui/card/Card.svelte';
5
+
6
+ let {
7
+ chart,
8
+ class: className = '',
9
+ delta,
10
+ label,
11
+ loading = false,
12
+ numerals = 'display',
13
+ sub,
14
+ value,
15
+ }: {
16
+ /** Small visual under the value/sub — a sparkline SVG, typically. */
17
+ chart?: Snippet;
18
+ class?: string;
19
+ /** Up/down/neutral change badge next to the value — owns its own color coding, so
20
+ * callers don't each reimplement the up=green/down=red/neutral=muted logic. */
21
+ delta?: { dir: 'down' | 'neutral' | 'up'; pct: string };
22
+ label: Snippet;
23
+ /** Loading ring on the card while its value reloads; drive it from `pendingFlag()`. */
24
+ loading?: boolean;
25
+ /** Type treatment for the value. `display` (default) is the DM Sans heading face; `plain`
26
+ * keeps the body sans at a slightly smaller size, for dense metric grids where a row of
27
+ * display numerals reads too loud. */
28
+ numerals?: 'display' | 'plain';
29
+ sub?: Snippet;
30
+ value: Snippet;
31
+ } = $props();
32
+ </script>
33
+
34
+ <Card class="flex flex-col gap-3.5 min-h-27 py-5 px-5.5 {className}" hover {loading}>
35
+ <div class="eyebrow">{@render label()}</div>
36
+ <div class="stat-num-row">
37
+ <div class="stat-num" data-numerals={numerals}>{@render value()}</div>
38
+ {#if delta}
39
+ <span class="stat-delta" data-dir={delta.dir}>{delta.pct}</span>
40
+ {/if}
41
+ </div>
42
+ {#if sub}<div class="stat-sub">{@render sub()}</div>{/if}
43
+ {#if chart}<div class="stat-chart">{@render chart()}</div>{/if}
44
+ </Card>
45
+
46
+ <style>
47
+ .eyebrow {
48
+ font-size: 11px;
49
+ font-weight: 400;
50
+ letter-spacing: 0.05em;
51
+ text-transform: uppercase;
52
+ color: var(--txs);
53
+ line-height: 1;
54
+ }
55
+ .stat-num-row {
56
+ display: flex;
57
+ align-items: baseline;
58
+ justify-content: space-between;
59
+ gap: var(--spacing-sm);
60
+ }
61
+ .stat-num {
62
+ font-family: var(--font-heading);
63
+ font-size: 32px;
64
+ font-weight: 400;
65
+ letter-spacing: -1px;
66
+ color: var(--tx);
67
+ line-height: 1;
68
+ font-variant-numeric: tabular-nums;
69
+ }
70
+ .stat-num[data-numerals='plain'] {
71
+ font-family: inherit;
72
+ font-size: 32px;
73
+ font-weight: 400;
74
+ letter-spacing: -0.01em;
75
+ }
76
+ .stat-sub {
77
+ font-size: 11px;
78
+ font-weight: 400;
79
+ color: var(--txs);
80
+ font-variant-numeric: tabular-nums;
81
+ letter-spacing: -0.005em;
82
+ }
83
+ .stat-delta {
84
+ font-size: 11px;
85
+ font-weight: 400;
86
+ padding: 2px 6px;
87
+ border-radius: var(--radius-full);
88
+ letter-spacing: -0.005em;
89
+ background: var(--sf);
90
+ color: var(--txt);
91
+ }
92
+ .stat-delta[data-dir='up'] {
93
+ background: #ecfdf5;
94
+ color: var(--ok);
95
+ }
96
+ .stat-delta[data-dir='down'] {
97
+ background: #fef2f2;
98
+ color: var(--err);
99
+ }
100
+ .stat-chart {
101
+ margin-top: var(--spacing-xs);
102
+ }
103
+ </style>
@@ -0,0 +1,38 @@
1
+ <!--
2
+ Button-height bordered box showing one value, optionally captioned — sits inline beside a
3
+ Button (a payout amount, a countdown). `emphasis` draws it as the selected/result value.
4
+ -->
5
+ <script lang="ts">
6
+ import Span from '../text/Span.svelte';
7
+
8
+ let {
9
+ emphasis = false,
10
+ label,
11
+ value,
12
+ }: {
13
+ emphasis?: boolean;
14
+ /** Small uppercase caption under the value. */
15
+ label?: string;
16
+ value: string;
17
+ } = $props();
18
+ </script>
19
+
20
+ <div
21
+ class="flex flex-col items-center justify-center h-10 px-3.5 rounded-md box-border select-none {label
22
+ ? 'min-w-24'
23
+ : 'min-w-32'} {emphasis ? 'border-2 border-(--tx) bg-(--ch)' : 'border border-(--bd)'}"
24
+ >
25
+ {#if label}
26
+ <Span class="tracking-[-0.2px] leading-[1.2] tabular-nums">{value}</Span>
27
+ <Span class="xs uppercase tracking-wider leading-[1.2]" color="tertiary">{label}</Span>
28
+ {:else}
29
+ <Span
30
+ class="tracking-[-0.3px] tabular-nums"
31
+ bold={emphasis}
32
+ color={emphasis ? undefined : 'secondary'}
33
+ size="lg"
34
+ >
35
+ {value}
36
+ </Span>
37
+ {/if}
38
+ </div>
@@ -0,0 +1,176 @@
1
+ <script lang="ts">
2
+ import type { BackgroundColorClass, StatusColor } from '../schema';
3
+ import type { StatusRowHeight, TickDensity, TickLabelSize } from './types';
4
+
5
+ export type StatusRowSlotValue = {
6
+ color: StatusColor;
7
+ label?: string;
8
+ };
9
+
10
+ // Shared by every slot — real, empty, interactive, or not.
11
+ const baseSlotClass = 'min-w-0 flex-1 rounded-[1px]';
12
+
13
+ const heightClass: Record<StatusRowHeight, string> = {
14
+ 10: 'h-[10px]',
15
+ 20: 'h-[20px]',
16
+ 30: 'h-[30px]',
17
+ 40: 'h-[40px]',
18
+ 50: 'h-[50px]',
19
+ };
20
+
21
+ const tickLabelSizePresets: Record<TickLabelSize, { labelClass: string; spacingClass: string }> =
22
+ {
23
+ large: { labelClass: 'sm', spacingClass: 'mt-1.5' },
24
+ medium: { labelClass: 'xs', spacingClass: 'mt-1' },
25
+ small: { labelClass: 'xs', spacingClass: 'mt-0.5' },
26
+ };
27
+
28
+ const tickDensityPresets: Record<TickDensity, { markClass: string; tickCount: number }> = {
29
+ dense: { markClass: 'h-1 w-px', tickCount: 8 },
30
+ light: { markClass: 'h-1 w-px', tickCount: 3 },
31
+ normal: { markClass: 'h-1.5 w-px', tickCount: 5 },
32
+ };
33
+
34
+ const range = (length: number) => [...Array(length).keys()];
35
+
36
+ // Converts between a slot's array position and its actual key, anchored at `latestKey` (the
37
+ // newest real key, at array position maxSlots - 1) and spaced by `slotInterval` — shared by slot
38
+ // placement and tick-label computation so both agree on where a given timestamp falls.
39
+ const indexToKey = (index: number, latestKey: number, slotInterval: number) =>
40
+ latestKey - (maxSlots - 1 - index) * slotInterval;
41
+ const keyToIndex = (key: number, latestKey: number, slotInterval: number) =>
42
+ maxSlots - 1 - Math.round((latestKey - key) / slotInterval);
43
+
44
+ /**
45
+ * A fixed-width row of `maxSlots` status-colored segments, right-aligned to the newest key, with
46
+ * an optional axis below. `slots`' keys must form an arithmetic sequence with common difference:
47
+ *
48
+ * `slotInterval` — key(i+1) = key(i) + slotInterval
49
+ *
50
+ * A position with no matching key renders as an empty placeholder.
51
+ */
52
+ let {
53
+ backgroundClass = {
54
+ error: 'bg-[var(--err)]',
55
+ ok: 'bg-[var(--ok)]',
56
+ warning: 'bg-[var(--w)]',
57
+ },
58
+ formatTick,
59
+ height = 30,
60
+ maxSlots = 100,
61
+ onSelect,
62
+ selected,
63
+ slotInterval,
64
+ slots,
65
+ tickDensity = 'normal',
66
+ tickLabelSize = 'medium',
67
+ }: {
68
+ // Override to point each status at different design tokens; see BackgroundColorClass.
69
+ backgroundClass?: Record<StatusColor, BackgroundColorClass>;
70
+ // slot key -> tick label
71
+ // omit/null to render no axis at all
72
+ formatTick?: ((key: number) => string) | null;
73
+ height?: StatusRowHeight;
74
+ maxSlots?: number;
75
+ // slot key -> onSelect callback
76
+ // omit/null to render slots as non-interactive
77
+ onSelect?: ((key: number) => void) | null;
78
+ selected?: number;
79
+ // The expected gap between consecutive slot keys (e.g. the bucket interval in ms)
80
+ slotInterval: number;
81
+ // slot key -> (color, label)
82
+ // the slot key should correspond exactly with onSelect and formatTick and does not imply the actual
83
+ // relative position of the rendered slots due to potential gaps
84
+ slots: Map<number, StatusRowSlotValue>;
85
+ tickDensity?: TickDensity;
86
+ tickLabelSize?: TickLabelSize;
87
+ } = $props();
88
+
89
+ const orderedSlots = $derived([...slots.entries()].sort(([a], [b]) => a - b));
90
+
91
+ // One entry per rendered position (length `maxSlots`): undefined for empty positions (no history
92
+ // yet, or a gap in the data), the real [key, value] pair everywhere else.
93
+ const paddedSlots = $derived.by(() => {
94
+ const result: ([number, StatusRowSlotValue] | undefined)[] = Array(maxSlots).fill(undefined);
95
+ if (orderedSlots.length === 0) return result;
96
+ const [latestKey] = orderedSlots[orderedSlots.length - 1];
97
+ for (const entry of orderedSlots) {
98
+ const arrayIndex = keyToIndex(entry[0], latestKey, slotInterval);
99
+ if (arrayIndex >= 0 && arrayIndex < maxSlots) result[arrayIndex] = entry;
100
+ }
101
+ return result;
102
+ });
103
+
104
+ // `tickDensity`'s tick count, evenly spaced across the full `maxSlots` grid (including any empty
105
+ // left-padding).
106
+ const ticks = $derived.by(() => {
107
+ const tickCount = tickDensityPresets[tickDensity].tickCount;
108
+ if (!formatTick || orderedSlots.length === 0 || tickCount < 2 || maxSlots < 2) return [];
109
+ const [latestKey] = orderedSlots[orderedSlots.length - 1];
110
+ return range(tickCount).map((tickNumber) => {
111
+ const fractionAcrossGrid = tickNumber / (tickCount - 1);
112
+ const slotIndex = Math.round(fractionAcrossGrid * (maxSlots - 1));
113
+ return {
114
+ label: formatTick(indexToKey(slotIndex, latestKey, slotInterval)),
115
+ positionPercent: (slotIndex / (maxSlots - 1)) * 100,
116
+ };
117
+ });
118
+ });
119
+ </script>
120
+
121
+ <div>
122
+ <div class="flex {heightClass[height]} items-stretch gap-px">
123
+ {#each range(maxSlots) as index (index)}
124
+ {@const slot = paddedSlots[index]}
125
+ {#if slot}
126
+ {@const [key, value] = slot}
127
+ {@const isDeselected = selected !== undefined && selected !== key}
128
+ {@const slotColor = backgroundClass[value.color]}
129
+ {#if onSelect}
130
+ <button
131
+ class="{baseSlotClass} cursor-pointer {slotColor} transition-opacity hover:opacity-80"
132
+ class:opacity-35={isDeselected}
133
+ aria-label={value.label}
134
+ onclick={() => onSelect(key)}
135
+ type="button"
136
+ ></button>
137
+ {:else}
138
+ <div
139
+ class="{baseSlotClass} {slotColor}"
140
+ class:opacity-35={isDeselected}
141
+ title={value.label}
142
+ ></div>
143
+ {/if}
144
+ {:else}
145
+ <div class="{baseSlotClass} bg-[var(--bds)] opacity-40"></div>
146
+ {/if}
147
+ {/each}
148
+ </div>
149
+ <!-- Axis: tick marks + labels below the bar -->
150
+ {#if ticks.length > 0}
151
+ <div class="relative h-3 {tickLabelSizePresets[tickLabelSize].spacingClass}">
152
+ {#each ticks as tick, index (index)}
153
+ <!-- tick mark -->
154
+ <span
155
+ style="--tick-left: {tick.positionPercent}%;"
156
+ class="absolute top-0 left-[var(--tick-left)] w-px -translate-x-1/2 bg-[var(--bd)] {tickDensityPresets[
157
+ tickDensity
158
+ ].markClass}"
159
+ ></span>
160
+ <!-- tick label -->
161
+ <span
162
+ style="--tick-left: {tick.positionPercent}%;"
163
+ class="absolute top-2 left-[var(--tick-left)] tabular-nums whitespace-nowrap text-[var(--txt)] {tickLabelSizePresets[
164
+ tickLabelSize
165
+ ].labelClass} {index === 0
166
+ ? 'translate-x-0'
167
+ : index === ticks.length - 1
168
+ ? '-translate-x-full'
169
+ : '-translate-x-1/2'}"
170
+ >
171
+ {tick.label}
172
+ </span>
173
+ {/each}
174
+ </div>
175
+ {/if}
176
+ </div>
@@ -0,0 +1,5 @@
1
+ export type StatusRowHeight = 10 | 20 | 30 | 40 | 50;
2
+
3
+ export type TickLabelSize = 'large' | 'medium' | 'small';
4
+
5
+ export type TickDensity = 'dense' | 'light' | 'normal';
@@ -0,0 +1,34 @@
1
+ <script lang="ts">
2
+ import { Checkbox } from '@zeyolabs/ui/form/primitives';
3
+
4
+ /**
5
+ * Content for a table's select-all header cell — place inside a <TableCell> (or a
6
+ * GroupedGrid column's `headerCell`, which already provides one). Pair with `SelectRowCell`.
7
+ */
8
+ let {
9
+ allSelected,
10
+ onToggleAll,
11
+ someSelected = false,
12
+ }: {
13
+ allSelected: boolean;
14
+ onToggleAll: () => void;
15
+ someSelected?: boolean;
16
+ } = $props();
17
+ </script>
18
+
19
+ <div class="select-cell">
20
+ <Checkbox
21
+ aria-label="Select all rows"
22
+ checked={allSelected}
23
+ indeterminate={!allSelected && someSelected}
24
+ onCheckedChange={onToggleAll}
25
+ />
26
+ </div>
27
+
28
+ <style>
29
+ .select-cell {
30
+ display: flex;
31
+ align-items: center;
32
+ justify-content: center;
33
+ }
34
+ </style>
@@ -0,0 +1,25 @@
1
+ <script lang="ts">
2
+ import SelectAllCell from './SelectAllCell.svelte';
3
+ import TableCell from './TableCell.svelte';
4
+
5
+ /**
6
+ * SelectAllCell pre-wrapped in its own fixed-width <TableCell> — drop directly inside
7
+ * <TableRow head>, no manual width/padding needed. Use SelectAllCell directly instead only
8
+ * inside a GroupedGrid column (its headerCell already provides the TableCell wrapper).
9
+ */
10
+ let {
11
+ allSelected,
12
+ onToggleAll,
13
+ someSelected = false,
14
+ stickyLeft = '0px',
15
+ }: {
16
+ allSelected: boolean;
17
+ onToggleAll: () => void;
18
+ someSelected?: boolean;
19
+ stickyLeft?: string;
20
+ } = $props();
21
+ </script>
22
+
23
+ <TableCell style="width: 40px; padding: 0 8px 0 16px;" {stickyLeft}>
24
+ <SelectAllCell {allSelected} {onToggleAll} {someSelected} />
25
+ </TableCell>
@@ -0,0 +1,31 @@
1
+ <script lang="ts">
2
+ import { Checkbox } from '@zeyolabs/ui/form/primitives';
3
+
4
+ /**
5
+ * Content for a table's select-row body cell — place inside a <TableCell> (or a
6
+ * GroupedGrid column's `cell`, which already provides one). Pair with `SelectAllCell`.
7
+ */
8
+ let {
9
+ label = 'row',
10
+ onToggle,
11
+ selected,
12
+ }: {
13
+ /** Used in the checkbox's aria-label, e.g. "Select {label}" — pass something identifying
14
+ * (a name, an id) when available; falls back to a generic "row". */
15
+ label?: string;
16
+ onToggle: () => void;
17
+ selected: boolean;
18
+ } = $props();
19
+ </script>
20
+
21
+ <div class="select-cell">
22
+ <Checkbox aria-label={`Select ${label}`} checked={selected} onCheckedChange={onToggle} />
23
+ </div>
24
+
25
+ <style>
26
+ .select-cell {
27
+ display: flex;
28
+ align-items: center;
29
+ justify-content: center;
30
+ }
31
+ </style>
@@ -0,0 +1,25 @@
1
+ <script lang="ts">
2
+ import SelectRowCell from './SelectRowCell.svelte';
3
+ import TableCell from './TableCell.svelte';
4
+
5
+ /**
6
+ * SelectRowCell pre-wrapped in its own fixed-width <TableCell> — drop directly inside
7
+ * <TableRow>, no manual width/padding needed. Use SelectRowCell directly instead only
8
+ * inside a GroupedGrid column (its cell already provides the TableCell wrapper).
9
+ */
10
+ let {
11
+ label = 'row',
12
+ onToggle,
13
+ selected,
14
+ stickyLeft = '0px',
15
+ }: {
16
+ label?: string;
17
+ onToggle: () => void;
18
+ selected: boolean;
19
+ stickyLeft?: string;
20
+ } = $props();
21
+ </script>
22
+
23
+ <TableCell style="width: 40px; padding: 0 8px 0 16px;" {stickyLeft} stopPropagation>
24
+ <SelectRowCell {label} {onToggle} {selected} />
25
+ </TableCell>