@diegopluna/narvi 0.4.1 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/dist/base.css +3 -0
- package/dist/components/app-shell/AppShellPanel.svelte +3 -2
- package/dist/components/button/Button.svelte +29 -17
- package/dist/components/checkbox/Checkbox.svelte +106 -54
- package/dist/components/checkbox/Checkbox.svelte.d.ts +22 -8
- package/dist/components/choice-cards/ChoiceCards.svelte +68 -39
- package/dist/components/choice-cards/ChoiceCards.svelte.d.ts +12 -8
- package/dist/components/collapsible/CollapsibleContent.svelte +71 -17
- package/dist/components/collapsible/CollapsibleContent.svelte.d.ts +14 -10
- package/dist/components/collapsible/CollapsibleRoot.svelte +13 -9
- package/dist/components/collapsible/CollapsibleRoot.svelte.d.ts +8 -9
- package/dist/components/collapsible/CollapsibleTrigger.svelte +24 -15
- package/dist/components/collapsible/CollapsibleTrigger.svelte.d.ts +10 -14
- package/dist/components/color-field/ColorField.svelte +13 -7
- package/dist/components/command/CommandDialog.svelte +30 -20
- package/dist/components/command/CommandDialog.svelte.d.ts +4 -3
- package/dist/components/command/CommandEmpty.svelte +11 -9
- package/dist/components/command/CommandEmpty.svelte.d.ts +6 -17
- package/dist/components/command/CommandGroup.svelte +32 -11
- package/dist/components/command/CommandGroup.svelte.d.ts +7 -11
- package/dist/components/command/CommandInput.svelte +25 -10
- package/dist/components/command/CommandInput.svelte.d.ts +8 -12
- package/dist/components/command/CommandItem.svelte +67 -29
- package/dist/components/command/CommandItem.svelte.d.ts +6 -32
- package/dist/components/command/CommandList.svelte +8 -10
- package/dist/components/command/CommandList.svelte.d.ts +6 -8
- package/dist/components/command/CommandRoot.svelte +247 -57
- package/dist/components/command/CommandRoot.svelte.d.ts +14 -28
- package/dist/components/command/CommandSeparator.svelte +18 -0
- package/dist/components/command/CommandSeparator.svelte.d.ts +7 -0
- package/dist/components/command/context.d.ts +27 -0
- package/dist/components/command/context.js +16 -0
- package/dist/components/command/index.d.ts +6 -4
- package/dist/components/command/index.js +5 -4
- package/dist/components/command/score.d.ts +27 -0
- package/dist/components/command/score.js +77 -0
- package/dist/components/command/styles.d.ts +32 -9
- package/dist/components/command/styles.js +42 -14
- package/dist/components/composer/ComposerModelPicker.svelte +350 -346
- package/dist/components/composer/ComposerModelPicker.svelte.d.ts +6 -3
- package/dist/components/composer/ComposerRoot.svelte.d.ts +1 -1
- package/dist/components/dialog/ConfirmDialog.svelte +73 -53
- package/dist/components/dialog/DialogClose.svelte +17 -0
- package/dist/components/dialog/DialogClose.svelte.d.ts +10 -0
- package/dist/components/dialog/DialogContent.svelte +35 -33
- package/dist/components/dialog/DialogContent.svelte.d.ts +6 -20
- package/dist/components/dialog/DialogDescription.svelte +9 -12
- package/dist/components/dialog/DialogDescription.svelte.d.ts +6 -8
- package/dist/components/dialog/DialogRoot.svelte +20 -0
- package/dist/components/dialog/DialogRoot.svelte.d.ts +7 -0
- package/dist/components/dialog/DialogTitle.svelte +12 -8
- package/dist/components/dialog/DialogTitle.svelte.d.ts +8 -8
- package/dist/components/dialog/DialogTrigger.svelte +17 -0
- package/dist/components/dialog/DialogTrigger.svelte.d.ts +10 -0
- package/dist/components/dialog/index.d.ts +6 -5
- package/dist/components/dialog/index.js +3 -6
- package/dist/components/dialog/styles.d.ts +1 -2
- package/dist/components/dialog/styles.js +11 -8
- package/dist/components/hover-card/HoverCardContent.svelte +35 -29
- package/dist/components/hover-card/HoverCardContent.svelte.d.ts +8 -12
- package/dist/components/hover-card/HoverCardRoot.svelte +7 -7
- package/dist/components/hover-card/HoverCardRoot.svelte.d.ts +5 -4
- package/dist/components/hover-card/HoverCardTrigger.svelte +18 -0
- package/dist/components/hover-card/HoverCardTrigger.svelte.d.ts +10 -0
- package/dist/components/hover-card/index.d.ts +2 -3
- package/dist/components/hover-card/index.js +1 -5
- package/dist/components/input/Input.svelte.d.ts +1 -1
- package/dist/components/markdown/MarkdownBlock.svelte +6 -3
- package/dist/components/markdown/MarkdownTable.svelte +15 -7
- package/dist/components/menu/ContextMenuContent.svelte +15 -15
- package/dist/components/menu/ContextMenuContent.svelte.d.ts +6 -9
- package/dist/components/menu/ContextMenuTrigger.svelte +14 -16
- package/dist/components/menu/ContextMenuTrigger.svelte.d.ts +8 -14
- package/dist/components/menu/MenuCheckboxItem.svelte +22 -11
- package/dist/components/menu/MenuCheckboxItem.svelte.d.ts +8 -22
- package/dist/components/menu/MenuContent.svelte +16 -18
- package/dist/components/menu/MenuContent.svelte.d.ts +6 -18
- package/dist/components/menu/MenuGroup.svelte +4 -4
- package/dist/components/menu/MenuGroup.svelte.d.ts +5 -4
- package/dist/components/menu/MenuItem.svelte +25 -12
- package/dist/components/menu/MenuItem.svelte.d.ts +6 -21
- package/dist/components/menu/MenuLabel.svelte +7 -11
- package/dist/components/menu/MenuLabel.svelte.d.ts +6 -8
- package/dist/components/menu/MenuRadioGroup.svelte +4 -4
- package/dist/components/menu/MenuRadioGroup.svelte.d.ts +5 -4
- package/dist/components/menu/MenuRadioItem.svelte +16 -14
- package/dist/components/menu/MenuRadioItem.svelte.d.ts +6 -19
- package/dist/components/menu/MenuSeparator.svelte +6 -10
- package/dist/components/menu/MenuSeparator.svelte.d.ts +6 -7
- package/dist/components/menu/MenuSubContent.svelte +22 -19
- package/dist/components/menu/MenuSubContent.svelte.d.ts +8 -15
- package/dist/components/menu/MenuSubTrigger.svelte +7 -11
- package/dist/components/menu/MenuSubTrigger.svelte.d.ts +6 -15
- package/dist/components/menu/MenuTrigger.svelte +17 -0
- package/dist/components/menu/MenuTrigger.svelte.d.ts +10 -0
- package/dist/components/menu/context-menu.d.ts +2 -2
- package/dist/components/menu/context-menu.js +3 -2
- package/dist/components/menu/group.js +1 -1
- package/dist/components/menu/index.d.ts +5 -4
- package/dist/components/menu/index.js +5 -5
- package/dist/components/menu/row.d.ts +20 -0
- package/dist/components/menu/row.js +12 -0
- package/dist/components/popover/PopoverClose.svelte +17 -0
- package/dist/components/popover/PopoverClose.svelte.d.ts +10 -0
- package/dist/components/popover/PopoverContent.svelte +30 -29
- package/dist/components/popover/PopoverContent.svelte.d.ts +6 -17
- package/dist/components/popover/PopoverTrigger.svelte +17 -0
- package/dist/components/popover/PopoverTrigger.svelte.d.ts +10 -0
- package/dist/components/popover/index.d.ts +6 -4
- package/dist/components/popover/index.js +6 -5
- package/dist/components/progress/Progress.svelte +16 -22
- package/dist/components/progress/Progress.svelte.d.ts +6 -5
- package/dist/components/reasoning/ReasoningRoot.svelte.d.ts +1 -1
- package/dist/components/resize-handle/ResizeHandle.svelte +80 -14
- package/dist/components/resize-handle/ResizeHandle.svelte.d.ts +15 -1
- package/dist/components/segmented/SegmentedControl.svelte +100 -91
- package/dist/components/segmented/SegmentedControl.svelte.d.ts +6 -4
- package/dist/components/select/Select.svelte +97 -59
- package/dist/components/select/Select.svelte.d.ts +3 -2
- package/dist/components/sheet/SheetContent.svelte +31 -38
- package/dist/components/sheet/SheetContent.svelte.d.ts +7 -22
- package/dist/components/sheet/index.d.ts +3 -5
- package/dist/components/sheet/index.js +3 -5
- package/dist/components/sheet/styles.js +26 -5
- package/dist/components/sidebar/SidebarItem.svelte +2 -3
- package/dist/components/slider/Slider.svelte +86 -65
- package/dist/components/slider/Slider.svelte.d.ts +9 -8
- package/dist/components/split-button/SplitButton.svelte +20 -3
- package/dist/components/split-button/SplitButton.svelte.d.ts +1 -1
- package/dist/components/switch/Switch.svelte +77 -49
- package/dist/components/switch/Switch.svelte.d.ts +15 -8
- package/dist/components/tab-strip/TabStrip.svelte +87 -68
- package/dist/components/tabs/Tabs.svelte +129 -99
- package/dist/components/tabs/Tabs.svelte.d.ts +6 -4
- package/dist/components/textarea/Textarea.svelte.d.ts +1 -1
- package/dist/components/toast/Toaster.svelte +132 -115
- package/dist/components/toast/Toaster.svelte.d.ts +5 -0
- package/dist/components/toast/toasts.svelte.d.ts +10 -23
- package/dist/components/toast/toasts.svelte.js +62 -40
- package/dist/components/toggle/Toggle.svelte +15 -9
- package/dist/components/toggle/Toggle.svelte.d.ts +8 -17
- package/dist/components/toggle-group/ToggleGroupItem.svelte +20 -9
- package/dist/components/toggle-group/ToggleGroupItem.svelte.d.ts +10 -10
- package/dist/components/toggle-group/ToggleGroupRoot.svelte +33 -18
- package/dist/components/toggle-group/ToggleGroupRoot.svelte.d.ts +4 -4
- package/dist/components/tool/ToolRoot.svelte.d.ts +1 -1
- package/dist/components/tooltip/TooltipContent.svelte +38 -28
- package/dist/components/tooltip/TooltipContent.svelte.d.ts +6 -15
- package/dist/components/tooltip/TooltipProvider.svelte +34 -10
- package/dist/components/tooltip/TooltipProvider.svelte.d.ts +18 -4
- package/dist/components/tooltip/TooltipRoot.svelte +52 -23
- package/dist/components/tooltip/TooltipRoot.svelte.d.ts +10 -10
- package/dist/components/tooltip/TooltipTrigger.svelte +14 -17
- package/dist/components/tooltip/TooltipTrigger.svelte.d.ts +10 -4
- package/dist/components/tooltip/index.d.ts +1 -1
- package/dist/components/tooltip/index.js +1 -1
- package/dist/components/work-fold/WorkFold.svelte +14 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +1 -1
- package/dist/internal/TooltipScope.svelte +4 -4
- package/dist/internal/layer.d.ts +11 -9
- package/dist/internal/layer.js +21 -15
- package/dist/internal/loose.d.ts +30 -5
- package/dist/internal/loose.js +1 -1
- package/dist/internal/markers.stylex.d.ts +0 -4
- package/dist/internal/markers.stylex.js +0 -2
- package/dist/internal/toggle.d.ts +3 -0
- package/dist/internal/toggle.js +6 -2
- package/dist/internal/tooltip-trigger.d.ts +7 -6
- package/dist/internal/tooltip-trigger.js +9 -12
- package/dist/vite.d.ts +7 -1
- package/dist/vite.js +20 -5
- package/package.json +3 -2
- package/skills/building-ui/SKILL.md +22 -22
- package/skills/building-ui/references/components.md +30 -4
- package/skills/markdown/SKILL.md +1 -1
- package/skills/setup/SKILL.md +4 -8
- package/skills/styling/SKILL.md +1 -1
- package/skills/theming/SKILL.md +3 -7
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
25
25
|
import Glyph from '../../internal/Glyph.svelte';
|
|
26
26
|
import { tabStripTabMarker } from '../../internal/markers.stylex.js';
|
|
27
|
-
import {
|
|
27
|
+
import { Tabs as UiTabs, TabsList, TabsTab } from '@ui-sdk/svelte/tabs';
|
|
28
28
|
import * as ContextMenu from '../menu/context-menu.js';
|
|
29
29
|
import * as Menu from '../menu/index.js';
|
|
30
30
|
import { TabDragging, tabOffset } from './drag.svelte.js';
|
|
@@ -241,6 +241,9 @@
|
|
|
241
241
|
transitionDuration: motion.fast,
|
|
242
242
|
transitionTimingFunction: 'ease'
|
|
243
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)' },
|
|
244
247
|
// Beside the open one, in a split view: lit, as under the pointer
|
|
245
248
|
beside: { backgroundColor: colors.fillHover, color: colors.text },
|
|
246
249
|
// The others slide aside, and a dropped tab settles, quickly; the dragged one follows
|
|
@@ -509,16 +512,32 @@
|
|
|
509
512
|
$effect(() => () => dragging.dispose());
|
|
510
513
|
const drag = $derived(dragging.drag);
|
|
511
514
|
|
|
512
|
-
// 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
|
+
|
|
513
531
|
$effect(() => {
|
|
514
532
|
void value;
|
|
515
533
|
void tabs.length;
|
|
516
534
|
const named = renaming;
|
|
517
535
|
tick().then(() =>
|
|
518
|
-
(
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
536
|
+
reveal(
|
|
537
|
+
named
|
|
538
|
+
? list?.querySelector<HTMLElement>('[data-renaming]')
|
|
539
|
+
: list?.querySelector<HTMLElement>('[role="tab"][aria-selected="true"]')
|
|
540
|
+
)
|
|
522
541
|
);
|
|
523
542
|
});
|
|
524
543
|
|
|
@@ -580,22 +599,12 @@
|
|
|
580
599
|
else startRename(tab);
|
|
581
600
|
}
|
|
582
601
|
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
// The arrow keys, Home and End move the focus to a tab; with automatic activation, the tab
|
|
590
|
-
// they reach opens. A tab focused any other way, such as as its menu closes, stays as it is.
|
|
591
|
-
let arrowed = false;
|
|
592
|
-
function onListKeydownCapture(event: KeyboardEvent) {
|
|
593
|
-
if (event.altKey || event.metaKey || event.ctrlKey || event.shiftKey) return;
|
|
594
|
-
if (!['ArrowLeft', 'ArrowRight', 'Home', 'End'].includes(event.key)) return;
|
|
595
|
-
if (!(event.target instanceof HTMLElement) || event.target.getAttribute('role') !== 'tab')
|
|
596
|
-
return;
|
|
597
|
-
arrowed = true;
|
|
598
|
-
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);
|
|
599
608
|
}
|
|
600
609
|
|
|
601
610
|
function moveByKey(tab: TabStripTab, event: KeyboardEvent) {
|
|
@@ -645,6 +654,7 @@
|
|
|
645
654
|
}}
|
|
646
655
|
{...stylex.attrs(
|
|
647
656
|
styles.tab,
|
|
657
|
+
trailing && styles.tabTrailing,
|
|
648
658
|
tab.id === beside && !selected && styles.beside,
|
|
649
659
|
selected && styles.selected,
|
|
650
660
|
notch && (selected ? styles.notchOpen : styles.notchStanding),
|
|
@@ -657,6 +667,7 @@
|
|
|
657
667
|
<input
|
|
658
668
|
{@attach selectAll}
|
|
659
669
|
aria-label={renameLabel(tab)}
|
|
670
|
+
dir="auto"
|
|
660
671
|
value={tab.label}
|
|
661
672
|
onkeydown={(event) => {
|
|
662
673
|
if (event.key !== 'Enter' && event.key !== 'Escape') return;
|
|
@@ -669,24 +680,19 @@
|
|
|
669
680
|
{...stylex.attrs(styles.rename)}
|
|
670
681
|
/>
|
|
671
682
|
{:else}
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
683
|
+
<!-- ui-sdk's tab: it is pressed, or reached with the arrows, to open -->
|
|
684
|
+
<TabsTab
|
|
685
|
+
value={tab.id}
|
|
675
686
|
id={tab.tabId}
|
|
676
|
-
aria-selected={selected}
|
|
677
687
|
aria-controls={tab.panelId ?? controls}
|
|
678
688
|
aria-current={selected ? 'true' : undefined}
|
|
679
689
|
aria-label={tabName(tab)}
|
|
680
690
|
title={tab.title ?? tab.label}
|
|
681
691
|
{...stylex.attrs(
|
|
682
692
|
styles.button,
|
|
683
|
-
onclose && !leading && !trailing && styles.closable,
|
|
693
|
+
(onclose || tab.mark) && !leading && !trailing && styles.closable,
|
|
684
694
|
trailing && styles.buttonBeforeTrailing
|
|
685
695
|
)}
|
|
686
|
-
onclick={() => open(tab)}
|
|
687
|
-
onfocus={() => {
|
|
688
|
-
if (arrowed && activation === 'automatic') open(tab);
|
|
689
|
-
}}
|
|
690
696
|
ondblclick={() => doubleClick(tab)}
|
|
691
697
|
onkeydown={(event) => {
|
|
692
698
|
if (moveByKey(tab, event)) return;
|
|
@@ -725,11 +731,14 @@
|
|
|
725
731
|
{/if}
|
|
726
732
|
</span>
|
|
727
733
|
{/if}
|
|
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 -->
|
|
728
736
|
<span
|
|
729
737
|
data-slot="tab-strip-label"
|
|
738
|
+
dir="auto"
|
|
730
739
|
{...stylex.attrs(styles.text, tab.temporary && styles.temporary)}>{tab.label}</span
|
|
731
740
|
>
|
|
732
|
-
</
|
|
741
|
+
</TabsTab>
|
|
733
742
|
{/if}
|
|
734
743
|
{#if trailing}
|
|
735
744
|
<span
|
|
@@ -751,7 +760,7 @@
|
|
|
751
760
|
<Glyph name="close" size={12} />
|
|
752
761
|
</button>
|
|
753
762
|
</span>
|
|
754
|
-
{:else if onclose || tab.mark}
|
|
763
|
+
{:else if onclose || (tab.mark && !leading)}
|
|
755
764
|
<span {...stylex.attrs(styles.end, notch && selected && styles.notchOpenAside)}>
|
|
756
765
|
{#if tab.mark}
|
|
757
766
|
<span
|
|
@@ -777,43 +786,53 @@
|
|
|
777
786
|
</div>
|
|
778
787
|
{/snippet}
|
|
779
788
|
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
>
|
|
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> })}
|
|
786
795
|
<div
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
{...
|
|
792
|
-
{@attach roving({ selector: '[role="tab"]', orientation: 'horizontal', wrap: true })}
|
|
793
|
-
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)}
|
|
794
801
|
>
|
|
795
|
-
|
|
796
|
-
{
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
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()}
|
|
816
832
|
</div>
|
|
833
|
+
{/snippet}
|
|
834
|
+
|
|
835
|
+
{#snippet add()}
|
|
817
836
|
{#snippet plus()}
|
|
818
837
|
<svg
|
|
819
838
|
data-glyph=""
|
|
@@ -855,4 +874,4 @@
|
|
|
855
874
|
{@render plus()}
|
|
856
875
|
</button>
|
|
857
876
|
{/if}
|
|
858
|
-
|
|
877
|
+
{/snippet}
|
|
@@ -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;
|