@diegopluna/narvi 0.3.0 → 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/README.md +3 -1
- 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/settings-row/SettingsRow.svelte +13 -2
- package/dist/components/settings-row/SettingsRow.svelte.d.ts +7 -1
- package/dist/components/sidebar/SidebarContent.svelte +59 -13
- package/dist/components/sidebar/SidebarContent.svelte.d.ts +6 -0
- package/dist/components/sidebar/SidebarFolder.svelte +44 -12
- package/dist/components/sidebar/SidebarGroup.svelte +50 -7
- package/dist/components/sidebar/SidebarGroup.svelte.d.ts +10 -1
- package/dist/components/sidebar/SidebarItem.svelte +139 -24
- 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/depth.d.ts +8 -6
- package/dist/components/sidebar/depth.js +7 -5
- 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/dist/vite.d.ts +15 -6
- package/dist/vite.js +38 -0
- package/package.json +1 -1
- package/skills/building-ui/SKILL.md +42 -8
- package/skills/building-ui/references/components.md +7 -6
- package/skills/markdown/SKILL.md +1 -1
- package/skills/setup/SKILL.md +9 -11
- package/skills/styling/SKILL.md +1 -1
- package/skills/theming/SKILL.md +1 -1
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
<!--
|
|
2
|
-
A row that holds other rows: a project and its threads.
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
A row that holds other rows: a project and its threads. Its chevron comes first, on the
|
|
3
|
+
edge where the other rows' icons sit; then its mark, if it has one, and its name. It folds,
|
|
4
|
+
and its rows are set in under it, their titles starting where its name does. It is a row in
|
|
5
|
+
the list like any other, so the arrow keys pass through it; the right arrow opens it and the
|
|
6
|
+
left one shuts it.
|
|
5
7
|
-->
|
|
6
8
|
<script lang="ts" module>
|
|
7
9
|
import * as stylex from '@stylexjs/stylex';
|
|
@@ -13,6 +15,7 @@
|
|
|
13
15
|
import { colors, font, motion, radius } from '../../tokens.stylex.js';
|
|
14
16
|
import { media } from '../../media.stylex.js';
|
|
15
17
|
import { getSidebarDepth, setSidebarDepth } from './depth.js';
|
|
18
|
+
import { getSidebarFold, setSidebarFold } from './fold.js';
|
|
16
19
|
|
|
17
20
|
export type SidebarFolderProps = Omit<HTMLAttributes<HTMLLIElement>, 'children'> & {
|
|
18
21
|
/** Its name: a project. */
|
|
@@ -30,6 +33,8 @@
|
|
|
30
33
|
|
|
31
34
|
const styles = stylex.create({
|
|
32
35
|
folder: { position: 'relative', listStyleType: 'none' },
|
|
36
|
+
// Its group is folded, and the open row is not in it
|
|
37
|
+
foldedAway: { display: 'none' },
|
|
33
38
|
row: {
|
|
34
39
|
boxSizing: 'border-box',
|
|
35
40
|
display: 'flex',
|
|
@@ -38,7 +43,7 @@
|
|
|
38
43
|
width: '100%',
|
|
39
44
|
margin: 0,
|
|
40
45
|
paddingBlock: '0.375rem',
|
|
41
|
-
// The same as Sidebar.Item, so a folder's
|
|
46
|
+
// The same as Sidebar.Item, so a folder's chevron and a row's icon share one edge. A
|
|
42
47
|
// folder in a folder is set in as a row is.
|
|
43
48
|
paddingInline: '0.5rem',
|
|
44
49
|
paddingInlineStart: 'calc(0.5rem + var(--narvi-sidebar-depth, 0) * 1.5rem)',
|
|
@@ -65,12 +70,13 @@
|
|
|
65
70
|
transitionDuration: motion.fast,
|
|
66
71
|
transitionTimingFunction: 'ease'
|
|
67
72
|
},
|
|
68
|
-
//
|
|
73
|
+
// In a row icon's slot and at its size, in the muted text: a control, not a decoration
|
|
69
74
|
chevron: {
|
|
70
75
|
display: 'grid',
|
|
76
|
+
placeItems: 'center',
|
|
71
77
|
flexShrink: 0,
|
|
72
|
-
|
|
73
|
-
color: colors.
|
|
78
|
+
width: '1rem',
|
|
79
|
+
color: colors.textMuted
|
|
74
80
|
},
|
|
75
81
|
lead: { display: 'grid', placeItems: 'center', flexShrink: 0, width: '1rem' },
|
|
76
82
|
grow: { flexGrow: 1 },
|
|
@@ -114,11 +120,37 @@
|
|
|
114
120
|
}: SidebarFolderProps = $props();
|
|
115
121
|
|
|
116
122
|
const uid = $props.id();
|
|
117
|
-
const
|
|
118
|
-
|
|
123
|
+
const parent = getSidebarDepth();
|
|
124
|
+
const depth = $derived(parent());
|
|
125
|
+
// Its rows start where its name does: past the chevron, and past the mark when it has one
|
|
126
|
+
setSidebarDepth(() => parent() + (leading ? 2 : 1));
|
|
127
|
+
|
|
128
|
+
// Folded, with the open row in it, the folder stays open on that row alone; and in a folded
|
|
129
|
+
// group, it shows only while it holds the open row
|
|
130
|
+
const outer = getSidebarFold();
|
|
131
|
+
let held = $state(0);
|
|
132
|
+
setSidebarFold(
|
|
133
|
+
outer && {
|
|
134
|
+
folded: () => outer.folded() || !open,
|
|
135
|
+
hold: () => {
|
|
136
|
+
held += 1;
|
|
137
|
+
const release = outer.hold();
|
|
138
|
+
return () => {
|
|
139
|
+
held -= 1;
|
|
140
|
+
release();
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
);
|
|
145
|
+
const shown = $derived(open || (outer !== undefined && held > 0));
|
|
146
|
+
const away = $derived(outer !== undefined && outer.folded() && held === 0);
|
|
119
147
|
</script>
|
|
120
148
|
|
|
121
|
-
<li
|
|
149
|
+
<li
|
|
150
|
+
data-slot="sidebar-folder"
|
|
151
|
+
{...rest}
|
|
152
|
+
{...attrs([styles.folder, away && styles.foldedAway, sx], className)}
|
|
153
|
+
>
|
|
122
154
|
<button
|
|
123
155
|
type="button"
|
|
124
156
|
data-sidebar-row
|
|
@@ -135,13 +167,13 @@
|
|
|
135
167
|
event.preventDefault();
|
|
136
168
|
}}
|
|
137
169
|
>
|
|
170
|
+
<span {...stylex.attrs(styles.chevron)}><Chevron {open} size={16} /></span>
|
|
138
171
|
{#if leading}<span {...stylex.attrs(styles.lead)}>{@render leading()}</span>{/if}
|
|
139
172
|
<span {...stylex.attrs(styles.label)}>{label}</span>
|
|
140
|
-
<span {...stylex.attrs(styles.chevron)}><Chevron {open} size={12} /></span>
|
|
141
173
|
<span {...stylex.attrs(styles.grow)}></span>
|
|
142
174
|
{#if trailing}<span {...stylex.attrs(styles.trail)}>{@render trailing()}</span>{/if}
|
|
143
175
|
</button>
|
|
144
|
-
<Collapse {
|
|
176
|
+
<Collapse open={shown} id="{uid}-rows">
|
|
145
177
|
<ul aria-label={label} {...stylex.attrs(styles.list)}>{@render children?.()}</ul>
|
|
146
178
|
</Collapse>
|
|
147
179
|
</li>
|
|
@@ -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
|
|
@@ -91,10 +140,18 @@
|
|
|
91
140
|
},
|
|
92
141
|
noLeadCompact: { gridTemplateAreas: '"title trail"' },
|
|
93
142
|
muted: { color: colors.textMuted },
|
|
94
|
-
// The open row: a flat fill
|
|
143
|
+
// The open row: a flat fill. The title keeps its weight, so it cuts off where it did
|
|
144
|
+
// and does not jump as the person moves between rows.
|
|
95
145
|
current: {
|
|
96
146
|
color: colors.text,
|
|
97
|
-
|
|
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' }
|
|
98
155
|
},
|
|
99
156
|
lead: {
|
|
100
157
|
gridArea: 'lead',
|
|
@@ -113,7 +170,6 @@
|
|
|
113
170
|
textOverflow: 'ellipsis',
|
|
114
171
|
whiteSpace: 'nowrap'
|
|
115
172
|
},
|
|
116
|
-
titleCurrent: { fontWeight: font.weightSemibold },
|
|
117
173
|
trail: {
|
|
118
174
|
gridArea: 'trail',
|
|
119
175
|
display: 'inline-flex',
|
|
@@ -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,18 +261,40 @@
|
|
|
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,
|
|
200
276
|
...rest
|
|
201
277
|
}: SidebarItemProps = $props();
|
|
202
278
|
|
|
203
|
-
const
|
|
279
|
+
const getDepth = getSidebarDepth();
|
|
280
|
+
const depth = $derived(getDepth());
|
|
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
|
+
}
|
|
204
298
|
|
|
205
299
|
const rowAttrs = $derived(
|
|
206
300
|
attrs(
|
|
@@ -211,6 +305,8 @@
|
|
|
211
305
|
!leading && (compact || !meta) && styles.noLeadCompact,
|
|
212
306
|
muted && !current && styles.muted,
|
|
213
307
|
current && styles.current,
|
|
308
|
+
picked && styles.picked,
|
|
309
|
+
disabled && styles.disabled,
|
|
214
310
|
sx
|
|
215
311
|
],
|
|
216
312
|
className
|
|
@@ -220,7 +316,10 @@
|
|
|
220
316
|
|
|
221
317
|
{#snippet inside()}
|
|
222
318
|
{#if leading}<span {...stylex.attrs(styles.lead)}>{@render leading()}</span>{/if}
|
|
223
|
-
<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
|
|
224
323
|
>
|
|
225
324
|
{#if trailing}
|
|
226
325
|
<span {...stylex.attrs(styles.trail, actions && styles.trailHides)}>{@render trailing()}</span>
|
|
@@ -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>;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* How
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
2
|
+
* How far a row is set in, in steps of 1.5rem: an icon's slot (1rem) and the gap after it
|
|
3
|
+
* (0.5rem). A row is set in by its text, not its box: its highlight runs the sidebar's width,
|
|
4
|
+
* as its folder's does, and its title starts where the folder's name does. A folder takes a
|
|
5
|
+
* step for its chevron, and another for its mark when it has one. The rows write the step in
|
|
6
|
+
* their own styles, as StyleX reads only its own files' constants.
|
|
6
7
|
*/
|
|
7
|
-
export declare function getSidebarDepth(): number;
|
|
8
|
-
|
|
8
|
+
export declare function getSidebarDepth(): () => number;
|
|
9
|
+
/** For a folder's rows: a getter, as whether the folder has a mark can change. */
|
|
10
|
+
export declare function setSidebarDepth(depth: () => number): void;
|