@diegopluna/narvi 0.4.1 → 0.5.1
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 +3 -1
- package/dist/base.css +3 -0
- package/dist/components/app-shell/AppShellPanel.svelte +3 -2
- package/dist/components/button/Button.svelte +29 -17
- package/dist/components/checkbox/Checkbox.svelte +106 -54
- package/dist/components/checkbox/Checkbox.svelte.d.ts +22 -8
- package/dist/components/choice-cards/ChoiceCards.svelte +68 -39
- package/dist/components/choice-cards/ChoiceCards.svelte.d.ts +12 -8
- package/dist/components/collapsible/CollapsibleContent.svelte +71 -17
- package/dist/components/collapsible/CollapsibleContent.svelte.d.ts +14 -10
- package/dist/components/collapsible/CollapsibleRoot.svelte +13 -9
- package/dist/components/collapsible/CollapsibleRoot.svelte.d.ts +8 -9
- package/dist/components/collapsible/CollapsibleTrigger.svelte +24 -15
- package/dist/components/collapsible/CollapsibleTrigger.svelte.d.ts +10 -14
- package/dist/components/color-field/ColorField.svelte +13 -7
- package/dist/components/command/CommandDialog.svelte +30 -20
- package/dist/components/command/CommandDialog.svelte.d.ts +4 -3
- package/dist/components/command/CommandEmpty.svelte +11 -9
- package/dist/components/command/CommandEmpty.svelte.d.ts +6 -17
- package/dist/components/command/CommandGroup.svelte +32 -11
- package/dist/components/command/CommandGroup.svelte.d.ts +7 -11
- package/dist/components/command/CommandInput.svelte +25 -10
- package/dist/components/command/CommandInput.svelte.d.ts +8 -12
- package/dist/components/command/CommandItem.svelte +67 -29
- package/dist/components/command/CommandItem.svelte.d.ts +6 -32
- package/dist/components/command/CommandList.svelte +8 -10
- package/dist/components/command/CommandList.svelte.d.ts +6 -8
- package/dist/components/command/CommandRoot.svelte +247 -57
- package/dist/components/command/CommandRoot.svelte.d.ts +14 -28
- package/dist/components/command/CommandSeparator.svelte +18 -0
- package/dist/components/command/CommandSeparator.svelte.d.ts +7 -0
- package/dist/components/command/context.d.ts +27 -0
- package/dist/components/command/context.js +16 -0
- package/dist/components/command/index.d.ts +6 -4
- package/dist/components/command/index.js +5 -4
- package/dist/components/command/score.d.ts +27 -0
- package/dist/components/command/score.js +77 -0
- package/dist/components/command/styles.d.ts +32 -9
- package/dist/components/command/styles.js +42 -14
- package/dist/components/composer/ComposerModelPicker.svelte +350 -346
- package/dist/components/composer/ComposerModelPicker.svelte.d.ts +6 -3
- package/dist/components/composer/ComposerRoot.svelte.d.ts +1 -1
- package/dist/components/dialog/ConfirmDialog.svelte +73 -53
- package/dist/components/dialog/DialogClose.svelte +17 -0
- package/dist/components/dialog/DialogClose.svelte.d.ts +10 -0
- package/dist/components/dialog/DialogContent.svelte +35 -33
- package/dist/components/dialog/DialogContent.svelte.d.ts +6 -20
- package/dist/components/dialog/DialogDescription.svelte +9 -12
- package/dist/components/dialog/DialogDescription.svelte.d.ts +6 -8
- package/dist/components/dialog/DialogRoot.svelte +20 -0
- package/dist/components/dialog/DialogRoot.svelte.d.ts +7 -0
- package/dist/components/dialog/DialogTitle.svelte +12 -8
- package/dist/components/dialog/DialogTitle.svelte.d.ts +8 -8
- package/dist/components/dialog/DialogTrigger.svelte +17 -0
- package/dist/components/dialog/DialogTrigger.svelte.d.ts +10 -0
- package/dist/components/dialog/index.d.ts +6 -5
- package/dist/components/dialog/index.js +3 -6
- package/dist/components/dialog/styles.d.ts +1 -2
- package/dist/components/dialog/styles.js +11 -8
- package/dist/components/hover-card/HoverCardContent.svelte +35 -29
- package/dist/components/hover-card/HoverCardContent.svelte.d.ts +8 -12
- package/dist/components/hover-card/HoverCardRoot.svelte +7 -7
- package/dist/components/hover-card/HoverCardRoot.svelte.d.ts +5 -4
- package/dist/components/hover-card/HoverCardTrigger.svelte +18 -0
- package/dist/components/hover-card/HoverCardTrigger.svelte.d.ts +10 -0
- package/dist/components/hover-card/index.d.ts +2 -3
- package/dist/components/hover-card/index.js +1 -5
- package/dist/components/input/Input.svelte.d.ts +1 -1
- package/dist/components/markdown/MarkdownBlock.svelte +6 -3
- package/dist/components/markdown/MarkdownTable.svelte +15 -7
- package/dist/components/menu/ContextMenuContent.svelte +15 -15
- package/dist/components/menu/ContextMenuContent.svelte.d.ts +6 -9
- package/dist/components/menu/ContextMenuTrigger.svelte +14 -16
- package/dist/components/menu/ContextMenuTrigger.svelte.d.ts +8 -14
- package/dist/components/menu/MenuCheckboxItem.svelte +22 -11
- package/dist/components/menu/MenuCheckboxItem.svelte.d.ts +8 -22
- package/dist/components/menu/MenuContent.svelte +16 -18
- package/dist/components/menu/MenuContent.svelte.d.ts +6 -18
- package/dist/components/menu/MenuGroup.svelte +4 -4
- package/dist/components/menu/MenuGroup.svelte.d.ts +5 -4
- package/dist/components/menu/MenuItem.svelte +25 -12
- package/dist/components/menu/MenuItem.svelte.d.ts +6 -21
- package/dist/components/menu/MenuLabel.svelte +7 -11
- package/dist/components/menu/MenuLabel.svelte.d.ts +6 -8
- package/dist/components/menu/MenuRadioGroup.svelte +4 -4
- package/dist/components/menu/MenuRadioGroup.svelte.d.ts +5 -4
- package/dist/components/menu/MenuRadioItem.svelte +16 -14
- package/dist/components/menu/MenuRadioItem.svelte.d.ts +6 -19
- package/dist/components/menu/MenuSeparator.svelte +6 -10
- package/dist/components/menu/MenuSeparator.svelte.d.ts +6 -7
- package/dist/components/menu/MenuSubContent.svelte +22 -19
- package/dist/components/menu/MenuSubContent.svelte.d.ts +8 -15
- package/dist/components/menu/MenuSubTrigger.svelte +7 -11
- package/dist/components/menu/MenuSubTrigger.svelte.d.ts +6 -15
- package/dist/components/menu/MenuTrigger.svelte +17 -0
- package/dist/components/menu/MenuTrigger.svelte.d.ts +10 -0
- package/dist/components/menu/context-menu.d.ts +2 -2
- package/dist/components/menu/context-menu.js +3 -2
- package/dist/components/menu/group.js +1 -1
- package/dist/components/menu/index.d.ts +5 -4
- package/dist/components/menu/index.js +5 -5
- package/dist/components/menu/row.d.ts +20 -0
- package/dist/components/menu/row.js +12 -0
- package/dist/components/popover/PopoverClose.svelte +17 -0
- package/dist/components/popover/PopoverClose.svelte.d.ts +10 -0
- package/dist/components/popover/PopoverContent.svelte +30 -29
- package/dist/components/popover/PopoverContent.svelte.d.ts +6 -17
- package/dist/components/popover/PopoverTrigger.svelte +17 -0
- package/dist/components/popover/PopoverTrigger.svelte.d.ts +10 -0
- package/dist/components/popover/index.d.ts +6 -4
- package/dist/components/popover/index.js +6 -5
- package/dist/components/progress/Progress.svelte +16 -22
- package/dist/components/progress/Progress.svelte.d.ts +6 -5
- package/dist/components/reasoning/ReasoningRoot.svelte.d.ts +1 -1
- package/dist/components/resize-handle/ResizeHandle.svelte +80 -14
- package/dist/components/resize-handle/ResizeHandle.svelte.d.ts +15 -1
- package/dist/components/segmented/SegmentedControl.svelte +100 -91
- package/dist/components/segmented/SegmentedControl.svelte.d.ts +6 -4
- package/dist/components/select/Select.svelte +97 -59
- package/dist/components/select/Select.svelte.d.ts +3 -2
- package/dist/components/sheet/SheetContent.svelte +31 -38
- package/dist/components/sheet/SheetContent.svelte.d.ts +7 -22
- package/dist/components/sheet/index.d.ts +3 -5
- package/dist/components/sheet/index.js +3 -5
- package/dist/components/sheet/styles.js +26 -5
- package/dist/components/sidebar/SidebarItem.svelte +2 -3
- package/dist/components/slider/Slider.svelte +86 -65
- package/dist/components/slider/Slider.svelte.d.ts +9 -8
- package/dist/components/split-button/SplitButton.svelte +20 -3
- package/dist/components/split-button/SplitButton.svelte.d.ts +1 -1
- package/dist/components/switch/Switch.svelte +77 -49
- package/dist/components/switch/Switch.svelte.d.ts +15 -8
- package/dist/components/tab-strip/TabStrip.svelte +87 -68
- package/dist/components/tabs/Tabs.svelte +129 -99
- package/dist/components/tabs/Tabs.svelte.d.ts +6 -4
- package/dist/components/textarea/Textarea.svelte.d.ts +1 -1
- package/dist/components/toast/Toaster.svelte +132 -115
- package/dist/components/toast/Toaster.svelte.d.ts +5 -0
- package/dist/components/toast/toasts.svelte.d.ts +10 -23
- package/dist/components/toast/toasts.svelte.js +62 -40
- package/dist/components/toggle/Toggle.svelte +15 -9
- package/dist/components/toggle/Toggle.svelte.d.ts +8 -17
- package/dist/components/toggle-group/ToggleGroupItem.svelte +20 -9
- package/dist/components/toggle-group/ToggleGroupItem.svelte.d.ts +10 -10
- package/dist/components/toggle-group/ToggleGroupRoot.svelte +33 -18
- package/dist/components/toggle-group/ToggleGroupRoot.svelte.d.ts +4 -4
- package/dist/components/tool/ToolRoot.svelte.d.ts +1 -1
- package/dist/components/tooltip/TooltipContent.svelte +38 -28
- package/dist/components/tooltip/TooltipContent.svelte.d.ts +6 -15
- package/dist/components/tooltip/TooltipProvider.svelte +34 -10
- package/dist/components/tooltip/TooltipProvider.svelte.d.ts +18 -4
- package/dist/components/tooltip/TooltipRoot.svelte +52 -23
- package/dist/components/tooltip/TooltipRoot.svelte.d.ts +10 -10
- package/dist/components/tooltip/TooltipTrigger.svelte +14 -17
- package/dist/components/tooltip/TooltipTrigger.svelte.d.ts +10 -4
- package/dist/components/tooltip/index.d.ts +1 -1
- package/dist/components/tooltip/index.js +1 -1
- package/dist/components/work-fold/WorkFold.svelte +14 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +1 -1
- package/dist/internal/TooltipScope.svelte +4 -4
- package/dist/internal/layer.d.ts +11 -9
- package/dist/internal/layer.js +21 -15
- package/dist/internal/loose.d.ts +30 -5
- package/dist/internal/loose.js +1 -1
- package/dist/internal/markers.stylex.d.ts +0 -4
- package/dist/internal/markers.stylex.js +0 -2
- package/dist/internal/toggle.d.ts +3 -0
- package/dist/internal/toggle.js +6 -2
- package/dist/internal/tooltip-trigger.d.ts +7 -6
- package/dist/internal/tooltip-trigger.js +9 -12
- package/dist/vite.d.ts +7 -1
- package/dist/vite.js +20 -5
- package/package.json +3 -2
- package/skills/building-ui/SKILL.md +22 -22
- package/skills/building-ui/references/components.md +30 -4
- package/skills/markdown/SKILL.md +1 -1
- package/skills/setup/SKILL.md +4 -8
- package/skills/styling/SKILL.md +1 -1
- package/skills/theming/SKILL.md +3 -7
package/README.md
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
A component library for Svelte 5, styled with [StyleX](https://stylexjs.com). Beside buttons and
|
|
4
4
|
dialogs it has the parts an app for AI agents is made of: a window's shell, a conversation, a
|
|
5
5
|
composer, and a timeline of what an agent did. Styles are compiled to atomic CSS at build time, so
|
|
6
|
-
no styling code runs in the browser.
|
|
6
|
+
no styling code runs in the browser. Menus, dialogs, tooltips, selects and the other controls that
|
|
7
|
+
take keys and focus are built on [ui-sdk](https://ui-sdk.dev), which handles their behaviour and
|
|
8
|
+
accessibility.
|
|
7
9
|
|
|
8
10
|
Docs, live examples and every component: **[narvi.dpeter.dev](https://narvi.dpeter.dev)**.
|
|
9
11
|
|
package/dist/base.css
CHANGED
|
@@ -10,6 +10,9 @@
|
|
|
10
10
|
* A colour followed by a comment naming a token is copied from that token when the library
|
|
11
11
|
* is built (`scripts/base-css.js`), so the page and the components never drift apart.
|
|
12
12
|
*/
|
|
13
|
+
/* ui-sdk's runtime rules sit below Narvi's (see `UI_SDK_LAYER` in the Vite plugin) */
|
|
14
|
+
@layer ui-sdk, narvi.base;
|
|
15
|
+
|
|
13
16
|
@layer narvi.base {
|
|
14
17
|
*,
|
|
15
18
|
*::before,
|
|
@@ -66,7 +66,9 @@
|
|
|
66
66
|
display: 'flex',
|
|
67
67
|
flexDirection: 'column',
|
|
68
68
|
flexShrink: 0,
|
|
69
|
-
|
|
69
|
+
// The handle's size while it is dragged, which is not inherited, so the panel restyles
|
|
70
|
+
// alone as it moves; its width once it is let go
|
|
71
|
+
width: 'var(--narvi-size, var(--narvi-panel-width))',
|
|
70
72
|
minWidth: 0,
|
|
71
73
|
minHeight: 0,
|
|
72
74
|
overflow: 'clip',
|
|
@@ -201,7 +203,6 @@
|
|
|
201
203
|
defaultValue={defaultWidth}
|
|
202
204
|
edge="start"
|
|
203
205
|
target={element}
|
|
204
|
-
property="--narvi-panel-width"
|
|
205
206
|
label={edgeLabel ?? `Resize the ${label.toLowerCase()} panel`}
|
|
206
207
|
title={edgeTitle}
|
|
207
208
|
sx={styles.handle}
|
|
@@ -9,9 +9,11 @@
|
|
|
9
9
|
import Spinner from '../spinner/Spinner.svelte';
|
|
10
10
|
import * as Tooltip from '../tooltip/index.js';
|
|
11
11
|
import TooltipScope from '../../internal/TooltipScope.svelte';
|
|
12
|
-
import { mergeProps } from 'bits-ui';
|
|
13
12
|
import '../../internal/icons.css';
|
|
14
13
|
|
|
14
|
+
// Last in its slot, not counting a tooltip, which ui-sdk renders in place after its trigger
|
|
15
|
+
const LAST = ':nth-last-child(1 of :not([data-slot="tooltip-content"]))';
|
|
16
|
+
|
|
15
17
|
/**
|
|
16
18
|
* `primary` is the one solid; `secondary` an edge; `soft` a fill of the accent. `ghost` has
|
|
17
19
|
* a fill only under the pointer, `bare` never has one, and `link` is words that underline.
|
|
@@ -83,7 +85,7 @@
|
|
|
83
85
|
|
|
84
86
|
// One key for every hover, so the catalog can show it without a pointer
|
|
85
87
|
const HOVER = ':is(:hover, [data-preview~="hover"])';
|
|
86
|
-
// The trigger of a menu, a popover or a select while what it opened is showing.
|
|
88
|
+
// The trigger of a menu, a popover or a select while what it opened is showing. ui-sdk
|
|
87
89
|
// marks it with `aria-expanded`, which a disclosure's trigger carries too: only a popup's
|
|
88
90
|
// (`aria-haspopup`) is held in its open look.
|
|
89
91
|
// A toggle button that is pressed holds the same look.
|
|
@@ -204,7 +206,7 @@
|
|
|
204
206
|
paddingInline: 0,
|
|
205
207
|
marginInlineEnd: {
|
|
206
208
|
default: null,
|
|
207
|
-
|
|
209
|
+
[LAST]: `calc(var(--narvi-icon-flush, 0) * (0.75rem - ${d('1.25rem')}) / 2)`
|
|
208
210
|
}
|
|
209
211
|
},
|
|
210
212
|
iconXs: {
|
|
@@ -212,7 +214,7 @@
|
|
|
212
214
|
paddingInline: 0,
|
|
213
215
|
marginInlineEnd: {
|
|
214
216
|
default: null,
|
|
215
|
-
|
|
217
|
+
[LAST]: `calc(var(--narvi-icon-flush, 0) * (0.875rem - ${d('1.5rem')}) / 2)`
|
|
216
218
|
}
|
|
217
219
|
},
|
|
218
220
|
iconSm: {
|
|
@@ -220,7 +222,7 @@
|
|
|
220
222
|
paddingInline: 0,
|
|
221
223
|
marginInlineEnd: {
|
|
222
224
|
default: null,
|
|
223
|
-
|
|
225
|
+
[LAST]: `calc(var(--narvi-icon-flush, 0) * (0.875rem - ${d('1.75rem')}) / 2)`
|
|
224
226
|
}
|
|
225
227
|
},
|
|
226
228
|
iconMd: {
|
|
@@ -228,7 +230,7 @@
|
|
|
228
230
|
paddingInline: 0,
|
|
229
231
|
marginInlineEnd: {
|
|
230
232
|
default: null,
|
|
231
|
-
|
|
233
|
+
[LAST]: `calc(var(--narvi-icon-flush, 0) * (1rem - ${d('2rem')}) / 2)`
|
|
232
234
|
}
|
|
233
235
|
},
|
|
234
236
|
iconLg: {
|
|
@@ -236,7 +238,7 @@
|
|
|
236
238
|
paddingInline: 0,
|
|
237
239
|
marginInlineEnd: {
|
|
238
240
|
default: null,
|
|
239
|
-
|
|
241
|
+
[LAST]: `calc(var(--narvi-icon-flush, 0) * (1.125rem - ${d('2.5rem')}) / 2)`
|
|
240
242
|
}
|
|
241
243
|
},
|
|
242
244
|
|
|
@@ -512,10 +514,14 @@
|
|
|
512
514
|
class: className,
|
|
513
515
|
ref = $bindable(null),
|
|
514
516
|
children,
|
|
517
|
+
onclick,
|
|
515
518
|
...rest
|
|
516
519
|
}: ButtonProps = $props();
|
|
517
520
|
|
|
518
|
-
|
|
521
|
+
// ui-sdk's triggers mark theirs disabled with an empty attribute, which reaches a Button
|
|
522
|
+
// rendered as one (`child`) as `disabled=""`
|
|
523
|
+
const off = $derived(!!disabled || (disabled as unknown) === '');
|
|
524
|
+
const inert = $derived(off || loading);
|
|
519
525
|
|
|
520
526
|
const rootAttrs = $derived(
|
|
521
527
|
attrs(
|
|
@@ -527,7 +533,7 @@
|
|
|
527
533
|
(shape === 'pill' || variant === 'floating') && styles.pill,
|
|
528
534
|
justify === 'start' && styles.start,
|
|
529
535
|
variantStyles[variant],
|
|
530
|
-
|
|
536
|
+
off && styles.disabled,
|
|
531
537
|
loading && styles.loading,
|
|
532
538
|
sx
|
|
533
539
|
],
|
|
@@ -554,9 +560,13 @@
|
|
|
554
560
|
{/if}
|
|
555
561
|
{/snippet}
|
|
556
562
|
|
|
557
|
-
<!--
|
|
558
|
-
|
|
559
|
-
|
|
563
|
+
<!--
|
|
564
|
+
The element, with its own props, or a tooltip trigger's: the Tooltip.Trigger takes the
|
|
565
|
+
button's props and hands them back merged with its own, which is ui-sdk's way to merge them.
|
|
566
|
+
Its `type="button"` gives way to the button's own type, and its click goes through here, so a
|
|
567
|
+
button that is loading ignores it.
|
|
568
|
+
-->
|
|
569
|
+
{#snippet control(own: Record<string, unknown>)}
|
|
560
570
|
{#if href !== undefined}
|
|
561
571
|
<a
|
|
562
572
|
bind:this={ref}
|
|
@@ -566,7 +576,9 @@
|
|
|
566
576
|
aria-disabled={inert ? true : undefined}
|
|
567
577
|
aria-busy={loading ? true : undefined}
|
|
568
578
|
{...own}
|
|
579
|
+
type={undefined}
|
|
569
580
|
{...rootAttrs}
|
|
581
|
+
onclick={onclick as HTMLAnchorAttributes['onclick']}
|
|
570
582
|
>
|
|
571
583
|
{@render content()}
|
|
572
584
|
</a>
|
|
@@ -574,19 +586,19 @@
|
|
|
574
586
|
<button
|
|
575
587
|
bind:this={ref}
|
|
576
588
|
data-icons
|
|
577
|
-
{
|
|
578
|
-
disabled={disabled || undefined}
|
|
589
|
+
disabled={off || undefined}
|
|
579
590
|
aria-pressed={pressed}
|
|
580
591
|
aria-disabled={loading ? true : undefined}
|
|
581
592
|
aria-busy={loading ? true : undefined}
|
|
582
593
|
{...own}
|
|
594
|
+
{type}
|
|
583
595
|
{...rootAttrs}
|
|
584
596
|
onclick={loading
|
|
585
597
|
? (event: MouseEvent) => {
|
|
586
598
|
event.preventDefault();
|
|
587
599
|
event.stopPropagation();
|
|
588
600
|
}
|
|
589
|
-
: (
|
|
601
|
+
: (onclick as HTMLButtonAttributes['onclick'])}
|
|
590
602
|
>
|
|
591
603
|
{@render content()}
|
|
592
604
|
</button>
|
|
@@ -596,7 +608,7 @@
|
|
|
596
608
|
{#if tooltip}
|
|
597
609
|
<TooltipScope>
|
|
598
610
|
<Tooltip.Root>
|
|
599
|
-
<Tooltip.Trigger>
|
|
611
|
+
<Tooltip.Trigger {...rest}>
|
|
600
612
|
{#snippet child({ props })}{@render control(props)}{/snippet}
|
|
601
613
|
</Tooltip.Trigger>
|
|
602
614
|
<Tooltip.Content side={tooltipSide} shortcut={tooltipShortcut}>
|
|
@@ -605,5 +617,5 @@
|
|
|
605
617
|
</Tooltip.Root>
|
|
606
618
|
</TooltipScope>
|
|
607
619
|
{:else}
|
|
608
|
-
{@render control(
|
|
620
|
+
{@render control(rest)}
|
|
609
621
|
{/if}
|
|
@@ -1,26 +1,58 @@
|
|
|
1
1
|
<script lang="ts" module>
|
|
2
|
+
import type { ChangeDetails } from '@ui-sdk/core';
|
|
3
|
+
import type { CheckboxCheckedChangeReason } from '@ui-sdk/core/checkbox';
|
|
4
|
+
import { Checkbox as UiCheckbox } from '@ui-sdk/svelte/checkbox';
|
|
2
5
|
import * as stylex from '@stylexjs/stylex';
|
|
3
6
|
import type { Snippet } from 'svelte';
|
|
4
|
-
import type { ChangeEventHandler
|
|
7
|
+
import type { ChangeEventHandler } from 'svelte/elements';
|
|
8
|
+
import type { Loose, PartProps } from '../../internal/loose.js';
|
|
5
9
|
import { attrs, classes, type Sx } from '../../internal/sx.js';
|
|
6
10
|
import { colors, font, motion, radius } from '../../tokens.stylex.js';
|
|
7
11
|
import { media } from '../../media.stylex.js';
|
|
12
|
+
import { getFieldContext } from '../field/context.js';
|
|
8
13
|
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
14
|
+
export interface CheckboxProps extends Loose<
|
|
15
|
+
Omit<
|
|
16
|
+
PartProps<typeof UiCheckbox>,
|
|
17
|
+
| 'children'
|
|
18
|
+
| 'render'
|
|
19
|
+
| 'checked'
|
|
20
|
+
| 'defaultChecked'
|
|
21
|
+
| 'onCheckedChange'
|
|
22
|
+
| 'onchange'
|
|
23
|
+
| 'parent'
|
|
24
|
+
> & {
|
|
25
|
+
/** Whether it is ticked. Bindable. */
|
|
26
|
+
checked?: boolean | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Called with the new value when the person ticks or clears it, and the change's details
|
|
29
|
+
* after: `details.reason`, and `details.cancel()` to keep it as it was.
|
|
30
|
+
*/
|
|
31
|
+
onCheckedChange?:
|
|
32
|
+
| ((checked: boolean, details: ChangeDetails<CheckboxCheckedChangeReason>) => void)
|
|
33
|
+
| undefined;
|
|
34
|
+
/**
|
|
35
|
+
* The native change event, from the form input underneath: `event.currentTarget.checked`
|
|
36
|
+
* is the new value. It follows `onCheckedChange`.
|
|
37
|
+
*/
|
|
38
|
+
onchange?: ChangeEventHandler<HTMLInputElement> | undefined;
|
|
39
|
+
/** Shows a dash for a partially selected group. Cleared when the user toggles the box. */
|
|
40
|
+
indeterminate?: boolean | undefined;
|
|
41
|
+
/** A second, quieter line under the label. */
|
|
42
|
+
description?: string | undefined;
|
|
43
|
+
/** Applied to the outermost element: the label when there is one, else the checkbox. */
|
|
44
|
+
sx?: Sx | undefined;
|
|
45
|
+
/** The checkbox's button. Bindable. */
|
|
46
|
+
ref?: HTMLButtonElement | null | undefined;
|
|
47
|
+
/** Label content. Without it, give the checkbox an `aria-label`. */
|
|
48
|
+
children?: Snippet | undefined;
|
|
49
|
+
}
|
|
50
|
+
> {}
|
|
51
|
+
|
|
52
|
+
// The same look serves ui-sdk's checkbox, a button with state attributes, and a native
|
|
53
|
+
// checkbox, which Markdown's task lists write as a string (`checkboxClass`)
|
|
54
|
+
const ON = ':is(:checked, [data-checked])';
|
|
55
|
+
const MIXED = ':is(:indeterminate, [data-indeterminate])';
|
|
24
56
|
|
|
25
57
|
const CHECK = `url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2.5 6.5 5 9l4.5-6'/%3E%3C/svg%3E")`;
|
|
26
58
|
const DASH = `url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M2.5 6h7'/%3E%3C/svg%3E")`;
|
|
@@ -37,6 +69,8 @@
|
|
|
37
69
|
cursor: 'pointer',
|
|
38
70
|
WebkitTapHighlightColor: 'transparent'
|
|
39
71
|
},
|
|
72
|
+
// A label with no break in it, such as a URL, wraps rather than running out of the box
|
|
73
|
+
text: { minWidth: 0, overflowWrap: 'anywhere' },
|
|
40
74
|
rootDisabled: {
|
|
41
75
|
color: colors.textSubtle,
|
|
42
76
|
cursor: 'not-allowed'
|
|
@@ -56,6 +90,7 @@
|
|
|
56
90
|
width: '1rem',
|
|
57
91
|
height: '1rem',
|
|
58
92
|
margin: 0,
|
|
93
|
+
padding: 0,
|
|
59
94
|
// Centre the 16px box on the label's 20px first line
|
|
60
95
|
marginBlock: '2px',
|
|
61
96
|
borderWidth: '1px',
|
|
@@ -64,20 +99,20 @@
|
|
|
64
99
|
borderColor: {
|
|
65
100
|
default: colors.borderControl,
|
|
66
101
|
':hover': { default: null, [media.hover]: colors.borderControlHover },
|
|
67
|
-
|
|
68
|
-
|
|
102
|
+
[ON]: 'transparent',
|
|
103
|
+
[MIXED]: 'transparent',
|
|
69
104
|
[media.forcedColors]: 'ButtonText'
|
|
70
105
|
},
|
|
71
106
|
backgroundColor: { default: 'transparent', [media.forcedColors]: 'Canvas' },
|
|
72
107
|
backgroundOrigin: 'border-box',
|
|
73
108
|
backgroundImage: {
|
|
74
109
|
default: 'none',
|
|
75
|
-
|
|
76
|
-
|
|
110
|
+
[ON]: `linear-gradient(${colors.accent}, ${colors.accent})`,
|
|
111
|
+
[MIXED]: `linear-gradient(${colors.accent}, ${colors.accent})`,
|
|
77
112
|
[media.forcedColors]: {
|
|
78
113
|
default: 'none',
|
|
79
|
-
|
|
80
|
-
|
|
114
|
+
[ON]: 'linear-gradient(Highlight, Highlight)',
|
|
115
|
+
[MIXED]: 'linear-gradient(Highlight, Highlight)'
|
|
81
116
|
}
|
|
82
117
|
},
|
|
83
118
|
forcedColorAdjust: 'none',
|
|
@@ -96,24 +131,24 @@
|
|
|
96
131
|
width: '0.625rem',
|
|
97
132
|
height: '0.625rem',
|
|
98
133
|
backgroundColor: { default: colors.onAccent, [media.forcedColors]: 'HighlightText' },
|
|
99
|
-
maskImage: { default: CHECK,
|
|
134
|
+
maskImage: { default: CHECK, [MIXED]: DASH },
|
|
100
135
|
maskSize: 'contain',
|
|
101
136
|
maskRepeat: 'no-repeat',
|
|
102
137
|
maskPosition: 'center',
|
|
103
|
-
opacity: { default: 0,
|
|
138
|
+
opacity: { default: 0, [ON]: 1, [MIXED]: 1 },
|
|
104
139
|
// The mark settles in from just under full size, with a touch of blur to
|
|
105
140
|
// soften the swap. It never grows from nothing, and it is quick: boxes
|
|
106
141
|
// get ticked many times a day.
|
|
107
142
|
scale: {
|
|
108
143
|
default: null,
|
|
109
|
-
[media.motion]: { default: 0.9,
|
|
144
|
+
[media.motion]: { default: 0.9, [ON]: 1, [MIXED]: 1 }
|
|
110
145
|
},
|
|
111
146
|
filter: {
|
|
112
147
|
default: null,
|
|
113
148
|
[media.motion]: {
|
|
114
149
|
default: 'blur(2px)',
|
|
115
|
-
|
|
116
|
-
|
|
150
|
+
[ON]: 'blur(0px)',
|
|
151
|
+
[MIXED]: 'blur(0px)'
|
|
117
152
|
}
|
|
118
153
|
},
|
|
119
154
|
transitionProperty: { default: 'opacity', [media.motion]: 'opacity, scale, filter' },
|
|
@@ -147,7 +182,11 @@
|
|
|
147
182
|
onCheckedChange,
|
|
148
183
|
onchange,
|
|
149
184
|
indeterminate = $bindable(false),
|
|
150
|
-
disabled
|
|
185
|
+
disabled,
|
|
186
|
+
required,
|
|
187
|
+
id,
|
|
188
|
+
'aria-describedby': describedBy,
|
|
189
|
+
'aria-invalid': ariaInvalid,
|
|
151
190
|
description,
|
|
152
191
|
sx,
|
|
153
192
|
class: className,
|
|
@@ -156,25 +195,47 @@
|
|
|
156
195
|
...rest
|
|
157
196
|
}: CheckboxProps = $props();
|
|
158
197
|
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
198
|
+
const field = getFieldContext();
|
|
199
|
+
const isDisabled = $derived(disabled ?? field?.disabled ?? false);
|
|
200
|
+
|
|
201
|
+
// ui-sdk's checkbox is a button, and the native change event fires on the form input it
|
|
202
|
+
// keeps beside it, so `onchange` is heard there, where `currentTarget.checked` is the new value.
|
|
203
|
+
$effect(() => {
|
|
204
|
+
const input = ref?.nextElementSibling;
|
|
205
|
+
if (!onchange || !(input instanceof HTMLInputElement)) return;
|
|
206
|
+
const listener = onchange as unknown as EventListener;
|
|
207
|
+
input.addEventListener('change', listener);
|
|
208
|
+
return () => input.removeEventListener('change', listener);
|
|
209
|
+
});
|
|
163
210
|
</script>
|
|
164
211
|
|
|
212
|
+
{#snippet control(own: (Sx | false)[], className?: CheckboxProps['class'])}
|
|
213
|
+
<UiCheckbox
|
|
214
|
+
checked={indeterminate ? 'indeterminate' : checked}
|
|
215
|
+
onCheckedChange={(next, details) => {
|
|
216
|
+
onCheckedChange?.(next === true, details);
|
|
217
|
+
if (details.canceled) return;
|
|
218
|
+
checked = next === true;
|
|
219
|
+
indeterminate = next === 'indeterminate';
|
|
220
|
+
}}
|
|
221
|
+
id={id ?? field?.id}
|
|
222
|
+
disabled={isDisabled}
|
|
223
|
+
required={required ?? field?.required}
|
|
224
|
+
aria-invalid={ariaInvalid ?? (field?.invalid || undefined)}
|
|
225
|
+
aria-describedby={describedBy ?? field?.describedBy}
|
|
226
|
+
{...rest}
|
|
227
|
+
{...attrs([styles.input, ...own], className)}
|
|
228
|
+
{@attach (element: HTMLButtonElement) => {
|
|
229
|
+
ref = element;
|
|
230
|
+
return () => (ref = null);
|
|
231
|
+
}}
|
|
232
|
+
/>
|
|
233
|
+
{/snippet}
|
|
234
|
+
|
|
165
235
|
{#if children}
|
|
166
|
-
<label {...attrs([styles.root,
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
bind:checked
|
|
170
|
-
bind:indeterminate
|
|
171
|
-
type="checkbox"
|
|
172
|
-
{disabled}
|
|
173
|
-
{...rest}
|
|
174
|
-
onchange={changed}
|
|
175
|
-
{...stylex.attrs(styles.input)}
|
|
176
|
-
/>
|
|
177
|
-
<span>
|
|
236
|
+
<label {...attrs([styles.root, isDisabled && styles.rootDisabled, sx], className)}>
|
|
237
|
+
{@render control([])}
|
|
238
|
+
<span {...stylex.attrs(styles.text)}>
|
|
178
239
|
{@render children()}
|
|
179
240
|
{#if description}
|
|
180
241
|
<span {...stylex.attrs(styles.description)}>{description}</span>
|
|
@@ -182,14 +243,5 @@
|
|
|
182
243
|
</span>
|
|
183
244
|
</label>
|
|
184
245
|
{:else}
|
|
185
|
-
|
|
186
|
-
bind:this={ref}
|
|
187
|
-
bind:checked
|
|
188
|
-
bind:indeterminate
|
|
189
|
-
type="checkbox"
|
|
190
|
-
{disabled}
|
|
191
|
-
{...rest}
|
|
192
|
-
onchange={changed}
|
|
193
|
-
{...attrs([styles.input, styles.standalone, sx], className)}
|
|
194
|
-
/>
|
|
246
|
+
{@render control([styles.standalone, sx], className)}
|
|
195
247
|
{/if}
|
|
@@ -1,21 +1,35 @@
|
|
|
1
|
+
import type { ChangeDetails } from '@ui-sdk/core';
|
|
2
|
+
import type { CheckboxCheckedChangeReason } from '@ui-sdk/core/checkbox';
|
|
3
|
+
import { Checkbox as UiCheckbox } from '@ui-sdk/svelte/checkbox';
|
|
1
4
|
import type { Snippet } from 'svelte';
|
|
2
|
-
import type {
|
|
5
|
+
import type { ChangeEventHandler } from 'svelte/elements';
|
|
6
|
+
import type { Loose, PartProps } from '../../internal/loose.js';
|
|
3
7
|
import { type Sx } from '../../internal/sx.js';
|
|
4
|
-
export
|
|
8
|
+
export interface CheckboxProps extends Loose<Omit<PartProps<typeof UiCheckbox>, 'children' | 'render' | 'checked' | 'defaultChecked' | 'onCheckedChange' | 'onchange' | 'parent'> & {
|
|
9
|
+
/** Whether it is ticked. Bindable. */
|
|
5
10
|
checked?: boolean | undefined;
|
|
6
|
-
/**
|
|
7
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Called with the new value when the person ticks or clears it, and the change's details
|
|
13
|
+
* after: `details.reason`, and `details.cancel()` to keep it as it was.
|
|
14
|
+
*/
|
|
15
|
+
onCheckedChange?: ((checked: boolean, details: ChangeDetails<CheckboxCheckedChangeReason>) => void) | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* The native change event, from the form input underneath: `event.currentTarget.checked`
|
|
18
|
+
* is the new value. It follows `onCheckedChange`.
|
|
19
|
+
*/
|
|
20
|
+
onchange?: ChangeEventHandler<HTMLInputElement> | undefined;
|
|
8
21
|
/** Shows a dash for a partially selected group. Cleared when the user toggles the box. */
|
|
9
22
|
indeterminate?: boolean | undefined;
|
|
10
|
-
disabled?: boolean | undefined;
|
|
11
23
|
/** A second, quieter line under the label. */
|
|
12
24
|
description?: string | undefined;
|
|
13
|
-
/** Applied to the outermost element: the label when there is one, else the
|
|
25
|
+
/** Applied to the outermost element: the label when there is one, else the checkbox. */
|
|
14
26
|
sx?: Sx | undefined;
|
|
15
|
-
|
|
27
|
+
/** The checkbox's button. Bindable. */
|
|
28
|
+
ref?: HTMLButtonElement | null | undefined;
|
|
16
29
|
/** Label content. Without it, give the checkbox an `aria-label`. */
|
|
17
30
|
children?: Snippet | undefined;
|
|
18
|
-
}
|
|
31
|
+
}> {
|
|
32
|
+
}
|
|
19
33
|
/**
|
|
20
34
|
* The class of a checkbox that stands alone, as the component gives it one: for the parts
|
|
21
35
|
* of Markdown that are written as a string.
|
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
<!--
|
|
2
2
|
One choice among a few, each a card with a title and a line of detail: a plan, a way to sign
|
|
3
|
-
in, where a thread runs.
|
|
4
|
-
the choice, and it submits with a form. For short labels alone,
|
|
3
|
+
in, where a thread runs. Built on ui-sdk's radio group: each card is a radio, the group is one
|
|
4
|
+
tab stop, the arrow keys move the choice, and it submits with a form. For short labels alone,
|
|
5
|
+
use a SegmentedControl.
|
|
5
6
|
-->
|
|
6
7
|
<script lang="ts" module>
|
|
8
|
+
import type { ChangeDetails } from '@ui-sdk/core';
|
|
9
|
+
import type { RadioGroupValueChangeReason } from '@ui-sdk/core/radio';
|
|
10
|
+
import { Radio, RadioGroup } from '@ui-sdk/svelte/radio';
|
|
7
11
|
import type { IconComponent } from '../../internal/icon.js';
|
|
8
12
|
import * as stylex from '@stylexjs/stylex';
|
|
9
|
-
import type { HTMLAttributes } from 'svelte/elements';
|
|
10
13
|
import '../../internal/icons.css';
|
|
14
|
+
import type { Loose, PartProps } from '../../internal/loose.js';
|
|
11
15
|
import { attrs, type Sx } from '../../internal/sx.js';
|
|
12
16
|
import { colors, density, motion, radius, space } from '../../tokens.stylex.js';
|
|
13
17
|
import { media } from '../../media.stylex.js';
|
|
14
18
|
import { typography } from '../../typography.js';
|
|
15
|
-
import { visuallyHidden } from '../../visually-hidden.js';
|
|
16
19
|
|
|
17
20
|
export type ChoiceCardOption = {
|
|
18
21
|
value: string;
|
|
@@ -24,23 +27,31 @@
|
|
|
24
27
|
disabled?: boolean | undefined;
|
|
25
28
|
};
|
|
26
29
|
|
|
27
|
-
export
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
30
|
+
export interface ChoiceCardsProps extends Loose<
|
|
31
|
+
Omit<
|
|
32
|
+
PartProps<typeof RadioGroup>,
|
|
33
|
+
'children' | 'render' | 'value' | 'defaultValue' | 'onValueChange'
|
|
34
|
+
> & {
|
|
35
|
+
options: ChoiceCardOption[];
|
|
36
|
+
/** The chosen option's value. Bindable. */
|
|
37
|
+
value?: string | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* Called with the new value when the person chooses, and the change's details after:
|
|
40
|
+
* `details.reason`, and `details.cancel()` to keep the choice as it was.
|
|
41
|
+
*/
|
|
42
|
+
onValueChange?:
|
|
43
|
+
((value: string, details: ChangeDetails<RadioGroupValueChangeReason>) => void) | undefined;
|
|
44
|
+
/** How many cards to a row. Without it, as many as fit at 12rem or more each. */
|
|
45
|
+
columns?: 1 | 2 | 3 | 4 | undefined;
|
|
46
|
+
sx?: Sx | undefined;
|
|
47
|
+
}
|
|
48
|
+
> {}
|
|
40
49
|
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
const
|
|
50
|
+
// Each card is ui-sdk's radio, a button with state attributes
|
|
51
|
+
const CHECKED = ':is([data-checked])';
|
|
52
|
+
const FOCUSED = ':focus-visible';
|
|
53
|
+
// One option disabled is a disabled button; the whole group disabled marks each `data-disabled`
|
|
54
|
+
const OFF = ':is(:disabled, [data-disabled])';
|
|
44
55
|
|
|
45
56
|
/** A length at the window's density (`density` in the tokens). */
|
|
46
57
|
const d = (rem: string) => `calc(${rem} * ${density.factor})`;
|
|
@@ -58,9 +69,20 @@
|
|
|
58
69
|
alignItems: 'flex-start',
|
|
59
70
|
gap: space.x3,
|
|
60
71
|
minWidth: 0,
|
|
72
|
+
margin: 0,
|
|
61
73
|
paddingBlock: space.x3,
|
|
62
74
|
paddingInline: d('0.875rem'),
|
|
75
|
+
borderWidth: 0,
|
|
63
76
|
borderRadius: radius.panel,
|
|
77
|
+
appearance: 'none',
|
|
78
|
+
// A button's own type and alignment give way to the text's
|
|
79
|
+
color: 'inherit',
|
|
80
|
+
fontFamily: 'inherit',
|
|
81
|
+
fontSize: 'inherit',
|
|
82
|
+
fontWeight: 'inherit',
|
|
83
|
+
lineHeight: 'inherit',
|
|
84
|
+
letterSpacing: 'inherit',
|
|
85
|
+
textAlign: 'start',
|
|
64
86
|
backgroundColor: colors.bgRaised,
|
|
65
87
|
// The edge says which is chosen: the accent, twice as thick
|
|
66
88
|
boxShadow: {
|
|
@@ -84,7 +106,14 @@
|
|
|
84
106
|
WebkitTapHighlightColor: 'transparent'
|
|
85
107
|
},
|
|
86
108
|
icon: { display: 'grid', placeItems: 'center', height: '1.25rem', color: colors.textMuted },
|
|
87
|
-
|
|
109
|
+
// A word too long for the card, such as a URL, wraps rather than running out of it
|
|
110
|
+
text: {
|
|
111
|
+
display: 'flex',
|
|
112
|
+
flexDirection: 'column',
|
|
113
|
+
gap: '0.125rem',
|
|
114
|
+
minWidth: 0,
|
|
115
|
+
overflowWrap: 'break-word'
|
|
116
|
+
},
|
|
88
117
|
label: { color: colors.text },
|
|
89
118
|
detail: { color: colors.textMuted }
|
|
90
119
|
});
|
|
@@ -102,36 +131,36 @@
|
|
|
102
131
|
options,
|
|
103
132
|
value = $bindable(),
|
|
104
133
|
onValueChange,
|
|
105
|
-
name,
|
|
106
134
|
columns,
|
|
107
|
-
disabled = false,
|
|
108
135
|
sx,
|
|
109
136
|
class: className,
|
|
110
137
|
...rest
|
|
111
138
|
}: ChoiceCardsProps = $props();
|
|
112
139
|
|
|
113
140
|
const uid = $props.id();
|
|
141
|
+
|
|
142
|
+
function change(next: string | null, details: ChangeDetails<RadioGroupValueChangeReason>) {
|
|
143
|
+
// Nothing is chosen only after a form reset with no default, which has nothing to report
|
|
144
|
+
if (next !== null) onValueChange?.(next, details);
|
|
145
|
+
if (!details.canceled) value = next ?? undefined;
|
|
146
|
+
}
|
|
114
147
|
</script>
|
|
115
148
|
|
|
116
|
-
<
|
|
117
|
-
|
|
118
|
-
|
|
149
|
+
<RadioGroup
|
|
150
|
+
value={value ?? null}
|
|
151
|
+
onValueChange={change}
|
|
119
152
|
{...rest}
|
|
120
153
|
{...attrs([styles.root, columns && columnStyles[columns], sx], className)}
|
|
121
154
|
>
|
|
122
155
|
{#each options as option, at (option.value)}
|
|
123
156
|
{@const detailId = option.detail ? `${uid}-detail-${at}` : undefined}
|
|
124
|
-
<
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
aria-describedby={detailId}
|
|
132
|
-
onchange={() => onValueChange?.(option.value)}
|
|
133
|
-
{...stylex.attrs(visuallyHidden)}
|
|
134
|
-
/>
|
|
157
|
+
<Radio
|
|
158
|
+
value={option.value}
|
|
159
|
+
disabled={option.disabled}
|
|
160
|
+
aria-describedby={detailId}
|
|
161
|
+
data-icons
|
|
162
|
+
{...stylex.attrs(styles.card)}
|
|
163
|
+
>
|
|
135
164
|
{#if option.icon}
|
|
136
165
|
<span {...stylex.attrs(styles.icon)}><option.icon aria-hidden="true" /></span>
|
|
137
166
|
{/if}
|
|
@@ -143,6 +172,6 @@
|
|
|
143
172
|
</span>
|
|
144
173
|
{/if}
|
|
145
174
|
</span>
|
|
146
|
-
</
|
|
175
|
+
</Radio>
|
|
147
176
|
{/each}
|
|
148
|
-
</
|
|
177
|
+
</RadioGroup>
|