@diegopluna/narvi 0.4.0 → 0.5.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/README.md +3 -1
- package/dist/base.css +3 -0
- 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 +365 -347
- 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/queued-message/QueuedMessage.svelte +10 -3
- package/dist/components/queued-message/QueuedMessage.svelte.d.ts +2 -1
- package/dist/components/rail/RailItem.svelte +20 -6
- package/dist/components/reasoning/ReasoningRoot.svelte.d.ts +1 -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 +10 -6
- 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 +110 -76
- package/dist/components/tab-strip/TabStrip.svelte.d.ts +7 -2
- 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/typography.d.ts +5 -0
- package/dist/typography.js +5 -0
- package/dist/vite.d.ts +7 -1
- package/dist/vite.js +20 -5
- package/package.json +3 -2
- package/skills/building-ui/SKILL.md +21 -21
- package/skills/building-ui/references/components.md +22 -7
- package/skills/markdown/SKILL.md +1 -1
- package/skills/setup/SKILL.md +4 -8
- package/skills/styling/SKILL.md +4 -2
- package/skills/theming/SKILL.md +3 -7
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
<script lang="ts" module>
|
|
2
|
-
import { visuallyHidden } from '../../visually-hidden.js';
|
|
3
2
|
import * as stylex from '@stylexjs/stylex';
|
|
4
3
|
import type { Snippet } from 'svelte';
|
|
5
4
|
import { shared } from '../../internal/shared.js';
|
|
@@ -123,6 +122,15 @@
|
|
|
123
122
|
|
|
124
123
|
const count = $derived(typeof badge === 'number' && badge > 0 ? badge : undefined);
|
|
125
124
|
const dot = $derived(badge === true);
|
|
125
|
+
// Named in full, not by words hidden inside it: a hidden word is a box of its own, and a box
|
|
126
|
+
// is read with a space each side, as "Eregion , 2 new"
|
|
127
|
+
const name = $derived(
|
|
128
|
+
count !== undefined
|
|
129
|
+
? `${label}, ${count} new`
|
|
130
|
+
: dot
|
|
131
|
+
? `${label}, ${badgeTone === 'success' ? 'online' : 'new'}`
|
|
132
|
+
: label
|
|
133
|
+
);
|
|
126
134
|
</script>
|
|
127
135
|
|
|
128
136
|
{#snippet face()}
|
|
@@ -133,13 +141,11 @@
|
|
|
133
141
|
{...stylex.attrs(styles.badge, badgeTone === 'success' && styles.badgeSuccess)}
|
|
134
142
|
>{count > 99 ? '99+' : count}</span
|
|
135
143
|
>
|
|
136
|
-
<span {...stylex.attrs(visuallyHidden)}>, {count} new</span>
|
|
137
144
|
{:else if dot}
|
|
138
145
|
<span
|
|
139
146
|
aria-hidden="true"
|
|
140
147
|
{...stylex.attrs(styles.badge, styles.dot, badgeTone === 'success' && styles.badgeSuccess)}
|
|
141
148
|
></span>
|
|
142
|
-
<span {...stylex.attrs(visuallyHidden)}>{badgeTone === 'success' ? ', online' : ', new'}</span>
|
|
143
149
|
{/if}
|
|
144
150
|
{/snippet}
|
|
145
151
|
|
|
@@ -151,13 +157,21 @@
|
|
|
151
157
|
className
|
|
152
158
|
)}
|
|
153
159
|
{#if href !== undefined}
|
|
154
|
-
<a
|
|
155
|
-
|
|
160
|
+
<a
|
|
161
|
+
{...props}
|
|
162
|
+
{href}
|
|
163
|
+
aria-label={name}
|
|
164
|
+
data-rail-item
|
|
165
|
+
aria-current={current ? 'page' : undefined}
|
|
166
|
+
{...own}
|
|
167
|
+
>
|
|
168
|
+
{@render face()}
|
|
156
169
|
</a>
|
|
157
170
|
{:else}
|
|
158
171
|
<button
|
|
159
172
|
{...props}
|
|
160
173
|
type="button"
|
|
174
|
+
aria-label={name}
|
|
161
175
|
data-rail-item
|
|
162
176
|
aria-current={current ? 'page' : undefined}
|
|
163
177
|
{...own}
|
|
@@ -166,7 +180,7 @@
|
|
|
166
180
|
onclick?.(event);
|
|
167
181
|
}}
|
|
168
182
|
>
|
|
169
|
-
|
|
183
|
+
{@render face()}
|
|
170
184
|
</button>
|
|
171
185
|
{/if}
|
|
172
186
|
{/snippet}
|
|
@@ -20,6 +20,6 @@ export type ReasoningRootProps = Omit<HTMLAttributes<HTMLDivElement>, 'children'
|
|
|
20
20
|
/** A Reasoning.Trigger and a Reasoning.Content. */
|
|
21
21
|
children?: Snippet | undefined;
|
|
22
22
|
};
|
|
23
|
-
declare const ReasoningRoot: import("svelte").Component<ReasoningRootProps, {}, "
|
|
23
|
+
declare const ReasoningRoot: import("svelte").Component<ReasoningRootProps, {}, "open" | "ref">;
|
|
24
24
|
type ReasoningRoot = ReturnType<typeof ReasoningRoot>;
|
|
25
25
|
export default ReasoningRoot;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
<script lang="ts" module>
|
|
2
2
|
import type { IconComponent } from '../../internal/icon.js';
|
|
3
|
-
import {
|
|
3
|
+
import type { Loose, PartProps } from '../../internal/loose.js';
|
|
4
|
+
import {
|
|
5
|
+
SegmentedControl as UiSegmentedControl,
|
|
6
|
+
SegmentedControlItem
|
|
7
|
+
} from '@ui-sdk/svelte/segmented-control';
|
|
4
8
|
import * as stylex from '@stylexjs/stylex';
|
|
5
|
-
import type { HTMLAttributes } from 'svelte/elements';
|
|
6
9
|
import { attrs, type Sx } from '../../internal/sx.js';
|
|
7
10
|
import { colors, density, font, motion, radius } from '../../tokens.stylex.js';
|
|
8
11
|
import { media } from '../../media.stylex.js';
|
|
@@ -24,21 +27,34 @@
|
|
|
24
27
|
disabled?: boolean | undefined;
|
|
25
28
|
};
|
|
26
29
|
|
|
27
|
-
export
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
30
|
+
export interface SegmentedControlProps extends Loose<
|
|
31
|
+
Omit<
|
|
32
|
+
PartProps<typeof UiSegmentedControl>,
|
|
33
|
+
| 'children'
|
|
34
|
+
| 'render'
|
|
35
|
+
| 'value'
|
|
36
|
+
| 'defaultValue'
|
|
37
|
+
| 'onValueChange'
|
|
38
|
+
| 'onchange'
|
|
39
|
+
| 'orientation'
|
|
40
|
+
| 'controller'
|
|
41
|
+
| 'debug'
|
|
42
|
+
> & {
|
|
43
|
+
/** The choices, in order. Two to five read best. */
|
|
44
|
+
options: SegmentedOption[];
|
|
45
|
+
/** The selected option's value. Bindable. */
|
|
46
|
+
value?: string | undefined;
|
|
47
|
+
/** Form field name. Without one, the choice is not submitted with a form. */
|
|
48
|
+
name?: string | undefined;
|
|
49
|
+
disabled?: boolean | undefined;
|
|
50
|
+
/** Called when the person picks an option, with its value: not when `value` is set. */
|
|
51
|
+
onchange?: ((value: string) => void) | undefined;
|
|
52
|
+
sx?: Sx | undefined;
|
|
53
|
+
}
|
|
54
|
+
> {}
|
|
55
|
+
|
|
56
|
+
const CHECKED = ':is([data-checked])';
|
|
57
|
+
const DISABLED = ':is([data-disabled])';
|
|
42
58
|
|
|
43
59
|
/** A length at the window's density (`density` in the tokens). */
|
|
44
60
|
const d = (rem: string) => `calc(${rem} * ${density.factor})`;
|
|
@@ -49,7 +65,9 @@
|
|
|
49
65
|
position: 'relative',
|
|
50
66
|
display: 'inline-grid',
|
|
51
67
|
gridAutoFlow: 'column',
|
|
52
|
-
|
|
68
|
+
// Equal columns even when a label is too long for its share, so the thumb, which steps by
|
|
69
|
+
// one column, stays under the chosen option; the label is cut short instead
|
|
70
|
+
gridAutoColumns: 'minmax(0, 1fr)',
|
|
53
71
|
boxSizing: 'border-box',
|
|
54
72
|
padding: '0.1875rem',
|
|
55
73
|
borderRadius: `calc(${radius.item} + 0.1875rem)`,
|
|
@@ -88,56 +106,50 @@
|
|
|
88
106
|
transitionTimingFunction: motion.easeInOut
|
|
89
107
|
},
|
|
90
108
|
thumbHidden: { opacity: 0 },
|
|
91
|
-
option
|
|
109
|
+
// Each option is a button with the radio role; ui-sdk keeps a hidden native radio beside it
|
|
110
|
+
// for forms, out of the layout
|
|
111
|
+
item: {
|
|
112
|
+
'--narvi-icon-size': '0.875rem',
|
|
92
113
|
position: 'relative',
|
|
93
114
|
zIndex: 1,
|
|
94
|
-
display: 'grid',
|
|
95
|
-
cursor: 'pointer',
|
|
96
|
-
WebkitTapHighlightColor: 'transparent'
|
|
97
|
-
},
|
|
98
|
-
optionDisabled: { cursor: 'not-allowed', opacity: 0.5 },
|
|
99
|
-
// The radio itself is invisible and covers its option, so it takes the click and the focus
|
|
100
|
-
input: {
|
|
101
|
-
position: 'absolute',
|
|
102
|
-
inset: 0,
|
|
103
|
-
width: '100%',
|
|
104
|
-
height: '100%',
|
|
105
|
-
margin: 0,
|
|
106
|
-
opacity: 0,
|
|
107
|
-
appearance: 'none',
|
|
108
|
-
cursor: 'inherit'
|
|
109
|
-
},
|
|
110
|
-
text: {
|
|
111
|
-
'--narvi-icon-size': '0.875rem',
|
|
112
115
|
display: 'flex',
|
|
113
116
|
alignItems: 'center',
|
|
114
117
|
justifyContent: 'center',
|
|
115
118
|
gap: '0.375rem',
|
|
116
119
|
minHeight: d('1.75rem'),
|
|
120
|
+
margin: 0,
|
|
121
|
+
paddingBlock: 0,
|
|
117
122
|
paddingInline: d('0.75rem'),
|
|
123
|
+
borderWidth: 0,
|
|
118
124
|
borderRadius: radius.item,
|
|
125
|
+
backgroundColor: 'transparent',
|
|
119
126
|
color: {
|
|
120
127
|
default: colors.textMuted,
|
|
121
128
|
':hover': { default: null, [media.hover]: colors.text },
|
|
122
|
-
[
|
|
129
|
+
[CHECKED]: colors.text
|
|
123
130
|
},
|
|
131
|
+
fontFamily: 'inherit',
|
|
124
132
|
fontSize: font.sizeBody,
|
|
125
|
-
fontWeight: {
|
|
126
|
-
default: font.weightMedium,
|
|
127
|
-
[stylex.when.siblingBefore(':checked', segmentedInputMarker)]: font.weightSemibold
|
|
128
|
-
},
|
|
133
|
+
fontWeight: { default: font.weightMedium, [CHECKED]: font.weightSemibold },
|
|
129
134
|
lineHeight: 1,
|
|
130
135
|
whiteSpace: 'nowrap',
|
|
136
|
+
cursor: { default: 'pointer', [DISABLED]: 'not-allowed' },
|
|
137
|
+
opacity: { default: 1, [DISABLED]: 0.5 },
|
|
138
|
+
WebkitTapHighlightColor: 'transparent',
|
|
131
139
|
outlineStyle: 'solid',
|
|
132
140
|
outlineWidth: '2px',
|
|
133
141
|
outlineOffset: '1px',
|
|
134
|
-
outlineColor: {
|
|
135
|
-
default: 'transparent',
|
|
136
|
-
[stylex.when.siblingBefore(':focus-visible', segmentedInputMarker)]: colors.focusRing
|
|
137
|
-
},
|
|
142
|
+
outlineColor: { default: 'transparent', ':focus-visible': colors.focusRing },
|
|
138
143
|
transitionProperty: 'color',
|
|
139
144
|
transitionDuration: motion.base,
|
|
140
145
|
transitionTimingFunction: 'ease'
|
|
146
|
+
},
|
|
147
|
+
// The line box is taller than the item's 1, so a cut label keeps its accents and descenders
|
|
148
|
+
label: {
|
|
149
|
+
minWidth: 0,
|
|
150
|
+
overflow: 'hidden',
|
|
151
|
+
textOverflow: 'ellipsis',
|
|
152
|
+
lineHeight: font.leadingSnug
|
|
141
153
|
}
|
|
142
154
|
});
|
|
143
155
|
</script>
|
|
@@ -154,7 +166,6 @@
|
|
|
154
166
|
...rest
|
|
155
167
|
}: SegmentedControlProps = $props();
|
|
156
168
|
|
|
157
|
-
const uid = $props.id();
|
|
158
169
|
const index = $derived(options.findIndex((option) => option.value === value));
|
|
159
170
|
|
|
160
171
|
// The thumb slides only for a choice made with a pointer. Arrow keys move the
|
|
@@ -166,11 +177,48 @@
|
|
|
166
177
|
const titled = $derived(options.some((option) => option.title));
|
|
167
178
|
</script>
|
|
168
179
|
|
|
169
|
-
|
|
170
|
-
|
|
180
|
+
{#snippet segments()}
|
|
181
|
+
{#each options as option (option.value)}
|
|
182
|
+
<!-- A title is the tooltip's, which describes the option whether open or not -->
|
|
183
|
+
{#snippet item(props: Record<string, unknown>)}
|
|
184
|
+
<SegmentedControlItem
|
|
185
|
+
{...props}
|
|
186
|
+
value={option.value}
|
|
187
|
+
disabled={option.disabled}
|
|
188
|
+
data-icons
|
|
189
|
+
{...stylex.attrs(styles.item)}
|
|
190
|
+
>
|
|
191
|
+
{#if option.icon}<option.icon aria-hidden="true" />{/if}<span
|
|
192
|
+
{...stylex.attrs(styles.label)}>{option.label}</span
|
|
193
|
+
>
|
|
194
|
+
</SegmentedControlItem>
|
|
195
|
+
{/snippet}
|
|
196
|
+
{#if option.title}
|
|
197
|
+
<Tooltip.Root>
|
|
198
|
+
<Tooltip.Trigger disabled={disabled || option.disabled}>
|
|
199
|
+
{#snippet child({ props })}{@render item(groupTrigger(props))}{/snippet}
|
|
200
|
+
</Tooltip.Trigger>
|
|
201
|
+
<Tooltip.Content side="top">{option.title}</Tooltip.Content>
|
|
202
|
+
</Tooltip.Root>
|
|
203
|
+
{:else}
|
|
204
|
+
{@render item({})}
|
|
205
|
+
{/if}
|
|
206
|
+
{/each}
|
|
207
|
+
{/snippet}
|
|
208
|
+
|
|
209
|
+
<!-- A radio group from ui-sdk: one tab stop, the arrow keys move and check, disabled options are
|
|
210
|
+
skipped. Its own sliding indicator is left out: the thumb below moves by index, over equal columns. -->
|
|
211
|
+
<UiSegmentedControl
|
|
171
212
|
{...rest}
|
|
213
|
+
bind:value={() => value ?? null, (next) => (value = next ?? undefined)}
|
|
214
|
+
{name}
|
|
215
|
+
{disabled}
|
|
216
|
+
onValueChange={(next) => {
|
|
217
|
+
// Set before the callback reads it, as a binding would be only after
|
|
218
|
+
value = next ?? undefined;
|
|
219
|
+
if (next !== null) onchange?.(next);
|
|
220
|
+
}}
|
|
172
221
|
{...attrs([styles.root, sx], className)}
|
|
173
|
-
style:--narvi-seg-count={options.length}
|
|
174
222
|
onpointerdowncapture={() => (slides = index >= 0)}
|
|
175
223
|
onkeydowncapture={() => (slides = false)}
|
|
176
224
|
>
|
|
@@ -178,51 +226,12 @@
|
|
|
178
226
|
<span
|
|
179
227
|
aria-hidden="true"
|
|
180
228
|
{...stylex.attrs(styles.thumb, slides && styles.thumbSlides, index < 0 && styles.thumbHidden)}
|
|
229
|
+
style:--narvi-seg-count={options.length}
|
|
181
230
|
style:--narvi-seg-index={Math.max(index, 0)}
|
|
182
231
|
></span>
|
|
183
|
-
{#snippet segments()}
|
|
184
|
-
{#each options as option, at (option.value)}
|
|
185
|
-
{@const off = disabled || option.disabled}
|
|
186
|
-
{@const titleId = option.title ? `${uid}-title-${at}` : undefined}
|
|
187
|
-
{#snippet radio(props: Record<string, unknown>)}
|
|
188
|
-
<input
|
|
189
|
-
{...props}
|
|
190
|
-
type="radio"
|
|
191
|
-
name={name ?? uid}
|
|
192
|
-
value={option.value}
|
|
193
|
-
bind:group={value}
|
|
194
|
-
onchange={() => {
|
|
195
|
-
// The binding may not have run yet: the value is set before the callback reads it
|
|
196
|
-
value = option.value;
|
|
197
|
-
onchange?.(option.value);
|
|
198
|
-
}}
|
|
199
|
-
disabled={off}
|
|
200
|
-
aria-describedby={titleId}
|
|
201
|
-
{...stylex.attrs(styles.input, segmentedInputMarker)}
|
|
202
|
-
/>
|
|
203
|
-
{/snippet}
|
|
204
|
-
<label {...stylex.attrs(styles.option, off && styles.optionDisabled)}>
|
|
205
|
-
{#if option.title}
|
|
206
|
-
<Tooltip.Root>
|
|
207
|
-
<Tooltip.Trigger disabled={off}>
|
|
208
|
-
{#snippet child({ props })}{@render radio(groupTrigger(props))}{/snippet}
|
|
209
|
-
</Tooltip.Trigger>
|
|
210
|
-
<Tooltip.Content side="top">{option.title}</Tooltip.Content>
|
|
211
|
-
</Tooltip.Root>
|
|
212
|
-
{:else}
|
|
213
|
-
{@render radio({})}
|
|
214
|
-
{/if}
|
|
215
|
-
<span data-icons {...stylex.attrs(styles.text)}>
|
|
216
|
-
{#if option.icon}<option.icon aria-hidden="true" />{/if}{option.label}
|
|
217
|
-
</span>
|
|
218
|
-
<!-- Always there to describe the radio, which the tooltip does only while open -->
|
|
219
|
-
{#if option.title}<span id={titleId} hidden>{option.title}</span>{/if}
|
|
220
|
-
</label>
|
|
221
|
-
{/each}
|
|
222
|
-
{/snippet}
|
|
223
232
|
{#if titled}
|
|
224
233
|
<TooltipScope>{@render segments()}</TooltipScope>
|
|
225
234
|
{:else}
|
|
226
235
|
{@render segments()}
|
|
227
236
|
{/if}
|
|
228
|
-
</
|
|
237
|
+
</UiSegmentedControl>
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { IconComponent } from '../../internal/icon.js';
|
|
2
|
-
import type {
|
|
2
|
+
import type { Loose, PartProps } from '../../internal/loose.js';
|
|
3
|
+
import { SegmentedControl as UiSegmentedControl } from '@ui-sdk/svelte/segmented-control';
|
|
3
4
|
import { type Sx } from '../../internal/sx.js';
|
|
4
5
|
import '../../internal/icons.css';
|
|
5
6
|
export type SegmentedOption = {
|
|
@@ -14,18 +15,19 @@ export type SegmentedOption = {
|
|
|
14
15
|
icon?: IconComponent | undefined;
|
|
15
16
|
disabled?: boolean | undefined;
|
|
16
17
|
};
|
|
17
|
-
export
|
|
18
|
+
export interface SegmentedControlProps extends Loose<Omit<PartProps<typeof UiSegmentedControl>, 'children' | 'render' | 'value' | 'defaultValue' | 'onValueChange' | 'onchange' | 'orientation' | 'controller' | 'debug'> & {
|
|
18
19
|
/** The choices, in order. Two to five read best. */
|
|
19
20
|
options: SegmentedOption[];
|
|
20
21
|
/** The selected option's value. Bindable. */
|
|
21
22
|
value?: string | undefined;
|
|
22
|
-
/** Form field name.
|
|
23
|
+
/** Form field name. Without one, the choice is not submitted with a form. */
|
|
23
24
|
name?: string | undefined;
|
|
24
25
|
disabled?: boolean | undefined;
|
|
25
26
|
/** Called when the person picks an option, with its value: not when `value` is set. */
|
|
26
27
|
onchange?: ((value: string) => void) | undefined;
|
|
27
28
|
sx?: Sx | undefined;
|
|
28
|
-
}
|
|
29
|
+
}> {
|
|
30
|
+
}
|
|
29
31
|
declare const SegmentedControl: import("svelte").Component<SegmentedControlProps, {}, "value">;
|
|
30
32
|
type SegmentedControl = ReturnType<typeof SegmentedControl>;
|
|
31
33
|
export default SegmentedControl;
|
|
@@ -4,7 +4,15 @@
|
|
|
4
4
|
-->
|
|
5
5
|
<script lang="ts" module>
|
|
6
6
|
import type { IconComponent } from '../../internal/icon.js';
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
Select as UiSelect,
|
|
9
|
+
SelectContent,
|
|
10
|
+
SelectGroup,
|
|
11
|
+
SelectGroupLabel,
|
|
12
|
+
SelectItem,
|
|
13
|
+
SelectTrigger,
|
|
14
|
+
type ListData
|
|
15
|
+
} from '@ui-sdk/svelte/select';
|
|
8
16
|
import * as stylex from '@stylexjs/stylex';
|
|
9
17
|
import type { Snippet } from 'svelte';
|
|
10
18
|
import Glyph from '../../internal/Glyph.svelte';
|
|
@@ -38,6 +46,8 @@
|
|
|
38
46
|
options: SelectOption[];
|
|
39
47
|
/** The chosen value. Bindable. */
|
|
40
48
|
value?: string | undefined;
|
|
49
|
+
/** Whether the list is open. Bindable. */
|
|
50
|
+
open?: boolean | undefined;
|
|
41
51
|
/** Shown while nothing is chosen. */
|
|
42
52
|
placeholder?: string | undefined;
|
|
43
53
|
/**
|
|
@@ -82,7 +92,15 @@
|
|
|
82
92
|
whiteSpace: 'nowrap'
|
|
83
93
|
},
|
|
84
94
|
placeholder: { color: colors.textSubtle },
|
|
85
|
-
|
|
95
|
+
// Never more than half the trigger, so a long prefix leaves the value room to be read
|
|
96
|
+
prefix: {
|
|
97
|
+
flexShrink: 0,
|
|
98
|
+
maxWidth: '50%',
|
|
99
|
+
overflow: 'hidden',
|
|
100
|
+
textOverflow: 'ellipsis',
|
|
101
|
+
whiteSpace: 'nowrap',
|
|
102
|
+
color: colors.textMuted
|
|
103
|
+
},
|
|
86
104
|
// The chosen option's icon, on the trigger
|
|
87
105
|
icon: {
|
|
88
106
|
'--narvi-icon-size': '1rem',
|
|
@@ -95,6 +113,16 @@
|
|
|
95
113
|
check: { display: 'grid', marginInlineStart: 'auto', color: colors.accent },
|
|
96
114
|
// Where options have details, every row keeps the check's room, so the details line up
|
|
97
115
|
unchecked: { visibility: 'hidden' },
|
|
116
|
+
// A detail never takes more than half the row, so a long one leaves the label room to be
|
|
117
|
+
// read; it is cut short instead
|
|
118
|
+
detail: {
|
|
119
|
+
display: 'block',
|
|
120
|
+
boxSizing: 'border-box',
|
|
121
|
+
maxWidth: '50%',
|
|
122
|
+
overflow: 'hidden',
|
|
123
|
+
textOverflow: 'ellipsis',
|
|
124
|
+
whiteSpace: 'nowrap'
|
|
125
|
+
},
|
|
98
126
|
mono: { fontFamily: font.mono }
|
|
99
127
|
});
|
|
100
128
|
|
|
@@ -112,12 +140,21 @@
|
|
|
112
140
|
}
|
|
113
141
|
return groups;
|
|
114
142
|
}
|
|
143
|
+
|
|
144
|
+
// The options as ui-sdk's data, so the trigger can find them by typing before the list opens
|
|
145
|
+
function listed(groups: Group[]): ListData {
|
|
146
|
+
return groups.flatMap((group): ListData => {
|
|
147
|
+
const items = group.options.map(({ value, label, disabled }) => ({ value, label, disabled }));
|
|
148
|
+
return group.name ? [{ type: 'group' as const, label: group.name, items }] : items;
|
|
149
|
+
});
|
|
150
|
+
}
|
|
115
151
|
</script>
|
|
116
152
|
|
|
117
153
|
<script lang="ts">
|
|
118
154
|
let {
|
|
119
155
|
options,
|
|
120
156
|
value = $bindable(),
|
|
157
|
+
open = $bindable(false),
|
|
121
158
|
placeholder = 'Choose…',
|
|
122
159
|
prefix,
|
|
123
160
|
optionIcon,
|
|
@@ -139,19 +176,20 @@
|
|
|
139
176
|
const detailed = $derived(options.some((option) => option.detail));
|
|
140
177
|
</script>
|
|
141
178
|
|
|
142
|
-
<
|
|
143
|
-
|
|
144
|
-
bind:value={() => value ??
|
|
145
|
-
|
|
146
|
-
|
|
179
|
+
<UiSelect
|
|
180
|
+
items={listed(groups)}
|
|
181
|
+
bind:value={() => value ?? null, (next) => (value = next ?? undefined)}
|
|
182
|
+
bind:open={() => open && options.length > 0, (next) => (open = next && options.length > 0)}
|
|
183
|
+
onValueChange={(next) => {
|
|
184
|
+
if (next !== null) onchange?.(next);
|
|
185
|
+
}}
|
|
147
186
|
{name}
|
|
148
187
|
disabled={disabled ?? field?.disabled}
|
|
149
188
|
>
|
|
150
|
-
<
|
|
189
|
+
<SelectTrigger
|
|
151
190
|
id={id ?? field?.id}
|
|
152
191
|
aria-label={label ?? (prefix ? `${prefix} ${selected?.label ?? placeholder}` : undefined)}
|
|
153
192
|
aria-describedby={describedBy ?? field?.describedBy}
|
|
154
|
-
data-slot="select"
|
|
155
193
|
{...attrs([control.base, control[size], styles.trigger, sx], className)}
|
|
156
194
|
>
|
|
157
195
|
{#if selected && optionIcon}
|
|
@@ -166,53 +204,53 @@
|
|
|
166
204
|
{selected?.label ?? placeholder}
|
|
167
205
|
</span>
|
|
168
206
|
<span {...stylex.attrs(styles.selector)}><Glyph name="selector" size={14} /></span>
|
|
169
|
-
</
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
{
|
|
213
|
-
|
|
214
|
-
{/
|
|
215
|
-
|
|
216
|
-
</
|
|
217
|
-
|
|
218
|
-
|
|
207
|
+
</SelectTrigger>
|
|
208
|
+
<!-- In place, in the top layer: ui-sdk needs no portal. The list scrolls in the surface. With
|
|
209
|
+
no options it stays shut, rather than open as an empty sliver. -->
|
|
210
|
+
<SelectContent {align} sideOffset={6} collisionPadding={8} {...stylex.attrs(layer.surface)}>
|
|
211
|
+
{#each groups as group, index (index)}
|
|
212
|
+
<!-- A hairline between groups, as a menu draws between its parts -->
|
|
213
|
+
{#if index > 0}<div aria-hidden="true" {...stylex.attrs(layer.separator)}></div>{/if}
|
|
214
|
+
{#if group.name}
|
|
215
|
+
<SelectGroup>
|
|
216
|
+
<SelectGroupLabel {...stylex.attrs(layer.heading)}>{group.name}</SelectGroupLabel>
|
|
217
|
+
{@render items(group.options)}
|
|
218
|
+
</SelectGroup>
|
|
219
|
+
{:else}
|
|
220
|
+
{@render items(group.options)}
|
|
221
|
+
{/if}
|
|
222
|
+
{/each}
|
|
223
|
+
</SelectContent>
|
|
224
|
+
</UiSelect>
|
|
225
|
+
|
|
226
|
+
{#snippet items(options: SelectOption[])}
|
|
227
|
+
{#each options as option (option.value)}
|
|
228
|
+
<SelectItem
|
|
229
|
+
value={option.value}
|
|
230
|
+
label={option.label}
|
|
231
|
+
disabled={option.disabled}
|
|
232
|
+
{...stylex.attrs(layer.item)}
|
|
233
|
+
>
|
|
234
|
+
{#snippet children({ selected })}
|
|
235
|
+
{#if optionIcon}
|
|
236
|
+
<span data-icons aria-hidden="true" {...stylex.attrs(layer.icon)}
|
|
237
|
+
>{@render optionIcon(option)}</span
|
|
238
|
+
>
|
|
239
|
+
{:else if option.icon}
|
|
240
|
+
<span data-icons {...stylex.attrs(layer.icon)}><option.icon aria-hidden="true" /></span>
|
|
241
|
+
{/if}
|
|
242
|
+
<span {...stylex.attrs(layer.label)}>{option.label}</span>
|
|
243
|
+
{#if option.detail}
|
|
244
|
+
<span {...stylex.attrs(layer.trailing, styles.detail, option.detailMono && styles.mono)}
|
|
245
|
+
>{option.detail}</span
|
|
246
|
+
>
|
|
247
|
+
{/if}
|
|
248
|
+
{#if selected || detailed}
|
|
249
|
+
<span aria-hidden={!selected || undefined} {...selected ? check : checkHidden}
|
|
250
|
+
><Glyph name="check" stroke={1.75} /></span
|
|
251
|
+
>
|
|
252
|
+
{/if}
|
|
253
|
+
{/snippet}
|
|
254
|
+
</SelectItem>
|
|
255
|
+
{/each}
|
|
256
|
+
{/snippet}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { IconComponent } from '../../internal/icon.js';
|
|
2
|
-
import { Select } from 'bits-ui';
|
|
3
2
|
import type { Snippet } from 'svelte';
|
|
4
3
|
import { type ControlSize } from '../../internal/control.js';
|
|
5
4
|
import { type Sx } from '../../internal/sx.js';
|
|
@@ -26,6 +25,8 @@ export type SelectProps = {
|
|
|
26
25
|
options: SelectOption[];
|
|
27
26
|
/** The chosen value. Bindable. */
|
|
28
27
|
value?: string | undefined;
|
|
28
|
+
/** Whether the list is open. Bindable. */
|
|
29
|
+
open?: boolean | undefined;
|
|
29
30
|
/** Shown while nothing is chosen. */
|
|
30
31
|
placeholder?: string | undefined;
|
|
31
32
|
/**
|
|
@@ -53,6 +54,6 @@ export type SelectProps = {
|
|
|
53
54
|
sx?: Sx | undefined;
|
|
54
55
|
class?: string | undefined;
|
|
55
56
|
};
|
|
56
|
-
declare const Select: import("svelte").Component<SelectProps, {}, "value">;
|
|
57
|
+
declare const Select: import("svelte").Component<SelectProps, {}, "open" | "value">;
|
|
57
58
|
type Select = ReturnType<typeof Select>;
|
|
58
59
|
export default Select;
|