@diegopluna/narvi 0.3.1 → 0.3.3
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/activity/ActivityIcon.svelte +54 -0
- package/dist/components/activity/ActivityIcon.svelte.d.ts +24 -0
- package/dist/components/activity/ActivityStep.svelte +47 -13
- package/dist/components/activity/ActivityStep.svelte.d.ts +13 -4
- package/dist/components/activity/ActivityThought.svelte +24 -5
- package/dist/components/activity/ActivityThought.svelte.d.ts +12 -2
- package/dist/components/activity/index.d.ts +3 -1
- package/dist/components/activity/index.js +2 -1
- package/dist/components/app-shell/AppShellHeader.svelte +18 -4
- package/dist/components/app-shell/AppShellHeader.svelte.d.ts +5 -0
- package/dist/components/app-shell/AppShellMain.svelte +5 -1
- package/dist/components/approval/Approval.svelte +14 -1
- package/dist/components/approval/Approval.svelte.d.ts +5 -0
- package/dist/components/badge/Badge.svelte +19 -2
- package/dist/components/badge/Badge.svelte.d.ts +4 -1
- package/dist/components/button/Button.svelte +63 -13
- package/dist/components/composer/ComposerModelPicker.svelte +80 -13
- package/dist/components/composer/ComposerModelPicker.svelte.d.ts +23 -6
- package/dist/components/composer/ComposerRoot.svelte +51 -12
- package/dist/components/composer/ComposerRoot.svelte.d.ts +16 -0
- package/dist/components/composer/ComposerSubmit.svelte +19 -5
- package/dist/components/composer/ComposerSubmit.svelte.d.ts +3 -1
- package/dist/components/composer/ComposerToggle.svelte +18 -4
- package/dist/components/composer/ComposerToggle.svelte.d.ts +2 -0
- package/dist/components/composer/ComposerTray.svelte +17 -3
- package/dist/components/composer/ComposerTray.svelte.d.ts +5 -0
- package/dist/components/composer/context.d.ts +4 -1
- package/dist/components/dialog/DialogContent.svelte +22 -12
- package/dist/components/dialog/DialogContent.svelte.d.ts +10 -0
- package/dist/components/divider/Divider.svelte +56 -14
- package/dist/components/divider/Divider.svelte.d.ts +13 -3
- package/dist/components/empty-state/EmptyState.svelte +12 -2
- package/dist/components/empty-state/EmptyState.svelte.d.ts +6 -0
- package/dist/components/heading/Heading.svelte +15 -0
- package/dist/components/heading/Heading.svelte.d.ts +6 -0
- package/dist/components/hover-card/HoverCardContent.svelte +19 -3
- package/dist/components/hover-card/HoverCardContent.svelte.d.ts +8 -0
- package/dist/components/input/Input.svelte +13 -3
- package/dist/components/input/Input.svelte.d.ts +10 -2
- package/dist/components/markdown/Markdown.svelte +22 -2
- package/dist/components/markdown/MarkdownDiagram.svelte +33 -2
- package/dist/components/markdown/MarkdownFile.svelte +56 -10
- package/dist/components/markdown/MarkdownMath.svelte +6 -0
- package/dist/components/markdown/MarkdownTable.svelte +3 -4
- package/dist/components/markdown/context.d.ts +6 -0
- package/dist/components/markdown/labels.d.ts +7 -0
- package/dist/components/markdown/labels.js +2 -0
- package/dist/components/menu/ContextMenuTrigger.svelte +14 -2
- package/dist/components/menu/ContextMenuTrigger.svelte.d.ts +10 -0
- package/dist/components/menu/MenuCheckboxItem.svelte +50 -7
- package/dist/components/menu/MenuCheckboxItem.svelte.d.ts +16 -0
- package/dist/components/menu/MenuContent.svelte +10 -2
- package/dist/components/menu/MenuContent.svelte.d.ts +10 -0
- package/dist/components/menu/MenuGroup.svelte +16 -0
- package/dist/components/menu/MenuGroup.svelte.d.ts +6 -0
- package/dist/components/menu/MenuItem.svelte +17 -2
- package/dist/components/menu/MenuItem.svelte.d.ts +8 -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/MenuSubContent.svelte +10 -2
- package/dist/components/menu/MenuSubContent.svelte.d.ts +10 -0
- package/dist/components/menu/MenuSubTrigger.svelte +19 -2
- package/dist/components/menu/MenuSubTrigger.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/message/MessageBubble.svelte +40 -0
- package/dist/components/message/MessageBubble.svelte.d.ts +12 -0
- package/dist/components/message/MessageContent.svelte +23 -14
- package/dist/components/message/MessageContent.svelte.d.ts +6 -0
- package/dist/components/message/MessageCopy.svelte +27 -15
- package/dist/components/message/MessageCopy.svelte.d.ts +9 -2
- package/dist/components/message/MessageRoot.svelte +20 -3
- package/dist/components/message/MessageRoot.svelte.d.ts +6 -0
- package/dist/components/message/context.d.ts +2 -0
- package/dist/components/message/index.d.ts +4 -1
- package/dist/components/message/index.js +3 -2
- package/dist/components/message/styles.d.ts +30 -0
- package/dist/components/message/styles.js +24 -0
- package/dist/components/notice/Notice.svelte +3 -3
- package/dist/components/popover/PopoverContent.svelte +27 -3
- package/dist/components/popover/PopoverContent.svelte.d.ts +18 -0
- package/dist/components/questionnaire/Questionnaire.svelte +103 -19
- package/dist/components/questionnaire/Questionnaire.svelte.d.ts +13 -1
- package/dist/components/queued-message/QueuedMessage.svelte +44 -6
- package/dist/components/queued-message/QueuedMessage.svelte.d.ts +12 -1
- package/dist/components/select/Select.svelte +18 -2
- package/dist/components/select/Select.svelte.d.ts +7 -0
- 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/components/toast/Toaster.svelte +1 -1
- package/dist/components/toggle/Toggle.svelte +12 -2
- package/dist/components/toggle/Toggle.svelte.d.ts +11 -1
- package/dist/components/toggle-group/ToggleGroupItem.svelte +10 -1
- package/dist/components/toggle-group/ToggleGroupRoot.svelte +7 -1
- package/dist/components/toggle-group/ToggleGroupRoot.svelte.d.ts +3 -1
- package/dist/components/toggle-group/context.d.ts +2 -1
- package/dist/components/tooltip/TooltipContent.svelte +13 -1
- package/dist/components/tooltip/TooltipContent.svelte.d.ts +10 -0
- package/dist/components/work-fold/WorkFold.svelte +13 -4
- package/dist/components/work-fold/WorkFold.svelte.d.ts +2 -1
- package/dist/focus-ring.d.ts +29 -0
- package/dist/focus-ring.js +42 -0
- package/dist/index.d.ts +9 -6
- package/dist/index.js +8 -2
- package/dist/internal/Collapse.svelte +15 -2
- package/dist/internal/Glyph.svelte +28 -0
- package/dist/internal/Glyph.svelte.d.ts +5 -0
- package/dist/internal/Tile.svelte +3 -2
- package/dist/internal/layer.d.ts +23 -0
- package/dist/internal/layer.js +19 -0
- package/dist/internal/toggle.d.ts +8 -1
- package/dist/internal/toggle.js +20 -2
- package/dist/markdown/file-paths.d.ts +7 -0
- package/dist/markdown/file-paths.js +29 -0
- package/dist/markdown/files.d.ts +22 -2
- package/dist/markdown/files.js +45 -14
- package/dist/tokens.stylex.d.ts +3 -0
- package/dist/tokens.stylex.js +5 -1
- package/package.json +1 -1
- package/skills/building-ui/SKILL.md +87 -8
- package/skills/building-ui/references/components.md +39 -38
- package/skills/markdown/SKILL.md +22 -6
- package/skills/setup/SKILL.md +1 -1
- package/skills/styling/SKILL.md +10 -3
- package/skills/theming/SKILL.md +11 -4
|
@@ -12,6 +12,12 @@
|
|
|
12
12
|
sx?: Sx | undefined;
|
|
13
13
|
/** Sidebar.Group and Sidebar.Item. */
|
|
14
14
|
children?: Snippet | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Groups held at the foot of the list, below what scrolls, such as shelves of settled
|
|
17
|
+
* threads. They are part of the same list: one tab stop, and the arrow keys run on into
|
|
18
|
+
* them. Opened, they take at most 40% of the height and scroll on their own.
|
|
19
|
+
*/
|
|
20
|
+
pinned?: Snippet | undefined;
|
|
15
21
|
};
|
|
16
22
|
|
|
17
23
|
const styles = stylex.create({
|
|
@@ -27,12 +33,29 @@
|
|
|
27
33
|
// The list fades at an edge with more beyond it
|
|
28
34
|
maskImage:
|
|
29
35
|
'linear-gradient(to bottom, transparent, #000 var(--narvi-fade-start, 0px), #000 calc(100% - var(--narvi-fade-end, 0px)), transparent)'
|
|
36
|
+
},
|
|
37
|
+
// With pinned groups, the list is a column: what scrolls, then what stays at its foot
|
|
38
|
+
split: {
|
|
39
|
+
display: 'flex',
|
|
40
|
+
flexDirection: 'column',
|
|
41
|
+
flexGrow: 1,
|
|
42
|
+
minHeight: 0
|
|
43
|
+
},
|
|
44
|
+
pinned: {
|
|
45
|
+
flexShrink: 0,
|
|
46
|
+
maxHeight: '40%',
|
|
47
|
+
overflowY: 'auto',
|
|
48
|
+
overscrollBehavior: 'contain',
|
|
49
|
+
paddingInline: '0.5rem',
|
|
50
|
+
paddingBottom: '0.5rem',
|
|
51
|
+
scrollbarWidth: 'thin',
|
|
52
|
+
scrollbarColor: `${colors.borderStrong} transparent`
|
|
30
53
|
}
|
|
31
54
|
});
|
|
32
55
|
</script>
|
|
33
56
|
|
|
34
57
|
<script lang="ts">
|
|
35
|
-
let { label, sx, class: className, children, ...rest }: SidebarContentProps = $props();
|
|
58
|
+
let { label, sx, class: className, children, pinned, ...rest }: SidebarContentProps = $props();
|
|
36
59
|
|
|
37
60
|
let fadeStart = $state(0);
|
|
38
61
|
let fadeEnd = $state(0);
|
|
@@ -56,15 +79,38 @@
|
|
|
56
79
|
</script>
|
|
57
80
|
|
|
58
81
|
<!-- One tab stop for every row in every group; the arrow keys move between them -->
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
82
|
+
{#if pinned}
|
|
83
|
+
<nav
|
|
84
|
+
aria-label={label}
|
|
85
|
+
data-slot="sidebar-content"
|
|
86
|
+
{...rest}
|
|
87
|
+
{...attrs([styles.split, sx], className)}
|
|
88
|
+
{@attach roving({ selector: '[data-sidebar-row]' })}
|
|
89
|
+
>
|
|
90
|
+
<div
|
|
91
|
+
data-slot="sidebar-content-scroll"
|
|
92
|
+
style:--narvi-fade-start="{fadeStart}px"
|
|
93
|
+
style:--narvi-fade-end="{fadeEnd}px"
|
|
94
|
+
{...stylex.attrs(styles.content)}
|
|
95
|
+
{@attach measure}
|
|
96
|
+
>
|
|
97
|
+
<div>{@render children?.()}</div>
|
|
98
|
+
</div>
|
|
99
|
+
<div data-slot="sidebar-content-pinned" {...stylex.attrs(styles.pinned)}>
|
|
100
|
+
{@render pinned()}
|
|
101
|
+
</div>
|
|
102
|
+
</nav>
|
|
103
|
+
{:else}
|
|
104
|
+
<nav
|
|
105
|
+
aria-label={label}
|
|
106
|
+
data-slot="sidebar-content"
|
|
107
|
+
style:--narvi-fade-start="{fadeStart}px"
|
|
108
|
+
style:--narvi-fade-end="{fadeEnd}px"
|
|
109
|
+
{...rest}
|
|
110
|
+
{...attrs([styles.content, sx], className)}
|
|
111
|
+
{@attach measure}
|
|
112
|
+
{@attach roving({ selector: '[data-sidebar-row]' })}
|
|
113
|
+
>
|
|
114
|
+
<div>{@render children?.()}</div>
|
|
115
|
+
</nav>
|
|
116
|
+
{/if}
|
|
@@ -7,6 +7,12 @@ export type SidebarContentProps = Omit<HTMLAttributes<HTMLElement>, 'children'>
|
|
|
7
7
|
sx?: Sx | undefined;
|
|
8
8
|
/** Sidebar.Group and Sidebar.Item. */
|
|
9
9
|
children?: Snippet | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* Groups held at the foot of the list, below what scrolls, such as shelves of settled
|
|
12
|
+
* threads. They are part of the same list: one tab stop, and the arrow keys run on into
|
|
13
|
+
* them. Opened, they take at most 40% of the height and scroll on their own.
|
|
14
|
+
*/
|
|
15
|
+
pinned?: Snippet | undefined;
|
|
10
16
|
};
|
|
11
17
|
declare const SidebarContent: import("svelte").Component<SidebarContentProps, {}, "">;
|
|
12
18
|
type SidebarContent = ReturnType<typeof SidebarContent>;
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
import { colors, font, motion, radius } from '../../tokens.stylex.js';
|
|
16
16
|
import { media } from '../../media.stylex.js';
|
|
17
17
|
import { getSidebarDepth, setSidebarDepth } from './depth.js';
|
|
18
|
+
import { getSidebarFold, setSidebarFold } from './fold.js';
|
|
18
19
|
|
|
19
20
|
export type SidebarFolderProps = Omit<HTMLAttributes<HTMLLIElement>, 'children'> & {
|
|
20
21
|
/** Its name: a project. */
|
|
@@ -32,6 +33,8 @@
|
|
|
32
33
|
|
|
33
34
|
const styles = stylex.create({
|
|
34
35
|
folder: { position: 'relative', listStyleType: 'none' },
|
|
36
|
+
// Its group is folded, and the open row is not in it
|
|
37
|
+
foldedAway: { display: 'none' },
|
|
35
38
|
row: {
|
|
36
39
|
boxSizing: 'border-box',
|
|
37
40
|
display: 'flex',
|
|
@@ -121,9 +124,33 @@
|
|
|
121
124
|
const depth = $derived(parent());
|
|
122
125
|
// Its rows start where its name does: past the chevron, and past the mark when it has one
|
|
123
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);
|
|
124
147
|
</script>
|
|
125
148
|
|
|
126
|
-
<li
|
|
149
|
+
<li
|
|
150
|
+
data-slot="sidebar-folder"
|
|
151
|
+
{...rest}
|
|
152
|
+
{...attrs([styles.folder, away && styles.foldedAway, sx], className)}
|
|
153
|
+
>
|
|
127
154
|
<button
|
|
128
155
|
type="button"
|
|
129
156
|
data-sidebar-row
|
|
@@ -146,7 +173,7 @@
|
|
|
146
173
|
<span {...stylex.attrs(styles.grow)}></span>
|
|
147
174
|
{#if trailing}<span {...stylex.attrs(styles.trail)}>{@render trailing()}</span>{/if}
|
|
148
175
|
</button>
|
|
149
|
-
<Collapse {
|
|
176
|
+
<Collapse open={shown} id="{uid}-rows">
|
|
150
177
|
<ul aria-label={label} {...stylex.attrs(styles.list)}>{@render children?.()}</ul>
|
|
151
178
|
</Collapse>
|
|
152
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
|
|
@@ -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>
|