@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.
Files changed (135) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +507 -0
  3. package/cli/index.mjs +410 -0
  4. package/dist/actions/anchor.d.ts +29 -0
  5. package/dist/actions/anchor.js +122 -0
  6. package/dist/actions/dismissable.d.ts +44 -0
  7. package/dist/actions/dismissable.js +147 -0
  8. package/dist/components/Accordion.svelte +14 -0
  9. package/dist/components/Accordion.svelte.d.ts +8 -0
  10. package/dist/components/AccordionItem.svelte +46 -0
  11. package/dist/components/AccordionItem.svelte.d.ts +14 -0
  12. package/dist/components/Alert.svelte +88 -0
  13. package/dist/components/Alert.svelte.d.ts +18 -0
  14. package/dist/components/Avatar.svelte +58 -0
  15. package/dist/components/Avatar.svelte.d.ts +16 -0
  16. package/dist/components/AvatarGroup.svelte +17 -0
  17. package/dist/components/AvatarGroup.svelte.d.ts +8 -0
  18. package/dist/components/Badge.svelte +53 -0
  19. package/dist/components/Badge.svelte.d.ts +18 -0
  20. package/dist/components/Breadcrumb.svelte +46 -0
  21. package/dist/components/Breadcrumb.svelte.d.ts +14 -0
  22. package/dist/components/Button.svelte +94 -0
  23. package/dist/components/Button.svelte.d.ts +21 -0
  24. package/dist/components/Calendar.svelte +206 -0
  25. package/dist/components/Calendar.svelte.d.ts +22 -0
  26. package/dist/components/Card.svelte +76 -0
  27. package/dist/components/Card.svelte.d.ts +21 -0
  28. package/dist/components/Checkbox.svelte +69 -0
  29. package/dist/components/Checkbox.svelte.d.ts +15 -0
  30. package/dist/components/CheckboxGroup.svelte +109 -0
  31. package/dist/components/CheckboxGroup.svelte.d.ts +30 -0
  32. package/dist/components/Combobox.svelte +268 -0
  33. package/dist/components/Combobox.svelte.d.ts +29 -0
  34. package/dist/components/CommandPalette.svelte +226 -0
  35. package/dist/components/CommandPalette.svelte.d.ts +32 -0
  36. package/dist/components/ConfirmDialog.svelte +97 -0
  37. package/dist/components/ConfirmDialog.svelte.d.ts +22 -0
  38. package/dist/components/ContextMenu.svelte +90 -0
  39. package/dist/components/ContextMenu.svelte.d.ts +15 -0
  40. package/dist/components/DatePicker.svelte +186 -0
  41. package/dist/components/DatePicker.svelte.d.ts +23 -0
  42. package/dist/components/Divider.svelte +30 -0
  43. package/dist/components/Divider.svelte.d.ts +10 -0
  44. package/dist/components/Drawer.svelte +161 -0
  45. package/dist/components/Drawer.svelte.d.ts +20 -0
  46. package/dist/components/Dropdown.svelte +112 -0
  47. package/dist/components/Dropdown.svelte.d.ts +23 -0
  48. package/dist/components/Dropzone.svelte +226 -0
  49. package/dist/components/Dropzone.svelte.d.ts +32 -0
  50. package/dist/components/EmptyState.svelte +57 -0
  51. package/dist/components/EmptyState.svelte.d.ts +18 -0
  52. package/dist/components/Field.svelte +42 -0
  53. package/dist/components/Field.svelte.d.ts +16 -0
  54. package/dist/components/Footer.svelte +93 -0
  55. package/dist/components/Footer.svelte.d.ts +25 -0
  56. package/dist/components/Input.svelte +60 -0
  57. package/dist/components/Input.svelte.d.ts +18 -0
  58. package/dist/components/InputGroup.svelte +19 -0
  59. package/dist/components/InputGroup.svelte.d.ts +10 -0
  60. package/dist/components/Kbd.svelte +17 -0
  61. package/dist/components/Kbd.svelte.d.ts +8 -0
  62. package/dist/components/Label.svelte +16 -0
  63. package/dist/components/Label.svelte.d.ts +9 -0
  64. package/dist/components/Link.svelte +44 -0
  65. package/dist/components/Link.svelte.d.ts +16 -0
  66. package/dist/components/LocaleProvider.svelte +24 -0
  67. package/dist/components/LocaleProvider.svelte.d.ts +10 -0
  68. package/dist/components/MenuItem.svelte +58 -0
  69. package/dist/components/MenuItem.svelte.d.ts +18 -0
  70. package/dist/components/MenuSeparator.svelte +22 -0
  71. package/dist/components/MenuSeparator.svelte.d.ts +8 -0
  72. package/dist/components/Modal.svelte +114 -0
  73. package/dist/components/Modal.svelte.d.ts +21 -0
  74. package/dist/components/MultiSelect.svelte +292 -0
  75. package/dist/components/MultiSelect.svelte.d.ts +31 -0
  76. package/dist/components/Navbar.svelte +190 -0
  77. package/dist/components/Navbar.svelte.d.ts +33 -0
  78. package/dist/components/NumberInput.svelte +100 -0
  79. package/dist/components/NumberInput.svelte.d.ts +15 -0
  80. package/dist/components/Pagination.svelte +90 -0
  81. package/dist/components/Pagination.svelte.d.ts +15 -0
  82. package/dist/components/PasswordInput.svelte +104 -0
  83. package/dist/components/PasswordInput.svelte.d.ts +12 -0
  84. package/dist/components/Popover.svelte +114 -0
  85. package/dist/components/Popover.svelte.d.ts +19 -0
  86. package/dist/components/Progress.svelte +56 -0
  87. package/dist/components/Progress.svelte.d.ts +17 -0
  88. package/dist/components/Radio.svelte +55 -0
  89. package/dist/components/Radio.svelte.d.ts +15 -0
  90. package/dist/components/RadioGroup.svelte +93 -0
  91. package/dist/components/RadioGroup.svelte.d.ts +27 -0
  92. package/dist/components/SegmentedControl.svelte +88 -0
  93. package/dist/components/SegmentedControl.svelte.d.ts +25 -0
  94. package/dist/components/Select.svelte +61 -0
  95. package/dist/components/Select.svelte.d.ts +20 -0
  96. package/dist/components/Sidebar.svelte +206 -0
  97. package/dist/components/Sidebar.svelte.d.ts +36 -0
  98. package/dist/components/Skeleton.svelte +46 -0
  99. package/dist/components/Skeleton.svelte.d.ts +13 -0
  100. package/dist/components/Slider.svelte +79 -0
  101. package/dist/components/Slider.svelte.d.ts +19 -0
  102. package/dist/components/Spinner.svelte +34 -0
  103. package/dist/components/Spinner.svelte.d.ts +13 -0
  104. package/dist/components/Stat.svelte +49 -0
  105. package/dist/components/Stat.svelte.d.ts +16 -0
  106. package/dist/components/Steps.svelte +136 -0
  107. package/dist/components/Steps.svelte.d.ts +24 -0
  108. package/dist/components/Switch.svelte +64 -0
  109. package/dist/components/Switch.svelte.d.ts +14 -0
  110. package/dist/components/Table.svelte +236 -0
  111. package/dist/components/Table.svelte.d.ts +70 -0
  112. package/dist/components/Tabs.svelte +91 -0
  113. package/dist/components/Tabs.svelte.d.ts +23 -0
  114. package/dist/components/Textarea.svelte +54 -0
  115. package/dist/components/Textarea.svelte.d.ts +12 -0
  116. package/dist/components/ThemeToggle.svelte +133 -0
  117. package/dist/components/ThemeToggle.svelte.d.ts +20 -0
  118. package/dist/components/Toaster.svelte +110 -0
  119. package/dist/components/Toaster.svelte.d.ts +8 -0
  120. package/dist/components/Tooltip.svelte +33 -0
  121. package/dist/components/Tooltip.svelte.d.ts +12 -0
  122. package/dist/date.d.ts +35 -0
  123. package/dist/date.js +108 -0
  124. package/dist/fonts.css +193 -0
  125. package/dist/index.d.ts +105 -0
  126. package/dist/index.js +77 -0
  127. package/dist/locale.svelte.d.ts +93 -0
  128. package/dist/locale.svelte.js +153 -0
  129. package/dist/theme.css +210 -0
  130. package/dist/toast.svelte.d.ts +47 -0
  131. package/dist/toast.svelte.js +60 -0
  132. package/dist/tones.d.ts +48 -0
  133. package/dist/tones.js +209 -0
  134. package/package.json +349 -0
  135. package/registry.json +669 -0
@@ -0,0 +1,19 @@
1
+ import type { Snippet } from 'svelte';
2
+ import { type Placement } from '../actions/anchor.js';
3
+ interface Props {
4
+ trigger: Snippet;
5
+ children: Snippet;
6
+ open?: boolean;
7
+ placement?: Placement;
8
+ offset?: number;
9
+ title?: string;
10
+ /** `'hover'` also opens on focus, for read-only content. */
11
+ on?: 'click' | 'hover';
12
+ /** Keep focus where it is — right for hover popovers and hover cards. */
13
+ trapFocus?: boolean;
14
+ class?: string;
15
+ triggerClass?: string;
16
+ }
17
+ declare const Popover: import("svelte").Component<Props, {}, "open">;
18
+ type Popover = ReturnType<typeof Popover>;
19
+ export default Popover;
@@ -0,0 +1,56 @@
1
+ <script lang="ts">
2
+ import type { HTMLAttributes } from 'svelte/elements';
3
+ import { toneFill, type Tone } from '../tones.js';
4
+
5
+ export type ProgressSize = 'sm' | 'md' | 'lg';
6
+
7
+ interface Props extends HTMLAttributes<HTMLDivElement> {
8
+ value?: number;
9
+ max?: number;
10
+ tone?: Tone;
11
+ size?: ProgressSize;
12
+ label?: string;
13
+ /** Prints the percentage on the right of the label row. */
14
+ showValue?: boolean;
15
+ /** Ignores `value` and runs a looping sweep. */
16
+ indeterminate?: boolean;
17
+ }
18
+
19
+ let {
20
+ value = 0,
21
+ max = 100,
22
+ tone = 'brand',
23
+ size = 'md',
24
+ label,
25
+ showValue = false,
26
+ indeterminate = false,
27
+ class: className = '',
28
+ ...rest
29
+ }: Props = $props();
30
+
31
+ const sizes: Record<ProgressSize, string> = { sm: 'h-1', md: 'h-2', lg: 'h-3' };
32
+ const pct = $derived(Math.min(100, Math.max(0, (value / max) * 100)));
33
+ </script>
34
+
35
+ <div class="flex w-full flex-col gap-2 {className}" {...rest}>
36
+ {#if label || showValue}
37
+ <div class="flex items-baseline justify-between gap-4 font-sans text-sm">
38
+ {#if label}<span class="text-text-secondary">{label}</span>{/if}
39
+ {#if showValue}<span class="font-mono text-xs text-text-muted">{Math.round(pct)}%</span>{/if}
40
+ </div>
41
+ {/if}
42
+ <div
43
+ role="progressbar"
44
+ aria-valuenow={indeterminate ? undefined : Math.round(pct)}
45
+ aria-valuemin={0}
46
+ aria-valuemax={100}
47
+ aria-label={label}
48
+ class="w-full overflow-hidden bg-bg-inset {sizes[size]}"
49
+ >
50
+ <div
51
+ class="h-full transition-[width] duration-300 ease-brand {toneFill[tone]}
52
+ {indeterminate ? 'w-1/3 animate-pulse' : ''}"
53
+ style={indeterminate ? undefined : `width:${pct}%`}
54
+ ></div>
55
+ </div>
56
+ </div>
@@ -0,0 +1,17 @@
1
+ import type { HTMLAttributes } from 'svelte/elements';
2
+ import { type Tone } from '../tones.js';
3
+ export type ProgressSize = 'sm' | 'md' | 'lg';
4
+ interface Props extends HTMLAttributes<HTMLDivElement> {
5
+ value?: number;
6
+ max?: number;
7
+ tone?: Tone;
8
+ size?: ProgressSize;
9
+ label?: string;
10
+ /** Prints the percentage on the right of the label row. */
11
+ showValue?: boolean;
12
+ /** Ignores `value` and runs a looping sweep. */
13
+ indeterminate?: boolean;
14
+ }
15
+ declare const Progress: import("svelte").Component<Props, {}, "">;
16
+ type Progress = ReturnType<typeof Progress>;
17
+ export default Progress;
@@ -0,0 +1,55 @@
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
+ /** Bind the same variable across a set of radios. */
8
+ group?: string;
9
+ value: string;
10
+ label?: string;
11
+ description?: string;
12
+ tone?: Tone;
13
+ children?: Snippet;
14
+ }
15
+
16
+ let {
17
+ group = $bindable(''),
18
+ value,
19
+ label,
20
+ description,
21
+ tone = 'brand',
22
+ disabled = false,
23
+ class: className = '',
24
+ children,
25
+ ...rest
26
+ }: Props = $props();
27
+ </script>
28
+
29
+ <label
30
+ class="group inline-flex items-start gap-3 font-sans text-[15px]
31
+ {disabled ? 'pointer-events-none opacity-50' : 'cursor-pointer'} {className}"
32
+ >
33
+ <input type="radio" bind:group {value} {disabled} class="peer sr-only" {...rest} />
34
+ <span
35
+ class="mt-0.5 flex size-[18px] shrink-0 items-center justify-center rounded-full border border-hairline-strong bg-bg transition-colors duration-150 ease-brand-out
36
+ {tonePeerChecked[tone]} {peerFocusRing} {tonePeerFocus[tone]}"
37
+ aria-hidden="true"
38
+ >
39
+ <span
40
+ class="size-1.5 rounded-full bg-text-inverse opacity-0 transition-opacity duration-150 group-has-[:checked]:opacity-100"
41
+ ></span>
42
+ </span>
43
+ {#if label || description || children}
44
+ <span class="flex flex-col gap-0.5">
45
+ {#if children}
46
+ {@render children()}
47
+ {:else if label}
48
+ <span class="leading-snug text-text">{label}</span>
49
+ {/if}
50
+ {#if description}
51
+ <span class="text-sm leading-snug text-text-muted">{description}</span>
52
+ {/if}
53
+ </span>
54
+ {/if}
55
+ </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
+ /** Bind the same variable across a set of radios. */
6
+ group?: string;
7
+ value: string;
8
+ label?: string;
9
+ description?: string;
10
+ tone?: Tone;
11
+ children?: Snippet;
12
+ }
13
+ declare const Radio: import("svelte").Component<Props, {}, "group">;
14
+ type Radio = ReturnType<typeof Radio>;
15
+ export default Radio;
@@ -0,0 +1,93 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from 'svelte';
3
+ import type { HTMLFieldsetAttributes } from 'svelte/elements';
4
+ import Radio from './Radio.svelte';
5
+ import type { Tone } from '../tones.js';
6
+
7
+ export interface RadioOption {
8
+ value: string;
9
+ label: string;
10
+ description?: string;
11
+ disabled?: boolean;
12
+ }
13
+
14
+ interface Props extends HTMLFieldsetAttributes {
15
+ /** Bindable — the selected option's `value`. */
16
+ value?: string;
17
+ options?: RadioOption[];
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
+ /** Pass your own `Radio`s instead of `options`. */
27
+ children?: Snippet;
28
+ }
29
+
30
+ let {
31
+ value = $bindable(''),
32
+ options,
33
+ legend,
34
+ hint,
35
+ error,
36
+ required = false,
37
+ tone = 'brand',
38
+ orientation = 'vertical',
39
+ boxed = false,
40
+ class: className = '',
41
+ children,
42
+ ...rest
43
+ }: Props = $props();
44
+ </script>
45
+
46
+ <fieldset class="flex flex-col gap-3 border-0 p-0 {className}" {...rest}>
47
+ {#if legend}
48
+ <legend class="mb-1 font-sans text-sm font-medium text-text">
49
+ {legend}
50
+ {#if required}<span class="text-danger" aria-hidden="true">*</span>{/if}
51
+ </legend>
52
+ {/if}
53
+
54
+ <div class="flex gap-3 {orientation === 'horizontal' ? 'flex-row flex-wrap' : 'flex-col'}">
55
+ {#if options}
56
+ {#each options as option (option.value)}
57
+ {#if boxed}
58
+ <label
59
+ class="flex flex-1 cursor-pointer items-start gap-3 border p-4 transition-colors duration-150 ease-brand-out
60
+ {value === option.value ? 'border-text bg-bg-alt' : 'border-hairline hover:border-hairline-strong'}
61
+ {option.disabled ? 'pointer-events-none opacity-50' : ''}"
62
+ >
63
+ <Radio
64
+ bind:group={value}
65
+ value={option.value}
66
+ label={option.label}
67
+ description={option.description}
68
+ disabled={option.disabled}
69
+ {tone}
70
+ />
71
+ </label>
72
+ {:else}
73
+ <Radio
74
+ bind:group={value}
75
+ value={option.value}
76
+ label={option.label}
77
+ description={option.description}
78
+ disabled={option.disabled}
79
+ {tone}
80
+ />
81
+ {/if}
82
+ {/each}
83
+ {:else if children}
84
+ {@render children()}
85
+ {/if}
86
+ </div>
87
+
88
+ {#if error}
89
+ <p class="font-sans text-sm text-danger">{error}</p>
90
+ {:else if hint}
91
+ <p class="font-sans text-sm text-text-muted">{hint}</p>
92
+ {/if}
93
+ </fieldset>
@@ -0,0 +1,27 @@
1
+ import type { Snippet } from 'svelte';
2
+ import type { HTMLFieldsetAttributes } from 'svelte/elements';
3
+ import type { Tone } from '../tones.js';
4
+ export interface RadioOption {
5
+ value: string;
6
+ label: string;
7
+ description?: string;
8
+ disabled?: boolean;
9
+ }
10
+ interface Props extends HTMLFieldsetAttributes {
11
+ /** Bindable — the selected option's `value`. */
12
+ value?: string;
13
+ options?: RadioOption[];
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
+ /** Pass your own `Radio`s instead of `options`. */
23
+ children?: Snippet;
24
+ }
25
+ declare const RadioGroup: import("svelte").Component<Props, {}, "value">;
26
+ type RadioGroup = ReturnType<typeof RadioGroup>;
27
+ export default RadioGroup;
@@ -0,0 +1,88 @@
1
+ <script lang="ts">
2
+ import type { HTMLAttributes } from 'svelte/elements';
3
+ import { focusRing, toneRing, toneSoft, type Tone } from '../tones.js';
4
+
5
+ export interface SegmentOption {
6
+ value: string;
7
+ label: string;
8
+ disabled?: boolean;
9
+ }
10
+
11
+ export type SegmentedSize = 'sm' | 'md';
12
+
13
+ interface Props extends Omit<HTMLAttributes<HTMLDivElement>, 'onchange'> {
14
+ /** Bindable — the selected option's `value`. */
15
+ value?: string;
16
+ options: SegmentOption[];
17
+ /** Submits with a form when set. */
18
+ name?: string;
19
+ size?: SegmentedSize;
20
+ tone?: Tone;
21
+ /** Spread the segments evenly across the full width. */
22
+ fullWidth?: boolean;
23
+ label?: string;
24
+ disabled?: boolean;
25
+ onchange?: (value: string) => void;
26
+ }
27
+
28
+ let {
29
+ value = $bindable(''),
30
+ options,
31
+ name,
32
+ size = 'md',
33
+ tone = 'brand',
34
+ fullWidth = false,
35
+ label,
36
+ disabled = false,
37
+ class: className = '',
38
+ onchange,
39
+ ...rest
40
+ }: Props = $props();
41
+
42
+ const sizes: Record<SegmentedSize, string> = {
43
+ sm: 'h-8 px-3 text-[13px]',
44
+ md: 'h-10 px-4 text-sm'
45
+ };
46
+
47
+ function select(option: SegmentOption) {
48
+ if (option.disabled || disabled) return;
49
+ value = option.value;
50
+ onchange?.(option.value);
51
+ }
52
+
53
+ function onKeydown(event: KeyboardEvent) {
54
+ const step = event.key === 'ArrowRight' ? 1 : event.key === 'ArrowLeft' ? -1 : 0;
55
+ if (!step) return;
56
+ event.preventDefault();
57
+ const usable = options.filter((option) => !option.disabled);
58
+ const index = usable.findIndex((option) => option.value === value);
59
+ select(usable[(index + step + usable.length) % usable.length]);
60
+ }
61
+ </script>
62
+
63
+ <div
64
+ role="radiogroup"
65
+ aria-label={label}
66
+ onkeydown={onKeydown}
67
+ class="inline-flex items-center border border-hairline bg-bg-alt p-1
68
+ {fullWidth ? 'flex w-full *:flex-1' : ''}
69
+ {disabled ? 'pointer-events-none opacity-50' : ''} {className}"
70
+ {...rest}
71
+ >
72
+ {#each options as option (option.value)}
73
+ <button
74
+ type="button"
75
+ role="radio"
76
+ aria-checked={value === option.value}
77
+ disabled={option.disabled || disabled}
78
+ tabindex={value === option.value ? 0 : -1}
79
+ onclick={() => select(option)}
80
+ class="inline-flex items-center justify-center font-sans whitespace-nowrap transition-colors duration-150 ease-brand-out disabled:pointer-events-none disabled:opacity-40
81
+ {sizes[size]} {focusRing} {toneRing[tone]}
82
+ {value === option.value ? `${toneSoft[tone]} font-medium` : 'text-text-secondary hover:text-text'}"
83
+ >
84
+ {option.label}
85
+ </button>
86
+ {/each}
87
+ {#if name}<input type="hidden" {name} {value} />{/if}
88
+ </div>
@@ -0,0 +1,25 @@
1
+ import type { HTMLAttributes } from 'svelte/elements';
2
+ import { type Tone } from '../tones.js';
3
+ export interface SegmentOption {
4
+ value: string;
5
+ label: string;
6
+ disabled?: boolean;
7
+ }
8
+ export type SegmentedSize = 'sm' | 'md';
9
+ interface Props extends Omit<HTMLAttributes<HTMLDivElement>, 'onchange'> {
10
+ /** Bindable — the selected option's `value`. */
11
+ value?: string;
12
+ options: SegmentOption[];
13
+ /** Submits with a form when set. */
14
+ name?: string;
15
+ size?: SegmentedSize;
16
+ tone?: Tone;
17
+ /** Spread the segments evenly across the full width. */
18
+ fullWidth?: boolean;
19
+ label?: string;
20
+ disabled?: boolean;
21
+ onchange?: (value: string) => void;
22
+ }
23
+ declare const SegmentedControl: import("svelte").Component<Props, {}, "value">;
24
+ type SegmentedControl = ReturnType<typeof SegmentedControl>;
25
+ export default SegmentedControl;
@@ -0,0 +1,61 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from 'svelte';
3
+ import type { HTMLSelectAttributes } from 'svelte/elements';
4
+ import { toneFocusBorder, type Tone } from '../tones.js';
5
+
6
+ export interface SelectOption {
7
+ value: string;
8
+ label: string;
9
+ disabled?: boolean;
10
+ }
11
+
12
+ interface Props extends HTMLSelectAttributes {
13
+ value?: string;
14
+ /** Data-driven options. Omit and pass `children` to write `<option>`s yourself. */
15
+ options?: SelectOption[];
16
+ placeholder?: string;
17
+ tone?: Tone;
18
+ invalid?: boolean;
19
+ children?: Snippet;
20
+ }
21
+
22
+ let {
23
+ value = $bindable(''),
24
+ options,
25
+ placeholder,
26
+ tone = 'brand',
27
+ invalid = false,
28
+ class: className = '',
29
+ children,
30
+ ...rest
31
+ }: Props = $props();
32
+ </script>
33
+
34
+ <span class="relative inline-flex w-full items-center">
35
+ <select
36
+ bind:value
37
+ aria-invalid={invalid ? 'true' : undefined}
38
+ class="h-11 w-full appearance-none border bg-bg py-0 pr-10 pl-4 font-sans text-[15px] text-text transition-colors duration-150 ease-brand-out focus:outline-none disabled:pointer-events-none disabled:opacity-50
39
+ {invalid ? 'border-danger' : `border-hairline ${toneFocusBorder[tone]}`} {className}"
40
+ {...rest}
41
+ >
42
+ {#if placeholder}
43
+ <option value="" disabled>{placeholder}</option>
44
+ {/if}
45
+ {#if options}
46
+ {#each options as option (option.value)}
47
+ <option value={option.value} disabled={option.disabled}>{option.label}</option>
48
+ {/each}
49
+ {:else if children}
50
+ {@render children()}
51
+ {/if}
52
+ </select>
53
+ <svg
54
+ class="pointer-events-none absolute right-4 size-4 text-text-muted"
55
+ viewBox="0 0 16 16"
56
+ fill="none"
57
+ aria-hidden="true"
58
+ >
59
+ <path d="m4 6 4 4 4-4" stroke="currentColor" stroke-width="1.5" stroke-linecap="square" />
60
+ </svg>
61
+ </span>
@@ -0,0 +1,20 @@
1
+ import type { Snippet } from 'svelte';
2
+ import type { HTMLSelectAttributes } from 'svelte/elements';
3
+ import { type Tone } from '../tones.js';
4
+ export interface SelectOption {
5
+ value: string;
6
+ label: string;
7
+ disabled?: boolean;
8
+ }
9
+ interface Props extends HTMLSelectAttributes {
10
+ value?: string;
11
+ /** Data-driven options. Omit and pass `children` to write `<option>`s yourself. */
12
+ options?: SelectOption[];
13
+ placeholder?: string;
14
+ tone?: Tone;
15
+ invalid?: boolean;
16
+ children?: Snippet;
17
+ }
18
+ declare const Select: import("svelte").Component<Props, {}, "value">;
19
+ type Select = ReturnType<typeof Select>;
20
+ export default Select;
@@ -0,0 +1,206 @@
1
+ <script module lang="ts">
2
+ export interface SidebarItem {
3
+ /** Stable id used for the active state. Falls back to `href`. */
4
+ id?: string;
5
+ label: string;
6
+ href?: string;
7
+ disabled?: boolean;
8
+ badge?: string | number;
9
+ /** Nested links — the parent becomes a collapsible group. */
10
+ items?: SidebarItem[];
11
+ /** Open the group on first render. */
12
+ open?: boolean;
13
+ }
14
+
15
+ export interface SidebarSection {
16
+ /** Small heading above a run of items. */
17
+ label?: string;
18
+ items: SidebarItem[];
19
+ }
20
+ </script>
21
+
22
+ <script lang="ts">
23
+ import type { Snippet } from 'svelte';
24
+ import { useLocale } from '../locale.svelte.js';
25
+ import { focusRing, toneRing, toneSoft, type Tone } from '../tones.js';
26
+
27
+ interface Props {
28
+ sections: SidebarSection[];
29
+ /** Bindable — the `id` (or `href`) of the current item. */
30
+ value?: string;
31
+ /** Bindable — narrow rail mode. */
32
+ collapsed?: boolean;
33
+ /** Show the collapse button. */
34
+ collapsible?: boolean;
35
+ tone?: Tone;
36
+ header?: Snippet;
37
+ footer?: Snippet;
38
+ onnavigate?: (item: SidebarItem) => void;
39
+ class?: string;
40
+ }
41
+
42
+ let {
43
+ sections,
44
+ value = $bindable(''),
45
+ collapsed = $bindable(false),
46
+ collapsible = true,
47
+ tone = 'brand',
48
+ header,
49
+ footer,
50
+ onnavigate,
51
+ class: className = ''
52
+ }: Props = $props();
53
+
54
+ const t = useLocale();
55
+
56
+ const keyOf = (item: SidebarItem) => item.id ?? item.href ?? item.label;
57
+
58
+ /** Groups start open when asked, or when they contain the active item. */
59
+ let opened = $state<Record<string, boolean>>({});
60
+
61
+ const isOpen = (item: SidebarItem) =>
62
+ opened[keyOf(item)] ?? (item.open || item.items!.some((child) => keyOf(child) === value));
63
+
64
+ function toggle(item: SidebarItem) {
65
+ opened = { ...opened, [keyOf(item)]: !isOpen(item) };
66
+ }
67
+
68
+ function go(item: SidebarItem) {
69
+ if (item.disabled) return;
70
+ value = keyOf(item);
71
+ onnavigate?.(item);
72
+ }
73
+
74
+ const row =
75
+ 'flex w-full items-center gap-3 px-3 py-2 text-left font-sans text-sm transition-colors duration-150 ease-brand-out disabled:pointer-events-none disabled:opacity-40';
76
+ </script>
77
+
78
+ <aside
79
+ class="flex h-full shrink-0 flex-col border-r border-hairline bg-bg transition-[width] duration-200 ease-brand-out
80
+ {collapsed ? 'w-16' : 'w-60'} {className}"
81
+ >
82
+ {#if header}
83
+ <div class="flex h-16 shrink-0 items-center gap-3 border-b border-hairline px-3">
84
+ {@render header()}
85
+ </div>
86
+ {/if}
87
+
88
+ <nav aria-label={t.current.navigation} class="flex-1 overflow-y-auto py-3">
89
+ {#each sections as section, i (section.label ?? i)}
90
+ <div class="flex flex-col gap-0.5 {i > 0 ? 'mt-4' : ''}">
91
+ {#if section.label && !collapsed}
92
+ <p class="px-3 pb-1 font-mono text-[10px] tracking-wide text-text-muted uppercase">
93
+ {section.label}
94
+ </p>
95
+ {:else if section.label && collapsed && i > 0}
96
+ <div class="mx-3 mb-1 h-px bg-hairline" role="separator"></div>
97
+ {/if}
98
+
99
+ {#each section.items as item (keyOf(item))}
100
+ {#if item.items?.length}
101
+ <button
102
+ type="button"
103
+ onclick={() => toggle(item)}
104
+ aria-expanded={isOpen(item)}
105
+ title={collapsed ? item.label : undefined}
106
+ class="{row} {focusRing} {toneRing[
107
+ tone
108
+ ]} text-text-secondary hover:bg-bg-inset hover:text-text"
109
+ >
110
+ <span class="min-w-0 flex-1 truncate {collapsed ? 'sr-only' : ''}">{item.label}</span>
111
+ {#if !collapsed}
112
+ <svg
113
+ class="size-3 shrink-0 transition-transform duration-200 {isOpen(item)
114
+ ? 'rotate-90'
115
+ : ''}"
116
+ viewBox="0 0 16 16"
117
+ fill="none"
118
+ aria-hidden="true"
119
+ >
120
+ <path
121
+ d="m6 4 4 4-4 4"
122
+ stroke="currentColor"
123
+ stroke-width="1.6"
124
+ stroke-linecap="square"
125
+ />
126
+ </svg>
127
+ {/if}
128
+ </button>
129
+
130
+ {#if isOpen(item) && !collapsed}
131
+ <div class="ml-5 flex flex-col gap-0.5 border-l border-hairline pl-1">
132
+ {#each item.items as child (keyOf(child))}
133
+ <a
134
+ href={child.href}
135
+ onclick={() => go(child)}
136
+ aria-current={value === keyOf(child) ? 'page' : undefined}
137
+ class="{row} {focusRing} {toneRing[tone]} {value === keyOf(child)
138
+ ? `${toneSoft[tone]} font-medium`
139
+ : 'text-text-muted hover:bg-bg-inset hover:text-text'} {child.disabled
140
+ ? 'pointer-events-none opacity-40'
141
+ : ''}"
142
+ >
143
+ <span class="min-w-0 flex-1 truncate">{child.label}</span>
144
+ {#if child.badge !== undefined}
145
+ <span class="shrink-0 font-mono text-[11px]">{child.badge}</span>
146
+ {/if}
147
+ </a>
148
+ {/each}
149
+ </div>
150
+ {/if}
151
+ {:else}
152
+ <a
153
+ href={item.href}
154
+ onclick={() => go(item)}
155
+ aria-current={value === keyOf(item) ? 'page' : undefined}
156
+ title={collapsed ? item.label : undefined}
157
+ class="{row} {focusRing} {toneRing[tone]} {value === keyOf(item)
158
+ ? `${toneSoft[tone]} font-medium`
159
+ : 'text-text-secondary hover:bg-bg-inset hover:text-text'} {item.disabled
160
+ ? 'pointer-events-none opacity-40'
161
+ : ''}"
162
+ >
163
+ <span class="min-w-0 flex-1 truncate {collapsed ? 'sr-only' : ''}">{item.label}</span>
164
+ {#if item.badge !== undefined && !collapsed}
165
+ <span class="shrink-0 font-mono text-[11px] text-text-muted">{item.badge}</span>
166
+ {/if}
167
+ </a>
168
+ {/if}
169
+ {/each}
170
+ </div>
171
+ {/each}
172
+ </nav>
173
+
174
+ {#if footer || collapsible}
175
+ <div class="flex shrink-0 flex-col gap-2 border-t border-hairline p-3">
176
+ {#if footer}
177
+ {@render footer()}
178
+ {/if}
179
+ {#if collapsible}
180
+ <button
181
+ type="button"
182
+ onclick={() => (collapsed = !collapsed)}
183
+ aria-label={collapsed ? t.current.expandSidebar : t.current.collapseSidebar}
184
+ class="inline-flex h-8 items-center justify-center gap-2 font-sans text-xs text-text-muted transition-colors duration-150 hover:text-text {focusRing} {toneRing[
185
+ tone
186
+ ]}"
187
+ >
188
+ <svg
189
+ class="size-4 transition-transform duration-200 {collapsed ? 'rotate-180' : ''}"
190
+ viewBox="0 0 16 16"
191
+ fill="none"
192
+ aria-hidden="true"
193
+ >
194
+ <path
195
+ d="m10 4-4 4 4 4"
196
+ stroke="currentColor"
197
+ stroke-width="1.6"
198
+ stroke-linecap="square"
199
+ />
200
+ </svg>
201
+ {#if !collapsed}<span>{t.current.collapseSidebar}</span>{/if}
202
+ </button>
203
+ {/if}
204
+ </div>
205
+ {/if}
206
+ </aside>