@diegopluna/narvi 0.3.3 → 0.3.4
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/dist/components/app-shell/AppShellMain.svelte +14 -2
- package/dist/components/app-shell/AppShellPanel.svelte +77 -12
- package/dist/components/app-shell/AppShellPanel.svelte.d.ts +11 -1
- package/dist/components/app-shell/AppShellSheet.svelte +11 -1
- package/dist/components/app-shell/context.d.ts +8 -0
- package/dist/components/app-shell/context.js +7 -0
- package/dist/components/avatar/AvatarRoot.svelte +20 -7
- package/dist/components/avatar/AvatarRoot.svelte.d.ts +10 -3
- package/dist/components/button/Button.svelte +12 -1
- package/dist/components/button/Button.svelte.d.ts +7 -0
- package/dist/components/segmented/SegmentedControl.svelte +12 -1
- package/dist/components/segmented/SegmentedControl.svelte.d.ts +3 -1
- package/dist/components/select/Select.svelte +25 -4
- package/dist/components/select/Select.svelte.d.ts +7 -0
- package/dist/components/settings-row/SettingsRow.svelte +87 -37
- package/dist/components/settings-row/SettingsRow.svelte.d.ts +13 -0
- package/dist/components/split-button/SplitButton.svelte +137 -0
- package/dist/components/split-button/SplitButton.svelte.d.ts +29 -0
- package/dist/components/tab-strip/TabStrip.svelte +337 -93
- package/dist/components/tab-strip/TabStrip.svelte.d.ts +36 -1
- package/dist/components/tab-strip/drag.svelte.d.ts +31 -0
- package/dist/components/tab-strip/drag.svelte.js +148 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/package.json +1 -1
- package/skills/building-ui/SKILL.md +24 -4
- package/skills/building-ui/references/components.md +21 -20
- package/skills/markdown/SKILL.md +1 -1
- package/skills/setup/SKILL.md +1 -1
- package/skills/styling/SKILL.md +1 -1
- package/skills/theming/SKILL.md +1 -1
|
@@ -5,9 +5,13 @@
|
|
|
5
5
|
sideways, and keeps the open one in view. A tab with a leading icon shows its
|
|
6
6
|
close button in the icon's place, so no room is kept at its end.
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
A tab can carry a menu (a right-click, the menu key or a long press), be
|
|
9
|
+
dragged into another place, be renamed where it stands, and hold buttons of
|
|
10
|
+
its own. Each is offered only when its callback or snippet is given.
|
|
11
|
+
|
|
12
|
+
It names the tabs and says which is open. The panels are yours: give each
|
|
13
|
+
`role="tabpanel"` and the id passed as `controls`, or one per tab, with its
|
|
14
|
+
own `panelId`. For a fixed set of sections that own their panel, use Tabs.
|
|
11
15
|
-->
|
|
12
16
|
<script lang="ts" module>
|
|
13
17
|
import { visuallyHidden } from '../../visually-hidden.js';
|
|
@@ -17,6 +21,8 @@
|
|
|
17
21
|
import Glyph from '../../internal/Glyph.svelte';
|
|
18
22
|
import { tabStripTabMarker } from '../../internal/markers.stylex.js';
|
|
19
23
|
import { roving } from '../../internal/roving.js';
|
|
24
|
+
import * as ContextMenu from '../menu/context-menu.js';
|
|
25
|
+
import { TabDragging, tabOffset } from './drag.svelte.js';
|
|
20
26
|
import { attrs, type Sx } from '../../internal/sx.js';
|
|
21
27
|
import { colors, font, motion, radius } from '../../tokens.stylex.js';
|
|
22
28
|
import { media } from '../../media.stylex.js';
|
|
@@ -24,8 +30,16 @@
|
|
|
24
30
|
export type TabStripTab = {
|
|
25
31
|
id: string;
|
|
26
32
|
label: string;
|
|
33
|
+
/** The tab's name in full, as a tooltip, where the label is short. Defaults to the label. */
|
|
34
|
+
title?: string | undefined;
|
|
27
35
|
/** Shown in place of the close button until the pointer is on the tab: unsaved, or live. */
|
|
28
36
|
mark?: 'unsaved' | 'live' | undefined;
|
|
37
|
+
/** The DOM id of the tab, for its panel's `aria-labelledby`. */
|
|
38
|
+
tabId?: string | undefined;
|
|
39
|
+
/** The id of this tab's own panel, in place of the strip's `controls`. */
|
|
40
|
+
panelId?: string | undefined;
|
|
41
|
+
/** With `onrename`, whether this tab can be renamed. Defaults to true. */
|
|
42
|
+
renamable?: boolean | undefined;
|
|
29
43
|
};
|
|
30
44
|
|
|
31
45
|
export type TabStripProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'onclose'> & {
|
|
@@ -45,6 +59,33 @@
|
|
|
45
59
|
closeLabel?: ((tab: TabStripTab) => string) | undefined;
|
|
46
60
|
/** Before a tab's label: an icon, or a StatusIndicator. */
|
|
47
61
|
leading?: Snippet<[TabStripTab]> | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* Buttons of a tab's own, after its label and before its close button: one that mutes a
|
|
64
|
+
* page, say. Keep them few and small: an `xs` or `micro` icon-only Button.
|
|
65
|
+
*/
|
|
66
|
+
trailing?: Snippet<[TabStripTab]> | undefined;
|
|
67
|
+
/**
|
|
68
|
+
* A tab's menu, of Menu parts: Move left, Rename, Close. It opens on a right-click, on
|
|
69
|
+
* Shift+F10 or the menu key, and on a long press on a touch screen.
|
|
70
|
+
*/
|
|
71
|
+
menu?: Snippet<[TabStripTab]> | undefined;
|
|
72
|
+
/**
|
|
73
|
+
* Called as a tab is dropped into another place, with its id and the index it goes to
|
|
74
|
+
* among the tabs. Without it the tabs cannot be dragged. Alt+Shift with an arrow moves
|
|
75
|
+
* the focused tab too.
|
|
76
|
+
*/
|
|
77
|
+
onmove?: ((id: string, index: number) => void) | undefined;
|
|
78
|
+
/**
|
|
79
|
+
* Called with a tab's new name, as Enter is pressed. Without it the tabs cannot be
|
|
80
|
+
* renamed. Renaming starts on a double-click, on F2, or as `renaming` is set.
|
|
81
|
+
*/
|
|
82
|
+
onrename?: ((id: string, label: string) => void) | undefined;
|
|
83
|
+
/** The id of the tab being renamed. Bindable: set it from a menu's Rename. */
|
|
84
|
+
renaming?: string | undefined;
|
|
85
|
+
/** The name of a tab's field while it is renamed. */
|
|
86
|
+
renameLabel?: ((tab: TabStripTab) => string) | undefined;
|
|
87
|
+
/** The id of a tab shown beside the open one, as in a split view: it is lit, as under the pointer. */
|
|
88
|
+
beside?: string | undefined;
|
|
48
89
|
sx?: Sx | undefined;
|
|
49
90
|
};
|
|
50
91
|
|
|
@@ -90,10 +131,32 @@
|
|
|
90
131
|
default: colors.textMuted,
|
|
91
132
|
[HOVER]: { default: null, [media.hover]: colors.text }
|
|
92
133
|
},
|
|
134
|
+
// Moved aside while another is dragged
|
|
135
|
+
translate: 'var(--narvi-tab-offset, 0px) 0',
|
|
93
136
|
transitionProperty: 'background-color, color',
|
|
94
137
|
transitionDuration: motion.fast,
|
|
95
138
|
transitionTimingFunction: 'ease'
|
|
96
139
|
},
|
|
140
|
+
// Beside the open one, in a split view: lit, as under the pointer
|
|
141
|
+
beside: { backgroundColor: colors.fillHover, color: colors.text },
|
|
142
|
+
// The others slide aside, and a dropped tab settles, quickly; the dragged one follows
|
|
143
|
+
// the pointer as it moves
|
|
144
|
+
sliding: {
|
|
145
|
+
transitionProperty: {
|
|
146
|
+
default: 'background-color, color',
|
|
147
|
+
[media.motion]: 'translate, background-color, color'
|
|
148
|
+
},
|
|
149
|
+
transitionDuration: motion.base,
|
|
150
|
+
transitionTimingFunction: motion.easeOut
|
|
151
|
+
},
|
|
152
|
+
// Picked up, it floats over the strip, so it takes the one shadow
|
|
153
|
+
lifted: {
|
|
154
|
+
zIndex: 10,
|
|
155
|
+
cursor: 'grabbing',
|
|
156
|
+
backgroundColor: { default: colors.bgRaised, [HOVER]: colors.bgRaised },
|
|
157
|
+
color: colors.text,
|
|
158
|
+
boxShadow: `inset 0 0 0 1px ${colors.border}, 0 4px 12px -2px ${colors.shadow}`
|
|
159
|
+
},
|
|
97
160
|
// The open tab: a fill, as the open row of a list has
|
|
98
161
|
selected: {
|
|
99
162
|
backgroundColor: { default: colors.fillSelected, [HOVER]: colors.fillSelected },
|
|
@@ -128,6 +191,35 @@
|
|
|
128
191
|
},
|
|
129
192
|
// A tab that can be closed keeps room at its end for the button
|
|
130
193
|
closable: { paddingInlineEnd: '1.625rem' },
|
|
194
|
+
// With buttons of its own, the room for the close button is kept after them
|
|
195
|
+
buttonBeforeTrailing: { paddingInlineEnd: '0.375rem' },
|
|
196
|
+
trailing: {
|
|
197
|
+
display: 'flex',
|
|
198
|
+
alignItems: 'center',
|
|
199
|
+
gap: '0.125rem',
|
|
200
|
+
flexShrink: 0,
|
|
201
|
+
paddingInlineEnd: '0.25rem'
|
|
202
|
+
},
|
|
203
|
+
trailingBeforeEnd: { paddingInlineEnd: '1.5rem' },
|
|
204
|
+
// The name, typed in place
|
|
205
|
+
rename: {
|
|
206
|
+
boxSizing: 'border-box',
|
|
207
|
+
flexGrow: 1,
|
|
208
|
+
width: '8rem',
|
|
209
|
+
minWidth: 0,
|
|
210
|
+
height: '1.25rem',
|
|
211
|
+
marginInline: '0.25rem',
|
|
212
|
+
paddingInline: '0.375rem',
|
|
213
|
+
borderWidth: 0,
|
|
214
|
+
borderRadius: radius.item,
|
|
215
|
+
backgroundColor: colors.bgRaised,
|
|
216
|
+
boxShadow: `inset 0 0 0 1px ${colors.focusRing}`,
|
|
217
|
+
color: colors.text,
|
|
218
|
+
fontFamily: 'inherit',
|
|
219
|
+
fontSize: font.sizeMeta,
|
|
220
|
+
fontWeight: font.weightRegular,
|
|
221
|
+
outlineStyle: 'none'
|
|
222
|
+
},
|
|
131
223
|
text: { minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' },
|
|
132
224
|
leading: { display: 'grid', flexShrink: 0 },
|
|
133
225
|
// With a leading icon, the close button and a mark take the icon's place: the icon
|
|
@@ -265,6 +357,13 @@
|
|
|
265
357
|
addLabel = 'New tab',
|
|
266
358
|
closeLabel = (tab) => `Close ${tab.label}`,
|
|
267
359
|
leading,
|
|
360
|
+
trailing,
|
|
361
|
+
menu,
|
|
362
|
+
onmove,
|
|
363
|
+
onrename,
|
|
364
|
+
renaming = $bindable(),
|
|
365
|
+
renameLabel = (tab) => `Name of ${tab.label}`,
|
|
366
|
+
beside,
|
|
268
367
|
sx,
|
|
269
368
|
class: className,
|
|
270
369
|
...rest
|
|
@@ -272,14 +371,35 @@
|
|
|
272
371
|
|
|
273
372
|
let list = $state<HTMLElement | null>(null);
|
|
274
373
|
|
|
275
|
-
|
|
374
|
+
const tabElements = () => [
|
|
375
|
+
...(list?.querySelectorAll<HTMLElement>('[data-slot="tab-strip-tab"]') ?? [])
|
|
376
|
+
];
|
|
377
|
+
const tabButton = (id: string) =>
|
|
378
|
+
tabElements()
|
|
379
|
+
.find((element) => element.dataset.tabId === id)
|
|
380
|
+
?.querySelector<HTMLElement>('[role="tab"]') ?? null;
|
|
381
|
+
|
|
382
|
+
const dragging = new TabDragging(
|
|
383
|
+
tabElements,
|
|
384
|
+
() => list,
|
|
385
|
+
(from, to) => {
|
|
386
|
+
const tab = tabs[from];
|
|
387
|
+
if (tab) onmove?.(tab.id, to);
|
|
388
|
+
}
|
|
389
|
+
);
|
|
390
|
+
$effect(() => () => dragging.dispose());
|
|
391
|
+
const drag = $derived(dragging.drag);
|
|
392
|
+
|
|
393
|
+
// The open tab stays in view as tabs come, go and are chosen, and so does one being renamed
|
|
276
394
|
$effect(() => {
|
|
277
395
|
void value;
|
|
278
396
|
void tabs.length;
|
|
397
|
+
const named = renaming;
|
|
279
398
|
tick().then(() =>
|
|
280
|
-
|
|
281
|
-
?.querySelector<HTMLElement>('[
|
|
282
|
-
?.
|
|
399
|
+
(named
|
|
400
|
+
? list?.querySelector<HTMLElement>('[data-renaming]')
|
|
401
|
+
: list?.querySelector<HTMLElement>('[role="tab"][aria-selected="true"]')
|
|
402
|
+
)?.scrollIntoView({ block: 'nearest', inline: 'nearest' })
|
|
283
403
|
);
|
|
284
404
|
});
|
|
285
405
|
|
|
@@ -294,111 +414,235 @@
|
|
|
294
414
|
(buttons?.[Math.min(index, (buttons?.length ?? 1) - 1)] ?? null)?.focus();
|
|
295
415
|
});
|
|
296
416
|
}
|
|
417
|
+
|
|
418
|
+
// The menu's trigger would make the tab's frame focusable; the tab inside is what takes focus
|
|
419
|
+
function withoutTabStop(props: Record<string, unknown>) {
|
|
420
|
+
const { tabindex: _, ...others } = props;
|
|
421
|
+
void _;
|
|
422
|
+
return others;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
const renamable = (tab: TabStripTab) => !!onrename && tab.renamable !== false;
|
|
426
|
+
|
|
427
|
+
function startRename(tab: TabStripTab) {
|
|
428
|
+
if (renamable(tab)) renaming = tab.id;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
// Enter keeps the name typed; Escape, or leaving the field, keeps the old one
|
|
432
|
+
function endRename(tab: TabStripTab, name: string | null, refocus: boolean) {
|
|
433
|
+
if (renaming !== tab.id) return;
|
|
434
|
+
renaming = undefined;
|
|
435
|
+
const next = name?.trim();
|
|
436
|
+
if (next) onrename?.(tab.id, next);
|
|
437
|
+
if (refocus) tick().then(() => tabButton(tab.id)?.focus());
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
// The field takes the focus, with its words chosen, so typing replaces them
|
|
441
|
+
const selectAll = (input: HTMLInputElement) => {
|
|
442
|
+
input.focus();
|
|
443
|
+
input.select();
|
|
444
|
+
};
|
|
445
|
+
|
|
446
|
+
function moveByKey(tab: TabStripTab, event: KeyboardEvent) {
|
|
447
|
+
if (!onmove || !event.altKey || !event.shiftKey) return false;
|
|
448
|
+
if (event.key !== 'ArrowLeft' && event.key !== 'ArrowRight') return false;
|
|
449
|
+
const rtl = list ? getComputedStyle(list).direction === 'rtl' : false;
|
|
450
|
+
const later = (event.key === 'ArrowRight') !== rtl;
|
|
451
|
+
const index = tabs.indexOf(tab);
|
|
452
|
+
const to = later ? index + 1 : index - 1;
|
|
453
|
+
event.preventDefault();
|
|
454
|
+
if (to < 0 || to >= tabs.length) return true;
|
|
455
|
+
onmove(tab.id, to);
|
|
456
|
+
// The tab keeps the focus in its new place
|
|
457
|
+
tick().then(() => tabButton(tab.id)?.focus());
|
|
458
|
+
return true;
|
|
459
|
+
}
|
|
297
460
|
</script>
|
|
298
461
|
|
|
299
|
-
|
|
462
|
+
{#snippet tabView(tab: TabStripTab, index: number, trigger: Record<string, unknown>)}
|
|
463
|
+
{@const selected = tab.id === value}
|
|
464
|
+
{@const lifted = !!drag && drag.from === index && !drag.settling}
|
|
465
|
+
{@const editing = renaming === tab.id && renamable(tab)}
|
|
466
|
+
{@const { onpointerdown: menuPointerDown, ...triggerRest } = withoutTabStop(trigger)}
|
|
300
467
|
<div
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
{
|
|
306
|
-
{
|
|
468
|
+
{...triggerRest}
|
|
469
|
+
data-slot="tab-strip-tab"
|
|
470
|
+
data-tab-id={tab.id}
|
|
471
|
+
data-renaming={editing || undefined}
|
|
472
|
+
data-lifted={lifted || undefined}
|
|
473
|
+
style:--narvi-tab-offset={drag ? `${tabOffset(drag, index)}px` : undefined}
|
|
474
|
+
onpointerdown={(event) => {
|
|
475
|
+
// The menu's own, which opens it on a long press on a touch screen
|
|
476
|
+
if (typeof menuPointerDown === 'function') menuPointerDown(event);
|
|
477
|
+
if (onmove && !editing) dragging.press(index, event);
|
|
478
|
+
}}
|
|
479
|
+
{...stylex.attrs(
|
|
480
|
+
styles.tab,
|
|
481
|
+
tab.id === beside && !selected && styles.beside,
|
|
482
|
+
selected && styles.selected,
|
|
483
|
+
drag && !lifted && styles.sliding,
|
|
484
|
+
lifted && styles.lifted,
|
|
485
|
+
tabStripTabMarker
|
|
486
|
+
)}
|
|
307
487
|
>
|
|
308
|
-
{#
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
{
|
|
488
|
+
{#if editing}
|
|
489
|
+
<input
|
|
490
|
+
{@attach selectAll}
|
|
491
|
+
aria-label={renameLabel(tab)}
|
|
492
|
+
value={tab.label}
|
|
493
|
+
onkeydown={(event) => {
|
|
494
|
+
if (event.key !== 'Enter' && event.key !== 'Escape') return;
|
|
495
|
+
// Its own keys, not the strip's, a dialog's or the window's
|
|
496
|
+
event.preventDefault();
|
|
497
|
+
event.stopPropagation();
|
|
498
|
+
endRename(tab, event.key === 'Enter' ? event.currentTarget.value : null, true);
|
|
499
|
+
}}
|
|
500
|
+
onblur={() => endRename(tab, null, false)}
|
|
501
|
+
{...stylex.attrs(styles.rename)}
|
|
502
|
+
/>
|
|
503
|
+
{:else}
|
|
504
|
+
<button
|
|
505
|
+
type="button"
|
|
506
|
+
role="tab"
|
|
507
|
+
id={tab.tabId}
|
|
508
|
+
aria-selected={selected}
|
|
509
|
+
aria-controls={tab.panelId ?? controls}
|
|
510
|
+
aria-current={selected ? 'true' : undefined}
|
|
511
|
+
title={tab.title ?? tab.label}
|
|
512
|
+
{...stylex.attrs(
|
|
513
|
+
styles.button,
|
|
514
|
+
onclose && !leading && !trailing && styles.closable,
|
|
515
|
+
trailing && styles.buttonBeforeTrailing
|
|
516
|
+
)}
|
|
517
|
+
onclick={() => (value = tab.id)}
|
|
518
|
+
ondblclick={() => startRename(tab)}
|
|
519
|
+
onauxclick={(event) => {
|
|
520
|
+
// The middle button closes, as it does in a browser
|
|
521
|
+
if (event.button === 1) close(tab);
|
|
522
|
+
}}
|
|
523
|
+
onkeydown={(event) => {
|
|
524
|
+
if (moveByKey(tab, event)) return;
|
|
525
|
+
if (event.key === 'F2' && renamable(tab)) {
|
|
526
|
+
event.preventDefault();
|
|
527
|
+
startRename(tab);
|
|
528
|
+
return;
|
|
529
|
+
}
|
|
530
|
+
if (!onclose || (event.key !== 'Delete' && event.key !== 'Backspace')) return;
|
|
531
|
+
event.preventDefault();
|
|
532
|
+
close(tab, true);
|
|
533
|
+
}}
|
|
534
|
+
>
|
|
535
|
+
{#if leading}
|
|
536
|
+
<span {...stylex.attrs(styles.leadCell)}>
|
|
537
|
+
{#if tab.mark}
|
|
538
|
+
<span
|
|
539
|
+
aria-hidden="true"
|
|
540
|
+
{...stylex.attrs(
|
|
541
|
+
styles.mark,
|
|
542
|
+
styles.markStill,
|
|
543
|
+
styles.leadMark,
|
|
544
|
+
tab.mark === 'live' && styles.live,
|
|
545
|
+
onclose && styles.leadIcon,
|
|
546
|
+
onclose && selected && styles.leadIconSelected
|
|
547
|
+
)}
|
|
548
|
+
></span>
|
|
549
|
+
{:else}
|
|
550
|
+
<span
|
|
551
|
+
{...stylex.attrs(
|
|
552
|
+
styles.leading,
|
|
553
|
+
onclose && styles.leadIcon,
|
|
554
|
+
onclose && selected && styles.leadIconSelected
|
|
555
|
+
)}>{@render leading(tab)}</span
|
|
556
|
+
>
|
|
557
|
+
{/if}
|
|
558
|
+
</span>
|
|
559
|
+
{/if}
|
|
560
|
+
<span {...stylex.attrs(styles.text)}>{tab.label}</span>
|
|
561
|
+
{#if tab.mark}<span {...stylex.attrs(visuallyHidden)}
|
|
562
|
+
>, {tab.mark === 'live' ? 'working' : 'unsaved'}</span
|
|
563
|
+
>{/if}
|
|
564
|
+
</button>
|
|
565
|
+
{/if}
|
|
566
|
+
{#if trailing}
|
|
567
|
+
<span
|
|
568
|
+
{...stylex.attrs(
|
|
569
|
+
styles.trailing,
|
|
570
|
+
!leading && (onclose || tab.mark) && styles.trailingBeforeEnd
|
|
571
|
+
)}>{@render trailing(tab)}</span
|
|
313
572
|
>
|
|
573
|
+
{/if}
|
|
574
|
+
{#if leading && onclose}
|
|
575
|
+
<span {...stylex.attrs(styles.start)}>
|
|
314
576
|
<button
|
|
315
577
|
type="button"
|
|
316
|
-
|
|
317
|
-
aria-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
title={tab.label}
|
|
321
|
-
{...stylex.attrs(styles.button, onclose && !leading && styles.closable)}
|
|
322
|
-
onclick={() => (value = tab.id)}
|
|
323
|
-
onauxclick={(event) => {
|
|
324
|
-
// The middle button closes, as it does in a browser
|
|
325
|
-
if (event.button === 1) close(tab);
|
|
326
|
-
}}
|
|
327
|
-
onkeydown={(event) => {
|
|
328
|
-
if (!onclose || (event.key !== 'Delete' && event.key !== 'Backspace')) return;
|
|
329
|
-
event.preventDefault();
|
|
330
|
-
close(tab, true);
|
|
331
|
-
}}
|
|
578
|
+
tabindex="-1"
|
|
579
|
+
aria-label={closeLabel(tab)}
|
|
580
|
+
{...stylex.attrs(styles.close, selected ? styles.closeLeadSelected : styles.closeLead)}
|
|
581
|
+
onclick={() => close(tab)}
|
|
332
582
|
>
|
|
333
|
-
{
|
|
334
|
-
<span {...stylex.attrs(styles.leadCell)}>
|
|
335
|
-
{#if tab.mark}
|
|
336
|
-
<span
|
|
337
|
-
aria-hidden="true"
|
|
338
|
-
{...stylex.attrs(
|
|
339
|
-
styles.mark,
|
|
340
|
-
styles.markStill,
|
|
341
|
-
styles.leadMark,
|
|
342
|
-
tab.mark === 'live' && styles.live,
|
|
343
|
-
onclose && styles.leadIcon,
|
|
344
|
-
onclose && selected && styles.leadIconSelected
|
|
345
|
-
)}
|
|
346
|
-
></span>
|
|
347
|
-
{:else}
|
|
348
|
-
<span
|
|
349
|
-
{...stylex.attrs(
|
|
350
|
-
styles.leading,
|
|
351
|
-
onclose && styles.leadIcon,
|
|
352
|
-
onclose && selected && styles.leadIconSelected
|
|
353
|
-
)}>{@render leading(tab)}</span
|
|
354
|
-
>
|
|
355
|
-
{/if}
|
|
356
|
-
</span>
|
|
357
|
-
{/if}
|
|
358
|
-
<span {...stylex.attrs(styles.text)}>{tab.label}</span>
|
|
359
|
-
{#if tab.mark}<span {...stylex.attrs(visuallyHidden)}
|
|
360
|
-
>, {tab.mark === 'live' ? 'working' : 'unsaved'}</span
|
|
361
|
-
>{/if}
|
|
583
|
+
<Glyph name="close" size={12} />
|
|
362
584
|
</button>
|
|
363
|
-
|
|
364
|
-
|
|
585
|
+
</span>
|
|
586
|
+
{:else if onclose || tab.mark}
|
|
587
|
+
<span {...stylex.attrs(styles.end)}>
|
|
588
|
+
{#if tab.mark}
|
|
589
|
+
<span
|
|
590
|
+
aria-hidden="true"
|
|
591
|
+
{...stylex.attrs(styles.mark, tab.mark === 'live' && styles.live)}
|
|
592
|
+
></span>
|
|
593
|
+
{/if}
|
|
594
|
+
{#if onclose}
|
|
595
|
+
<span {...stylex.attrs(styles.closeCell)}>
|
|
365
596
|
<button
|
|
366
597
|
type="button"
|
|
367
598
|
tabindex="-1"
|
|
368
599
|
aria-label={closeLabel(tab)}
|
|
369
|
-
{...stylex.attrs(
|
|
370
|
-
styles.close,
|
|
371
|
-
selected ? styles.closeLeadSelected : styles.closeLead
|
|
372
|
-
)}
|
|
600
|
+
{...stylex.attrs(styles.close, selected && !tab.mark && styles.closeShown)}
|
|
373
601
|
onclick={() => close(tab)}
|
|
374
602
|
>
|
|
375
603
|
<Glyph name="close" size={12} />
|
|
376
604
|
</button>
|
|
377
605
|
</span>
|
|
378
|
-
{:else if onclose || tab.mark}
|
|
379
|
-
<span {...stylex.attrs(styles.end)}>
|
|
380
|
-
{#if tab.mark}
|
|
381
|
-
<span
|
|
382
|
-
aria-hidden="true"
|
|
383
|
-
{...stylex.attrs(styles.mark, tab.mark === 'live' && styles.live)}
|
|
384
|
-
></span>
|
|
385
|
-
{/if}
|
|
386
|
-
{#if onclose}
|
|
387
|
-
<span {...stylex.attrs(styles.closeCell)}>
|
|
388
|
-
<button
|
|
389
|
-
type="button"
|
|
390
|
-
tabindex="-1"
|
|
391
|
-
aria-label={closeLabel(tab)}
|
|
392
|
-
{...stylex.attrs(styles.close, selected && !tab.mark && styles.closeShown)}
|
|
393
|
-
onclick={() => close(tab)}
|
|
394
|
-
>
|
|
395
|
-
<Glyph name="close" size={12} />
|
|
396
|
-
</button>
|
|
397
|
-
</span>
|
|
398
|
-
{/if}
|
|
399
|
-
</span>
|
|
400
606
|
{/if}
|
|
401
|
-
</
|
|
607
|
+
</span>
|
|
608
|
+
{/if}
|
|
609
|
+
</div>
|
|
610
|
+
{/snippet}
|
|
611
|
+
|
|
612
|
+
<div
|
|
613
|
+
data-slot="tab-strip"
|
|
614
|
+
data-dragging={drag ? '' : undefined}
|
|
615
|
+
{...rest}
|
|
616
|
+
{...attrs([styles.root, sx], className)}
|
|
617
|
+
>
|
|
618
|
+
<div
|
|
619
|
+
bind:this={list}
|
|
620
|
+
role="tablist"
|
|
621
|
+
aria-label={label}
|
|
622
|
+
aria-orientation="horizontal"
|
|
623
|
+
{...stylex.attrs(styles.list)}
|
|
624
|
+
{@attach roving({ selector: '[role="tab"]', orientation: 'horizontal' })}
|
|
625
|
+
>
|
|
626
|
+
{#each tabs as tab, index (tab.id)}
|
|
627
|
+
{#if menu}
|
|
628
|
+
<ContextMenu.Root>
|
|
629
|
+
<ContextMenu.Trigger>
|
|
630
|
+
{#snippet child({ props })}{@render tabView(tab, index, props)}{/snippet}
|
|
631
|
+
</ContextMenu.Trigger>
|
|
632
|
+
<!-- Renaming from it, the field keeps the focus the menu would give back -->
|
|
633
|
+
<ContextMenu.Content
|
|
634
|
+
onCloseAutoFocus={(event) => {
|
|
635
|
+
if (renaming !== tab.id) return;
|
|
636
|
+
event.preventDefault();
|
|
637
|
+
list?.querySelector<HTMLInputElement>('[data-renaming] input')?.focus();
|
|
638
|
+
}}
|
|
639
|
+
>
|
|
640
|
+
{@render menu(tab)}
|
|
641
|
+
</ContextMenu.Content>
|
|
642
|
+
</ContextMenu.Root>
|
|
643
|
+
{:else}
|
|
644
|
+
{@render tabView(tab, index, {})}
|
|
645
|
+
{/if}
|
|
402
646
|
{/each}
|
|
403
647
|
</div>
|
|
404
648
|
{#if onadd}
|
|
@@ -4,8 +4,16 @@ import { type Sx } from '../../internal/sx.js';
|
|
|
4
4
|
export type TabStripTab = {
|
|
5
5
|
id: string;
|
|
6
6
|
label: string;
|
|
7
|
+
/** The tab's name in full, as a tooltip, where the label is short. Defaults to the label. */
|
|
8
|
+
title?: string | undefined;
|
|
7
9
|
/** Shown in place of the close button until the pointer is on the tab: unsaved, or live. */
|
|
8
10
|
mark?: 'unsaved' | 'live' | undefined;
|
|
11
|
+
/** The DOM id of the tab, for its panel's `aria-labelledby`. */
|
|
12
|
+
tabId?: string | undefined;
|
|
13
|
+
/** The id of this tab's own panel, in place of the strip's `controls`. */
|
|
14
|
+
panelId?: string | undefined;
|
|
15
|
+
/** With `onrename`, whether this tab can be renamed. Defaults to true. */
|
|
16
|
+
renamable?: boolean | undefined;
|
|
9
17
|
};
|
|
10
18
|
export type TabStripProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'onclose'> & {
|
|
11
19
|
tabs: TabStripTab[];
|
|
@@ -24,8 +32,35 @@ export type TabStripProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'o
|
|
|
24
32
|
closeLabel?: ((tab: TabStripTab) => string) | undefined;
|
|
25
33
|
/** Before a tab's label: an icon, or a StatusIndicator. */
|
|
26
34
|
leading?: Snippet<[TabStripTab]> | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* Buttons of a tab's own, after its label and before its close button: one that mutes a
|
|
37
|
+
* page, say. Keep them few and small: an `xs` or `micro` icon-only Button.
|
|
38
|
+
*/
|
|
39
|
+
trailing?: Snippet<[TabStripTab]> | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* A tab's menu, of Menu parts: Move left, Rename, Close. It opens on a right-click, on
|
|
42
|
+
* Shift+F10 or the menu key, and on a long press on a touch screen.
|
|
43
|
+
*/
|
|
44
|
+
menu?: Snippet<[TabStripTab]> | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* Called as a tab is dropped into another place, with its id and the index it goes to
|
|
47
|
+
* among the tabs. Without it the tabs cannot be dragged. Alt+Shift with an arrow moves
|
|
48
|
+
* the focused tab too.
|
|
49
|
+
*/
|
|
50
|
+
onmove?: ((id: string, index: number) => void) | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* Called with a tab's new name, as Enter is pressed. Without it the tabs cannot be
|
|
53
|
+
* renamed. Renaming starts on a double-click, on F2, or as `renaming` is set.
|
|
54
|
+
*/
|
|
55
|
+
onrename?: ((id: string, label: string) => void) | undefined;
|
|
56
|
+
/** The id of the tab being renamed. Bindable: set it from a menu's Rename. */
|
|
57
|
+
renaming?: string | undefined;
|
|
58
|
+
/** The name of a tab's field while it is renamed. */
|
|
59
|
+
renameLabel?: ((tab: TabStripTab) => string) | undefined;
|
|
60
|
+
/** The id of a tab shown beside the open one, as in a split view: it is lit, as under the pointer. */
|
|
61
|
+
beside?: string | undefined;
|
|
27
62
|
sx?: Sx | undefined;
|
|
28
63
|
};
|
|
29
|
-
declare const TabStrip: import("svelte").Component<TabStripProps, {}, "value">;
|
|
64
|
+
declare const TabStrip: import("svelte").Component<TabStripProps, {}, "value" | "renaming">;
|
|
30
65
|
type TabStrip = ReturnType<typeof TabStrip>;
|
|
31
66
|
export default TabStrip;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dragging a tab along a TabStrip into another place: it follows the pointer, the others slide
|
|
3
|
+
* aside to make room, and let go, it settles into its place before the move is made. From
|
|
4
|
+
* Eregion's side panel (`tabDrag.svelte.ts`).
|
|
5
|
+
*/
|
|
6
|
+
type Rect = {
|
|
7
|
+
readonly left: number;
|
|
8
|
+
readonly width: number;
|
|
9
|
+
};
|
|
10
|
+
export type TabDrag = {
|
|
11
|
+
/** The place of the tab being dragged, and the place it would drop into. */
|
|
12
|
+
readonly from: number;
|
|
13
|
+
readonly to: number;
|
|
14
|
+
/** How far it has moved, in pixels. */
|
|
15
|
+
readonly dx: number;
|
|
16
|
+
/** Let go, and moving into its place. */
|
|
17
|
+
readonly settling: boolean;
|
|
18
|
+
readonly rects: readonly Rect[];
|
|
19
|
+
};
|
|
20
|
+
/** How far the tab at `index` moves while another is dragged: aside, to make room, or not at all. */
|
|
21
|
+
export declare function tabOffset(drag: TabDrag | null, index: number): number;
|
|
22
|
+
export declare class TabDragging {
|
|
23
|
+
#private;
|
|
24
|
+
drag: TabDrag | null;
|
|
25
|
+
constructor(tabs: () => HTMLElement[], strip: () => HTMLElement | null, onmove: (from: number, to: number) => void);
|
|
26
|
+
/** A press on the tab at `index`, which becomes a drag once the pointer moves far enough. */
|
|
27
|
+
press(index: number, event: PointerEvent): void;
|
|
28
|
+
/** Stops a drop settling, as the strip goes. */
|
|
29
|
+
dispose(): void;
|
|
30
|
+
}
|
|
31
|
+
export {};
|