@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,24 +1,38 @@
|
|
|
1
1
|
<script lang="ts" module>
|
|
2
|
+
import { Switch as UiSwitch } from '@ui-sdk/svelte/switch';
|
|
2
3
|
import * as stylex from '@stylexjs/stylex';
|
|
3
4
|
import type { Snippet } from 'svelte';
|
|
4
|
-
import type { ChangeEventHandler
|
|
5
|
+
import type { ChangeEventHandler } from 'svelte/elements';
|
|
6
|
+
import type { Loose, PartProps } from '../../internal/loose.js';
|
|
5
7
|
import { attrs, type Sx } from '../../internal/sx.js';
|
|
6
8
|
import { colors, font, motion, radius } from '../../tokens.stylex.js';
|
|
7
9
|
import { media } from '../../media.stylex.js';
|
|
10
|
+
import { getFieldContext } from '../field/context.js';
|
|
8
11
|
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
12
|
+
export interface SwitchProps extends Loose<
|
|
13
|
+
Omit<
|
|
14
|
+
PartProps<typeof UiSwitch>,
|
|
15
|
+
'children' | 'render' | 'checked' | 'defaultChecked' | 'onchange'
|
|
16
|
+
> & {
|
|
17
|
+
/** Whether it is on. Bindable. */
|
|
18
|
+
checked?: boolean | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* The native change event, from the form input underneath: `event.currentTarget.checked`
|
|
21
|
+
* is the new value. It follows `onCheckedChange`.
|
|
22
|
+
*/
|
|
23
|
+
onchange?: ChangeEventHandler<HTMLInputElement> | undefined;
|
|
24
|
+
/** A second, quieter line under the label. */
|
|
25
|
+
description?: string | undefined;
|
|
26
|
+
/** Applied to the outermost element: the label when there is one, else the switch. */
|
|
27
|
+
sx?: Sx | undefined;
|
|
28
|
+
/** The switch's button. Bindable. */
|
|
29
|
+
ref?: HTMLButtonElement | null | undefined;
|
|
30
|
+
/** Label content. Without it, give the switch an `aria-label`. */
|
|
31
|
+
children?: Snippet | undefined;
|
|
32
|
+
}
|
|
33
|
+
> {}
|
|
34
|
+
|
|
35
|
+
const ON = ':is([data-checked])';
|
|
22
36
|
|
|
23
37
|
const styles = stylex.create({
|
|
24
38
|
root: {
|
|
@@ -32,6 +46,8 @@
|
|
|
32
46
|
cursor: 'pointer',
|
|
33
47
|
WebkitTapHighlightColor: 'transparent'
|
|
34
48
|
},
|
|
49
|
+
// A label with no break in it, such as a URL, wraps rather than running out of the box
|
|
50
|
+
text: { minWidth: 0, overflowWrap: 'anywhere' },
|
|
35
51
|
rootDisabled: {
|
|
36
52
|
color: colors.textSubtle,
|
|
37
53
|
cursor: 'not-allowed'
|
|
@@ -42,24 +58,26 @@
|
|
|
42
58
|
fontSize: font.sizeCaption,
|
|
43
59
|
lineHeight: font.leadingSnug
|
|
44
60
|
},
|
|
45
|
-
|
|
61
|
+
control: {
|
|
46
62
|
position: 'relative',
|
|
63
|
+
display: 'inline-block',
|
|
47
64
|
flexShrink: 0,
|
|
48
65
|
boxSizing: 'border-box',
|
|
49
66
|
width: '2rem',
|
|
50
67
|
height: '1.125rem',
|
|
51
68
|
margin: 0,
|
|
52
69
|
marginBlock: '1px',
|
|
70
|
+
padding: 0,
|
|
53
71
|
borderWidth: 0,
|
|
54
72
|
borderRadius: radius.pill,
|
|
55
73
|
backgroundColor: {
|
|
56
74
|
default: colors.borderControl,
|
|
57
75
|
':hover': { default: null, [media.hover]: colors.borderControlHover },
|
|
58
|
-
[media.forcedColors]: { default: 'Canvas',
|
|
76
|
+
[media.forcedColors]: { default: 'Canvas', [ON]: 'Highlight' }
|
|
59
77
|
},
|
|
60
78
|
backgroundImage: {
|
|
61
79
|
default: 'none',
|
|
62
|
-
|
|
80
|
+
[ON]: `linear-gradient(${colors.accent}, ${colors.accent})`,
|
|
63
81
|
[media.forcedColors]: 'none'
|
|
64
82
|
},
|
|
65
83
|
forcedColorAdjust: 'none',
|
|
@@ -88,20 +106,20 @@
|
|
|
88
106
|
height: '0.875rem',
|
|
89
107
|
translate: {
|
|
90
108
|
default: '0 0',
|
|
91
|
-
|
|
109
|
+
[ON]: { default: '14px 0', ':dir(rtl)': '-14px 0' }
|
|
92
110
|
},
|
|
93
111
|
// While pressed, the thumb stretches towards where it is about to go
|
|
94
112
|
scale: { default: null, ':active': { default: null, [media.motion]: '1.2 1' } },
|
|
95
113
|
transformOrigin: {
|
|
96
114
|
default: 'left center',
|
|
97
115
|
':dir(rtl)': 'right center',
|
|
98
|
-
|
|
116
|
+
[ON]: { default: 'right center', ':dir(rtl)': 'left center' }
|
|
99
117
|
},
|
|
100
118
|
borderRadius: radius.pill,
|
|
101
119
|
backgroundColor: {
|
|
102
120
|
default: colors.thumb,
|
|
103
|
-
|
|
104
|
-
[media.forcedColors]: { default: 'ButtonText',
|
|
121
|
+
[ON]: colors.onAccent,
|
|
122
|
+
[media.forcedColors]: { default: 'ButtonText', [ON]: 'HighlightText' }
|
|
105
123
|
},
|
|
106
124
|
transitionProperty: {
|
|
107
125
|
default: 'background-color',
|
|
@@ -127,9 +145,12 @@
|
|
|
127
145
|
<script lang="ts">
|
|
128
146
|
let {
|
|
129
147
|
checked = $bindable(false),
|
|
130
|
-
onCheckedChange,
|
|
131
148
|
onchange,
|
|
132
|
-
disabled
|
|
149
|
+
disabled,
|
|
150
|
+
required,
|
|
151
|
+
id,
|
|
152
|
+
'aria-describedby': describedBy,
|
|
153
|
+
'aria-invalid': ariaInvalid,
|
|
133
154
|
description,
|
|
134
155
|
sx,
|
|
135
156
|
class: className,
|
|
@@ -138,25 +159,41 @@
|
|
|
138
159
|
...rest
|
|
139
160
|
}: SwitchProps = $props();
|
|
140
161
|
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
162
|
+
const field = getFieldContext();
|
|
163
|
+
const isDisabled = $derived(disabled ?? field?.disabled ?? false);
|
|
164
|
+
|
|
165
|
+
// ui-sdk's switch is a button, and the native change event fires on the form input it keeps
|
|
166
|
+
// beside it, so `onchange` is heard there, where `currentTarget.checked` is the new value.
|
|
167
|
+
$effect(() => {
|
|
168
|
+
const input = ref?.nextElementSibling;
|
|
169
|
+
if (!onchange || !(input instanceof HTMLInputElement)) return;
|
|
170
|
+
const listener = onchange as unknown as EventListener;
|
|
171
|
+
input.addEventListener('change', listener);
|
|
172
|
+
return () => input.removeEventListener('change', listener);
|
|
173
|
+
});
|
|
145
174
|
</script>
|
|
146
175
|
|
|
176
|
+
{#snippet control(own: (Sx | false)[], className?: SwitchProps['class'])}
|
|
177
|
+
<UiSwitch
|
|
178
|
+
bind:checked
|
|
179
|
+
id={id ?? field?.id}
|
|
180
|
+
disabled={isDisabled}
|
|
181
|
+
required={required ?? field?.required}
|
|
182
|
+
aria-invalid={ariaInvalid ?? (field?.invalid || undefined)}
|
|
183
|
+
aria-describedby={describedBy ?? field?.describedBy}
|
|
184
|
+
{...rest}
|
|
185
|
+
{...attrs([styles.control, ...own], className)}
|
|
186
|
+
{@attach (element: HTMLButtonElement) => {
|
|
187
|
+
ref = element;
|
|
188
|
+
return () => (ref = null);
|
|
189
|
+
}}
|
|
190
|
+
/>
|
|
191
|
+
{/snippet}
|
|
192
|
+
|
|
147
193
|
{#if children}
|
|
148
|
-
<label {...attrs([styles.root,
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
bind:checked
|
|
152
|
-
type="checkbox"
|
|
153
|
-
role="switch"
|
|
154
|
-
{disabled}
|
|
155
|
-
{...rest}
|
|
156
|
-
onchange={changed}
|
|
157
|
-
{...stylex.attrs(styles.input)}
|
|
158
|
-
/>
|
|
159
|
-
<span>
|
|
194
|
+
<label {...attrs([styles.root, isDisabled && styles.rootDisabled, sx], className)}>
|
|
195
|
+
{@render control([])}
|
|
196
|
+
<span {...stylex.attrs(styles.text)}>
|
|
160
197
|
{@render children()}
|
|
161
198
|
{#if description}
|
|
162
199
|
<span {...stylex.attrs(styles.description)}>{description}</span>
|
|
@@ -164,14 +201,5 @@
|
|
|
164
201
|
</span>
|
|
165
202
|
</label>
|
|
166
203
|
{:else}
|
|
167
|
-
|
|
168
|
-
bind:this={ref}
|
|
169
|
-
bind:checked
|
|
170
|
-
type="checkbox"
|
|
171
|
-
role="switch"
|
|
172
|
-
{disabled}
|
|
173
|
-
{...rest}
|
|
174
|
-
onchange={changed}
|
|
175
|
-
{...attrs([styles.input, styles.standalone, sx], className)}
|
|
176
|
-
/>
|
|
204
|
+
{@render control([styles.standalone, sx], className)}
|
|
177
205
|
{/if}
|
|
@@ -1,19 +1,26 @@
|
|
|
1
|
+
import { Switch as UiSwitch } from '@ui-sdk/svelte/switch';
|
|
1
2
|
import type { Snippet } from 'svelte';
|
|
2
|
-
import type {
|
|
3
|
+
import type { ChangeEventHandler } from 'svelte/elements';
|
|
4
|
+
import type { Loose, PartProps } from '../../internal/loose.js';
|
|
3
5
|
import { type Sx } from '../../internal/sx.js';
|
|
4
|
-
export
|
|
6
|
+
export interface SwitchProps extends Loose<Omit<PartProps<typeof UiSwitch>, 'children' | 'render' | 'checked' | 'defaultChecked' | 'onchange'> & {
|
|
7
|
+
/** Whether it is on. Bindable. */
|
|
5
8
|
checked?: boolean | undefined;
|
|
6
|
-
/**
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
/**
|
|
10
|
+
* The native change event, from the form input underneath: `event.currentTarget.checked`
|
|
11
|
+
* is the new value. It follows `onCheckedChange`.
|
|
12
|
+
*/
|
|
13
|
+
onchange?: ChangeEventHandler<HTMLInputElement> | undefined;
|
|
9
14
|
/** A second, quieter line under the label. */
|
|
10
15
|
description?: string | undefined;
|
|
11
|
-
/** Applied to the outermost element: the label when there is one, else the
|
|
16
|
+
/** Applied to the outermost element: the label when there is one, else the switch. */
|
|
12
17
|
sx?: Sx | undefined;
|
|
13
|
-
|
|
18
|
+
/** The switch's button. Bindable. */
|
|
19
|
+
ref?: HTMLButtonElement | null | undefined;
|
|
14
20
|
/** Label content. Without it, give the switch an `aria-label`. */
|
|
15
21
|
children?: Snippet | undefined;
|
|
16
|
-
}
|
|
22
|
+
}> {
|
|
23
|
+
}
|
|
17
24
|
declare const Switch: import("svelte").Component<SwitchProps, {}, "ref" | "checked">;
|
|
18
25
|
type Switch = ReturnType<typeof Switch>;
|
|
19
26
|
export default Switch;
|
|
@@ -19,13 +19,12 @@
|
|
|
19
19
|
own `panelId`. For a fixed set of sections that own their panel, use Tabs.
|
|
20
20
|
-->
|
|
21
21
|
<script lang="ts" module>
|
|
22
|
-
import { visuallyHidden } from '../../visually-hidden.js';
|
|
23
22
|
import * as stylex from '@stylexjs/stylex';
|
|
24
23
|
import { tick, type Snippet } from 'svelte';
|
|
25
24
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
26
25
|
import Glyph from '../../internal/Glyph.svelte';
|
|
27
26
|
import { tabStripTabMarker } from '../../internal/markers.stylex.js';
|
|
28
|
-
import {
|
|
27
|
+
import { Tabs as UiTabs, TabsList, TabsTab } from '@ui-sdk/svelte/tabs';
|
|
29
28
|
import * as ContextMenu from '../menu/context-menu.js';
|
|
30
29
|
import * as Menu from '../menu/index.js';
|
|
31
30
|
import { TabDragging, tabOffset } from './drag.svelte.js';
|
|
@@ -48,7 +47,9 @@
|
|
|
48
47
|
renamable?: boolean | undefined;
|
|
49
48
|
/**
|
|
50
49
|
* A preview, which the next one opened takes the place of: in italics, and said as
|
|
51
|
-
* "preview" after its name.
|
|
50
|
+
* "preview" after its name. The italics are on the label inside the tab
|
|
51
|
+
* (`[data-slot="tab-strip-label"]`), not on the tab itself. A double-click calls `onkeep`,
|
|
52
|
+
* ahead of renaming.
|
|
52
53
|
*/
|
|
53
54
|
temporary?: boolean | undefined;
|
|
54
55
|
};
|
|
@@ -83,7 +84,10 @@
|
|
|
83
84
|
addLabel?: string | undefined;
|
|
84
85
|
/** The name of a tab's close button. */
|
|
85
86
|
closeLabel?: ((tab: TabStripTab) => string) | undefined;
|
|
86
|
-
/**
|
|
87
|
+
/**
|
|
88
|
+
* Before a tab's label: an icon, or a StatusIndicator. It is not part of the tab's name,
|
|
89
|
+
* which is its label and what `temporary` and `mark` add: say a tab's state there.
|
|
90
|
+
*/
|
|
87
91
|
leading?: Snippet<[TabStripTab]> | undefined;
|
|
88
92
|
/**
|
|
89
93
|
* Buttons of a tab's own, after its label and before its close button: one that mutes a
|
|
@@ -237,6 +241,9 @@
|
|
|
237
241
|
transitionDuration: motion.fast,
|
|
238
242
|
transitionTimingFunction: 'ease'
|
|
239
243
|
},
|
|
244
|
+
// With buttons of its own, a tab narrows to a least width that keeps as much room for its
|
|
245
|
+
// title as any other: one micro button's more
|
|
246
|
+
tabTrailing: { minWidth: 'calc(5.5rem + 1.25rem)' },
|
|
240
247
|
// Beside the open one, in a split view: lit, as under the pointer
|
|
241
248
|
beside: { backgroundColor: colors.fillHover, color: colors.text },
|
|
242
249
|
// The others slide aside, and a dropped tab settles, quickly; the dragged one follows
|
|
@@ -505,16 +512,32 @@
|
|
|
505
512
|
$effect(() => () => dragging.dispose());
|
|
506
513
|
const drag = $derived(dragging.drag);
|
|
507
514
|
|
|
508
|
-
// The open tab stays in view as tabs come, go and are chosen, and so does one being renamed
|
|
515
|
+
// The open tab stays in view as tabs come, go and are chosen, and so does one being renamed.
|
|
516
|
+
// Only the strip scrolls, sideways: scrollIntoView would scroll the page too, to a strip out
|
|
517
|
+
// of sight below the fold, as it loads.
|
|
518
|
+
function reveal(element: HTMLElement | null | undefined) {
|
|
519
|
+
if (!list || !element) return;
|
|
520
|
+
const room = list.getBoundingClientRect();
|
|
521
|
+
const box = element.getBoundingClientRect();
|
|
522
|
+
const by =
|
|
523
|
+
box.left < room.left
|
|
524
|
+
? box.left - room.left
|
|
525
|
+
: box.right > room.right
|
|
526
|
+
? Math.min(box.right - room.right, box.left - room.left)
|
|
527
|
+
: 0;
|
|
528
|
+
if (by) list.scrollLeft += by;
|
|
529
|
+
}
|
|
530
|
+
|
|
509
531
|
$effect(() => {
|
|
510
532
|
void value;
|
|
511
533
|
void tabs.length;
|
|
512
534
|
const named = renaming;
|
|
513
535
|
tick().then(() =>
|
|
514
|
-
(
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
536
|
+
reveal(
|
|
537
|
+
named
|
|
538
|
+
? list?.querySelector<HTMLElement>('[data-renaming]')
|
|
539
|
+
: list?.querySelector<HTMLElement>('[role="tab"][aria-selected="true"]')
|
|
540
|
+
)
|
|
518
541
|
);
|
|
519
542
|
});
|
|
520
543
|
|
|
@@ -537,6 +560,17 @@
|
|
|
537
560
|
return others;
|
|
538
561
|
}
|
|
539
562
|
|
|
563
|
+
// Named in full, not by words hidden inside it: a hidden word is a box of its own, and a box
|
|
564
|
+
// is read with a space each side, as "Fix the parser , preview"
|
|
565
|
+
const tabName = (tab: TabStripTab) =>
|
|
566
|
+
[
|
|
567
|
+
tab.label,
|
|
568
|
+
tab.temporary && 'preview',
|
|
569
|
+
tab.mark && (tab.mark === 'live' ? 'working' : 'unsaved')
|
|
570
|
+
]
|
|
571
|
+
.filter(Boolean)
|
|
572
|
+
.join(', ');
|
|
573
|
+
|
|
540
574
|
const renamable = (tab: TabStripTab) => !!onrename && tab.renamable !== false;
|
|
541
575
|
|
|
542
576
|
function startRename(tab: TabStripTab) {
|
|
@@ -565,22 +599,12 @@
|
|
|
565
599
|
else startRename(tab);
|
|
566
600
|
}
|
|
567
601
|
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
// The arrow keys, Home and End move the focus to a tab; with automatic activation, the tab
|
|
575
|
-
// they reach opens. A tab focused any other way, such as as its menu closes, stays as it is.
|
|
576
|
-
let arrowed = false;
|
|
577
|
-
function onListKeydownCapture(event: KeyboardEvent) {
|
|
578
|
-
if (event.altKey || event.metaKey || event.ctrlKey || event.shiftKey) return;
|
|
579
|
-
if (!['ArrowLeft', 'ArrowRight', 'Home', 'End'].includes(event.key)) return;
|
|
580
|
-
if (!(event.target instanceof HTMLElement) || event.target.getAttribute('role') !== 'tab')
|
|
581
|
-
return;
|
|
582
|
-
arrowed = true;
|
|
583
|
-
setTimeout(() => (arrowed = false));
|
|
602
|
+
// A tab pressed, or reached with the arrow keys while activation is automatic. A tab focused
|
|
603
|
+
// any other way, such as as its menu closes, stays as it is.
|
|
604
|
+
function open(id: string | null) {
|
|
605
|
+
if (id === null || value === id) return;
|
|
606
|
+
value = id;
|
|
607
|
+
onchange?.(id);
|
|
584
608
|
}
|
|
585
609
|
|
|
586
610
|
function moveByKey(tab: TabStripTab, event: KeyboardEvent) {
|
|
@@ -630,6 +654,7 @@
|
|
|
630
654
|
}}
|
|
631
655
|
{...stylex.attrs(
|
|
632
656
|
styles.tab,
|
|
657
|
+
trailing && styles.tabTrailing,
|
|
633
658
|
tab.id === beside && !selected && styles.beside,
|
|
634
659
|
selected && styles.selected,
|
|
635
660
|
notch && (selected ? styles.notchOpen : styles.notchStanding),
|
|
@@ -642,6 +667,7 @@
|
|
|
642
667
|
<input
|
|
643
668
|
{@attach selectAll}
|
|
644
669
|
aria-label={renameLabel(tab)}
|
|
670
|
+
dir="auto"
|
|
645
671
|
value={tab.label}
|
|
646
672
|
onkeydown={(event) => {
|
|
647
673
|
if (event.key !== 'Enter' && event.key !== 'Escape') return;
|
|
@@ -654,23 +680,19 @@
|
|
|
654
680
|
{...stylex.attrs(styles.rename)}
|
|
655
681
|
/>
|
|
656
682
|
{:else}
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
683
|
+
<!-- ui-sdk's tab: it is pressed, or reached with the arrows, to open -->
|
|
684
|
+
<TabsTab
|
|
685
|
+
value={tab.id}
|
|
660
686
|
id={tab.tabId}
|
|
661
|
-
aria-selected={selected}
|
|
662
687
|
aria-controls={tab.panelId ?? controls}
|
|
663
688
|
aria-current={selected ? 'true' : undefined}
|
|
689
|
+
aria-label={tabName(tab)}
|
|
664
690
|
title={tab.title ?? tab.label}
|
|
665
691
|
{...stylex.attrs(
|
|
666
692
|
styles.button,
|
|
667
|
-
onclose && !leading && !trailing && styles.closable,
|
|
693
|
+
(onclose || tab.mark) && !leading && !trailing && styles.closable,
|
|
668
694
|
trailing && styles.buttonBeforeTrailing
|
|
669
695
|
)}
|
|
670
|
-
onclick={() => open(tab)}
|
|
671
|
-
onfocus={() => {
|
|
672
|
-
if (arrowed && activation === 'automatic') open(tab);
|
|
673
|
-
}}
|
|
674
696
|
ondblclick={() => doubleClick(tab)}
|
|
675
697
|
onkeydown={(event) => {
|
|
676
698
|
if (moveByKey(tab, event)) return;
|
|
@@ -709,12 +731,14 @@
|
|
|
709
731
|
{/if}
|
|
710
732
|
</span>
|
|
711
733
|
{/if}
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
734
|
+
<!-- In the direction of its own words, so an English name in a right-to-left strip is cut
|
|
735
|
+
at its end, not its start -->
|
|
736
|
+
<span
|
|
737
|
+
data-slot="tab-strip-label"
|
|
738
|
+
dir="auto"
|
|
739
|
+
{...stylex.attrs(styles.text, tab.temporary && styles.temporary)}>{tab.label}</span
|
|
740
|
+
>
|
|
741
|
+
</TabsTab>
|
|
718
742
|
{/if}
|
|
719
743
|
{#if trailing}
|
|
720
744
|
<span
|
|
@@ -736,7 +760,7 @@
|
|
|
736
760
|
<Glyph name="close" size={12} />
|
|
737
761
|
</button>
|
|
738
762
|
</span>
|
|
739
|
-
{:else if onclose || tab.mark}
|
|
763
|
+
{:else if onclose || (tab.mark && !leading)}
|
|
740
764
|
<span {...stylex.attrs(styles.end, notch && selected && styles.notchOpenAside)}>
|
|
741
765
|
{#if tab.mark}
|
|
742
766
|
<span
|
|
@@ -762,43 +786,53 @@
|
|
|
762
786
|
</div>
|
|
763
787
|
{/snippet}
|
|
764
788
|
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
>
|
|
789
|
+
<!-- ui-sdk's tabs, controlled: one tab stop, on the open tab; the arrow keys, Home and End move
|
|
790
|
+
from it, past the ends, in either direction of text. The tabs sit inside frames of the strip's own,
|
|
791
|
+
which take the drag, the middle click and the menu. -->
|
|
792
|
+
<UiTabs bind:value={() => value ?? null, open} {activation} render={strip} />
|
|
793
|
+
|
|
794
|
+
{#snippet strip({ props }: { props: Record<string, unknown> })}
|
|
771
795
|
<div
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
{...
|
|
777
|
-
{@attach roving({ selector: '[role="tab"]', orientation: 'horizontal', wrap: true })}
|
|
778
|
-
onkeydowncapture={onListKeydownCapture}
|
|
796
|
+
{...props}
|
|
797
|
+
data-slot="tab-strip"
|
|
798
|
+
data-dragging={drag ? '' : undefined}
|
|
799
|
+
{...rest}
|
|
800
|
+
{...attrs([styles.root, variant === 'notch' && styles.notchRoot, sx], className)}
|
|
779
801
|
>
|
|
780
|
-
|
|
781
|
-
{
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
802
|
+
<TabsList
|
|
803
|
+
aria-label={label}
|
|
804
|
+
{...stylex.attrs(styles.list, variant === 'notch' && styles.notchList)}
|
|
805
|
+
{@attach (element: HTMLElement) => {
|
|
806
|
+
list = element;
|
|
807
|
+
return () => (list = null);
|
|
808
|
+
}}
|
|
809
|
+
>
|
|
810
|
+
{#each tabs as tab, index (tab.id)}
|
|
811
|
+
{#if menu}
|
|
812
|
+
<ContextMenu.Root>
|
|
813
|
+
<ContextMenu.Trigger>
|
|
814
|
+
{#snippet child({ props })}{@render tabView(tab, index, props)}{/snippet}
|
|
815
|
+
</ContextMenu.Trigger>
|
|
816
|
+
<!-- Renaming from it, the field keeps the focus the menu would give back -->
|
|
817
|
+
<ContextMenu.Content
|
|
818
|
+
finalFocus={() =>
|
|
819
|
+
renaming === tab.id
|
|
820
|
+
? list?.querySelector<HTMLInputElement>('[data-renaming] input')
|
|
821
|
+
: undefined}
|
|
822
|
+
>
|
|
823
|
+
{@render menu(tab)}
|
|
824
|
+
</ContextMenu.Content>
|
|
825
|
+
</ContextMenu.Root>
|
|
826
|
+
{:else}
|
|
827
|
+
{@render tabView(tab, index, {})}
|
|
828
|
+
{/if}
|
|
829
|
+
{/each}
|
|
830
|
+
</TabsList>
|
|
831
|
+
{@render add()}
|
|
801
832
|
</div>
|
|
833
|
+
{/snippet}
|
|
834
|
+
|
|
835
|
+
{#snippet add()}
|
|
802
836
|
{#snippet plus()}
|
|
803
837
|
<svg
|
|
804
838
|
data-glyph=""
|
|
@@ -840,4 +874,4 @@
|
|
|
840
874
|
{@render plus()}
|
|
841
875
|
</button>
|
|
842
876
|
{/if}
|
|
843
|
-
|
|
877
|
+
{/snippet}
|
|
@@ -16,7 +16,9 @@ export type TabStripTab = {
|
|
|
16
16
|
renamable?: boolean | undefined;
|
|
17
17
|
/**
|
|
18
18
|
* A preview, which the next one opened takes the place of: in italics, and said as
|
|
19
|
-
* "preview" after its name.
|
|
19
|
+
* "preview" after its name. The italics are on the label inside the tab
|
|
20
|
+
* (`[data-slot="tab-strip-label"]`), not on the tab itself. A double-click calls `onkeep`,
|
|
21
|
+
* ahead of renaming.
|
|
20
22
|
*/
|
|
21
23
|
temporary?: boolean | undefined;
|
|
22
24
|
};
|
|
@@ -47,7 +49,10 @@ export type TabStripProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'o
|
|
|
47
49
|
addLabel?: string | undefined;
|
|
48
50
|
/** The name of a tab's close button. */
|
|
49
51
|
closeLabel?: ((tab: TabStripTab) => string) | undefined;
|
|
50
|
-
/**
|
|
52
|
+
/**
|
|
53
|
+
* Before a tab's label: an icon, or a StatusIndicator. It is not part of the tab's name,
|
|
54
|
+
* which is its label and what `temporary` and `mark` add: say a tab's state there.
|
|
55
|
+
*/
|
|
51
56
|
leading?: Snippet<[TabStripTab]> | undefined;
|
|
52
57
|
/**
|
|
53
58
|
* Buttons of a tab's own, after its label and before its close button: one that mutes a
|