@zeyolabs/ui 0.0.0-stage → 2026.11.5
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.
- package/README.md +43 -2
- package/back-button/BackButton.svelte +26 -0
- package/badge/Badge.svelte +73 -0
- package/badge/PromoBadge.svelte +319 -0
- package/badge/color.ts +10 -0
- package/bar/Bar.svelte +63 -0
- package/base.css +47 -0
- package/boundary/Boundary.svelte +59 -0
- package/boundary/BoundaryFailed.svelte +40 -0
- package/boundary/PendingTracker.svelte +14 -0
- package/boundary/pending-context.ts +15 -0
- package/boundary/pending-flag.svelte.ts +33 -0
- package/boundary/report-boundary-error.ts +13 -0
- package/card/Card.svelte +239 -0
- package/card/CardBody.svelte +41 -0
- package/card/CardFooter.svelte +36 -0
- package/card/CardHeader.svelte +36 -0
- package/copy/CopyArea.svelte +37 -0
- package/copy/CopyButton.svelte +59 -0
- package/copy/copy-state.svelte.ts +23 -0
- package/copy/types.ts +1 -0
- package/dialog/ConfirmDialog.svelte +61 -0
- package/dialog/Dialog.svelte +31 -0
- package/dialog/DialogBody.svelte +88 -0
- package/dialog/DialogCloseButton.svelte +26 -0
- package/dialog/DialogFooter.svelte +23 -0
- package/dialog/DialogTrigger.svelte +15 -0
- package/distribution-bar/DistributionBar.svelte +37 -0
- package/drawer/Drawer.svelte +31 -0
- package/drawer/DrawerBody.svelte +61 -0
- package/empty-state/EmptyState.svelte +74 -0
- package/error/ErrorPage.svelte +54 -0
- package/eyebrow/Eyebrow.svelte +10 -0
- package/faq/FAQList.svelte +89 -0
- package/filter/FilterChipGroup.svelte +78 -0
- package/filter/FilterOptionList.svelte +188 -0
- package/filter/FilterPopover.svelte +122 -0
- package/filter/filter-draft.svelte.ts +25 -0
- package/form/Button.svelte +73 -0
- package/form/Field.svelte +111 -0
- package/form/FieldLabel.svelte +19 -0
- package/form/Form.svelte +133 -0
- package/form/PhoneField.svelte +214 -0
- package/form/UnsavedBar.svelte +22 -0
- package/form/field-view.svelte.ts +213 -0
- package/form/fields/CheckboxField.svelte +85 -0
- package/form/fields/Combobox.svelte +327 -0
- package/form/fields/ComboboxAction.svelte +16 -0
- package/form/fields/DateField.svelte +31 -0
- package/form/fields/DateRangeField.svelte +188 -0
- package/form/fields/DateRangePresetField.svelte +119 -0
- package/form/fields/EmailField.svelte +63 -0
- package/form/fields/FileField.svelte +145 -0
- package/form/fields/HexColorField.svelte +83 -0
- package/form/fields/IntervalField.svelte +100 -0
- package/form/fields/MessageField.svelte +99 -0
- package/form/fields/NumberField.svelte +64 -0
- package/form/fields/Option.svelte +48 -0
- package/form/fields/OptionRegistrar.svelte +15 -0
- package/form/fields/PasswordField.svelte +44 -0
- package/form/fields/RadioField.svelte +60 -0
- package/form/fields/RichTextField.svelte +221 -0
- package/form/fields/SelectField.svelte +216 -0
- package/form/fields/SliderField.svelte +182 -0
- package/form/fields/SwitchField.svelte +102 -0
- package/form/fields/TextField.svelte +72 -0
- package/form/fields/TimeField.svelte +31 -0
- package/form/fields/index.ts +19 -0
- package/form/fields/select-field-context.ts +21 -0
- package/form/index.ts +21 -0
- package/form/primitives/Checkbox.svelte +103 -0
- package/form/primitives/DateInput.svelte +51 -0
- package/form/primitives/IconInputWrapper.svelte +40 -0
- package/form/primitives/Input.svelte +47 -0
- package/form/primitives/SearchBar.svelte +37 -0
- package/form/primitives/Select.svelte +139 -0
- package/form/primitives/TextArea.svelte +51 -0
- package/form/primitives/index.ts +6 -0
- package/gallery/ImageGallery.svelte +133 -0
- package/gallery/flickity-fullscreen.d.ts +2 -0
- package/grouped-grid/GroupedGrid.svelte +143 -0
- package/grouped-grid/types.ts +25 -0
- package/layout/Cluster.svelte +92 -0
- package/layout/Container.svelte +9 -0
- package/layout/Grid.svelte +131 -0
- package/layout/Section.svelte +146 -0
- package/layout/Shell.svelte +32 -0
- package/layout/SplitShell.svelte +47 -0
- package/layout/Stack.svelte +78 -0
- package/list-row/ListRow.svelte +77 -0
- package/menu/MenuButton.svelte +101 -0
- package/mini-stat/MiniStat.svelte +13 -0
- package/package.json +169 -5
- package/page-hero/PageHero.svelte +35 -0
- package/pagination/Pagination.svelte +44 -0
- package/pagination/finder-pagination.svelte.ts +55 -0
- package/pagination/finder-search.svelte.ts +292 -0
- package/percentage-ring/PercentageRing.svelte +76 -0
- package/percentage-ring/types.ts +1 -0
- package/popover/InfoTip.svelte +36 -0
- package/popover/Popover.svelte +157 -0
- package/query-state/QueryState.svelte +42 -0
- package/schema.ts +20 -0
- package/skeleton/Skeleton.svelte +86 -0
- package/skeleton/SkeletonButton.svelte +27 -0
- package/skeleton/SkeletonCard.svelte +49 -0
- package/skeleton/SkeletonCircle.svelte +25 -0
- package/skeleton/SkeletonField.svelte +19 -0
- package/skeleton/SkeletonRow.svelte +47 -0
- package/skeleton/SkeletonText.svelte +46 -0
- package/skeleton/TableSkeleton.svelte +60 -0
- package/spacing.css +32 -0
- package/stat/NextPayoutCountdown.svelte +52 -0
- package/stat/Stat.svelte +103 -0
- package/stat/ValueBox.svelte +38 -0
- package/status-row/StatusRow.svelte +176 -0
- package/status-row/types.ts +5 -0
- package/table/SelectAllCell.svelte +34 -0
- package/table/SelectAllTableCell.svelte +25 -0
- package/table/SelectRowCell.svelte +31 -0
- package/table/SelectRowTableCell.svelte +25 -0
- package/table/SelectionBar.svelte +68 -0
- package/table/SelectionOverlay.svelte +83 -0
- package/table/Table.svelte +64 -0
- package/table/TableCell.svelte +185 -0
- package/table/TableRow.svelte +86 -0
- package/table/index.ts +9 -0
- package/table/selection.svelte.ts +79 -0
- package/tabs/TabBlock.svelte +56 -0
- package/tabs/TabButton.svelte +33 -0
- package/template.css +1393 -0
- package/text/Span.svelte +83 -0
- package/text/Text.svelte +94 -0
- package/text/Title.svelte +75 -0
- package/text/color.ts +41 -0
- package/theme/theme.svelte.ts +33 -0
- package/tokens.css +62 -0
- package/typography.css +164 -0
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
|
|
4
|
+
import { ChevronDown, ChevronsUpDown, ChevronUp } from '@lucide/svelte';
|
|
5
|
+
import { getContext } from 'svelte';
|
|
6
|
+
|
|
7
|
+
let {
|
|
8
|
+
align = 'left',
|
|
9
|
+
children,
|
|
10
|
+
colspan,
|
|
11
|
+
compact = false,
|
|
12
|
+
mono = false,
|
|
13
|
+
muted = false,
|
|
14
|
+
onSort,
|
|
15
|
+
sortDirection = null,
|
|
16
|
+
stickyLeft,
|
|
17
|
+
stopPropagation = false,
|
|
18
|
+
style = '',
|
|
19
|
+
valign = 'middle',
|
|
20
|
+
}: {
|
|
21
|
+
align?: 'left' | 'right';
|
|
22
|
+
children?: Snippet;
|
|
23
|
+
colspan?: number;
|
|
24
|
+
// Tighter padding for a dense data grid (e.g. a drill-down table) — opt in per usage, the
|
|
25
|
+
// default stays the general-purpose spacing every other Table consumer already renders at.
|
|
26
|
+
compact?: boolean;
|
|
27
|
+
mono?: boolean;
|
|
28
|
+
muted?: boolean;
|
|
29
|
+
// Head cell only. Presence makes the header clickable; caller owns the actual sort
|
|
30
|
+
// state/logic and passes the current direction back via `sortDirection`.
|
|
31
|
+
onSort?: () => void;
|
|
32
|
+
sortDirection?: 'asc' | 'desc' | null;
|
|
33
|
+
// A CSS length (must be a px value, e.g. '0px'/'32px') — pins this cell via
|
|
34
|
+
// position: sticky at that left offset. Apply to the matching header AND body cell for
|
|
35
|
+
// a given column. See GroupedGrid's `sticky` column flag for automatic offset math.
|
|
36
|
+
stickyLeft?: string;
|
|
37
|
+
stopPropagation?: boolean;
|
|
38
|
+
style?: string;
|
|
39
|
+
valign?: 'middle' | 'top';
|
|
40
|
+
} = $props();
|
|
41
|
+
|
|
42
|
+
const isHead = getContext<boolean>('table:head');
|
|
43
|
+
const isBoldHead = getContext<boolean>('table:head-bold');
|
|
44
|
+
const sticky = $derived(stickyLeft != null);
|
|
45
|
+
|
|
46
|
+
function handleClick(e: MouseEvent) {
|
|
47
|
+
e.stopPropagation();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function handleHeadClick(e: MouseEvent) {
|
|
51
|
+
if (stopPropagation) e.stopPropagation();
|
|
52
|
+
onSort?.();
|
|
53
|
+
}
|
|
54
|
+
</script>
|
|
55
|
+
|
|
56
|
+
{#if isHead}
|
|
57
|
+
<th
|
|
58
|
+
{style}
|
|
59
|
+
style:left={stickyLeft}
|
|
60
|
+
class:bold-head={isBoldHead}
|
|
61
|
+
class:compact
|
|
62
|
+
class:num={align === 'right'}
|
|
63
|
+
class:sortable={!!onSort}
|
|
64
|
+
class:sticky
|
|
65
|
+
onclick={onSort || stopPropagation ? handleHeadClick : undefined}
|
|
66
|
+
>
|
|
67
|
+
{#if onSort}
|
|
68
|
+
<span class="sort-label">
|
|
69
|
+
{@render children?.()}
|
|
70
|
+
{#if sortDirection === 'asc'}
|
|
71
|
+
<ChevronUp size={11} />
|
|
72
|
+
{:else if sortDirection === 'desc'}
|
|
73
|
+
<ChevronDown size={11} />
|
|
74
|
+
{:else}
|
|
75
|
+
<span class="sort-icon-idle"><ChevronsUpDown size={11} /></span>
|
|
76
|
+
{/if}
|
|
77
|
+
</span>
|
|
78
|
+
{:else}
|
|
79
|
+
{@render children?.()}
|
|
80
|
+
{/if}
|
|
81
|
+
</th>
|
|
82
|
+
{:else}
|
|
83
|
+
<!-- svelte-ignore a11y_click_events_have_key_events a11y_no_noninteractive_element_interactions -->
|
|
84
|
+
<td
|
|
85
|
+
{style}
|
|
86
|
+
style:left={stickyLeft}
|
|
87
|
+
class:compact
|
|
88
|
+
class:mono
|
|
89
|
+
class:muted
|
|
90
|
+
class:num={align === 'right'}
|
|
91
|
+
class:sticky
|
|
92
|
+
class:top={valign === 'top'}
|
|
93
|
+
{colspan}
|
|
94
|
+
onclick={stopPropagation ? handleClick : undefined}
|
|
95
|
+
>
|
|
96
|
+
{@render children?.()}
|
|
97
|
+
</td>
|
|
98
|
+
{/if}
|
|
99
|
+
|
|
100
|
+
<style>
|
|
101
|
+
th {
|
|
102
|
+
text-align: left;
|
|
103
|
+
font-size: 11px;
|
|
104
|
+
font-weight: 400;
|
|
105
|
+
letter-spacing: 0.05em;
|
|
106
|
+
text-transform: uppercase;
|
|
107
|
+
color: var(--txt);
|
|
108
|
+
padding: 13px 18px;
|
|
109
|
+
border-bottom: 1px solid var(--bds);
|
|
110
|
+
background: var(--sf);
|
|
111
|
+
white-space: nowrap;
|
|
112
|
+
}
|
|
113
|
+
th.num {
|
|
114
|
+
text-align: right;
|
|
115
|
+
}
|
|
116
|
+
/* Same heading font/weight as `Title` (var(--font-heading)), scaled down for a table row —
|
|
117
|
+
for a header that needs to read as more prominent than the default small tracked-out
|
|
118
|
+
uppercase label. */
|
|
119
|
+
th.bold-head {
|
|
120
|
+
font-family: var(--font-heading);
|
|
121
|
+
font-size: 15px;
|
|
122
|
+
font-weight: 400;
|
|
123
|
+
letter-spacing: normal;
|
|
124
|
+
text-transform: none;
|
|
125
|
+
color: var(--tx);
|
|
126
|
+
}
|
|
127
|
+
th.compact {
|
|
128
|
+
padding: 7px 10px;
|
|
129
|
+
}
|
|
130
|
+
th.sortable {
|
|
131
|
+
cursor: pointer;
|
|
132
|
+
user-select: none;
|
|
133
|
+
}
|
|
134
|
+
th.sortable:hover {
|
|
135
|
+
color: var(--tx);
|
|
136
|
+
}
|
|
137
|
+
.sort-label {
|
|
138
|
+
display: inline-flex;
|
|
139
|
+
align-items: center;
|
|
140
|
+
gap: 3px;
|
|
141
|
+
}
|
|
142
|
+
.sort-icon-idle {
|
|
143
|
+
display: inline-flex;
|
|
144
|
+
opacity: 0.4;
|
|
145
|
+
}
|
|
146
|
+
th.sticky,
|
|
147
|
+
td.sticky {
|
|
148
|
+
position: sticky;
|
|
149
|
+
z-index: 1;
|
|
150
|
+
}
|
|
151
|
+
th.sticky {
|
|
152
|
+
z-index: 2;
|
|
153
|
+
background: var(--sf);
|
|
154
|
+
}
|
|
155
|
+
td.sticky {
|
|
156
|
+
background: var(--row-bg, var(--bg));
|
|
157
|
+
}
|
|
158
|
+
td {
|
|
159
|
+
padding: 14px 18px;
|
|
160
|
+
font-size: 13px;
|
|
161
|
+
color: var(--tx);
|
|
162
|
+
background: var(--row-bg, var(--bg));
|
|
163
|
+
border-bottom: 1px solid var(--bds);
|
|
164
|
+
vertical-align: middle;
|
|
165
|
+
}
|
|
166
|
+
td.compact {
|
|
167
|
+
padding: 6px 10px;
|
|
168
|
+
}
|
|
169
|
+
td.top {
|
|
170
|
+
vertical-align: top;
|
|
171
|
+
}
|
|
172
|
+
td.num {
|
|
173
|
+
text-align: right;
|
|
174
|
+
font-variant-numeric: tabular-nums;
|
|
175
|
+
}
|
|
176
|
+
td.muted {
|
|
177
|
+
color: var(--txs);
|
|
178
|
+
font-size: 13px;
|
|
179
|
+
}
|
|
180
|
+
td.mono {
|
|
181
|
+
font-family: var(--font-mono);
|
|
182
|
+
font-variant-numeric: tabular-nums;
|
|
183
|
+
font-size: 13px;
|
|
184
|
+
}
|
|
185
|
+
</style>
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
|
|
4
|
+
import { setContext } from 'svelte';
|
|
5
|
+
|
|
6
|
+
let {
|
|
7
|
+
boldHeader = false,
|
|
8
|
+
children,
|
|
9
|
+
elevated = false,
|
|
10
|
+
head = false,
|
|
11
|
+
hoverable = false,
|
|
12
|
+
onclick,
|
|
13
|
+
selected = false,
|
|
14
|
+
sticky = false,
|
|
15
|
+
warning = false,
|
|
16
|
+
}: {
|
|
17
|
+
/** Head row only — renders column labels in the shared heading font/weight (same
|
|
18
|
+
* treatment as `Title`) instead of the default small uppercase tracked-out label,
|
|
19
|
+
* for a table whose header needs to read as more prominent. Opt-in — every existing
|
|
20
|
+
* Table keeps the default label style unless it asks for this. */
|
|
21
|
+
boldHeader?: boolean;
|
|
22
|
+
children: Snippet;
|
|
23
|
+
elevated?: boolean;
|
|
24
|
+
head?: boolean;
|
|
25
|
+
hoverable?: boolean;
|
|
26
|
+
onclick?: () => void;
|
|
27
|
+
selected?: boolean;
|
|
28
|
+
/** Head row only — pins it via position: sticky while the table body scrolls past.
|
|
29
|
+
* Each TableCell head cell already renders an opaque background, so no extra
|
|
30
|
+
* backdrop is needed here. */
|
|
31
|
+
sticky?: boolean;
|
|
32
|
+
/** Row-wide tint (e.g. "this row has invalid data") via a `--row-bg` custom property
|
|
33
|
+
* every TableCell's background reads — unlike `selected`, this DOES need to paint
|
|
34
|
+
* through, including sticky cells, so it's a custom property rather than a `tr`
|
|
35
|
+
* background: a `td`'s own opaque background would otherwise hide a plain `tr` tint. */
|
|
36
|
+
warning?: boolean;
|
|
37
|
+
} = $props();
|
|
38
|
+
|
|
39
|
+
// svelte-ignore state_referenced_locally
|
|
40
|
+
setContext('table:head', head);
|
|
41
|
+
// svelte-ignore state_referenced_locally
|
|
42
|
+
setContext('table:head-bold', boldHeader);
|
|
43
|
+
</script>
|
|
44
|
+
|
|
45
|
+
<tr
|
|
46
|
+
class:clickable={!!onclick}
|
|
47
|
+
class:elevated
|
|
48
|
+
class:hoverable={!onclick && hoverable}
|
|
49
|
+
class:selected
|
|
50
|
+
class:sticky
|
|
51
|
+
class:warning
|
|
52
|
+
{onclick}
|
|
53
|
+
>
|
|
54
|
+
{@render children()}
|
|
55
|
+
</tr>
|
|
56
|
+
|
|
57
|
+
<style>
|
|
58
|
+
tr.clickable,
|
|
59
|
+
tr.hoverable {
|
|
60
|
+
transition: background 0.1s ease;
|
|
61
|
+
}
|
|
62
|
+
tr.clickable {
|
|
63
|
+
cursor: pointer;
|
|
64
|
+
}
|
|
65
|
+
tr.clickable:hover,
|
|
66
|
+
tr.hoverable:hover {
|
|
67
|
+
background: var(--sf);
|
|
68
|
+
}
|
|
69
|
+
/* No background tint on `.selected` — a sticky checkbox column (TableCell's `td.sticky`)
|
|
70
|
+
always paints its own opaque `var(--bg)` so pinned content stays readable while scrolling,
|
|
71
|
+
which can't pick up a semi-transparent row tint sitting behind it. Tinting the rest of the
|
|
72
|
+
row while that one cell stayed plain background looked like a rendering bug, not a design
|
|
73
|
+
choice — the checkbox's own checked state already communicates "selected" on its own. */
|
|
74
|
+
tr.elevated {
|
|
75
|
+
position: relative;
|
|
76
|
+
z-index: 9999;
|
|
77
|
+
}
|
|
78
|
+
tr.sticky {
|
|
79
|
+
position: sticky;
|
|
80
|
+
top: 0;
|
|
81
|
+
z-index: 3;
|
|
82
|
+
}
|
|
83
|
+
tr.warning {
|
|
84
|
+
--row-bg: color-mix(in srgb, var(--w) 10%, var(--bg));
|
|
85
|
+
}
|
|
86
|
+
</style>
|
package/table/index.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { default as SelectAllCell } from './SelectAllCell.svelte';
|
|
2
|
+
export { default as SelectAllTableCell } from './SelectAllTableCell.svelte';
|
|
3
|
+
export { default as SelectionBar } from './SelectionBar.svelte';
|
|
4
|
+
export { default as SelectionOverlay } from './SelectionOverlay.svelte';
|
|
5
|
+
export { default as SelectRowCell } from './SelectRowCell.svelte';
|
|
6
|
+
export { default as SelectRowTableCell } from './SelectRowTableCell.svelte';
|
|
7
|
+
export { default as Table } from './Table.svelte';
|
|
8
|
+
export { default as TableCell } from './TableCell.svelte';
|
|
9
|
+
export { default as TableRow } from './TableRow.svelte';
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared row-selection state for a paginated, selectable list — exclusion-based so "select all N
|
|
3
|
+
* matching" never materializes the full matching set into memory. `scope: 'ids'` is the ordinary
|
|
4
|
+
* case (`ids` holds the selected rows); `scope: 'allMatching'` means "everything the current
|
|
5
|
+
* filter matches, except `ids`" — so `ids` stays small (only what's been manually deselected)
|
|
6
|
+
* regardless of how big the matching set actually is.
|
|
7
|
+
*
|
|
8
|
+
* In `'allMatching'` scope the header checkbox (`toggleAll`) is a master toggle: any click clears
|
|
9
|
+
* the whole selection rather than excluding just the visible page. Per-row checkboxes (`toggle`)
|
|
10
|
+
* are how individual rows get excluded while the rest of the matching set stays selected.
|
|
11
|
+
*/
|
|
12
|
+
export function createSelectionState() {
|
|
13
|
+
let scope = $state<'allMatching' | 'ids'>('ids');
|
|
14
|
+
let ids = $state(new Set<string>());
|
|
15
|
+
|
|
16
|
+
function toggle(id: string) {
|
|
17
|
+
const next = new Set(ids);
|
|
18
|
+
if (next.has(id)) next.delete(id);
|
|
19
|
+
else next.add(id);
|
|
20
|
+
ids = next;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function toggleAll(pageIds: string[]) {
|
|
24
|
+
if (scope === 'allMatching') {
|
|
25
|
+
// The header checkbox is a master toggle once everything matching is already selected —
|
|
26
|
+
// there's nothing "more" to select, so any click on it means "give up the whole
|
|
27
|
+
// selection," not "toggle just the visible page." Per-row checkboxes (toggle()) remain
|
|
28
|
+
// the way to exclude specific rows while keeping the rest of the matching set selected.
|
|
29
|
+
clear();
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const allSelected = pageIds.length > 0 && pageIds.every((id) => ids.has(id));
|
|
33
|
+
ids = allSelected
|
|
34
|
+
? new Set([...ids].filter((id) => !pageIds.includes(id)))
|
|
35
|
+
: new Set([...ids, ...pageIds]);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function selectAllMatching() {
|
|
39
|
+
scope = 'allMatching';
|
|
40
|
+
ids = new Set();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function clear() {
|
|
44
|
+
scope = 'ids';
|
|
45
|
+
ids = new Set();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Selected count given the total matching the current filter — feeds straight into
|
|
49
|
+
* `SelectionBar`/`SelectionOverlay`'s `count` prop. */
|
|
50
|
+
function countGiven(total: number): number {
|
|
51
|
+
return scope === 'ids' ? ids.size : Math.max(0, total - ids.size);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Is a given row currently selected, given whether it's part of the matching set at all
|
|
55
|
+
* (always true for a row actually rendered on a page that matches the active filter). */
|
|
56
|
+
function has(id: string): boolean {
|
|
57
|
+
return scope === 'ids' ? ids.has(id) : !ids.has(id);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
get allMatchingSelected() {
|
|
62
|
+
return scope === 'allMatching';
|
|
63
|
+
},
|
|
64
|
+
clear,
|
|
65
|
+
countGiven,
|
|
66
|
+
has,
|
|
67
|
+
get ids() {
|
|
68
|
+
return ids;
|
|
69
|
+
},
|
|
70
|
+
get scope() {
|
|
71
|
+
return scope;
|
|
72
|
+
},
|
|
73
|
+
selectAllMatching,
|
|
74
|
+
toggle,
|
|
75
|
+
toggleAll,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export type SelectionState = ReturnType<typeof createSelectionState>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
<script generics="V" lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
|
|
4
|
+
import { setContext } from 'svelte';
|
|
5
|
+
|
|
6
|
+
type Props = {
|
|
7
|
+
'aria-invalid'?: 'false' | 'true' | boolean;
|
|
8
|
+
children: Snippet;
|
|
9
|
+
class?: string;
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
onChange?: (value: V) => void;
|
|
12
|
+
readonly?: boolean;
|
|
13
|
+
value?: V;
|
|
14
|
+
vertical?: boolean;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
let {
|
|
18
|
+
'aria-invalid': ariaInvalid,
|
|
19
|
+
children,
|
|
20
|
+
class: className,
|
|
21
|
+
disabled = false,
|
|
22
|
+
onChange,
|
|
23
|
+
readonly = false,
|
|
24
|
+
value = $bindable(undefined),
|
|
25
|
+
vertical = false,
|
|
26
|
+
}: Props = $props();
|
|
27
|
+
|
|
28
|
+
setContext(Symbol.for('tab'), {
|
|
29
|
+
get disabled() {
|
|
30
|
+
return disabled;
|
|
31
|
+
},
|
|
32
|
+
isActive: (v: unknown) => value === v,
|
|
33
|
+
get readonly() {
|
|
34
|
+
return readonly;
|
|
35
|
+
},
|
|
36
|
+
select(v: unknown) {
|
|
37
|
+
value = v as V;
|
|
38
|
+
onChange?.(v as V);
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
</script>
|
|
42
|
+
|
|
43
|
+
<div
|
|
44
|
+
class={[
|
|
45
|
+
'tab',
|
|
46
|
+
vertical && 'tab--vertical',
|
|
47
|
+
disabled && 'tab--disabled',
|
|
48
|
+
!disabled && readonly && 'tab--readonly',
|
|
49
|
+
ariaInvalid && 'tab--invalid',
|
|
50
|
+
className,
|
|
51
|
+
]
|
|
52
|
+
.filter(Boolean)
|
|
53
|
+
.join(' ')}
|
|
54
|
+
>
|
|
55
|
+
{@render children()}
|
|
56
|
+
</div>
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
<script generics="V" lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
|
|
4
|
+
import { getContext } from 'svelte';
|
|
5
|
+
|
|
6
|
+
type TabCtx = {
|
|
7
|
+
disabled: boolean;
|
|
8
|
+
isActive: (v: unknown) => boolean;
|
|
9
|
+
readonly: boolean;
|
|
10
|
+
select: (v: unknown) => void;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
type Props = {
|
|
14
|
+
children: Snippet;
|
|
15
|
+
value: V;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
let { children, value }: Props = $props();
|
|
19
|
+
|
|
20
|
+
const ctx = getContext<TabCtx>(Symbol.for('tab'));
|
|
21
|
+
</script>
|
|
22
|
+
|
|
23
|
+
<button
|
|
24
|
+
class="tab-btn"
|
|
25
|
+
data-state={ctx.isActive(value) ? 'active' : 'inactive'}
|
|
26
|
+
onclick={() => {
|
|
27
|
+
if (ctx.disabled || ctx.readonly) return;
|
|
28
|
+
ctx.select(value);
|
|
29
|
+
}}
|
|
30
|
+
type="button"
|
|
31
|
+
>
|
|
32
|
+
{@render children()}
|
|
33
|
+
</button>
|