@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
|
@@ -0,0 +1,148 @@
|
|
|
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
|
+
/** How far the pointer moves before a press on a tab becomes a drag, in pixels. */
|
|
7
|
+
const THRESHOLD = 4;
|
|
8
|
+
/** How long a dropped tab takes to settle into its place: `motion.fast`. */
|
|
9
|
+
const SETTLE_MS = 120;
|
|
10
|
+
/**
|
|
11
|
+
* The place a tab dragged by `dx` would drop into. It passes another once its leading edge
|
|
12
|
+
* crosses that one's middle, so a wide tab passes a narrow one as readily as the other way.
|
|
13
|
+
*/
|
|
14
|
+
function dropPlace(rects, from, dx) {
|
|
15
|
+
const moving = rects[from];
|
|
16
|
+
if (!moving)
|
|
17
|
+
return from;
|
|
18
|
+
const left = moving.left + dx;
|
|
19
|
+
const right = left + moving.width;
|
|
20
|
+
return rects.filter((rect, index) => {
|
|
21
|
+
const middle = rect.left + rect.width / 2;
|
|
22
|
+
return index !== from && (index < from ? left > middle : right > middle);
|
|
23
|
+
}).length;
|
|
24
|
+
}
|
|
25
|
+
/** How far the dragged tab moves to sit in the place it drops into. */
|
|
26
|
+
function settledOffset(rects, from, to) {
|
|
27
|
+
const moving = rects[from];
|
|
28
|
+
const target = rects[to];
|
|
29
|
+
if (!moving || !target || to === from)
|
|
30
|
+
return 0;
|
|
31
|
+
return to < from
|
|
32
|
+
? target.left - moving.left
|
|
33
|
+
: target.left + target.width - moving.width - moving.left;
|
|
34
|
+
}
|
|
35
|
+
/** How far the tab at `index` moves while another is dragged: aside, to make room, or not at all. */
|
|
36
|
+
export function tabOffset(drag, index) {
|
|
37
|
+
if (!drag)
|
|
38
|
+
return 0;
|
|
39
|
+
if (index === drag.from)
|
|
40
|
+
return drag.dx;
|
|
41
|
+
const moving = drag.rects[drag.from];
|
|
42
|
+
const [first, second] = drag.rects;
|
|
43
|
+
const gap = first && second ? second.left - (first.left + first.width) : 0;
|
|
44
|
+
const room = (moving?.width ?? 0) + gap;
|
|
45
|
+
if (index > drag.from && index <= drag.to)
|
|
46
|
+
return -room;
|
|
47
|
+
if (index < drag.from && index >= drag.to)
|
|
48
|
+
return room;
|
|
49
|
+
return 0;
|
|
50
|
+
}
|
|
51
|
+
export class TabDragging {
|
|
52
|
+
drag = $state.raw(null);
|
|
53
|
+
#settling = 0;
|
|
54
|
+
/** The tabs, in order. */
|
|
55
|
+
#tabs;
|
|
56
|
+
/** The strip they are dragged along, and kept within. */
|
|
57
|
+
#strip;
|
|
58
|
+
#onmove;
|
|
59
|
+
constructor(tabs, strip, onmove) {
|
|
60
|
+
this.#tabs = tabs;
|
|
61
|
+
this.#strip = strip;
|
|
62
|
+
this.#onmove = onmove;
|
|
63
|
+
}
|
|
64
|
+
/** A press on the tab at `index`, which becomes a drag once the pointer moves far enough. */
|
|
65
|
+
press(index, event) {
|
|
66
|
+
const strip = this.#strip();
|
|
67
|
+
const tab = event.currentTarget;
|
|
68
|
+
const target = event.target instanceof Element ? event.target : null;
|
|
69
|
+
// Its close button and its own buttons keep their presses, and so does a name being typed
|
|
70
|
+
const control = target?.closest('button, input, a');
|
|
71
|
+
if (!strip ||
|
|
72
|
+
!(tab instanceof HTMLElement) ||
|
|
73
|
+
event.button !== 0 ||
|
|
74
|
+
(control && control.getAttribute('role') !== 'tab'))
|
|
75
|
+
return;
|
|
76
|
+
const pointer = event.pointerId;
|
|
77
|
+
const startX = event.clientX;
|
|
78
|
+
const bounds = strip.getBoundingClientRect();
|
|
79
|
+
const rects = this.#tabs().map((each) => {
|
|
80
|
+
const rect = each.getBoundingClientRect();
|
|
81
|
+
return { left: rect.left, width: rect.width };
|
|
82
|
+
});
|
|
83
|
+
const moving = rects[index];
|
|
84
|
+
if (!moving)
|
|
85
|
+
return;
|
|
86
|
+
const state = { started: false, to: index, dx: 0 };
|
|
87
|
+
const move = (next) => {
|
|
88
|
+
if (next.pointerId !== pointer)
|
|
89
|
+
return;
|
|
90
|
+
const dx = next.clientX - startX;
|
|
91
|
+
if (!state.started && Math.abs(dx) < THRESHOLD)
|
|
92
|
+
return;
|
|
93
|
+
if (!state.started) {
|
|
94
|
+
state.started = true;
|
|
95
|
+
tab.setPointerCapture?.(pointer);
|
|
96
|
+
}
|
|
97
|
+
// It stays within the strip
|
|
98
|
+
const low = bounds.left - moving.left;
|
|
99
|
+
const high = bounds.right - (moving.left + moving.width);
|
|
100
|
+
state.dx = Math.min(high, Math.max(low, dx));
|
|
101
|
+
state.to = dropPlace(rects, index, state.dx);
|
|
102
|
+
this.drag = { from: index, to: state.to, dx: state.dx, settling: false, rects };
|
|
103
|
+
};
|
|
104
|
+
const end = (last) => {
|
|
105
|
+
if (last.pointerId !== pointer)
|
|
106
|
+
return;
|
|
107
|
+
removeEventListener('pointermove', move);
|
|
108
|
+
removeEventListener('pointerup', end);
|
|
109
|
+
removeEventListener('pointercancel', end);
|
|
110
|
+
if (!state.started)
|
|
111
|
+
return;
|
|
112
|
+
// The press ends in a click, which would open the tab, and a drag is not one
|
|
113
|
+
const swallow = (click) => {
|
|
114
|
+
click.stopPropagation();
|
|
115
|
+
click.preventDefault();
|
|
116
|
+
};
|
|
117
|
+
addEventListener('click', swallow, { capture: true, once: true });
|
|
118
|
+
setTimeout(() => removeEventListener('click', swallow, { capture: true }));
|
|
119
|
+
const commit = () => {
|
|
120
|
+
this.drag = null;
|
|
121
|
+
if (state.to !== index)
|
|
122
|
+
this.#onmove(index, state.to);
|
|
123
|
+
};
|
|
124
|
+
if (last.type === 'pointercancel' || matchMedia('(prefers-reduced-motion: reduce)').matches) {
|
|
125
|
+
if (last.type === 'pointercancel')
|
|
126
|
+
state.to = index;
|
|
127
|
+
commit();
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
this.drag = {
|
|
131
|
+
from: index,
|
|
132
|
+
to: state.to,
|
|
133
|
+
dx: settledOffset(rects, index, state.to),
|
|
134
|
+
settling: true,
|
|
135
|
+
rects
|
|
136
|
+
};
|
|
137
|
+
clearTimeout(this.#settling);
|
|
138
|
+
this.#settling = window.setTimeout(commit, SETTLE_MS);
|
|
139
|
+
};
|
|
140
|
+
addEventListener('pointermove', move);
|
|
141
|
+
addEventListener('pointerup', end);
|
|
142
|
+
addEventListener('pointercancel', end);
|
|
143
|
+
}
|
|
144
|
+
/** Stops a drop settling, as the strip goes. */
|
|
145
|
+
dispose() {
|
|
146
|
+
clearTimeout(this.#settling);
|
|
147
|
+
}
|
|
148
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -122,6 +122,8 @@ export { default as Slider } from './components/slider/Slider.svelte';
|
|
|
122
122
|
export type { SliderProps } from './components/slider/Slider.svelte';
|
|
123
123
|
export { default as Spinner } from './components/spinner/Spinner.svelte';
|
|
124
124
|
export type { SpinnerProps } from './components/spinner/Spinner.svelte';
|
|
125
|
+
export { default as SplitButton } from './components/split-button/SplitButton.svelte';
|
|
126
|
+
export type { SplitButtonProps } from './components/split-button/SplitButton.svelte';
|
|
125
127
|
export { default as Stack } from './components/stack/Stack.svelte';
|
|
126
128
|
export type { StackAlign, StackDirection, StackGap, StackJustify, StackProps } from './components/stack/Stack.svelte';
|
|
127
129
|
export * as Suggestions from './components/suggestions/index.js';
|
package/dist/index.js
CHANGED
|
@@ -92,6 +92,7 @@ export * as Sidebar from './components/sidebar/index.js';
|
|
|
92
92
|
export { default as Skeleton } from './components/skeleton/Skeleton.svelte';
|
|
93
93
|
export { default as Slider } from './components/slider/Slider.svelte';
|
|
94
94
|
export { default as Spinner } from './components/spinner/Spinner.svelte';
|
|
95
|
+
export { default as SplitButton } from './components/split-button/SplitButton.svelte';
|
|
95
96
|
export { default as Stack } from './components/stack/Stack.svelte';
|
|
96
97
|
// Compound: <Suggestions.Root>, <Suggestions.Item>
|
|
97
98
|
export * as Suggestions from './components/suggestions/index.js';
|
package/package.json
CHANGED
|
@@ -12,7 +12,7 @@ metadata:
|
|
|
12
12
|
Grid, and Narvi's conventions for colour, labels and copy.
|
|
13
13
|
type: core
|
|
14
14
|
library: '@diegopluna/narvi'
|
|
15
|
-
library_version: '0.3.
|
|
15
|
+
library_version: '0.3.4'
|
|
16
16
|
requires:
|
|
17
17
|
- setup
|
|
18
18
|
sources:
|
|
@@ -32,6 +32,9 @@ sources:
|
|
|
32
32
|
- src/lib/components/list/ListRoot.svelte
|
|
33
33
|
- src/lib/components/choice-cards/ChoiceCards.svelte
|
|
34
34
|
- src/lib/components/dialog/DialogContent.svelte
|
|
35
|
+
- src/lib/components/tab-strip/TabStrip.svelte
|
|
36
|
+
- src/lib/components/split-button/SplitButton.svelte
|
|
37
|
+
- src/lib/components/app-shell/AppShellPanel.svelte
|
|
35
38
|
---
|
|
36
39
|
|
|
37
40
|
# Build interfaces with Narvi
|
|
@@ -168,7 +171,8 @@ The other controls don't read Field, so label them directly:
|
|
|
168
171
|
|
|
169
172
|
- `Checkbox` and `Switch` take their label as children: `<Switch bind:checked>Night shift</Switch>`.
|
|
170
173
|
To act on a change, `onCheckedChange={(checked) => save(checked)}` gets the new value; the
|
|
171
|
-
native `onchange` gets the event. `Select`'s `onchange`
|
|
174
|
+
native `onchange` gets the event. `Select`'s and `SegmentedControl`'s `onchange` get the new
|
|
175
|
+
value, as the person picks it: narrow it to your type there rather than in a `bind:value` setter.
|
|
172
176
|
- `SegmentedControl`, `ToggleGroup.Root` and `Slider` need an `aria-label` (or
|
|
173
177
|
`aria-labelledby`), for example `<SegmentedControl aria-label="Theme" … />`.
|
|
174
178
|
A `SegmentedControl` option with a short label can carry a `title` that names it in full
|
|
@@ -232,6 +236,9 @@ of the heading), which lays them on one card with a line between each, and each
|
|
|
232
236
|
- Attributes such as `id`, `tabindex` and `data-*` go on the row's element (and on the group's
|
|
233
237
|
`<section>`), so search can scroll to one and focus it. Set `highlighted` for a moment as it
|
|
234
238
|
lands to light it.
|
|
239
|
+
- `leading` is a snippet before the label (a provider's mark, an icon), `dimmed` mutes the
|
|
240
|
+
label (an agent switched off), and `mono` sets it in monospace (an environment variable, a
|
|
241
|
+
tool). Don't draw a row of your own for these.
|
|
235
242
|
- A `SettingsGroup` draws its lines between any children, so rows of the app's own go in it too;
|
|
236
243
|
give them their own padding (`SettingsRow` is inset 16px on the card).
|
|
237
244
|
|
|
@@ -315,7 +322,11 @@ line, `lines={2}` for several). Use `Code` and `Kbd` inline, and
|
|
|
315
322
|
says what it is doing beside the spinner instead. `variant="link"` sits in a sentence, at its
|
|
316
323
|
size, with no padding. A ghost, bare, secondary or floating Button that opens a menu or a
|
|
317
324
|
popover holds an open look while it shows, by the `aria-expanded` bits-ui sets: don't style
|
|
318
|
-
the open trigger yourself.
|
|
325
|
+
the open trigger yourself. `pressed` makes it a toggle button (`aria-pressed`) held in the same
|
|
326
|
+
look while true: don't style `aria-pressed` by hand.
|
|
327
|
+
- A main action with a menu of how to do it (Merge, Sign in) is a `SplitButton`: `menu` snippet,
|
|
328
|
+
`menuLabel` for the chevron, `label` for the group, both halves disabled together. Without
|
|
329
|
+
`menu` it stands alone. Don't join two Buttons by hand.
|
|
319
330
|
- `Toggle` and `ToggleGroup.Root` take `tone="neutral"` for a toolbar's icons that show or hide
|
|
320
331
|
something: pressed, they take the fill of what is chosen instead of lighting in the accent.
|
|
321
332
|
- `Menu.Item`, `Menu.SubTrigger` and `Menu.CheckboxItem` take a `description` (a line under the
|
|
@@ -326,6 +337,8 @@ line, `lines={2}` for several). Use `Code` and `Kbd` inline, and
|
|
|
326
337
|
`HoverCard.Content` takes `layout="column"` and `padding`; `Tooltip.Content` takes
|
|
327
338
|
`layout="column"` for a title over a line that says more.
|
|
328
339
|
- `Select` takes an `optionIcon` snippet, given each option, for an icon with props of its own.
|
|
340
|
+
An option's `detail` (a hash, a size, a count; `detailMono` for code) is muted at the end of
|
|
341
|
+
its row in the list, and kept off the trigger.
|
|
329
342
|
- `EmptyState`'s title is a heading (`level`, 2 by default). `Heading` takes a `weight`.
|
|
330
343
|
|
|
331
344
|
### App and chat screens
|
|
@@ -374,7 +387,14 @@ Parts of the shell that are easy to redraw by hand, and shouldn't be:
|
|
|
374
387
|
- **A mark with a badge** in a row's `meta` may overhang it; the line clips only far past its end.
|
|
375
388
|
- `AppShell.Main` is not focusable, so a press on text in the page leaves focus where it was.
|
|
376
389
|
- **TabStrip** tabs narrow to an ellipsis before the strip scrolls. With a `leading` icon, a
|
|
377
|
-
tab's close button takes the icon's place, so no room is kept at its end.
|
|
390
|
+
tab's close button takes the icon's place, so no room is kept at its end. A side panel's tabs
|
|
391
|
+
are a TabStrip too: `menu` (a snippet of Menu parts, given the tab: right-click, the menu key,
|
|
392
|
+
a long press), `onmove(id, index)` (drag, or Alt+Shift+arrow), `onrename(id, label)` with
|
|
393
|
+
`bind:renaming` (double-click, F2, or a menu's Rename), `trailing` for a tab's own buttons,
|
|
394
|
+
`beside` for the tab shown in a split, and per tab `tabId`, `panelId`, `title`, `renamable`.
|
|
395
|
+
- **AppShell.Panel** goes narrow by its row (the sheet less the sidebar), not the window.
|
|
396
|
+
`maximized` lays it over the whole page, header too; the page underneath is kept, inert. Give
|
|
397
|
+
the panel its own `AppShell.Header` with `AppShell.Toggle when="closed"`.
|
|
378
398
|
- **A Sheet** focuses itself as it opens (`focusOnOpen="sheet"`), so a Rail or a list in it
|
|
379
399
|
shows no focus ring until the keys move in. Pass `focusOnOpen="first"` for a sheet that
|
|
380
400
|
holds a form.
|
|
@@ -26,25 +26,26 @@ component: import the namespace (`Dialog`) and use `Dialog.Root`. Docs and live
|
|
|
26
26
|
|
|
27
27
|
## Controls and forms
|
|
28
28
|
|
|
29
|
-
| Component | Use it for
|
|
30
|
-
| --------------------------- |
|
|
31
|
-
| `Button` | An action; `href` makes it a link; `variant` (12, from `primary` to `success-outline`), `size` (`micro` to `lg`), `shape`, `loading`, `iconOnly`
|
|
32
|
-
| `Field` | Label, help text and error around one control
|
|
33
|
-
| `Input` | One line of text
|
|
34
|
-
| `Textarea` | Several lines of text
|
|
35
|
-
| `Select` | One choice from a short list (`options: { value, label, icon?, group? }[]`, `align`, `optionIcon`)
|
|
36
|
-
| `Checkbox` | An option on or off, or several from a list
|
|
37
|
-
| `ChoiceCards` | One choice among a few, each a card with a title and a line of detail
|
|
38
|
-
| `Switch` | A setting that takes effect at once
|
|
39
|
-
| `SegmentedControl` | One of a few options, all visible (`options: { value, label, title? }[]`)
|
|
40
|
-
| `Slider` | A value or a range along a track
|
|
41
|
-
| `
|
|
42
|
-
| `
|
|
43
|
-
| `
|
|
44
|
-
| `
|
|
45
|
-
| `
|
|
46
|
-
| `
|
|
47
|
-
| `
|
|
29
|
+
| Component | Use it for | Docs slug |
|
|
30
|
+
| --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------- |
|
|
31
|
+
| `Button` | An action; `href` makes it a link; `variant` (12, from `primary` to `success-outline`), `size` (`micro` to `lg`), `shape`, `loading`, `iconOnly`, `pressed` | `button` |
|
|
32
|
+
| `Field` | Label, help text and error around one control | `field` |
|
|
33
|
+
| `Input` | One line of text | `input` |
|
|
34
|
+
| `Textarea` | Several lines of text | `textarea` |
|
|
35
|
+
| `Select` | One choice from a short list (`options: { value, label, icon?, detail?, detailMono?, group? }[]`, `align`, `optionIcon`) | `select` |
|
|
36
|
+
| `Checkbox` | An option on or off, or several from a list | `checkbox` |
|
|
37
|
+
| `ChoiceCards` | One choice among a few, each a card with a title and a line of detail | `choice-cards` |
|
|
38
|
+
| `Switch` | A setting that takes effect at once | `switch` |
|
|
39
|
+
| `SegmentedControl` | One of a few options, all visible (`options: { value, label, title? }[]`, `onchange`) | `segmented-control` |
|
|
40
|
+
| `Slider` | A value or a range along a track | `slider` |
|
|
41
|
+
| `SplitButton` | A main action joined to a menu of how to do it (`menu`, `menuLabel`, `label`, `variant`) | `split-button` |
|
|
42
|
+
| `Toggle` | A button that stays pressed (`tone`: `accent`, or `neutral` for toolbar icons) | `toggle` |
|
|
43
|
+
| `ToggleGroup.Root`, `.Item` | Toggles that belong together: one pressed, or any number | `toggle-group` |
|
|
44
|
+
| `SettingsGroup` | A titled group of settings: a heading, an action, the rows on one card | `settings-group` |
|
|
45
|
+
| `SettingsRow` | One setting: what it is, beside its control (`leading`, `dimmed`, `mono`) | `settings-row` |
|
|
46
|
+
| `Tabs` | Views that share one place (`items: TabItem[]`) | `tabs` |
|
|
47
|
+
| `SearchButton` | Looks like a search field and opens search (`label`, `shortcut`): for a window's bar | `search-button` |
|
|
48
|
+
| `TabStrip` | Tabs for what is open in a pane: closable, addable, scrolling (`tabs`, `bind:value`, `onclose`, `onadd`); `menu`, `onmove`, `onrename`, `trailing`. The panels are yours | `tab-strip` |
|
|
48
49
|
|
|
49
50
|
## Overlays (bits-ui; use `child` snippets on triggers)
|
|
50
51
|
|
|
@@ -77,7 +78,7 @@ component: import the namespace (`Dialog`) and use `Dialog.Root`. Docs and live
|
|
|
77
78
|
| `Shimmer` | Text that says work is under way | `shimmer` |
|
|
78
79
|
| `RollingText` | A phrase that rolls to its next value ("Reading…", "Running…") | none |
|
|
79
80
|
| `Announcer` | Says a short message to screen readers without showing anything | `announcer` |
|
|
80
|
-
| `Avatar.Root`, `.Image`, `.Fallback` | A person: a picture, or initials
|
|
81
|
+
| `Avatar.Root`, `.Image`, `.Fallback` | A person: a picture, or initials (`size` `xs` is 20px; `label={null}` beside a written name) | `avatar` |
|
|
81
82
|
|
|
82
83
|
## App shell
|
|
83
84
|
|
package/skills/markdown/SKILL.md
CHANGED
package/skills/setup/SKILL.md
CHANGED
package/skills/styling/SKILL.md
CHANGED
package/skills/theming/SKILL.md
CHANGED