@diegopluna/narvi 0.4.1 → 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 +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/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 +20 -20
- package/skills/building-ui/references/components.md +11 -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
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
<script lang="ts" module>
|
|
2
2
|
import type { IconComponent } from '../../internal/icon.js';
|
|
3
|
+
import type { Loose, PartProps } from '../../internal/loose.js';
|
|
4
|
+
import { Tabs as UiTabs, TabsList, TabsPanel, TabsTab } from '@ui-sdk/svelte/tabs';
|
|
3
5
|
import * as stylex from '@stylexjs/stylex';
|
|
4
|
-
import type
|
|
5
|
-
import type { HTMLAttributes } from 'svelte/elements';
|
|
6
|
+
import { tick, type Snippet } from 'svelte';
|
|
6
7
|
import '../../internal/icons.css';
|
|
7
8
|
import { groupTrigger } from '../../internal/tooltip-trigger.js';
|
|
8
9
|
import * as Tooltip from '../tooltip/index.js';
|
|
@@ -22,20 +23,35 @@
|
|
|
22
23
|
disabled?: boolean | undefined;
|
|
23
24
|
};
|
|
24
25
|
|
|
25
|
-
export
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
26
|
+
export interface TabsProps extends Loose<
|
|
27
|
+
Omit<
|
|
28
|
+
PartProps<typeof UiTabs>,
|
|
29
|
+
| 'children'
|
|
30
|
+
| 'render'
|
|
31
|
+
| 'value'
|
|
32
|
+
| 'defaultValue'
|
|
33
|
+
| 'onValueChange'
|
|
34
|
+
| 'orientation'
|
|
35
|
+
| 'hiddenUntilFound'
|
|
36
|
+
| 'controller'
|
|
37
|
+
| 'debug'
|
|
38
|
+
> & {
|
|
39
|
+
tabs: TabItem[];
|
|
40
|
+
/** The selected tab's value. Bindable. Defaults to the first tab. */
|
|
41
|
+
value?: string | undefined;
|
|
42
|
+
/** Accessible name for the row of tabs. */
|
|
43
|
+
label: string;
|
|
44
|
+
sx?: Sx | undefined;
|
|
45
|
+
/** Styles for the row of tabs: its height and padding, to line it up with what is beside it. */
|
|
46
|
+
listSx?: Sx | undefined;
|
|
47
|
+
/** Styles for the panel under the tabs. */
|
|
48
|
+
panelSx?: Sx | undefined;
|
|
49
|
+
/** The panel for the selected tab. It receives the selected value. */
|
|
50
|
+
children?: Snippet<[string]> | undefined;
|
|
51
|
+
}
|
|
52
|
+
> {}
|
|
53
|
+
|
|
54
|
+
const DISABLED = ':is([data-disabled])';
|
|
39
55
|
|
|
40
56
|
/** A length at the window's density (`density` in the tokens). */
|
|
41
57
|
const d = (rem: string) => `calc(${rem} * ${density.factor})`;
|
|
@@ -45,9 +61,23 @@
|
|
|
45
61
|
minWidth: 0,
|
|
46
62
|
fontFamily: font.body
|
|
47
63
|
},
|
|
64
|
+
// More tabs than there is room for scroll sideways, under the row's rule. The rule is the
|
|
65
|
+
// list's, so the list runs the whole width it scrolls; the room around it keeps a tab's
|
|
66
|
+
// focus ring and its lit line from being cut off by the scroller.
|
|
67
|
+
scroller: {
|
|
68
|
+
overflowX: 'auto',
|
|
69
|
+
overflowY: 'hidden',
|
|
70
|
+
overscrollBehaviorX: 'contain',
|
|
71
|
+
scrollbarWidth: 'none',
|
|
72
|
+
padding: '0.25rem',
|
|
73
|
+
margin: '-0.25rem'
|
|
74
|
+
},
|
|
48
75
|
list: {
|
|
49
76
|
WebkitAppRegion: 'no-drag',
|
|
50
77
|
display: 'flex',
|
|
78
|
+
width: 'max-content',
|
|
79
|
+
minWidth: '100%',
|
|
80
|
+
boxSizing: 'border-box',
|
|
51
81
|
gap: d('1.25rem'),
|
|
52
82
|
borderBottomWidth: '1px',
|
|
53
83
|
borderBottomStyle: 'solid',
|
|
@@ -75,8 +105,8 @@
|
|
|
75
105
|
fontWeight: font.weightMedium,
|
|
76
106
|
lineHeight: 1,
|
|
77
107
|
whiteSpace: 'nowrap',
|
|
78
|
-
cursor: { default: 'pointer',
|
|
79
|
-
opacity: { default: 1,
|
|
108
|
+
cursor: { default: 'pointer', [DISABLED]: 'not-allowed' },
|
|
109
|
+
opacity: { default: 1, [DISABLED]: 0.5 },
|
|
80
110
|
WebkitTapHighlightColor: 'transparent',
|
|
81
111
|
outlineStyle: 'solid',
|
|
82
112
|
outlineWidth: { default: 0, ':focus-visible': '2px' },
|
|
@@ -128,94 +158,94 @@
|
|
|
128
158
|
...rest
|
|
129
159
|
}: TabsProps = $props();
|
|
130
160
|
|
|
131
|
-
const uid = $props.id();
|
|
132
161
|
const selected = $derived(value ?? tabs[0]?.value);
|
|
133
|
-
|
|
162
|
+
const titled = $derived(tabs.some((tab) => tab.title));
|
|
163
|
+
|
|
164
|
+
// The selected tab stays in view in a row that scrolls: as tabs come and go and are chosen, and
|
|
165
|
+
// as the row is resized. Only the row scrolls; the page stays where it is.
|
|
166
|
+
let scroller: HTMLElement | null = null;
|
|
134
167
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
const
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
if (
|
|
143
|
-
else if (
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
168
|
+
function reveal() {
|
|
169
|
+
const row = scroller;
|
|
170
|
+
const tab = row?.querySelector<HTMLElement>('[role="tab"][aria-selected="true"]');
|
|
171
|
+
if (!row || !tab) return;
|
|
172
|
+
const outer = row.getBoundingClientRect();
|
|
173
|
+
const inner = tab.getBoundingClientRect();
|
|
174
|
+
const pad = parseFloat(getComputedStyle(row).paddingInlineStart) || 0;
|
|
175
|
+
if (inner.left < outer.left + pad) row.scrollLeft -= outer.left + pad - inner.left;
|
|
176
|
+
else if (inner.right > outer.right - pad) row.scrollLeft += inner.right - (outer.right - pad);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
$effect(() => {
|
|
180
|
+
void selected;
|
|
181
|
+
void tabs.length;
|
|
182
|
+
tick().then(reveal);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
function scrolls(element: HTMLElement) {
|
|
186
|
+
scroller = element;
|
|
187
|
+
const observer = new ResizeObserver(() => reveal());
|
|
188
|
+
observer.observe(element);
|
|
189
|
+
return () => {
|
|
190
|
+
observer.disconnect();
|
|
191
|
+
scroller = null;
|
|
192
|
+
};
|
|
149
193
|
}
|
|
150
194
|
</script>
|
|
151
195
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
{
|
|
164
|
-
|
|
165
|
-
<
|
|
166
|
-
{
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
id="{uid}-tab-{tab.value}"
|
|
170
|
-
data-value={tab.value}
|
|
171
|
-
data-icons
|
|
172
|
-
aria-selected={active}
|
|
173
|
-
aria-controls={children ? `${uid}-panel` : undefined}
|
|
174
|
-
aria-describedby={titleId}
|
|
175
|
-
tabindex={active ? 0 : -1}
|
|
176
|
-
disabled={tab.disabled}
|
|
177
|
-
onclick={(event) => {
|
|
178
|
-
(props.onclick as ((event: MouseEvent) => void) | undefined)?.(event);
|
|
179
|
-
value = tab.value;
|
|
180
|
-
}}
|
|
181
|
-
{...stylex.attrs(styles.tab, active && styles.selected)}
|
|
182
|
-
>
|
|
183
|
-
{#if tab.icon}<tab.icon
|
|
184
|
-
aria-hidden="true"
|
|
185
|
-
/>{/if}{tab.label}{#if tab.count !== undefined}<span {...stylex.attrs(styles.count)}
|
|
186
|
-
>{tab.count}</span
|
|
187
|
-
>{/if}
|
|
188
|
-
</button>
|
|
189
|
-
{/snippet}
|
|
190
|
-
{#if tab.title}
|
|
191
|
-
<Tooltip.Root>
|
|
192
|
-
<Tooltip.Trigger disabled={tab.disabled}>
|
|
193
|
-
{#snippet child({ props })}{@render button(groupTrigger(props))}{/snippet}
|
|
194
|
-
</Tooltip.Trigger>
|
|
195
|
-
<Tooltip.Content side="top">{tab.title}</Tooltip.Content>
|
|
196
|
-
</Tooltip.Root>
|
|
197
|
-
<!-- Always there to describe the tab, which the tooltip does only while open -->
|
|
198
|
-
<span id={titleId} hidden>{tab.title}</span>
|
|
199
|
-
{:else}
|
|
200
|
-
{@render button({})}
|
|
201
|
-
{/if}
|
|
202
|
-
{/each}
|
|
196
|
+
{#snippet items()}
|
|
197
|
+
{#each tabs as tab (tab.value)}
|
|
198
|
+
<!-- A title is the tooltip's, which describes the tab whether open or not -->
|
|
199
|
+
{#snippet button(props: Record<string, unknown>)}
|
|
200
|
+
<TabsTab
|
|
201
|
+
{...props}
|
|
202
|
+
value={tab.value}
|
|
203
|
+
disabled={tab.disabled}
|
|
204
|
+
data-icons
|
|
205
|
+
{...stylex.attrs(styles.tab, tab.value === selected && styles.selected)}
|
|
206
|
+
>
|
|
207
|
+
{#if tab.icon}<tab.icon
|
|
208
|
+
aria-hidden="true"
|
|
209
|
+
/>{/if}{tab.label}{#if tab.count !== undefined}<span {...stylex.attrs(styles.count)}
|
|
210
|
+
>{tab.count}</span
|
|
211
|
+
>{/if}
|
|
212
|
+
</TabsTab>
|
|
203
213
|
{/snippet}
|
|
204
|
-
{#if
|
|
205
|
-
<
|
|
214
|
+
{#if tab.title}
|
|
215
|
+
<Tooltip.Root>
|
|
216
|
+
<Tooltip.Trigger disabled={tab.disabled}>
|
|
217
|
+
{#snippet child({ props })}{@render button(groupTrigger(props))}{/snippet}
|
|
218
|
+
</Tooltip.Trigger>
|
|
219
|
+
<Tooltip.Content side="top">{tab.title}</Tooltip.Content>
|
|
220
|
+
</Tooltip.Root>
|
|
206
221
|
{:else}
|
|
207
|
-
{@render
|
|
222
|
+
{@render button({})}
|
|
208
223
|
{/if}
|
|
224
|
+
{/each}
|
|
225
|
+
{/snippet}
|
|
226
|
+
|
|
227
|
+
<!-- ui-sdk's tabs: one tab stop, the arrow keys, Home and End select as they go, in either
|
|
228
|
+
direction of text. A disabled tab can still be reached, and says so, but is not selected. -->
|
|
229
|
+
<UiTabs
|
|
230
|
+
{...rest}
|
|
231
|
+
bind:value={() => selected ?? null, (next) => (value = next ?? undefined)}
|
|
232
|
+
{...attrs([styles.root, sx], className)}
|
|
233
|
+
>
|
|
234
|
+
<div {@attach scrolls} {...stylex.attrs(styles.scroller)}>
|
|
235
|
+
<TabsList aria-label={label} {...attrs([styles.list, listSx])}>
|
|
236
|
+
{#if titled}
|
|
237
|
+
<TooltipScope>{@render items()}</TooltipScope>
|
|
238
|
+
{:else}
|
|
239
|
+
{@render items()}
|
|
240
|
+
{/if}
|
|
241
|
+
</TabsList>
|
|
209
242
|
</div>
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
>
|
|
218
|
-
{@render children(selected)}
|
|
219
|
-
</div>
|
|
243
|
+
<!-- Only the selected tab's panel is in the page -->
|
|
244
|
+
{#if children}
|
|
245
|
+
{#each tabs as tab (tab.value)}
|
|
246
|
+
<TabsPanel value={tab.value} {...attrs([styles.panel, panelSx])}>
|
|
247
|
+
{@render children(tab.value)}
|
|
248
|
+
</TabsPanel>
|
|
249
|
+
{/each}
|
|
220
250
|
{/if}
|
|
221
|
-
</
|
|
251
|
+
</UiTabs>
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { IconComponent } from '../../internal/icon.js';
|
|
2
|
-
import type {
|
|
3
|
-
import
|
|
2
|
+
import type { Loose, PartProps } from '../../internal/loose.js';
|
|
3
|
+
import { Tabs as UiTabs } from '@ui-sdk/svelte/tabs';
|
|
4
|
+
import { type Snippet } from 'svelte';
|
|
4
5
|
import '../../internal/icons.css';
|
|
5
6
|
import { type Sx } from '../../internal/sx.js';
|
|
6
7
|
export type TabItem = {
|
|
@@ -13,7 +14,7 @@ export type TabItem = {
|
|
|
13
14
|
count?: number | undefined;
|
|
14
15
|
disabled?: boolean | undefined;
|
|
15
16
|
};
|
|
16
|
-
export
|
|
17
|
+
export interface TabsProps extends Loose<Omit<PartProps<typeof UiTabs>, 'children' | 'render' | 'value' | 'defaultValue' | 'onValueChange' | 'orientation' | 'hiddenUntilFound' | 'controller' | 'debug'> & {
|
|
17
18
|
tabs: TabItem[];
|
|
18
19
|
/** The selected tab's value. Bindable. Defaults to the first tab. */
|
|
19
20
|
value?: string | undefined;
|
|
@@ -26,7 +27,8 @@ export type TabsProps = Omit<HTMLAttributes<HTMLDivElement>, 'children'> & {
|
|
|
26
27
|
panelSx?: Sx | undefined;
|
|
27
28
|
/** The panel for the selected tab. It receives the selected value. */
|
|
28
29
|
children?: Snippet<[string]> | undefined;
|
|
29
|
-
}
|
|
30
|
+
}> {
|
|
31
|
+
}
|
|
30
32
|
declare const Tabs: import("svelte").Component<TabsProps, {}, "value">;
|
|
31
33
|
type Tabs = ReturnType<typeof Tabs>;
|
|
32
34
|
export default Tabs;
|
|
@@ -8,6 +8,6 @@ export type TextareaProps = Omit<HTMLTextareaAttributes, 'children'> & {
|
|
|
8
8
|
sx?: Sx | undefined;
|
|
9
9
|
ref?: HTMLTextAreaElement | null | undefined;
|
|
10
10
|
};
|
|
11
|
-
declare const Textarea: import("svelte").Component<TextareaProps, {}, "
|
|
11
|
+
declare const Textarea: import("svelte").Component<TextareaProps, {}, "value" | "ref">;
|
|
12
12
|
type Textarea = ReturnType<typeof Textarea>;
|
|
13
13
|
export default Textarea;
|
|
@@ -1,41 +1,62 @@
|
|
|
1
1
|
<!--
|
|
2
2
|
Where toasts appear. Place one near the root of the app.
|
|
3
3
|
|
|
4
|
-
It sits in the top layer, so toasts stay above
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
Built on ui-sdk's toast region. It sits in the top layer, so toasts stay above
|
|
5
|
+
dialogs, and ui-sdk keeps them usable while a modal dialog is open. Each
|
|
6
|
+
toast waits while the pointer or focus is on the stack, while the window is
|
|
7
|
+
hidden or in the background, so none goes unread.
|
|
7
8
|
-->
|
|
8
9
|
<script lang="ts" module>
|
|
9
10
|
import * as stylex from '@stylexjs/stylex';
|
|
11
|
+
import {
|
|
12
|
+
Toast,
|
|
13
|
+
ToastClose,
|
|
14
|
+
ToastDescription,
|
|
15
|
+
ToastRegion,
|
|
16
|
+
ToastTitle
|
|
17
|
+
} from '@ui-sdk/svelte/toast';
|
|
10
18
|
import { colors, density, font, motion, radius, space } from '../../tokens.stylex.js';
|
|
11
19
|
import { media } from '../../media.stylex.js';
|
|
12
20
|
import Glyph from '../../internal/Glyph.svelte';
|
|
21
|
+
import { shared } from '../../internal/shared.js';
|
|
13
22
|
import Button from '../button/Button.svelte';
|
|
14
23
|
import Spinner from '../spinner/Spinner.svelte';
|
|
15
|
-
import {
|
|
24
|
+
import { answer, toaster, type ToastData } from './toasts.svelte.js';
|
|
16
25
|
|
|
17
26
|
export type ToasterProps = {
|
|
18
27
|
/** Distance from the top of the window, to clear an app's own header. */
|
|
19
28
|
offset?: string | undefined;
|
|
20
29
|
/** Accessible name of the region. */
|
|
21
30
|
label?: string | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* The key that moves focus to the newest toast, and back again: `F6` by default, or
|
|
33
|
+
* `alt+t`. `null` leaves the key to the app, for one that cycles its own areas with F6.
|
|
34
|
+
*/
|
|
35
|
+
shortcut?: string | null | undefined;
|
|
22
36
|
};
|
|
23
37
|
|
|
24
38
|
/** A length at the window's density (`density` in the tokens). */
|
|
25
39
|
const d = (rem: string) => `calc(${rem} * ${density.factor})`;
|
|
26
40
|
|
|
41
|
+
// ui-sdk's state attributes on a toast: its first frame, while it leaves, while it is swiped
|
|
42
|
+
const STARTING = ':is([data-starting-style])';
|
|
43
|
+
const ENDING = ':is([data-ending-style])';
|
|
44
|
+
const SWIPING = ':is([data-swiping])';
|
|
45
|
+
// Where a swipe has taken it, which it leaves from
|
|
46
|
+
const SWIPE = 'var(--toast-swipe-x, 0px) var(--toast-swipe-y, 0px)';
|
|
47
|
+
|
|
27
48
|
const styles = stylex.create({
|
|
28
|
-
// The top layer brings the browser's popover styles; these undo them
|
|
49
|
+
// The top layer brings the browser's popover styles; these undo them. ui-sdk measures the
|
|
50
|
+
// toasts, newest first, and the stack is as tall as they are with the gaps between them.
|
|
29
51
|
region: {
|
|
30
52
|
position: 'fixed',
|
|
31
53
|
inset: 'auto',
|
|
32
54
|
top: 'var(--narvi-toaster-offset)',
|
|
33
55
|
insetInlineEnd: space.x4,
|
|
34
|
-
display: '
|
|
35
|
-
flexDirection: 'column',
|
|
36
|
-
gap: space.x2,
|
|
56
|
+
display: 'block',
|
|
37
57
|
width: 'min(22rem, calc(100vw - 2rem))',
|
|
38
|
-
|
|
58
|
+
maxWidth: 'none',
|
|
59
|
+
height: `max(0px, calc(var(--toast-stack-height, 0px) + (var(--toast-count, 1) - 1) * ${space.x2}))`,
|
|
39
60
|
margin: 0,
|
|
40
61
|
padding: 0,
|
|
41
62
|
overflow: 'visible',
|
|
@@ -43,7 +64,22 @@
|
|
|
43
64
|
backgroundColor: 'transparent',
|
|
44
65
|
pointerEvents: 'none'
|
|
45
66
|
},
|
|
67
|
+
// More toasts than the window holds: the stack stops at the window's foot and scrolls, so
|
|
68
|
+
// the oldest can still be read and put away. Only then, as it clips what spills out of it,
|
|
69
|
+
// a shadow or a toast being swiped away.
|
|
70
|
+
crowded: {
|
|
71
|
+
maxHeight: `calc(100dvh - var(--narvi-toaster-offset) - ${space.x4})`,
|
|
72
|
+
overflowY: 'auto',
|
|
73
|
+
overscrollBehavior: 'contain',
|
|
74
|
+
pointerEvents: 'auto'
|
|
75
|
+
},
|
|
76
|
+
// Each toast below the newer ones. One that leaves keeps its place while it fades, and
|
|
77
|
+
// the rest close up behind it.
|
|
46
78
|
toast: {
|
|
79
|
+
position: 'absolute',
|
|
80
|
+
insetInline: 0,
|
|
81
|
+
top: `calc(var(--toast-offset, 0px) + var(--toast-index, 0) * ${space.x2})`,
|
|
82
|
+
boxSizing: 'border-box',
|
|
47
83
|
display: 'grid',
|
|
48
84
|
gridTemplateColumns: 'auto minmax(0, 1fr) auto',
|
|
49
85
|
alignItems: 'start',
|
|
@@ -59,20 +95,24 @@
|
|
|
59
95
|
fontSize: font.sizeBody,
|
|
60
96
|
lineHeight: font.leadingSnug,
|
|
61
97
|
pointerEvents: 'auto',
|
|
62
|
-
opacity: { default: 1,
|
|
98
|
+
opacity: { default: 1, [STARTING]: 0, [ENDING]: 0 },
|
|
99
|
+
// A swipe follows the pointer, with or without motion
|
|
63
100
|
translate: {
|
|
64
|
-
default:
|
|
65
|
-
[media.motion]: {
|
|
101
|
+
default: SWIPE,
|
|
102
|
+
[media.motion]: {
|
|
103
|
+
default: SWIPE,
|
|
104
|
+
[STARTING]: '0 -0.5rem',
|
|
105
|
+
[ENDING]: 'calc(var(--toast-swipe-x, 0px) + 0.5rem) var(--toast-swipe-y, 0px)'
|
|
106
|
+
}
|
|
66
107
|
},
|
|
67
|
-
transitionProperty: {
|
|
68
|
-
|
|
108
|
+
transitionProperty: {
|
|
109
|
+
default: 'opacity',
|
|
110
|
+
[media.motion]: 'opacity, translate, top',
|
|
111
|
+
[SWIPING]: 'none'
|
|
112
|
+
},
|
|
113
|
+
transitionDuration: { default: motion.slow, [ENDING]: motion.fast },
|
|
69
114
|
transitionTimingFunction: motion.easeOut
|
|
70
115
|
},
|
|
71
|
-
leaving: {
|
|
72
|
-
opacity: 0,
|
|
73
|
-
translate: { default: null, [media.motion]: '0.5rem 0' },
|
|
74
|
-
transitionDuration: motion.fast
|
|
75
|
-
},
|
|
76
116
|
icon: { display: 'grid', placeItems: 'center', width: '1rem', height: '1.25rem' },
|
|
77
117
|
dot: {
|
|
78
118
|
width: '0.375rem',
|
|
@@ -90,7 +130,9 @@
|
|
|
90
130
|
flexDirection: 'column',
|
|
91
131
|
gap: '0.125rem',
|
|
92
132
|
minWidth: 0,
|
|
93
|
-
paddingTop: '1px'
|
|
133
|
+
paddingTop: '1px',
|
|
134
|
+
// A branch or a hash with nowhere to break breaks anywhere, rather than running out
|
|
135
|
+
overflowWrap: 'anywhere'
|
|
94
136
|
},
|
|
95
137
|
title: { fontWeight: font.weightMedium },
|
|
96
138
|
// What went wrong can be selected and copied
|
|
@@ -100,6 +142,14 @@
|
|
|
100
142
|
userSelect: 'text',
|
|
101
143
|
overflowWrap: 'anywhere'
|
|
102
144
|
},
|
|
145
|
+
// An action's label past 10rem is cut short, so the title keeps its room beside it
|
|
146
|
+
action: { maxWidth: '10rem', minWidth: 0 },
|
|
147
|
+
actionLabel: {
|
|
148
|
+
minWidth: 0,
|
|
149
|
+
overflow: 'hidden',
|
|
150
|
+
textOverflow: 'ellipsis',
|
|
151
|
+
whiteSpace: 'nowrap'
|
|
152
|
+
},
|
|
103
153
|
// Its small buttons are centred on the title's line, about 20px, at any density
|
|
104
154
|
actions: {
|
|
105
155
|
display: 'flex',
|
|
@@ -111,131 +161,98 @@
|
|
|
111
161
|
</script>
|
|
112
162
|
|
|
113
163
|
<script lang="ts">
|
|
114
|
-
let { offset = '1rem', label = 'Notifications' }: ToasterProps = $props();
|
|
164
|
+
let { offset = '1rem', label = 'Notifications', shortcut }: ToasterProps = $props();
|
|
115
165
|
|
|
116
|
-
|
|
117
|
-
let
|
|
118
|
-
let hidden = $state(false);
|
|
119
|
-
// Toasts on their way out, by revision, kept a moment so they can fade. A toast replaced
|
|
120
|
-
// while it fades comes back at once.
|
|
121
|
-
let leaving = $state<number[]>([]);
|
|
166
|
+
const id = $props.id();
|
|
167
|
+
let crowded = $state(false);
|
|
122
168
|
|
|
169
|
+
// Whether the stack runs past the window's foot. Measured as the stack or the window changes
|
|
170
|
+
// size; while crowded the region keeps one height, and grows again only once the stack fits.
|
|
123
171
|
$effect(() => {
|
|
124
|
-
region
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
function close(entry: ToastEntry, how: ToastEnd) {
|
|
131
|
-
const { id, revision } = entry;
|
|
132
|
-
if (leaving.includes(revision)) return;
|
|
133
|
-
leaving = [...leaving, revision];
|
|
134
|
-
setTimeout(() => {
|
|
135
|
-
finish(id, how, revision);
|
|
136
|
-
leaving = leaving.filter((each) => each !== revision);
|
|
137
|
-
}, 140);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
// Each toast's own timer, which runs only while nothing holds the stack
|
|
141
|
-
function timed(element: HTMLElement, entry: ToastEntry) {
|
|
142
|
-
let remaining = entry.duration ?? Infinity;
|
|
143
|
-
let started = 0;
|
|
144
|
-
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
145
|
-
const run = () => {
|
|
146
|
-
if (!Number.isFinite(remaining)) return;
|
|
147
|
-
started = performance.now();
|
|
148
|
-
timer = setTimeout(() => close(entry, 'auto'), remaining);
|
|
172
|
+
const region = document.querySelector<HTMLElement>(`[data-narvi-toaster="${id}"]`);
|
|
173
|
+
if (!region) return;
|
|
174
|
+
const measure = () => {
|
|
175
|
+
// The room `crowded` leaves it: down to 1rem above the window's foot
|
|
176
|
+
const room = window.innerHeight - region.getBoundingClientRect().top - 16;
|
|
177
|
+
crowded = region.scrollHeight > room + 1;
|
|
149
178
|
};
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
179
|
+
const observer = new ResizeObserver(measure);
|
|
180
|
+
observer.observe(region);
|
|
181
|
+
window.addEventListener('resize', measure);
|
|
182
|
+
return () => {
|
|
183
|
+
observer.disconnect();
|
|
184
|
+
window.removeEventListener('resize', measure);
|
|
155
185
|
};
|
|
156
|
-
|
|
157
|
-
}
|
|
186
|
+
});
|
|
158
187
|
</script>
|
|
159
188
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
189
|
+
<!-- Every toast shows at once, so nothing waits unseen behind the stack -->
|
|
190
|
+
<ToastRegion
|
|
191
|
+
{toaster}
|
|
192
|
+
side="top"
|
|
193
|
+
align="end"
|
|
194
|
+
maxVisible={Infinity}
|
|
195
|
+
expanded
|
|
196
|
+
{shortcut}
|
|
163
197
|
aria-label={label}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
{...stylex.attrs(styles.region)}
|
|
167
|
-
onpointerenter={() => (held = true)}
|
|
168
|
-
onpointerleave={() => (held = false)}
|
|
169
|
-
onfocusin={() => (held = true)}
|
|
170
|
-
onfocusout={(event) => {
|
|
171
|
-
if (!region?.contains(event.relatedTarget as Node | null)) held = false;
|
|
172
|
-
}}
|
|
198
|
+
style="--narvi-toaster-offset: {offset}"
|
|
199
|
+
data-narvi-toaster={id}
|
|
200
|
+
{...stylex.attrs(styles.region, crowded && styles.crowded)}
|
|
173
201
|
>
|
|
174
|
-
{#
|
|
175
|
-
{@const
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
data-tone={entry.tone}
|
|
179
|
-
{...stylex.attrs(styles.toast, leaving.includes(entry.revision) && styles.leaving)}
|
|
180
|
-
{@attach () => {
|
|
181
|
-
// Restarts when the toast changes, as a loading toast turns into a result
|
|
182
|
-
void entry.revision;
|
|
183
|
-
if (!held && !hidden) clock.run();
|
|
184
|
-
return () => clock.pause();
|
|
185
|
-
}}
|
|
186
|
-
>
|
|
202
|
+
{#snippet children(item, place)}
|
|
203
|
+
{@const data = item.data as ToastData}
|
|
204
|
+
<!-- One on its way out can no longer be pressed, nor be read a second time -->
|
|
205
|
+
<Toast inert={place.leaving || undefined} {...stylex.attrs(shared.focusable, styles.toast)}>
|
|
187
206
|
<span
|
|
188
207
|
{...stylex.attrs(
|
|
189
208
|
styles.icon,
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
(
|
|
209
|
+
data.tone === 'info' && styles.info,
|
|
210
|
+
data.tone === 'success' && styles.success,
|
|
211
|
+
data.tone === 'warning' && styles.warning,
|
|
212
|
+
data.tone === 'error' && styles.error,
|
|
213
|
+
(data.tone === 'default' || data.tone === 'loading') && styles.muted
|
|
195
214
|
)}
|
|
196
215
|
>
|
|
197
|
-
{#if
|
|
216
|
+
{#if data.tone === 'loading'}
|
|
198
217
|
<Spinner size={14} label={null} />
|
|
199
|
-
{:else if
|
|
218
|
+
{:else if data.tone === 'success'}
|
|
200
219
|
<Glyph name="check" stroke={1.75} />
|
|
201
|
-
{:else if
|
|
220
|
+
{:else if data.tone === 'error' || data.tone === 'warning'}
|
|
202
221
|
<Glyph name="alert" />
|
|
203
|
-
{:else if
|
|
222
|
+
{:else if data.tone === 'info'}
|
|
204
223
|
<Glyph name="info" />
|
|
205
224
|
{:else}
|
|
206
225
|
<span {...stylex.attrs(styles.dot)}></span>
|
|
207
226
|
{/if}
|
|
208
227
|
</span>
|
|
209
|
-
<
|
|
210
|
-
<
|
|
211
|
-
{
|
|
212
|
-
|
|
213
|
-
{/if}
|
|
214
|
-
</span>
|
|
228
|
+
<div {...stylex.attrs(styles.text)}>
|
|
229
|
+
<ToastTitle {...stylex.attrs(styles.title)} />
|
|
230
|
+
<ToastDescription {...stylex.attrs(styles.description)} />
|
|
231
|
+
</div>
|
|
215
232
|
<span {...stylex.attrs(styles.actions)}>
|
|
216
|
-
{#if
|
|
233
|
+
{#if data.action}
|
|
234
|
+
{@const action = data.action}
|
|
217
235
|
<Button
|
|
218
236
|
size="sm"
|
|
219
237
|
variant="secondary"
|
|
238
|
+
sx={styles.action}
|
|
220
239
|
onclick={(event) => {
|
|
221
|
-
|
|
222
|
-
if (!event.defaultPrevented)
|
|
240
|
+
action.onclick(event);
|
|
241
|
+
if (!event.defaultPrevented) answer(data.id);
|
|
223
242
|
}}
|
|
224
243
|
>
|
|
225
|
-
{
|
|
244
|
+
<span {...stylex.attrs(styles.actionLabel)}>{action.label}</span>
|
|
226
245
|
</Button>
|
|
227
246
|
{/if}
|
|
228
247
|
<!-- Every toast can be put away, a lasting one most of all; work under way goes on -->
|
|
229
|
-
<
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
>
|
|
236
|
-
<Glyph name="close" size={14} />
|
|
237
|
-
</Button>
|
|
248
|
+
<ToastClose>
|
|
249
|
+
{#snippet render({ props })}
|
|
250
|
+
<Button {...props} size="sm" variant="ghost" iconOnly aria-label="Dismiss">
|
|
251
|
+
<Glyph name="close" size={14} />
|
|
252
|
+
</Button>
|
|
253
|
+
{/snippet}
|
|
254
|
+
</ToastClose>
|
|
238
255
|
</span>
|
|
239
|
-
</
|
|
240
|
-
{/
|
|
241
|
-
</
|
|
256
|
+
</Toast>
|
|
257
|
+
{/snippet}
|
|
258
|
+
</ToastRegion>
|