@nqmcreative/ui 0.1.0
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/LICENSE +21 -0
- package/README.md +507 -0
- package/cli/index.mjs +410 -0
- package/dist/actions/anchor.d.ts +29 -0
- package/dist/actions/anchor.js +122 -0
- package/dist/actions/dismissable.d.ts +44 -0
- package/dist/actions/dismissable.js +147 -0
- package/dist/components/Accordion.svelte +14 -0
- package/dist/components/Accordion.svelte.d.ts +8 -0
- package/dist/components/AccordionItem.svelte +46 -0
- package/dist/components/AccordionItem.svelte.d.ts +14 -0
- package/dist/components/Alert.svelte +88 -0
- package/dist/components/Alert.svelte.d.ts +18 -0
- package/dist/components/Avatar.svelte +58 -0
- package/dist/components/Avatar.svelte.d.ts +16 -0
- package/dist/components/AvatarGroup.svelte +17 -0
- package/dist/components/AvatarGroup.svelte.d.ts +8 -0
- package/dist/components/Badge.svelte +53 -0
- package/dist/components/Badge.svelte.d.ts +18 -0
- package/dist/components/Breadcrumb.svelte +46 -0
- package/dist/components/Breadcrumb.svelte.d.ts +14 -0
- package/dist/components/Button.svelte +94 -0
- package/dist/components/Button.svelte.d.ts +21 -0
- package/dist/components/Calendar.svelte +206 -0
- package/dist/components/Calendar.svelte.d.ts +22 -0
- package/dist/components/Card.svelte +76 -0
- package/dist/components/Card.svelte.d.ts +21 -0
- package/dist/components/Checkbox.svelte +69 -0
- package/dist/components/Checkbox.svelte.d.ts +15 -0
- package/dist/components/CheckboxGroup.svelte +109 -0
- package/dist/components/CheckboxGroup.svelte.d.ts +30 -0
- package/dist/components/Combobox.svelte +268 -0
- package/dist/components/Combobox.svelte.d.ts +29 -0
- package/dist/components/CommandPalette.svelte +226 -0
- package/dist/components/CommandPalette.svelte.d.ts +32 -0
- package/dist/components/ConfirmDialog.svelte +97 -0
- package/dist/components/ConfirmDialog.svelte.d.ts +22 -0
- package/dist/components/ContextMenu.svelte +90 -0
- package/dist/components/ContextMenu.svelte.d.ts +15 -0
- package/dist/components/DatePicker.svelte +186 -0
- package/dist/components/DatePicker.svelte.d.ts +23 -0
- package/dist/components/Divider.svelte +30 -0
- package/dist/components/Divider.svelte.d.ts +10 -0
- package/dist/components/Drawer.svelte +161 -0
- package/dist/components/Drawer.svelte.d.ts +20 -0
- package/dist/components/Dropdown.svelte +112 -0
- package/dist/components/Dropdown.svelte.d.ts +23 -0
- package/dist/components/Dropzone.svelte +226 -0
- package/dist/components/Dropzone.svelte.d.ts +32 -0
- package/dist/components/EmptyState.svelte +57 -0
- package/dist/components/EmptyState.svelte.d.ts +18 -0
- package/dist/components/Field.svelte +42 -0
- package/dist/components/Field.svelte.d.ts +16 -0
- package/dist/components/Footer.svelte +93 -0
- package/dist/components/Footer.svelte.d.ts +25 -0
- package/dist/components/Input.svelte +60 -0
- package/dist/components/Input.svelte.d.ts +18 -0
- package/dist/components/InputGroup.svelte +19 -0
- package/dist/components/InputGroup.svelte.d.ts +10 -0
- package/dist/components/Kbd.svelte +17 -0
- package/dist/components/Kbd.svelte.d.ts +8 -0
- package/dist/components/Label.svelte +16 -0
- package/dist/components/Label.svelte.d.ts +9 -0
- package/dist/components/Link.svelte +44 -0
- package/dist/components/Link.svelte.d.ts +16 -0
- package/dist/components/LocaleProvider.svelte +24 -0
- package/dist/components/LocaleProvider.svelte.d.ts +10 -0
- package/dist/components/MenuItem.svelte +58 -0
- package/dist/components/MenuItem.svelte.d.ts +18 -0
- package/dist/components/MenuSeparator.svelte +22 -0
- package/dist/components/MenuSeparator.svelte.d.ts +8 -0
- package/dist/components/Modal.svelte +114 -0
- package/dist/components/Modal.svelte.d.ts +21 -0
- package/dist/components/MultiSelect.svelte +292 -0
- package/dist/components/MultiSelect.svelte.d.ts +31 -0
- package/dist/components/Navbar.svelte +190 -0
- package/dist/components/Navbar.svelte.d.ts +33 -0
- package/dist/components/NumberInput.svelte +100 -0
- package/dist/components/NumberInput.svelte.d.ts +15 -0
- package/dist/components/Pagination.svelte +90 -0
- package/dist/components/Pagination.svelte.d.ts +15 -0
- package/dist/components/PasswordInput.svelte +104 -0
- package/dist/components/PasswordInput.svelte.d.ts +12 -0
- package/dist/components/Popover.svelte +114 -0
- package/dist/components/Popover.svelte.d.ts +19 -0
- package/dist/components/Progress.svelte +56 -0
- package/dist/components/Progress.svelte.d.ts +17 -0
- package/dist/components/Radio.svelte +55 -0
- package/dist/components/Radio.svelte.d.ts +15 -0
- package/dist/components/RadioGroup.svelte +93 -0
- package/dist/components/RadioGroup.svelte.d.ts +27 -0
- package/dist/components/SegmentedControl.svelte +88 -0
- package/dist/components/SegmentedControl.svelte.d.ts +25 -0
- package/dist/components/Select.svelte +61 -0
- package/dist/components/Select.svelte.d.ts +20 -0
- package/dist/components/Sidebar.svelte +206 -0
- package/dist/components/Sidebar.svelte.d.ts +36 -0
- package/dist/components/Skeleton.svelte +46 -0
- package/dist/components/Skeleton.svelte.d.ts +13 -0
- package/dist/components/Slider.svelte +79 -0
- package/dist/components/Slider.svelte.d.ts +19 -0
- package/dist/components/Spinner.svelte +34 -0
- package/dist/components/Spinner.svelte.d.ts +13 -0
- package/dist/components/Stat.svelte +49 -0
- package/dist/components/Stat.svelte.d.ts +16 -0
- package/dist/components/Steps.svelte +136 -0
- package/dist/components/Steps.svelte.d.ts +24 -0
- package/dist/components/Switch.svelte +64 -0
- package/dist/components/Switch.svelte.d.ts +14 -0
- package/dist/components/Table.svelte +236 -0
- package/dist/components/Table.svelte.d.ts +70 -0
- package/dist/components/Tabs.svelte +91 -0
- package/dist/components/Tabs.svelte.d.ts +23 -0
- package/dist/components/Textarea.svelte +54 -0
- package/dist/components/Textarea.svelte.d.ts +12 -0
- package/dist/components/ThemeToggle.svelte +133 -0
- package/dist/components/ThemeToggle.svelte.d.ts +20 -0
- package/dist/components/Toaster.svelte +110 -0
- package/dist/components/Toaster.svelte.d.ts +8 -0
- package/dist/components/Tooltip.svelte +33 -0
- package/dist/components/Tooltip.svelte.d.ts +12 -0
- package/dist/date.d.ts +35 -0
- package/dist/date.js +108 -0
- package/dist/fonts.css +193 -0
- package/dist/index.d.ts +105 -0
- package/dist/index.js +77 -0
- package/dist/locale.svelte.d.ts +93 -0
- package/dist/locale.svelte.js +153 -0
- package/dist/theme.css +210 -0
- package/dist/toast.svelte.d.ts +47 -0
- package/dist/toast.svelte.js +60 -0
- package/dist/tones.d.ts +48 -0
- package/dist/tones.js +209 -0
- package/package.json +349 -0
- package/registry.json +669 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { HTMLButtonAttributes } from 'svelte/elements';
|
|
3
|
+
import { type Tone } from '../tones.js';
|
|
4
|
+
export type ButtonVariant = 'solid' | 'soft' | 'outline' | 'ghost' | 'link' | 'primary';
|
|
5
|
+
export type ButtonSize = 'sm' | 'md' | 'lg' | 'xl';
|
|
6
|
+
interface Props extends HTMLButtonAttributes {
|
|
7
|
+
variant?: ButtonVariant;
|
|
8
|
+
tone?: Tone;
|
|
9
|
+
size?: ButtonSize;
|
|
10
|
+
/** Renders an `<a>` instead of a `<button>`. */
|
|
11
|
+
href?: string;
|
|
12
|
+
target?: string;
|
|
13
|
+
rel?: string;
|
|
14
|
+
loading?: boolean;
|
|
15
|
+
/** Stretch to the container's full width. */
|
|
16
|
+
block?: boolean;
|
|
17
|
+
children: Snippet;
|
|
18
|
+
}
|
|
19
|
+
declare const Button: import("svelte").Component<Props, {}, "">;
|
|
20
|
+
type Button = ReturnType<typeof Button>;
|
|
21
|
+
export default Button;
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import {
|
|
3
|
+
addDays,
|
|
4
|
+
addMonths,
|
|
5
|
+
fromISO,
|
|
6
|
+
isOutOfRange,
|
|
7
|
+
isSameDay,
|
|
8
|
+
monthGrid,
|
|
9
|
+
monthLabel,
|
|
10
|
+
toISO,
|
|
11
|
+
today,
|
|
12
|
+
weekdayNames
|
|
13
|
+
} from '../date.js';
|
|
14
|
+
import { useLocale } from '../locale.svelte.js';
|
|
15
|
+
import { focusRing, toneFill, toneRing, toneText, type Tone } from '../tones.js';
|
|
16
|
+
|
|
17
|
+
interface Props {
|
|
18
|
+
/** Bindable `YYYY-MM-DD`, or `''` for nothing selected. */
|
|
19
|
+
value?: string;
|
|
20
|
+
/** Bindable `YYYY-MM-DD` inside the month on show. */
|
|
21
|
+
month?: string;
|
|
22
|
+
/** Inclusive bounds, `YYYY-MM-DD`. */
|
|
23
|
+
min?: string;
|
|
24
|
+
max?: string;
|
|
25
|
+
/** Return true to grey out a specific day — weekends, holidays. */
|
|
26
|
+
isDisabled?: (date: Date) => boolean;
|
|
27
|
+
/** 1 = Monday (default), 0 = Sunday. */
|
|
28
|
+
weekStart?: 0 | 1;
|
|
29
|
+
tone?: Tone;
|
|
30
|
+
/** Show the "Today" shortcut under the grid. */
|
|
31
|
+
showToday?: boolean;
|
|
32
|
+
onselect?: (value: string) => void;
|
|
33
|
+
class?: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
let {
|
|
37
|
+
value = $bindable(''),
|
|
38
|
+
month = $bindable(''),
|
|
39
|
+
min,
|
|
40
|
+
max,
|
|
41
|
+
isDisabled,
|
|
42
|
+
weekStart = 1,
|
|
43
|
+
tone = 'brand',
|
|
44
|
+
showToday = true,
|
|
45
|
+
onselect,
|
|
46
|
+
class: className = ''
|
|
47
|
+
}: Props = $props();
|
|
48
|
+
|
|
49
|
+
const t = useLocale();
|
|
50
|
+
|
|
51
|
+
const selected = $derived(fromISO(value));
|
|
52
|
+
const now = today();
|
|
53
|
+
|
|
54
|
+
let view = $state(fromISO(month) ?? fromISO(value) ?? today());
|
|
55
|
+
/** The day the arrow keys are on — not necessarily the selected one. */
|
|
56
|
+
let focused = $state(fromISO(value) ?? today());
|
|
57
|
+
let grid: HTMLElement | null = $state(null);
|
|
58
|
+
|
|
59
|
+
// Follow the bound `month`/`value` when the parent changes them.
|
|
60
|
+
$effect(() => {
|
|
61
|
+
const next = fromISO(month) ?? fromISO(value);
|
|
62
|
+
if (next && (next.getMonth() !== view.getMonth() || next.getFullYear() !== view.getFullYear()))
|
|
63
|
+
view = next;
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
const days = $derived(monthGrid(view, weekStart));
|
|
67
|
+
const weekdays = $derived(weekdayNames(t.current.dateLocale, weekStart));
|
|
68
|
+
|
|
69
|
+
function blocked(date: Date) {
|
|
70
|
+
return isOutOfRange(date, min, max) || (isDisabled?.(date) ?? false);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function show(next: Date) {
|
|
74
|
+
view = next;
|
|
75
|
+
month = toISO(new Date(next.getFullYear(), next.getMonth(), 1));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function pick(date: Date) {
|
|
79
|
+
if (blocked(date)) return;
|
|
80
|
+
value = toISO(date);
|
|
81
|
+
focused = date;
|
|
82
|
+
if (date.getMonth() !== view.getMonth()) show(date);
|
|
83
|
+
onselect?.(value);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function moveFocus(next: Date) {
|
|
87
|
+
focused = next;
|
|
88
|
+
if (next.getMonth() !== view.getMonth() || next.getFullYear() !== view.getFullYear())
|
|
89
|
+
show(next);
|
|
90
|
+
queueMicrotask(() => grid?.querySelector<HTMLElement>('[data-focused="true"]')?.focus());
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function onKeydown(event: KeyboardEvent) {
|
|
94
|
+
const moves: Record<string, () => Date> = {
|
|
95
|
+
ArrowLeft: () => addDays(focused, -1),
|
|
96
|
+
ArrowRight: () => addDays(focused, 1),
|
|
97
|
+
ArrowUp: () => addDays(focused, -7),
|
|
98
|
+
ArrowDown: () => addDays(focused, 7),
|
|
99
|
+
Home: () => addDays(focused, -((focused.getDay() - weekStart + 7) % 7)),
|
|
100
|
+
End: () => addDays(focused, 6 - ((focused.getDay() - weekStart + 7) % 7)),
|
|
101
|
+
PageUp: () => addMonths(focused, event.shiftKey ? -12 : -1),
|
|
102
|
+
PageDown: () => addMonths(focused, event.shiftKey ? 12 : 1)
|
|
103
|
+
};
|
|
104
|
+
const move = moves[event.key];
|
|
105
|
+
if (move) {
|
|
106
|
+
event.preventDefault();
|
|
107
|
+
moveFocus(move());
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
111
|
+
event.preventDefault();
|
|
112
|
+
pick(focused);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
</script>
|
|
116
|
+
|
|
117
|
+
<div class="flex w-[17.5rem] flex-col gap-3 p-3 font-sans {className}">
|
|
118
|
+
<div class="flex items-center justify-between gap-2">
|
|
119
|
+
<button
|
|
120
|
+
type="button"
|
|
121
|
+
onclick={() => show(addMonths(view, -1))}
|
|
122
|
+
aria-label={t.current.previousMonth}
|
|
123
|
+
class="inline-flex size-8 items-center justify-center text-text-secondary transition-colors duration-150 hover:bg-bg-inset hover:text-text {focusRing} {toneRing[
|
|
124
|
+
tone
|
|
125
|
+
]}"
|
|
126
|
+
>
|
|
127
|
+
<svg class="size-4" viewBox="0 0 16 16" fill="none" aria-hidden="true">
|
|
128
|
+
<path d="m10 4-4 4 4 4" stroke="currentColor" stroke-width="1.6" stroke-linecap="square" />
|
|
129
|
+
</svg>
|
|
130
|
+
</button>
|
|
131
|
+
|
|
132
|
+
<span aria-live="polite" class="text-sm font-medium text-text">
|
|
133
|
+
{monthLabel(view, t.current.dateLocale)}
|
|
134
|
+
</span>
|
|
135
|
+
|
|
136
|
+
<button
|
|
137
|
+
type="button"
|
|
138
|
+
onclick={() => show(addMonths(view, 1))}
|
|
139
|
+
aria-label={t.current.nextMonth}
|
|
140
|
+
class="inline-flex size-8 items-center justify-center text-text-secondary transition-colors duration-150 hover:bg-bg-inset hover:text-text {focusRing} {toneRing[
|
|
141
|
+
tone
|
|
142
|
+
]}"
|
|
143
|
+
>
|
|
144
|
+
<svg class="size-4" viewBox="0 0 16 16" fill="none" aria-hidden="true">
|
|
145
|
+
<path d="m6 4 4 4-4 4" stroke="currentColor" stroke-width="1.6" stroke-linecap="square" />
|
|
146
|
+
</svg>
|
|
147
|
+
</button>
|
|
148
|
+
</div>
|
|
149
|
+
|
|
150
|
+
<div class="grid grid-cols-7 gap-px">
|
|
151
|
+
{#each weekdays as name, i (i)}
|
|
152
|
+
<span class="pb-1 text-center font-mono text-[10px] text-text-muted uppercase">{name}</span>
|
|
153
|
+
{/each}
|
|
154
|
+
</div>
|
|
155
|
+
|
|
156
|
+
<!-- Roving tabindex: the grid itself is never a tab stop, the focused day is. -->
|
|
157
|
+
<div
|
|
158
|
+
bind:this={grid}
|
|
159
|
+
role="grid"
|
|
160
|
+
tabindex="-1"
|
|
161
|
+
aria-label={t.current.selectDate}
|
|
162
|
+
onkeydown={onKeydown}
|
|
163
|
+
class="grid grid-cols-7 gap-px focus:outline-none"
|
|
164
|
+
>
|
|
165
|
+
{#each days as day (toISO(day))}
|
|
166
|
+
{@const outside = day.getMonth() !== view.getMonth()}
|
|
167
|
+
{@const off = blocked(day)}
|
|
168
|
+
{@const isSelected = isSameDay(day, selected)}
|
|
169
|
+
{@const isFocused = isSameDay(day, focused)}
|
|
170
|
+
<button
|
|
171
|
+
type="button"
|
|
172
|
+
role="gridcell"
|
|
173
|
+
data-focused={isFocused}
|
|
174
|
+
tabindex={isFocused ? 0 : -1}
|
|
175
|
+
disabled={off}
|
|
176
|
+
aria-selected={isSelected}
|
|
177
|
+
aria-current={isSameDay(day, now) ? 'date' : undefined}
|
|
178
|
+
onclick={() => pick(day)}
|
|
179
|
+
class="flex h-9 items-center justify-center font-mono text-[13px] tabular-nums transition-colors duration-100 disabled:pointer-events-none disabled:opacity-30 {focusRing} {toneRing[
|
|
180
|
+
tone
|
|
181
|
+
]}
|
|
182
|
+
{isSelected
|
|
183
|
+
? `${toneFill[tone]} font-medium text-text-inverse`
|
|
184
|
+
: outside
|
|
185
|
+
? 'text-text-muted/60 hover:bg-bg-inset'
|
|
186
|
+
: 'text-text-secondary hover:bg-bg-inset hover:text-text'}
|
|
187
|
+
{!isSelected && isSameDay(day, now) ? `${toneText[tone]} font-medium` : ''}"
|
|
188
|
+
>
|
|
189
|
+
{day.getDate()}
|
|
190
|
+
</button>
|
|
191
|
+
{/each}
|
|
192
|
+
</div>
|
|
193
|
+
|
|
194
|
+
{#if showToday}
|
|
195
|
+
<button
|
|
196
|
+
type="button"
|
|
197
|
+
onclick={() => pick(now)}
|
|
198
|
+
disabled={blocked(now)}
|
|
199
|
+
class="self-start px-1 text-sm transition-colors duration-150 disabled:pointer-events-none disabled:opacity-40 {toneText[
|
|
200
|
+
tone
|
|
201
|
+
]} hover:underline hover:underline-offset-4 {focusRing} {toneRing[tone]}"
|
|
202
|
+
>
|
|
203
|
+
{t.current.today}
|
|
204
|
+
</button>
|
|
205
|
+
{/if}
|
|
206
|
+
</div>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type Tone } from '../tones.js';
|
|
2
|
+
interface Props {
|
|
3
|
+
/** Bindable `YYYY-MM-DD`, or `''` for nothing selected. */
|
|
4
|
+
value?: string;
|
|
5
|
+
/** Bindable `YYYY-MM-DD` inside the month on show. */
|
|
6
|
+
month?: string;
|
|
7
|
+
/** Inclusive bounds, `YYYY-MM-DD`. */
|
|
8
|
+
min?: string;
|
|
9
|
+
max?: string;
|
|
10
|
+
/** Return true to grey out a specific day — weekends, holidays. */
|
|
11
|
+
isDisabled?: (date: Date) => boolean;
|
|
12
|
+
/** 1 = Monday (default), 0 = Sunday. */
|
|
13
|
+
weekStart?: 0 | 1;
|
|
14
|
+
tone?: Tone;
|
|
15
|
+
/** Show the "Today" shortcut under the grid. */
|
|
16
|
+
showToday?: boolean;
|
|
17
|
+
onselect?: (value: string) => void;
|
|
18
|
+
class?: string;
|
|
19
|
+
}
|
|
20
|
+
declare const Calendar: import("svelte").Component<Props, {}, "month" | "value">;
|
|
21
|
+
type Calendar = ReturnType<typeof Calendar>;
|
|
22
|
+
export default Calendar;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
4
|
+
import { toneBorderLeft, toneHoverBorder, toneSurface, type Tone } from '../tones.js';
|
|
5
|
+
|
|
6
|
+
export type CardVariant = 'outline' | 'filled' | 'tinted';
|
|
7
|
+
|
|
8
|
+
interface Props extends HTMLAttributes<HTMLDivElement> {
|
|
9
|
+
variant?: CardVariant;
|
|
10
|
+
tone?: Tone;
|
|
11
|
+
/** Draws a 2px tone-coloured rule down the left edge. */
|
|
12
|
+
accent?: boolean;
|
|
13
|
+
/** Lifts the border to the tone colour on hover — use for clickable cards. */
|
|
14
|
+
interactive?: boolean;
|
|
15
|
+
padded?: boolean;
|
|
16
|
+
title?: string;
|
|
17
|
+
eyebrow?: string;
|
|
18
|
+
header?: Snippet;
|
|
19
|
+
footer?: Snippet;
|
|
20
|
+
children: Snippet;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
let {
|
|
24
|
+
variant = 'outline',
|
|
25
|
+
tone = 'brand',
|
|
26
|
+
accent = false,
|
|
27
|
+
interactive = false,
|
|
28
|
+
padded = true,
|
|
29
|
+
title,
|
|
30
|
+
eyebrow,
|
|
31
|
+
header,
|
|
32
|
+
footer,
|
|
33
|
+
class: className = '',
|
|
34
|
+
children,
|
|
35
|
+
...rest
|
|
36
|
+
}: Props = $props();
|
|
37
|
+
|
|
38
|
+
const variants = $derived({
|
|
39
|
+
outline: 'border border-hairline bg-bg',
|
|
40
|
+
filled: 'border border-hairline bg-bg-alt',
|
|
41
|
+
tinted: `border ${toneSurface[tone]} border-transparent`
|
|
42
|
+
});
|
|
43
|
+
</script>
|
|
44
|
+
|
|
45
|
+
<div
|
|
46
|
+
class="flex flex-col {variants[variant]}
|
|
47
|
+
{accent ? `border-l-2 ${toneBorderLeft[tone]}` : ''}
|
|
48
|
+
{interactive ? `transition-colors duration-150 ease-brand-out ${toneHoverBorder[tone]}` : ''}
|
|
49
|
+
{className}"
|
|
50
|
+
{...rest}
|
|
51
|
+
>
|
|
52
|
+
{#if header || title || eyebrow}
|
|
53
|
+
<div class="flex flex-col gap-1 {padded ? 'px-6 pt-6' : ''}">
|
|
54
|
+
{#if header}
|
|
55
|
+
{@render header()}
|
|
56
|
+
{:else}
|
|
57
|
+
{#if eyebrow}
|
|
58
|
+
<span class="font-mono text-xs tracking-wide text-text-muted uppercase">{eyebrow}</span>
|
|
59
|
+
{/if}
|
|
60
|
+
{#if title}
|
|
61
|
+
<h3 class="font-heading text-lg font-medium text-text">{title}</h3>
|
|
62
|
+
{/if}
|
|
63
|
+
{/if}
|
|
64
|
+
</div>
|
|
65
|
+
{/if}
|
|
66
|
+
|
|
67
|
+
<div class="flex-1 {padded ? (header || title || eyebrow ? 'px-6 pt-4 pb-6' : 'p-6') : ''}">
|
|
68
|
+
{@render children()}
|
|
69
|
+
</div>
|
|
70
|
+
|
|
71
|
+
{#if footer}
|
|
72
|
+
<div class="border-t border-hairline {padded ? 'px-6 py-4' : ''}">
|
|
73
|
+
{@render footer()}
|
|
74
|
+
</div>
|
|
75
|
+
{/if}
|
|
76
|
+
</div>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
|
+
import { type Tone } from '../tones.js';
|
|
4
|
+
export type CardVariant = 'outline' | 'filled' | 'tinted';
|
|
5
|
+
interface Props extends HTMLAttributes<HTMLDivElement> {
|
|
6
|
+
variant?: CardVariant;
|
|
7
|
+
tone?: Tone;
|
|
8
|
+
/** Draws a 2px tone-coloured rule down the left edge. */
|
|
9
|
+
accent?: boolean;
|
|
10
|
+
/** Lifts the border to the tone colour on hover — use for clickable cards. */
|
|
11
|
+
interactive?: boolean;
|
|
12
|
+
padded?: boolean;
|
|
13
|
+
title?: string;
|
|
14
|
+
eyebrow?: string;
|
|
15
|
+
header?: Snippet;
|
|
16
|
+
footer?: Snippet;
|
|
17
|
+
children: Snippet;
|
|
18
|
+
}
|
|
19
|
+
declare const Card: import("svelte").Component<Props, {}, "">;
|
|
20
|
+
type Card = ReturnType<typeof Card>;
|
|
21
|
+
export default Card;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import type { HTMLInputAttributes } from 'svelte/elements';
|
|
4
|
+
import { peerFocusRing, tonePeerChecked, tonePeerFocus, type Tone } from '../tones.js';
|
|
5
|
+
|
|
6
|
+
interface Props extends Omit<HTMLInputAttributes, 'type' | 'size'> {
|
|
7
|
+
checked?: boolean;
|
|
8
|
+
/** Renders the dash state — visual only, `checked` stays false. */
|
|
9
|
+
indeterminate?: boolean;
|
|
10
|
+
label?: string;
|
|
11
|
+
description?: string;
|
|
12
|
+
tone?: Tone;
|
|
13
|
+
children?: Snippet;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
let {
|
|
17
|
+
checked = $bindable(false),
|
|
18
|
+
indeterminate = false,
|
|
19
|
+
label,
|
|
20
|
+
description,
|
|
21
|
+
tone = 'brand',
|
|
22
|
+
disabled = false,
|
|
23
|
+
class: className = '',
|
|
24
|
+
children,
|
|
25
|
+
...rest
|
|
26
|
+
}: Props = $props();
|
|
27
|
+
|
|
28
|
+
let el: HTMLInputElement | null = $state(null);
|
|
29
|
+
|
|
30
|
+
$effect(() => {
|
|
31
|
+
if (el) el.indeterminate = indeterminate;
|
|
32
|
+
});
|
|
33
|
+
</script>
|
|
34
|
+
|
|
35
|
+
<label
|
|
36
|
+
class="group inline-flex items-start gap-3 font-sans text-[15px]
|
|
37
|
+
{disabled ? 'pointer-events-none opacity-50' : 'cursor-pointer'} {className}"
|
|
38
|
+
>
|
|
39
|
+
<input bind:this={el} type="checkbox" bind:checked {disabled} class="peer sr-only" {...rest} />
|
|
40
|
+
<span
|
|
41
|
+
class="mt-0.5 flex size-[18px] shrink-0 items-center justify-center border border-hairline-strong bg-bg transition-colors duration-150 ease-brand-out
|
|
42
|
+
{tonePeerChecked[tone]} {peerFocusRing} {tonePeerFocus[tone]}"
|
|
43
|
+
aria-hidden="true"
|
|
44
|
+
>
|
|
45
|
+
{#if indeterminate}
|
|
46
|
+
<span class="h-px w-2.5 bg-text-muted"></span>
|
|
47
|
+
{:else}
|
|
48
|
+
<svg
|
|
49
|
+
class="size-3 text-text-inverse opacity-0 transition-opacity duration-150 group-has-[:checked]:opacity-100"
|
|
50
|
+
viewBox="0 0 12 12"
|
|
51
|
+
fill="none"
|
|
52
|
+
>
|
|
53
|
+
<path d="m2 6 2.6 2.6L10 3.2" stroke="currentColor" stroke-width="1.8" />
|
|
54
|
+
</svg>
|
|
55
|
+
{/if}
|
|
56
|
+
</span>
|
|
57
|
+
{#if label || description || children}
|
|
58
|
+
<span class="flex flex-col gap-0.5">
|
|
59
|
+
{#if children}
|
|
60
|
+
{@render children()}
|
|
61
|
+
{:else if label}
|
|
62
|
+
<span class="leading-snug text-text">{label}</span>
|
|
63
|
+
{/if}
|
|
64
|
+
{#if description}
|
|
65
|
+
<span class="text-sm leading-snug text-text-muted">{description}</span>
|
|
66
|
+
{/if}
|
|
67
|
+
</span>
|
|
68
|
+
{/if}
|
|
69
|
+
</label>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { HTMLInputAttributes } from 'svelte/elements';
|
|
3
|
+
import { type Tone } from '../tones.js';
|
|
4
|
+
interface Props extends Omit<HTMLInputAttributes, 'type' | 'size'> {
|
|
5
|
+
checked?: boolean;
|
|
6
|
+
/** Renders the dash state — visual only, `checked` stays false. */
|
|
7
|
+
indeterminate?: boolean;
|
|
8
|
+
label?: string;
|
|
9
|
+
description?: string;
|
|
10
|
+
tone?: Tone;
|
|
11
|
+
children?: Snippet;
|
|
12
|
+
}
|
|
13
|
+
declare const Checkbox: import("svelte").Component<Props, {}, "checked">;
|
|
14
|
+
type Checkbox = ReturnType<typeof Checkbox>;
|
|
15
|
+
export default Checkbox;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import type { HTMLFieldsetAttributes } from 'svelte/elements';
|
|
4
|
+
import Checkbox from './Checkbox.svelte';
|
|
5
|
+
import type { Tone } from '../tones.js';
|
|
6
|
+
|
|
7
|
+
export interface CheckboxOption {
|
|
8
|
+
value: string;
|
|
9
|
+
label: string;
|
|
10
|
+
description?: string;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface Props extends Omit<HTMLFieldsetAttributes, 'onchange'> {
|
|
15
|
+
/** Bindable — the `value` of every checked option. */
|
|
16
|
+
value?: string[];
|
|
17
|
+
options?: CheckboxOption[];
|
|
18
|
+
legend?: string;
|
|
19
|
+
hint?: string;
|
|
20
|
+
error?: string;
|
|
21
|
+
required?: boolean;
|
|
22
|
+
tone?: Tone;
|
|
23
|
+
orientation?: 'vertical' | 'horizontal';
|
|
24
|
+
/** Wraps each option in a bordered, clickable card. */
|
|
25
|
+
boxed?: boolean;
|
|
26
|
+
/** Cap on how many may be checked at once. `0` means no limit. */
|
|
27
|
+
max?: number;
|
|
28
|
+
onchange?: (value: string[]) => void;
|
|
29
|
+
/** Pass your own `Checkbox`es instead of `options`. */
|
|
30
|
+
children?: Snippet;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
let {
|
|
34
|
+
value = $bindable([]),
|
|
35
|
+
options,
|
|
36
|
+
legend,
|
|
37
|
+
hint,
|
|
38
|
+
error,
|
|
39
|
+
required = false,
|
|
40
|
+
tone = 'brand',
|
|
41
|
+
orientation = 'vertical',
|
|
42
|
+
boxed = false,
|
|
43
|
+
max = 0,
|
|
44
|
+
onchange,
|
|
45
|
+
class: className = '',
|
|
46
|
+
children,
|
|
47
|
+
...rest
|
|
48
|
+
}: Props = $props();
|
|
49
|
+
|
|
50
|
+
const full = $derived(max > 0 && value.length >= max);
|
|
51
|
+
|
|
52
|
+
function toggle(option: CheckboxOption) {
|
|
53
|
+
value = value.includes(option.value)
|
|
54
|
+
? value.filter((v) => v !== option.value)
|
|
55
|
+
: [...value, option.value];
|
|
56
|
+
onchange?.(value);
|
|
57
|
+
}
|
|
58
|
+
</script>
|
|
59
|
+
|
|
60
|
+
<fieldset class="flex flex-col gap-3 border-0 p-0 {className}" {...rest}>
|
|
61
|
+
{#if legend}
|
|
62
|
+
<legend class="mb-1 font-sans text-sm font-medium text-text">
|
|
63
|
+
{legend}
|
|
64
|
+
{#if required}<span class="text-danger" aria-hidden="true">*</span>{/if}
|
|
65
|
+
</legend>
|
|
66
|
+
{/if}
|
|
67
|
+
|
|
68
|
+
<div class="flex gap-3 {orientation === 'horizontal' ? 'flex-row flex-wrap' : 'flex-col'}">
|
|
69
|
+
{#if options}
|
|
70
|
+
{#each options as option (option.value)}
|
|
71
|
+
{@const checked = value.includes(option.value)}
|
|
72
|
+
{@const disabled = option.disabled || (full && !checked)}
|
|
73
|
+
{#if boxed}
|
|
74
|
+
<label
|
|
75
|
+
class="flex flex-1 cursor-pointer items-start gap-3 border p-4 transition-colors duration-150 ease-brand-out
|
|
76
|
+
{checked ? 'border-text bg-bg-alt' : 'border-hairline hover:border-hairline-strong'}
|
|
77
|
+
{disabled ? 'pointer-events-none opacity-50' : ''}"
|
|
78
|
+
>
|
|
79
|
+
<Checkbox
|
|
80
|
+
{checked}
|
|
81
|
+
{disabled}
|
|
82
|
+
{tone}
|
|
83
|
+
label={option.label}
|
|
84
|
+
description={option.description}
|
|
85
|
+
onchange={() => toggle(option)}
|
|
86
|
+
/>
|
|
87
|
+
</label>
|
|
88
|
+
{:else}
|
|
89
|
+
<Checkbox
|
|
90
|
+
{checked}
|
|
91
|
+
{disabled}
|
|
92
|
+
{tone}
|
|
93
|
+
label={option.label}
|
|
94
|
+
description={option.description}
|
|
95
|
+
onchange={() => toggle(option)}
|
|
96
|
+
/>
|
|
97
|
+
{/if}
|
|
98
|
+
{/each}
|
|
99
|
+
{:else if children}
|
|
100
|
+
{@render children()}
|
|
101
|
+
{/if}
|
|
102
|
+
</div>
|
|
103
|
+
|
|
104
|
+
{#if error}
|
|
105
|
+
<p class="font-sans text-sm text-danger">{error}</p>
|
|
106
|
+
{:else if hint}
|
|
107
|
+
<p class="font-sans text-sm text-text-muted">{hint}</p>
|
|
108
|
+
{/if}
|
|
109
|
+
</fieldset>
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { HTMLFieldsetAttributes } from 'svelte/elements';
|
|
3
|
+
import type { Tone } from '../tones.js';
|
|
4
|
+
export interface CheckboxOption {
|
|
5
|
+
value: string;
|
|
6
|
+
label: string;
|
|
7
|
+
description?: string;
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
}
|
|
10
|
+
interface Props extends Omit<HTMLFieldsetAttributes, 'onchange'> {
|
|
11
|
+
/** Bindable — the `value` of every checked option. */
|
|
12
|
+
value?: string[];
|
|
13
|
+
options?: CheckboxOption[];
|
|
14
|
+
legend?: string;
|
|
15
|
+
hint?: string;
|
|
16
|
+
error?: string;
|
|
17
|
+
required?: boolean;
|
|
18
|
+
tone?: Tone;
|
|
19
|
+
orientation?: 'vertical' | 'horizontal';
|
|
20
|
+
/** Wraps each option in a bordered, clickable card. */
|
|
21
|
+
boxed?: boolean;
|
|
22
|
+
/** Cap on how many may be checked at once. `0` means no limit. */
|
|
23
|
+
max?: number;
|
|
24
|
+
onchange?: (value: string[]) => void;
|
|
25
|
+
/** Pass your own `Checkbox`es instead of `options`. */
|
|
26
|
+
children?: Snippet;
|
|
27
|
+
}
|
|
28
|
+
declare const CheckboxGroup: import("svelte").Component<Props, {}, "value">;
|
|
29
|
+
type CheckboxGroup = ReturnType<typeof CheckboxGroup>;
|
|
30
|
+
export default CheckboxGroup;
|