@diegopluna/narvi 0.3.1 → 0.3.2
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 +5 -1
- package/dist/components/badge/Badge.svelte +16 -1
- package/dist/components/badge/Badge.svelte.d.ts +3 -0
- package/dist/components/button/Button.svelte +46 -7
- package/dist/components/hover-card/HoverCardContent.svelte +1 -1
- package/dist/components/menu/ContextMenuTrigger.svelte +14 -2
- package/dist/components/menu/ContextMenuTrigger.svelte.d.ts +10 -0
- package/dist/components/menu/MenuCheckboxItem.svelte +8 -2
- package/dist/components/menu/MenuCheckboxItem.svelte.d.ts +6 -0
- package/dist/components/menu/MenuGroup.svelte +16 -0
- package/dist/components/menu/MenuGroup.svelte.d.ts +6 -0
- package/dist/components/menu/MenuLabel.svelte +22 -8
- package/dist/components/menu/MenuRadioGroup.svelte +16 -0
- package/dist/components/menu/MenuRadioGroup.svelte.d.ts +6 -0
- package/dist/components/menu/group.d.ts +2 -0
- package/dist/components/menu/group.js +9 -0
- package/dist/components/menu/index.d.ts +4 -2
- package/dist/components/menu/index.js +2 -2
- package/dist/components/sidebar/SidebarContent.svelte +59 -13
- package/dist/components/sidebar/SidebarContent.svelte.d.ts +6 -0
- package/dist/components/sidebar/SidebarFolder.svelte +29 -2
- package/dist/components/sidebar/SidebarGroup.svelte +50 -7
- package/dist/components/sidebar/SidebarGroup.svelte.d.ts +10 -1
- package/dist/components/sidebar/SidebarItem.svelte +136 -21
- package/dist/components/sidebar/SidebarItem.svelte.d.ts +22 -2
- package/dist/components/sidebar/SidebarSwitcher.svelte +18 -2
- package/dist/components/sidebar/SidebarSwitcher.svelte.d.ts +2 -0
- package/dist/components/sidebar/fold.d.ts +12 -0
- package/dist/components/sidebar/fold.js +8 -0
- package/dist/components/status-indicator/StatusDot.svelte +90 -0
- package/dist/components/status-indicator/StatusDot.svelte.d.ts +18 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +1 -0
- package/package.json +1 -1
- package/skills/building-ui/SKILL.md +33 -6
- package/skills/building-ui/references/components.md +7 -6
- 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
|
@@ -7,14 +7,24 @@
|
|
|
7
7
|
import { attrs, type Sx } from '../../internal/sx.js';
|
|
8
8
|
import { colors, font, motion, radius } from '../../tokens.stylex.js';
|
|
9
9
|
import { media } from '../../media.stylex.js';
|
|
10
|
+
import { setSidebarFold } from './fold.js';
|
|
10
11
|
|
|
11
12
|
export type SidebarGroupProps = Omit<HTMLAttributes<HTMLElement>, 'children'> & {
|
|
12
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* The group's name: "Projects", or "Today". It names the list of rows too, so a screen
|
|
15
|
+
* reader tells one group's list from the next. Without one, the rows stand alone; name the
|
|
16
|
+
* group with `aria-label`, which its list then takes.
|
|
17
|
+
*/
|
|
13
18
|
label?: string | undefined;
|
|
14
19
|
/** Lets the person fold the group away. */
|
|
15
20
|
collapsible?: boolean | undefined;
|
|
16
21
|
/** Whether a collapsible group is open. Bindable. */
|
|
17
22
|
open?: boolean | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Folded, the open row (`current`) stays in view, in its folder, and the rest hide. On by
|
|
25
|
+
* default; `false` folds every row away.
|
|
26
|
+
*/
|
|
27
|
+
keepCurrent?: boolean | undefined;
|
|
18
28
|
/** Controls at the end of the label, such as a button to add an item. */
|
|
19
29
|
actions?: Snippet | undefined;
|
|
20
30
|
sx?: Sx | undefined;
|
|
@@ -31,8 +41,9 @@
|
|
|
31
41
|
alignItems: 'center',
|
|
32
42
|
gap: '0.25rem',
|
|
33
43
|
minHeight: '1.75rem',
|
|
34
|
-
|
|
35
|
-
|
|
44
|
+
// The rows' own inset at both ends: the label starts where their titles do, and the
|
|
45
|
+
// actions end where their trailing column does
|
|
46
|
+
paddingInline: '0.5rem'
|
|
36
47
|
},
|
|
37
48
|
label: {
|
|
38
49
|
display: 'inline-flex',
|
|
@@ -66,6 +77,14 @@
|
|
|
66
77
|
transitionTimingFunction: 'ease'
|
|
67
78
|
},
|
|
68
79
|
button: { cursor: 'pointer' },
|
|
80
|
+
// An icon button at the end ends by its icon (Button's `--narvi-icon-flush`)
|
|
81
|
+
actions: {
|
|
82
|
+
'--narvi-icon-flush': 1,
|
|
83
|
+
display: 'flex',
|
|
84
|
+
alignItems: 'center',
|
|
85
|
+
gap: '0.25rem',
|
|
86
|
+
flexShrink: 0
|
|
87
|
+
},
|
|
69
88
|
list: {
|
|
70
89
|
display: 'flex',
|
|
71
90
|
flexDirection: 'column',
|
|
@@ -83,6 +102,7 @@
|
|
|
83
102
|
label,
|
|
84
103
|
collapsible = false,
|
|
85
104
|
open = $bindable(true),
|
|
105
|
+
keepCurrent = true,
|
|
86
106
|
actions,
|
|
87
107
|
sx,
|
|
88
108
|
class: className,
|
|
@@ -91,6 +111,24 @@
|
|
|
91
111
|
}: SidebarGroupProps = $props();
|
|
92
112
|
|
|
93
113
|
const uid = $props.id();
|
|
114
|
+
|
|
115
|
+
// How many current rows hold the group open while it is folded: one, as a rule
|
|
116
|
+
let held = $state(0);
|
|
117
|
+
setSidebarFold({
|
|
118
|
+
folded: () => collapsible && !!label && keepCurrent && !open,
|
|
119
|
+
hold: () => {
|
|
120
|
+
held += 1;
|
|
121
|
+
return () => (held -= 1);
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
const shown = $derived(open || (keepCurrent && held > 0));
|
|
125
|
+
|
|
126
|
+
// The list says whose it is, or a screen reader announces only "list, 3 items"
|
|
127
|
+
const listName = $derived(
|
|
128
|
+
label
|
|
129
|
+
? { 'aria-labelledby': `${uid}-label` }
|
|
130
|
+
: { 'aria-label': (rest as { 'aria-label'?: string | null })['aria-label'] ?? undefined }
|
|
131
|
+
);
|
|
94
132
|
</script>
|
|
95
133
|
|
|
96
134
|
<section
|
|
@@ -116,14 +154,19 @@
|
|
|
116
154
|
{:else}
|
|
117
155
|
<h3 id="{uid}-label" {...stylex.attrs(styles.label)}><bdi>{label}</bdi></h3>
|
|
118
156
|
{/if}
|
|
119
|
-
{
|
|
157
|
+
{#if actions}
|
|
158
|
+
<!-- Ends where the rows' counts do: a count on the line, an icon button by its icon -->
|
|
159
|
+
<div data-slot="sidebar-group-actions" {...stylex.attrs(styles.actions)}>
|
|
160
|
+
{@render actions()}
|
|
161
|
+
</div>
|
|
162
|
+
{/if}
|
|
120
163
|
</div>
|
|
121
164
|
{/if}
|
|
122
165
|
{#if collapsible && label}
|
|
123
|
-
<Collapse {
|
|
124
|
-
<ul {...stylex.attrs(styles.list)}>{@render children?.()}</ul>
|
|
166
|
+
<Collapse open={shown} id="{uid}-list">
|
|
167
|
+
<ul {...listName} {...stylex.attrs(styles.list)}>{@render children?.()}</ul>
|
|
125
168
|
</Collapse>
|
|
126
169
|
{:else}
|
|
127
|
-
<ul {...stylex.attrs(styles.list)}>{@render children?.()}</ul>
|
|
170
|
+
<ul {...listName} {...stylex.attrs(styles.list)}>{@render children?.()}</ul>
|
|
128
171
|
{/if}
|
|
129
172
|
</section>
|
|
@@ -2,12 +2,21 @@ import type { Snippet } from 'svelte';
|
|
|
2
2
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
3
|
import { type Sx } from '../../internal/sx.js';
|
|
4
4
|
export type SidebarGroupProps = Omit<HTMLAttributes<HTMLElement>, 'children'> & {
|
|
5
|
-
/**
|
|
5
|
+
/**
|
|
6
|
+
* The group's name: "Projects", or "Today". It names the list of rows too, so a screen
|
|
7
|
+
* reader tells one group's list from the next. Without one, the rows stand alone; name the
|
|
8
|
+
* group with `aria-label`, which its list then takes.
|
|
9
|
+
*/
|
|
6
10
|
label?: string | undefined;
|
|
7
11
|
/** Lets the person fold the group away. */
|
|
8
12
|
collapsible?: boolean | undefined;
|
|
9
13
|
/** Whether a collapsible group is open. Bindable. */
|
|
10
14
|
open?: boolean | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Folded, the open row (`current`) stays in view, in its folder, and the rest hide. On by
|
|
17
|
+
* default; `false` folds every row away.
|
|
18
|
+
*/
|
|
19
|
+
keepCurrent?: boolean | undefined;
|
|
11
20
|
/** Controls at the end of the label, such as a button to add an item. */
|
|
12
21
|
actions?: Snippet | undefined;
|
|
13
22
|
sx?: Sx | undefined;
|
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
<!--
|
|
2
2
|
A row in the sidebar. The title, a time or status at the end, and a second
|
|
3
3
|
quiet line beneath; actions appear on hover or focus, and the note at the
|
|
4
|
-
end steps aside for them.
|
|
4
|
+
end steps aside for them. Its fills (under the pointer, open, picked) lie on a
|
|
5
|
+
layer of their own, over the row's background, so a background given in `sx`
|
|
6
|
+
is the row's resting fill and the fills still show over it.
|
|
5
7
|
-->
|
|
6
8
|
<script lang="ts" module>
|
|
7
9
|
import * as stylex from '@stylexjs/stylex';
|
|
8
|
-
import type
|
|
9
|
-
import type { HTMLAnchorAttributes } from 'svelte/elements';
|
|
10
|
+
import { untrack, type Snippet } from 'svelte';
|
|
11
|
+
import type { HTMLAnchorAttributes, HTMLAttributes } from 'svelte/elements';
|
|
10
12
|
import { sidebarItemMarker } from '../../internal/markers.stylex.js';
|
|
11
13
|
import { attrs, type Sx } from '../../internal/sx.js';
|
|
12
14
|
import { colors, font, motion, radius } from '../../tokens.stylex.js';
|
|
13
15
|
import { media } from '../../media.stylex.js';
|
|
16
|
+
import { visuallyHidden } from '../../visually-hidden.js';
|
|
14
17
|
import { getSidebarDepth } from './depth.js';
|
|
18
|
+
import { getSidebarFold } from './fold.js';
|
|
15
19
|
|
|
16
20
|
export type SidebarItemProps = Omit<HTMLAnchorAttributes, 'children'> & {
|
|
17
21
|
/** A link to go to. Without it the row is a button; listen with `onclick`. */
|
|
@@ -22,6 +26,21 @@
|
|
|
22
26
|
muted?: boolean | undefined;
|
|
23
27
|
/** One line, without `meta`: for rows that are settled. */
|
|
24
28
|
compact?: boolean | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Can't be used now. The row stays in the arrow keys' path and says why it is dimmed to
|
|
31
|
+
* assistive technology (`aria-disabled`), but a press does nothing and a link goes nowhere.
|
|
32
|
+
*/
|
|
33
|
+
disabled?: boolean | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* One of several rows the person has picked, to act on together: with ⌘- or Shift-click,
|
|
36
|
+
* which the app handles. A fill of the accent, over the open row's too.
|
|
37
|
+
*/
|
|
38
|
+
picked?: boolean | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* Said before the title of a picked row, as the row is not an option in a listbox. With
|
|
41
|
+
* `role="option"` the row says it with `aria-selected` instead.
|
|
42
|
+
*/
|
|
43
|
+
pickedLabel?: string | undefined;
|
|
25
44
|
/** Before the title: an icon, or a StatusIndicator. */
|
|
26
45
|
leading?: Snippet | undefined;
|
|
27
46
|
/** At the end of the title's line: a time, or a status. */
|
|
@@ -35,6 +54,11 @@
|
|
|
35
54
|
* such as search results that are a listbox (pass `role="option"` to the row).
|
|
36
55
|
*/
|
|
37
56
|
as?: 'li' | 'div' | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* Attributes, handlers and attachments for that element: a ContextMenu.Trigger's props,
|
|
59
|
+
* say, while a HoverCard.Trigger's go on the row itself, as each needs an element of its own.
|
|
60
|
+
*/
|
|
61
|
+
itemProps?: (HTMLAttributes<HTMLElement> & Record<string | symbol, unknown>) | undefined;
|
|
38
62
|
sx?: Sx | undefined;
|
|
39
63
|
/** The title. */
|
|
40
64
|
children?: Snippet | undefined;
|
|
@@ -42,10 +66,22 @@
|
|
|
42
66
|
|
|
43
67
|
// StyleX reads `when` only where it is written inline, in the keys below
|
|
44
68
|
|
|
69
|
+
// A menu opened from the actions takes focus with it, into a layer of its own; until it
|
|
70
|
+
// closes, the actions stay over the row, under the menu that came from them
|
|
71
|
+
const OPEN = ':has([data-slot="sidebar-item-actions"] [aria-expanded="true"])';
|
|
72
|
+
// The row stays lit while a menu from it is open: the actions', or a context menu whose
|
|
73
|
+
// trigger is the element around the row (`itemProps`)
|
|
74
|
+
const LIT =
|
|
75
|
+
':is([data-state="open"], :has([data-slot="sidebar-item-actions"] [aria-expanded="true"]))';
|
|
76
|
+
|
|
45
77
|
const styles = stylex.create({
|
|
46
78
|
item: { position: 'relative', listStyleType: 'none' },
|
|
79
|
+
// Its group or folder is folded, and this is not the open row
|
|
80
|
+
foldedAway: { display: 'none' },
|
|
47
81
|
row: {
|
|
48
82
|
position: 'relative',
|
|
83
|
+
// The fills' layer sits under the content and over the background
|
|
84
|
+
isolation: 'isolate',
|
|
49
85
|
boxSizing: 'border-box',
|
|
50
86
|
display: 'grid',
|
|
51
87
|
gridTemplateColumns: 'auto minmax(0, 1fr) auto',
|
|
@@ -61,10 +97,7 @@
|
|
|
61
97
|
paddingInlineStart: 'calc(0.5rem + var(--narvi-sidebar-depth, 0) * 1.5rem)',
|
|
62
98
|
borderWidth: 0,
|
|
63
99
|
borderRadius: radius.control,
|
|
64
|
-
backgroundColor:
|
|
65
|
-
default: 'transparent',
|
|
66
|
-
':hover': { default: null, [media.hover]: colors.fillHover }
|
|
67
|
-
},
|
|
100
|
+
backgroundColor: 'transparent',
|
|
68
101
|
color: colors.text,
|
|
69
102
|
fontFamily: 'inherit',
|
|
70
103
|
fontSize: font.sizeMeta,
|
|
@@ -79,9 +112,25 @@
|
|
|
79
112
|
outlineWidth: { default: 0, ':focus-visible': '2px', [media.forcedColors]: '1px' },
|
|
80
113
|
outlineColor: { default: 'transparent', ':focus-visible': colors.focusRing },
|
|
81
114
|
outlineOffset: '-2px',
|
|
82
|
-
transitionProperty: '
|
|
115
|
+
transitionProperty: 'color',
|
|
83
116
|
transitionDuration: motion.fast,
|
|
84
|
-
transitionTimingFunction: 'ease'
|
|
117
|
+
transitionTimingFunction: 'ease',
|
|
118
|
+
'::before': {
|
|
119
|
+
content: '""',
|
|
120
|
+
position: 'absolute',
|
|
121
|
+
inset: 0,
|
|
122
|
+
zIndex: -1,
|
|
123
|
+
borderRadius: 'inherit',
|
|
124
|
+
pointerEvents: 'none',
|
|
125
|
+
backgroundColor: {
|
|
126
|
+
default: 'transparent',
|
|
127
|
+
':hover': { default: null, [media.hover]: colors.fillHover },
|
|
128
|
+
[stylex.when.ancestor(LIT, sidebarItemMarker)]: colors.fillHover
|
|
129
|
+
},
|
|
130
|
+
transitionProperty: 'background-color',
|
|
131
|
+
transitionDuration: motion.fast,
|
|
132
|
+
transitionTimingFunction: 'ease'
|
|
133
|
+
}
|
|
85
134
|
},
|
|
86
135
|
compact: { gridTemplateAreas: '"lead title trail"' },
|
|
87
136
|
// Without a leading icon there is no column for one, so the title starts at the edge
|
|
@@ -95,7 +144,14 @@
|
|
|
95
144
|
// and does not jump as the person moves between rows.
|
|
96
145
|
current: {
|
|
97
146
|
color: colors.text,
|
|
98
|
-
|
|
147
|
+
'::before': { backgroundColor: colors.fillSelected }
|
|
148
|
+
},
|
|
149
|
+
// Picked to act on with others: the accent's soft fill, which marks a selection
|
|
150
|
+
picked: { '::before': { backgroundColor: colors.accentSoft } },
|
|
151
|
+
disabled: {
|
|
152
|
+
color: colors.textSubtle,
|
|
153
|
+
cursor: 'default',
|
|
154
|
+
'::before': { backgroundColor: 'transparent' }
|
|
99
155
|
},
|
|
100
156
|
lead: {
|
|
101
157
|
gridArea: 'lead',
|
|
@@ -131,8 +187,13 @@
|
|
|
131
187
|
trailHides: {
|
|
132
188
|
opacity: {
|
|
133
189
|
default: 1,
|
|
134
|
-
[media.hover]: {
|
|
135
|
-
|
|
190
|
+
[media.hover]: {
|
|
191
|
+
default: 1,
|
|
192
|
+
[stylex.when.ancestor(':hover', sidebarItemMarker)]: 0,
|
|
193
|
+
[stylex.when.ancestor(OPEN, sidebarItemMarker)]: 0
|
|
194
|
+
},
|
|
195
|
+
[stylex.when.ancestor(':focus-within', sidebarItemMarker)]: 0,
|
|
196
|
+
[stylex.when.ancestor(OPEN, sidebarItemMarker)]: 0
|
|
136
197
|
}
|
|
137
198
|
},
|
|
138
199
|
meta: {
|
|
@@ -141,7 +202,11 @@
|
|
|
141
202
|
alignItems: 'center',
|
|
142
203
|
gap: '0.375rem',
|
|
143
204
|
minWidth: 0,
|
|
144
|
-
|
|
205
|
+
// Cut off at its end, but a mark's badge may overhang it, below and to the side,
|
|
206
|
+
// into the row's padding
|
|
207
|
+
overflowX: 'clip',
|
|
208
|
+
overflowY: 'visible',
|
|
209
|
+
overflowClipMargin: '0.375rem',
|
|
145
210
|
color: colors.textSubtle,
|
|
146
211
|
fontSize: font.sizeCaption,
|
|
147
212
|
whiteSpace: 'nowrap'
|
|
@@ -165,16 +230,23 @@
|
|
|
165
230
|
outlineOffset: '1px',
|
|
166
231
|
opacity: {
|
|
167
232
|
default: 1,
|
|
168
|
-
[media.hover]: {
|
|
169
|
-
|
|
233
|
+
[media.hover]: {
|
|
234
|
+
default: 0,
|
|
235
|
+
[stylex.when.ancestor(':hover', sidebarItemMarker)]: 1,
|
|
236
|
+
[stylex.when.ancestor(OPEN, sidebarItemMarker)]: 1
|
|
237
|
+
},
|
|
238
|
+
[stylex.when.ancestor(':focus-within', sidebarItemMarker)]: 1,
|
|
239
|
+
[stylex.when.ancestor(OPEN, sidebarItemMarker)]: 1
|
|
170
240
|
},
|
|
171
241
|
pointerEvents: {
|
|
172
242
|
default: 'auto',
|
|
173
243
|
[media.hover]: {
|
|
174
244
|
default: 'none',
|
|
175
|
-
[stylex.when.ancestor(':hover', sidebarItemMarker)]: 'auto'
|
|
245
|
+
[stylex.when.ancestor(':hover', sidebarItemMarker)]: 'auto',
|
|
246
|
+
[stylex.when.ancestor(OPEN, sidebarItemMarker)]: 'auto'
|
|
176
247
|
},
|
|
177
|
-
[stylex.when.ancestor(':focus-within', sidebarItemMarker)]: 'auto'
|
|
248
|
+
[stylex.when.ancestor(':focus-within', sidebarItemMarker)]: 'auto',
|
|
249
|
+
[stylex.when.ancestor(OPEN, sidebarItemMarker)]: 'auto'
|
|
178
250
|
},
|
|
179
251
|
transitionProperty: 'opacity',
|
|
180
252
|
transitionDuration: motion.fast,
|
|
@@ -189,11 +261,15 @@
|
|
|
189
261
|
current = false,
|
|
190
262
|
muted = false,
|
|
191
263
|
compact = false,
|
|
264
|
+
disabled = false,
|
|
265
|
+
picked = false,
|
|
266
|
+
pickedLabel = 'Selected',
|
|
192
267
|
leading,
|
|
193
268
|
trailing,
|
|
194
269
|
meta,
|
|
195
270
|
actions,
|
|
196
271
|
as = 'li',
|
|
272
|
+
itemProps,
|
|
197
273
|
sx,
|
|
198
274
|
class: className,
|
|
199
275
|
children,
|
|
@@ -203,6 +279,23 @@
|
|
|
203
279
|
const getDepth = getSidebarDepth();
|
|
204
280
|
const depth = $derived(getDepth());
|
|
205
281
|
|
|
282
|
+
// The open row holds its folded group and folders open on itself; the others fold away
|
|
283
|
+
const fold = getSidebarFold();
|
|
284
|
+
$effect(() => {
|
|
285
|
+
// The count is the group's and the folders' state, not this effect's to follow
|
|
286
|
+
if (current && fold) return untrack(fold.hold);
|
|
287
|
+
});
|
|
288
|
+
const away = $derived(!current && fold !== undefined && fold.folded());
|
|
289
|
+
|
|
290
|
+
// An option in a listbox says it is picked with `aria-selected`; any other row in words
|
|
291
|
+
const option = $derived((rest as { role?: unknown }).role === 'option');
|
|
292
|
+
const selected = $derived(option ? { 'aria-selected': picked } : {});
|
|
293
|
+
|
|
294
|
+
function block(event: MouseEvent) {
|
|
295
|
+
event.preventDefault();
|
|
296
|
+
event.stopImmediatePropagation();
|
|
297
|
+
}
|
|
298
|
+
|
|
206
299
|
const rowAttrs = $derived(
|
|
207
300
|
attrs(
|
|
208
301
|
[
|
|
@@ -212,6 +305,8 @@
|
|
|
212
305
|
!leading && (compact || !meta) && styles.noLeadCompact,
|
|
213
306
|
muted && !current && styles.muted,
|
|
214
307
|
current && styles.current,
|
|
308
|
+
picked && styles.picked,
|
|
309
|
+
disabled && styles.disabled,
|
|
215
310
|
sx
|
|
216
311
|
],
|
|
217
312
|
className
|
|
@@ -221,7 +316,11 @@
|
|
|
221
316
|
|
|
222
317
|
{#snippet inside()}
|
|
223
318
|
{#if leading}<span {...stylex.attrs(styles.lead)}>{@render leading()}</span>{/if}
|
|
224
|
-
<span {...stylex.attrs(styles.title)}
|
|
319
|
+
<span {...stylex.attrs(styles.title)}
|
|
320
|
+
>{#if picked && !option}<span {...stylex.attrs(visuallyHidden)}
|
|
321
|
+
>{pickedLabel},
|
|
322
|
+
</span>{/if}{@render children?.()}</span
|
|
323
|
+
>
|
|
225
324
|
{#if trailing}
|
|
226
325
|
<span {...stylex.attrs(styles.trail, actions && styles.trailHides)}>{@render trailing()}</span>
|
|
227
326
|
{/if}
|
|
@@ -230,21 +329,37 @@
|
|
|
230
329
|
|
|
231
330
|
<svelte:element
|
|
232
331
|
this={as}
|
|
233
|
-
data-slot="sidebar-item"
|
|
234
332
|
style:--narvi-sidebar-depth={depth || undefined}
|
|
235
|
-
{...
|
|
333
|
+
{...itemProps}
|
|
334
|
+
data-slot="sidebar-item"
|
|
335
|
+
{...attrs([styles.item, away && styles.foldedAway, sidebarItemMarker], itemProps?.class)}
|
|
236
336
|
>
|
|
237
337
|
{#if href !== undefined}
|
|
238
|
-
<a
|
|
338
|
+
<a
|
|
339
|
+
href={disabled ? undefined : href}
|
|
340
|
+
role={disabled ? 'link' : undefined}
|
|
341
|
+
data-sidebar-row
|
|
342
|
+
data-picked={picked || undefined}
|
|
343
|
+
aria-current={current ? 'page' : undefined}
|
|
344
|
+
aria-disabled={disabled || undefined}
|
|
345
|
+
{...selected}
|
|
346
|
+
{...rest}
|
|
347
|
+
{...rowAttrs}
|
|
348
|
+
onclickcapture={disabled ? block : (rest.onclickcapture as typeof block | undefined)}
|
|
349
|
+
>
|
|
239
350
|
{@render inside()}
|
|
240
351
|
</a>
|
|
241
352
|
{:else}
|
|
242
353
|
<button
|
|
243
354
|
type="button"
|
|
244
355
|
data-sidebar-row
|
|
356
|
+
data-picked={picked || undefined}
|
|
245
357
|
aria-current={current ? 'page' : undefined}
|
|
358
|
+
aria-disabled={disabled || undefined}
|
|
359
|
+
{...selected}
|
|
246
360
|
{...rest as Record<string, unknown>}
|
|
247
361
|
{...rowAttrs}
|
|
362
|
+
onclickcapture={disabled ? block : (rest.onclickcapture as typeof block | undefined)}
|
|
248
363
|
>
|
|
249
364
|
{@render inside()}
|
|
250
365
|
</button>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type { HTMLAnchorAttributes } from 'svelte/elements';
|
|
1
|
+
import { type Snippet } from 'svelte';
|
|
2
|
+
import type { HTMLAnchorAttributes, HTMLAttributes } from 'svelte/elements';
|
|
3
3
|
import { type Sx } from '../../internal/sx.js';
|
|
4
4
|
export type SidebarItemProps = Omit<HTMLAnchorAttributes, 'children'> & {
|
|
5
5
|
/** A link to go to. Without it the row is a button; listen with `onclick`. */
|
|
@@ -10,6 +10,21 @@ export type SidebarItemProps = Omit<HTMLAnchorAttributes, 'children'> & {
|
|
|
10
10
|
muted?: boolean | undefined;
|
|
11
11
|
/** One line, without `meta`: for rows that are settled. */
|
|
12
12
|
compact?: boolean | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* Can't be used now. The row stays in the arrow keys' path and says why it is dimmed to
|
|
15
|
+
* assistive technology (`aria-disabled`), but a press does nothing and a link goes nowhere.
|
|
16
|
+
*/
|
|
17
|
+
disabled?: boolean | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* One of several rows the person has picked, to act on together: with ⌘- or Shift-click,
|
|
20
|
+
* which the app handles. A fill of the accent, over the open row's too.
|
|
21
|
+
*/
|
|
22
|
+
picked?: boolean | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Said before the title of a picked row, as the row is not an option in a listbox. With
|
|
25
|
+
* `role="option"` the row says it with `aria-selected` instead.
|
|
26
|
+
*/
|
|
27
|
+
pickedLabel?: string | undefined;
|
|
13
28
|
/** Before the title: an icon, or a StatusIndicator. */
|
|
14
29
|
leading?: Snippet | undefined;
|
|
15
30
|
/** At the end of the title's line: a time, or a status. */
|
|
@@ -23,6 +38,11 @@ export type SidebarItemProps = Omit<HTMLAnchorAttributes, 'children'> & {
|
|
|
23
38
|
* such as search results that are a listbox (pass `role="option"` to the row).
|
|
24
39
|
*/
|
|
25
40
|
as?: 'li' | 'div' | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* Attributes, handlers and attachments for that element: a ContextMenu.Trigger's props,
|
|
43
|
+
* say, while a HoverCard.Trigger's go on the row itself, as each needs an element of its own.
|
|
44
|
+
*/
|
|
45
|
+
itemProps?: (HTMLAttributes<HTMLElement> & Record<string | symbol, unknown>) | undefined;
|
|
26
46
|
sx?: Sx | undefined;
|
|
27
47
|
/** The title. */
|
|
28
48
|
children?: Snippet | undefined;
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Put it in a Menu.Trigger's `child`, and spread the props it hands you onto it.
|
|
4
4
|
-->
|
|
5
5
|
<script lang="ts" module>
|
|
6
|
+
import * as stylex from '@stylexjs/stylex';
|
|
6
7
|
import type { Snippet } from 'svelte';
|
|
7
8
|
import Glyph from '../../internal/Glyph.svelte';
|
|
8
9
|
import SidebarItem, { type SidebarItemProps } from './SidebarItem.svelte';
|
|
@@ -15,14 +16,29 @@
|
|
|
15
16
|
leading?: Snippet | undefined;
|
|
16
17
|
/** The name of what is chosen now. */
|
|
17
18
|
children?: Snippet | undefined;
|
|
19
|
+
/** Just after the name: a StatusDot, say. The name is cut short before it is. */
|
|
20
|
+
aside?: Snippet | undefined;
|
|
18
21
|
};
|
|
22
|
+
|
|
23
|
+
const styles = stylex.create({
|
|
24
|
+
named: { display: 'flex', alignItems: 'center', gap: '0.375rem', minWidth: 0 },
|
|
25
|
+
name: { minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis' }
|
|
26
|
+
});
|
|
19
27
|
</script>
|
|
20
28
|
|
|
21
29
|
<script lang="ts">
|
|
22
|
-
let { leading, children, ...rest }: SidebarSwitcherProps = $props();
|
|
30
|
+
let { leading, aside, children, ...rest }: SidebarSwitcherProps = $props();
|
|
23
31
|
</script>
|
|
24
32
|
|
|
25
33
|
<SidebarItem compact {leading} {...rest}>
|
|
26
|
-
{
|
|
34
|
+
{#if aside}
|
|
35
|
+
<!-- The name gives way, cut short, and what is beside it stays whole -->
|
|
36
|
+
<span {...stylex.attrs(styles.named)}>
|
|
37
|
+
<span {...stylex.attrs(styles.name)}>{@render children?.()}</span>
|
|
38
|
+
{@render aside()}
|
|
39
|
+
</span>
|
|
40
|
+
{:else}
|
|
41
|
+
{@render children?.()}
|
|
42
|
+
{/if}
|
|
27
43
|
{#snippet trailing()}<Glyph name="selector" size={14} />{/snippet}
|
|
28
44
|
</SidebarItem>
|
|
@@ -5,6 +5,8 @@ export type SidebarSwitcherProps = Omit<SidebarItemProps, 'compact' | 'current'
|
|
|
5
5
|
leading?: Snippet | undefined;
|
|
6
6
|
/** The name of what is chosen now. */
|
|
7
7
|
children?: Snippet | undefined;
|
|
8
|
+
/** Just after the name: a StatusDot, say. The name is cut short before it is. */
|
|
9
|
+
aside?: Snippet | undefined;
|
|
8
10
|
};
|
|
9
11
|
declare const SidebarSwitcher: import("svelte").Component<SidebarSwitcherProps, {}, "">;
|
|
10
12
|
type SidebarSwitcher = ReturnType<typeof SidebarSwitcher>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether the rows under a group or folder are folded away, and a way for the open row to stay
|
|
3
|
+
* in view while they are: a current row holds its group and folders open, and the rest of the
|
|
4
|
+
* rows hide. A folder passes the hold on, so the group above it stays open too.
|
|
5
|
+
*/
|
|
6
|
+
export type SidebarFold = {
|
|
7
|
+
folded: () => boolean;
|
|
8
|
+
/** Called by a current row; returns the release. */
|
|
9
|
+
hold: () => () => void;
|
|
10
|
+
};
|
|
11
|
+
export declare function getSidebarFold(): SidebarFold | undefined;
|
|
12
|
+
export declare function setSidebarFold(fold: SidebarFold | undefined): void;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
A dot of status colour, small enough to sit beside a name or on the corner of a mark: a
|
|
3
|
+
machine that is reachable, a thread with something new, a workspace at work. Its shape can say
|
|
4
|
+
it too, for those who cannot tell the colours apart: a ring while something is on its way, a
|
|
5
|
+
diamond when it failed. For a run's status, with a shape for each, use StatusIndicator.
|
|
6
|
+
-->
|
|
7
|
+
<script lang="ts" module>
|
|
8
|
+
import * as stylex from '@stylexjs/stylex';
|
|
9
|
+
import { attrs, type Sx } from '../../internal/sx.js';
|
|
10
|
+
import { colors, radius } from '../../tokens.stylex.js';
|
|
11
|
+
|
|
12
|
+
export type StatusDotTone = 'neutral' | 'accent' | 'success' | 'warning' | 'danger';
|
|
13
|
+
export type StatusDotShape = 'dot' | 'ring' | 'diamond';
|
|
14
|
+
|
|
15
|
+
export type StatusDotProps = {
|
|
16
|
+
/** `accent` for something live or new; `success`, `warning` and `danger` once settled. */
|
|
17
|
+
tone?: StatusDotTone | undefined;
|
|
18
|
+
/** `ring` for something on its way, `diamond` for a failure; a filled dot otherwise. */
|
|
19
|
+
shape?: StatusDotShape | undefined;
|
|
20
|
+
/** Width and height, in pixels. */
|
|
21
|
+
size?: number | undefined;
|
|
22
|
+
/** Names it for assistive technology. Without one it is hidden, as words beside it say it. */
|
|
23
|
+
label?: string | null | undefined;
|
|
24
|
+
sx?: Sx | undefined;
|
|
25
|
+
class?: string | undefined;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const styles = stylex.create({
|
|
29
|
+
root: {
|
|
30
|
+
display: 'inline-block',
|
|
31
|
+
flexShrink: 0,
|
|
32
|
+
boxSizing: 'border-box',
|
|
33
|
+
borderRadius: radius.pill,
|
|
34
|
+
verticalAlign: 'middle',
|
|
35
|
+
forcedColorAdjust: 'none'
|
|
36
|
+
},
|
|
37
|
+
ring: { backgroundColor: 'transparent' },
|
|
38
|
+
// A square on its point, a little smaller, so it weighs what the dot does
|
|
39
|
+
diamond: { borderRadius: '1px', transform: 'scale(0.75) rotate(45deg)' }
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const fills = stylex.create({
|
|
43
|
+
neutral: { backgroundColor: colors.textSubtle },
|
|
44
|
+
accent: { backgroundColor: colors.accent },
|
|
45
|
+
success: { backgroundColor: colors.success },
|
|
46
|
+
warning: { backgroundColor: colors.warning },
|
|
47
|
+
danger: { backgroundColor: colors.danger }
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const rings = stylex.create({
|
|
51
|
+
neutral: { boxShadow: `inset 0 0 0 1px ${colors.textSubtle}` },
|
|
52
|
+
accent: { boxShadow: `inset 0 0 0 1px ${colors.accent}` },
|
|
53
|
+
success: { boxShadow: `inset 0 0 0 1px ${colors.success}` },
|
|
54
|
+
warning: { boxShadow: `inset 0 0 0 1px ${colors.warning}` },
|
|
55
|
+
danger: { boxShadow: `inset 0 0 0 1px ${colors.danger}` }
|
|
56
|
+
});
|
|
57
|
+
</script>
|
|
58
|
+
|
|
59
|
+
<script lang="ts">
|
|
60
|
+
let {
|
|
61
|
+
tone = 'neutral',
|
|
62
|
+
shape = 'dot',
|
|
63
|
+
size = 6,
|
|
64
|
+
label,
|
|
65
|
+
sx,
|
|
66
|
+
class: className
|
|
67
|
+
}: StatusDotProps = $props();
|
|
68
|
+
</script>
|
|
69
|
+
|
|
70
|
+
<span
|
|
71
|
+
role={label ? 'img' : undefined}
|
|
72
|
+
aria-label={label || undefined}
|
|
73
|
+
aria-hidden={label ? undefined : true}
|
|
74
|
+
data-slot="status-dot"
|
|
75
|
+
data-tone={tone}
|
|
76
|
+
data-shape={shape}
|
|
77
|
+
{...attrs(
|
|
78
|
+
[
|
|
79
|
+
styles.root,
|
|
80
|
+
fills[tone],
|
|
81
|
+
shape === 'ring' && styles.ring,
|
|
82
|
+
shape === 'ring' && rings[tone],
|
|
83
|
+
shape === 'diamond' && styles.diamond,
|
|
84
|
+
sx
|
|
85
|
+
],
|
|
86
|
+
className
|
|
87
|
+
)}
|
|
88
|
+
style:width="{size}px"
|
|
89
|
+
style:height="{size}px"
|
|
90
|
+
></span>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type Sx } from '../../internal/sx.js';
|
|
2
|
+
export type StatusDotTone = 'neutral' | 'accent' | 'success' | 'warning' | 'danger';
|
|
3
|
+
export type StatusDotShape = 'dot' | 'ring' | 'diamond';
|
|
4
|
+
export type StatusDotProps = {
|
|
5
|
+
/** `accent` for something live or new; `success`, `warning` and `danger` once settled. */
|
|
6
|
+
tone?: StatusDotTone | undefined;
|
|
7
|
+
/** `ring` for something on its way, `diamond` for a failure; a filled dot otherwise. */
|
|
8
|
+
shape?: StatusDotShape | undefined;
|
|
9
|
+
/** Width and height, in pixels. */
|
|
10
|
+
size?: number | undefined;
|
|
11
|
+
/** Names it for assistive technology. Without one it is hidden, as words beside it say it. */
|
|
12
|
+
label?: string | null | undefined;
|
|
13
|
+
sx?: Sx | undefined;
|
|
14
|
+
class?: string | undefined;
|
|
15
|
+
};
|
|
16
|
+
declare const StatusDot: import("svelte").Component<StatusDotProps, {}, "">;
|
|
17
|
+
type StatusDot = ReturnType<typeof StatusDot>;
|
|
18
|
+
export default StatusDot;
|
package/dist/index.d.ts
CHANGED
|
@@ -65,7 +65,7 @@ export type { KbdProps } from './components/kbd/Kbd.svelte';
|
|
|
65
65
|
export { default as Link } from './components/link/Link.svelte';
|
|
66
66
|
export type { LinkProps } from './components/link/Link.svelte';
|
|
67
67
|
export * as Menu from './components/menu/index.js';
|
|
68
|
-
export type { MenuCheckboxItemProps, MenuContentProps, MenuItemProps, MenuLabelProps, MenuRadioItemProps, MenuSeparatorProps, MenuSubContentProps, MenuSubTriggerProps } from './components/menu/index.js';
|
|
68
|
+
export type { MenuCheckboxItemProps, MenuContentProps, MenuGroupProps, MenuItemProps, MenuLabelProps, MenuRadioGroupProps, MenuRadioItemProps, MenuSeparatorProps, MenuSubContentProps, MenuSubTriggerProps } from './components/menu/index.js';
|
|
69
69
|
export * as Message from './components/message/index.js';
|
|
70
70
|
export type { MessageActionProps, MessageActionsProps, MessageContentProps, MessageCopyProps, MessageFrom, MessageHeaderProps, MessagePendingProps, MessageRootProps, MessageTimeProps } from './components/message/index.js';
|
|
71
71
|
export { default as Markdown } from './components/markdown/Markdown.svelte';
|
|
@@ -127,6 +127,8 @@ export type { StackAlign, StackDirection, StackGap, StackJustify, StackProps } f
|
|
|
127
127
|
export * as Suggestions from './components/suggestions/index.js';
|
|
128
128
|
export type { SuggestionsItemProps, SuggestionsRootProps } from './components/suggestions/index.js';
|
|
129
129
|
export { default as StatusIndicator } from './components/status-indicator/StatusIndicator.svelte';
|
|
130
|
+
export { default as StatusDot } from './components/status-indicator/StatusDot.svelte';
|
|
131
|
+
export type { StatusDotProps, StatusDotShape, StatusDotTone } from './components/status-indicator/StatusDot.svelte';
|
|
130
132
|
export type { Status, StatusIndicatorProps } from './components/status-indicator/StatusIndicator.svelte';
|
|
131
133
|
export { default as Switch } from './components/switch/Switch.svelte';
|
|
132
134
|
export type { SwitchProps } from './components/switch/Switch.svelte';
|