@diegopluna/narvi 0.3.3 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/app-shell/AppShellMain.svelte +14 -2
- package/dist/components/app-shell/AppShellPanel.svelte +77 -12
- package/dist/components/app-shell/AppShellPanel.svelte.d.ts +11 -1
- package/dist/components/app-shell/AppShellSheet.svelte +11 -1
- package/dist/components/app-shell/context.d.ts +8 -0
- package/dist/components/app-shell/context.js +7 -0
- package/dist/components/avatar/AvatarRoot.svelte +20 -7
- package/dist/components/avatar/AvatarRoot.svelte.d.ts +10 -3
- package/dist/components/button/Button.svelte +12 -1
- package/dist/components/button/Button.svelte.d.ts +7 -0
- package/dist/components/segmented/SegmentedControl.svelte +12 -1
- package/dist/components/segmented/SegmentedControl.svelte.d.ts +3 -1
- package/dist/components/select/Select.svelte +25 -4
- package/dist/components/select/Select.svelte.d.ts +7 -0
- package/dist/components/settings-row/SettingsRow.svelte +87 -37
- package/dist/components/settings-row/SettingsRow.svelte.d.ts +13 -0
- package/dist/components/split-button/SplitButton.svelte +137 -0
- package/dist/components/split-button/SplitButton.svelte.d.ts +29 -0
- package/dist/components/tab-strip/TabStrip.svelte +337 -93
- package/dist/components/tab-strip/TabStrip.svelte.d.ts +36 -1
- package/dist/components/tab-strip/drag.svelte.d.ts +31 -0
- package/dist/components/tab-strip/drag.svelte.js +148 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/package.json +1 -1
- package/skills/building-ui/SKILL.md +24 -4
- package/skills/building-ui/references/components.md +21 -20
- package/skills/markdown/SKILL.md +1 -1
- package/skills/setup/SKILL.md +1 -1
- package/skills/styling/SKILL.md +1 -1
- package/skills/theming/SKILL.md +1 -1
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import type { Snippet } from 'svelte';
|
|
4
4
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
5
5
|
import { attrs, type Sx } from '../../internal/sx.js';
|
|
6
|
+
import { getAppShellSheetContext } from './context.js';
|
|
6
7
|
|
|
7
8
|
export type AppShellMainProps = Omit<HTMLAttributes<HTMLElement>, 'children'> & {
|
|
8
9
|
sx?: Sx | undefined;
|
|
@@ -21,17 +22,28 @@
|
|
|
21
22
|
minHeight: 0,
|
|
22
23
|
// Focused from a skip link, it is the page that is reached, not a control
|
|
23
24
|
outlineStyle: 'none'
|
|
24
|
-
}
|
|
25
|
+
},
|
|
26
|
+
// Under a maximized panel: out of sight and out of reach, but still laid out, so its
|
|
27
|
+
// scroll and what is typed in it are as they were when the panel is restored
|
|
28
|
+
covered: { visibility: 'hidden' }
|
|
25
29
|
});
|
|
26
30
|
</script>
|
|
27
31
|
|
|
28
32
|
<script lang="ts">
|
|
29
33
|
let { sx, class: className, children, ...rest }: AppShellMainProps = $props();
|
|
34
|
+
|
|
35
|
+
const sheet = getAppShellSheetContext();
|
|
36
|
+
const covered = $derived(sheet?.covered ?? false);
|
|
30
37
|
</script>
|
|
31
38
|
|
|
32
39
|
<!-- Not focusable by default: with `tabindex="-1"` a click on plain text in the page would move
|
|
33
40
|
focus to the whole of it, away from a panel that keeps its own, such as a find bar. Pass a
|
|
34
41
|
`tabindex` to make it the target of a skip link. -->
|
|
35
|
-
<main
|
|
42
|
+
<main
|
|
43
|
+
data-slot="app-shell-main"
|
|
44
|
+
inert={covered || undefined}
|
|
45
|
+
{...rest}
|
|
46
|
+
{...attrs([styles.main, covered && styles.covered, sx], className)}
|
|
47
|
+
>
|
|
36
48
|
{@render children?.()}
|
|
37
49
|
</main>
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
<!--
|
|
2
2
|
The last column of the sheet, beside the page: what the page is about, such as
|
|
3
3
|
the files a thread changed. Its start edge drags to resize it.
|
|
4
|
+
|
|
5
|
+
Where its row has no room for it beside the page (the row's width less the
|
|
6
|
+
sidebar's, not the window's), it takes the page's place under the page's
|
|
7
|
+
header. Maximized, it takes the page's place whole, header and all.
|
|
4
8
|
-->
|
|
5
9
|
<script lang="ts" module>
|
|
6
10
|
import * as stylex from '@stylexjs/stylex';
|
|
@@ -9,7 +13,7 @@
|
|
|
9
13
|
import { attrs, type Sx } from '../../internal/sx.js';
|
|
10
14
|
import { colors } from '../../tokens.stylex.js';
|
|
11
15
|
import ResizeHandle from '../resize-handle/ResizeHandle.svelte';
|
|
12
|
-
import { useAppShell } from './context.js';
|
|
16
|
+
import { getAppShellSheetContext, useAppShell } from './context.js';
|
|
13
17
|
|
|
14
18
|
export type AppShellPanelProps = Omit<HTMLAttributes<HTMLElement>, 'children'> & {
|
|
15
19
|
/** Names the region: "Changes", "Files". */
|
|
@@ -18,8 +22,18 @@
|
|
|
18
22
|
width?: number | undefined;
|
|
19
23
|
minWidth?: number | undefined;
|
|
20
24
|
defaultWidth?: number | undefined;
|
|
21
|
-
/**
|
|
25
|
+
/**
|
|
26
|
+
* How much room it always leaves the main area, in pixels. Where the row has less than
|
|
27
|
+
* this and `minWidth` together, the panel takes the page's place under its header.
|
|
28
|
+
*/
|
|
22
29
|
mainMinWidth?: number | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Fills the row in the page's place, over its header too, with no handle. The page
|
|
32
|
+
* stays as it was underneath, out of sight and out of reach, until it is restored. Give
|
|
33
|
+
* the panel a header of its own: with `AppShell.Toggle when="closed"` in it, the sidebar
|
|
34
|
+
* stays in reach.
|
|
35
|
+
*/
|
|
36
|
+
maximized?: boolean | undefined;
|
|
23
37
|
sx?: Sx | undefined;
|
|
24
38
|
children?: Snippet | undefined;
|
|
25
39
|
};
|
|
@@ -38,20 +52,27 @@
|
|
|
38
52
|
borderInlineStartWidth: '1px',
|
|
39
53
|
borderInlineStartStyle: 'solid',
|
|
40
54
|
borderInlineStartColor: colors.border,
|
|
41
|
-
// The traffic lights are never over a panel, so a header inside one
|
|
55
|
+
// The traffic lights are never over a panel beside the page, so a header inside one
|
|
56
|
+
// keeps no room for them
|
|
42
57
|
'--narvi-inset-page': '0px'
|
|
43
58
|
},
|
|
44
|
-
//
|
|
45
|
-
//
|
|
46
|
-
|
|
59
|
+
// In the page's place: from the sidebar's end (none on a narrow window, where the
|
|
60
|
+
// sidebar is a drawer) to the sheet's
|
|
61
|
+
over: {
|
|
47
62
|
position: 'absolute',
|
|
48
|
-
|
|
49
|
-
|
|
63
|
+
insetBlockEnd: 0,
|
|
64
|
+
insetInlineStart: 'var(--narvi-panel-start, 0px)',
|
|
65
|
+
insetInlineEnd: 0,
|
|
50
66
|
zIndex: 5,
|
|
51
67
|
width: 'auto',
|
|
52
68
|
borderInlineStartWidth: 0,
|
|
53
69
|
backgroundColor: colors.bgRaised
|
|
54
70
|
},
|
|
71
|
+
// Under the page's header, which stays in reach with the sidebar's toggle
|
|
72
|
+
narrow: { insetBlockStart: '3rem' },
|
|
73
|
+
// Over all of the page. Where the page's header kept room for the traffic lights, the
|
|
74
|
+
// panel's own header keeps it now.
|
|
75
|
+
maximized: { insetBlockStart: 0, '--narvi-inset-page': 'inherit' },
|
|
55
76
|
handle: { position: 'relative', alignSelf: 'stretch' }
|
|
56
77
|
});
|
|
57
78
|
</script>
|
|
@@ -63,6 +84,7 @@
|
|
|
63
84
|
minWidth = 320,
|
|
64
85
|
defaultWidth = 560,
|
|
65
86
|
mainMinWidth = 352,
|
|
87
|
+
maximized = false,
|
|
66
88
|
sx,
|
|
67
89
|
class: className,
|
|
68
90
|
children,
|
|
@@ -70,21 +92,58 @@
|
|
|
70
92
|
}: AppShellPanelProps = $props();
|
|
71
93
|
|
|
72
94
|
const shell = useAppShell('Panel');
|
|
95
|
+
const sheetContext = getAppShellSheetContext();
|
|
73
96
|
let element = $state<HTMLElement | null>(null);
|
|
97
|
+
// The room the row gives the page and the panel together, and where that room starts
|
|
98
|
+
let row = $state(Infinity);
|
|
99
|
+
let start = $state(0);
|
|
100
|
+
|
|
101
|
+
const sidebarOf = (sheet: Element | null | undefined) =>
|
|
102
|
+
sheet?.querySelector<HTMLElement>(':scope > [data-slot="app-shell-sidebar"]') ?? null;
|
|
103
|
+
|
|
104
|
+
// The row is measured, not the window: a sheet among several panes is narrower than it
|
|
105
|
+
$effect(() => {
|
|
106
|
+
const sheet = element?.parentElement;
|
|
107
|
+
if (!sheet) return;
|
|
108
|
+
const measure = () => {
|
|
109
|
+
const sidebar = sidebarOf(sheet);
|
|
110
|
+
// A drawer is over the page, not beside it
|
|
111
|
+
const beside = shell.narrow ? 0 : (sidebar?.offsetWidth ?? 0);
|
|
112
|
+
row = sheet.clientWidth - beside;
|
|
113
|
+
start = beside;
|
|
114
|
+
};
|
|
115
|
+
measure();
|
|
116
|
+
const observer = new ResizeObserver(measure);
|
|
117
|
+
observer.observe(sheet);
|
|
118
|
+
const sidebar = sidebarOf(sheet);
|
|
119
|
+
if (sidebar) observer.observe(sidebar);
|
|
120
|
+
return () => observer.disconnect();
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
const narrow = $derived(shell.narrow || row < minWidth + Math.max(mainMinWidth, 0));
|
|
124
|
+
const over = $derived(maximized || narrow);
|
|
125
|
+
|
|
126
|
+
// The page steps out of view under a maximized panel
|
|
127
|
+
$effect(() => {
|
|
128
|
+
if (!sheetContext || !maximized) return;
|
|
129
|
+
sheetContext.setCovered(true);
|
|
130
|
+
return () => sheetContext.setCovered(false);
|
|
131
|
+
});
|
|
74
132
|
|
|
75
133
|
// It never takes so much that the main area falls below its minimum
|
|
76
134
|
const largest = () => {
|
|
77
135
|
// On the server there is no window to measure: no limit yet
|
|
78
136
|
if (typeof window === 'undefined') return Infinity;
|
|
79
137
|
const sheet = element?.parentElement;
|
|
80
|
-
const sidebar = sheet?.querySelector<HTMLElement>(':scope > [data-slot="app-shell-sidebar"]');
|
|
81
138
|
return (
|
|
82
|
-
(sheet?.clientWidth ?? innerWidth) -
|
|
139
|
+
(sheet?.clientWidth ?? innerWidth) -
|
|
140
|
+
(sidebarOf(sheet)?.offsetWidth ?? 0) -
|
|
141
|
+
Math.max(mainMinWidth, 0)
|
|
83
142
|
);
|
|
84
143
|
};
|
|
85
144
|
</script>
|
|
86
145
|
|
|
87
|
-
{#if !
|
|
146
|
+
{#if !over}
|
|
88
147
|
<ResizeHandle
|
|
89
148
|
bind:value={width}
|
|
90
149
|
min={minWidth}
|
|
@@ -101,9 +160,15 @@
|
|
|
101
160
|
bind:this={element}
|
|
102
161
|
aria-label={label}
|
|
103
162
|
data-slot="app-shell-panel"
|
|
163
|
+
data-maximized={maximized || undefined}
|
|
164
|
+
data-narrow={(narrow && !maximized) || undefined}
|
|
104
165
|
style:--narvi-panel-width="{width}px"
|
|
166
|
+
style:--narvi-panel-start="{start}px"
|
|
105
167
|
{...rest}
|
|
106
|
-
{...attrs(
|
|
168
|
+
{...attrs(
|
|
169
|
+
[styles.panel, over && styles.over, maximized ? styles.maximized : narrow && styles.narrow, sx],
|
|
170
|
+
className
|
|
171
|
+
)}
|
|
107
172
|
>
|
|
108
173
|
{@render children?.()}
|
|
109
174
|
</aside>
|
|
@@ -8,8 +8,18 @@ export type AppShellPanelProps = Omit<HTMLAttributes<HTMLElement>, 'children'> &
|
|
|
8
8
|
width?: number | undefined;
|
|
9
9
|
minWidth?: number | undefined;
|
|
10
10
|
defaultWidth?: number | undefined;
|
|
11
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* How much room it always leaves the main area, in pixels. Where the row has less than
|
|
13
|
+
* this and `minWidth` together, the panel takes the page's place under its header.
|
|
14
|
+
*/
|
|
12
15
|
mainMinWidth?: number | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Fills the row in the page's place, over its header too, with no handle. The page
|
|
18
|
+
* stays as it was underneath, out of sight and out of reach, until it is restored. Give
|
|
19
|
+
* the panel a header of its own: with `AppShell.Toggle when="closed"` in it, the sidebar
|
|
20
|
+
* stays in reach.
|
|
21
|
+
*/
|
|
22
|
+
maximized?: boolean | undefined;
|
|
13
23
|
sx?: Sx | undefined;
|
|
14
24
|
children?: Snippet | undefined;
|
|
15
25
|
};
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
import { shared } from '../../internal/shared.js';
|
|
13
13
|
import { attrs, type Sx } from '../../internal/sx.js';
|
|
14
14
|
import { colors, radius } from '../../tokens.stylex.js';
|
|
15
|
-
import { useAppShell } from './context.js';
|
|
15
|
+
import { setAppShellSheetContext, useAppShell } from './context.js';
|
|
16
16
|
|
|
17
17
|
export type AppShellSheetProps = Omit<HTMLAttributes<HTMLDivElement>, 'children'> & {
|
|
18
18
|
/**
|
|
@@ -73,6 +73,16 @@
|
|
|
73
73
|
}: AppShellSheetProps = $props();
|
|
74
74
|
|
|
75
75
|
const shell = useAppShell('Sheet');
|
|
76
|
+
|
|
77
|
+
let covered = $state(false);
|
|
78
|
+
setAppShellSheetContext({
|
|
79
|
+
get covered() {
|
|
80
|
+
return covered;
|
|
81
|
+
},
|
|
82
|
+
setCovered(next) {
|
|
83
|
+
covered = next;
|
|
84
|
+
}
|
|
85
|
+
});
|
|
76
86
|
</script>
|
|
77
87
|
|
|
78
88
|
<div
|
|
@@ -19,3 +19,11 @@ export declare function setAppShellContext(context: AppShellContext): void;
|
|
|
19
19
|
/** The surrounding AppShell, for building parts of your own. */
|
|
20
20
|
export declare function getAppShellContext(): AppShellContext | undefined;
|
|
21
21
|
export declare function useAppShell(part: string): AppShellContext;
|
|
22
|
+
/** @internal What the parts of one sheet tell each other. */
|
|
23
|
+
export type AppShellSheetContext = {
|
|
24
|
+
/** True while a panel in the sheet is maximized, over the page, which then steps out of view. */
|
|
25
|
+
readonly covered: boolean;
|
|
26
|
+
setCovered(covered: boolean): void;
|
|
27
|
+
};
|
|
28
|
+
export declare function setAppShellSheetContext(context: AppShellSheetContext): void;
|
|
29
|
+
export declare function getAppShellSheetContext(): AppShellSheetContext | undefined;
|
|
@@ -13,3 +13,10 @@ export function useAppShell(part) {
|
|
|
13
13
|
throw new Error(`<AppShell.${part}> must be placed inside <AppShell.Root>.`);
|
|
14
14
|
return context;
|
|
15
15
|
}
|
|
16
|
+
const SHEET_KEY = Symbol('narvi.app-shell-sheet');
|
|
17
|
+
export function setAppShellSheetContext(context) {
|
|
18
|
+
setContext(SHEET_KEY, context);
|
|
19
|
+
}
|
|
20
|
+
export function getAppShellSheetContext() {
|
|
21
|
+
return getContext(SHEET_KEY);
|
|
22
|
+
}
|
|
@@ -6,14 +6,21 @@
|
|
|
6
6
|
import { font, radius } from '../../tokens.stylex.js';
|
|
7
7
|
import { setAvatarContext, type AvatarImageStatus } from './context.js';
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
/** 20, 24, 28, 36 and 56px. */
|
|
10
|
+
export type AvatarSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
10
11
|
|
|
11
12
|
export type AvatarRootProps = Omit<HTMLAttributes<HTMLSpanElement>, 'children'> & {
|
|
12
13
|
/**
|
|
13
|
-
* The person's name. It
|
|
14
|
-
*
|
|
14
|
+
* The person's name. It picks the colour behind the initials, so each person keeps
|
|
15
|
+
* theirs, and is the avatar's accessible name unless `label` says otherwise.
|
|
15
16
|
*/
|
|
16
17
|
name?: string | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* The accessible name, in place of `name`: "Ada, the thread's owner". `null` where the
|
|
20
|
+
* name is written beside the avatar, so it is not read twice: the avatar is then hidden
|
|
21
|
+
* from assistive technology.
|
|
22
|
+
*/
|
|
23
|
+
label?: string | null | undefined;
|
|
17
24
|
size?: AvatarSize | undefined;
|
|
18
25
|
sx?: Sx | undefined;
|
|
19
26
|
ref?: HTMLSpanElement | null | undefined;
|
|
@@ -52,8 +59,10 @@
|
|
|
52
59
|
});
|
|
53
60
|
|
|
54
61
|
const sizes = stylex.create({
|
|
62
|
+
// Beside a line of meta text, as in a row of who is in a thread
|
|
63
|
+
xs: { width: '1.25rem', height: '1.25rem', fontSize: '0.5625rem' },
|
|
55
64
|
sm: { width: '1.5rem', height: '1.5rem', fontSize: '0.625rem' },
|
|
56
|
-
md: { width: '1.75rem', height: '1.75rem', fontSize:
|
|
65
|
+
md: { width: '1.75rem', height: '1.75rem', fontSize: font.sizeMicro },
|
|
57
66
|
lg: { width: '2.25rem', height: '2.25rem', fontSize: font.sizeMeta },
|
|
58
67
|
xl: { width: '3.5rem', height: '3.5rem', fontSize: '1.125rem' }
|
|
59
68
|
});
|
|
@@ -70,6 +79,7 @@
|
|
|
70
79
|
<script lang="ts">
|
|
71
80
|
let {
|
|
72
81
|
name,
|
|
82
|
+
label,
|
|
73
83
|
size = 'md',
|
|
74
84
|
sx,
|
|
75
85
|
class: className,
|
|
@@ -79,6 +89,7 @@
|
|
|
79
89
|
}: AvatarRootProps = $props();
|
|
80
90
|
|
|
81
91
|
let status = $state<AvatarImageStatus>('none');
|
|
92
|
+
const spoken = $derived(label === null ? undefined : (label ?? name) || undefined);
|
|
82
93
|
|
|
83
94
|
setAvatarContext({
|
|
84
95
|
get status() {
|
|
@@ -93,11 +104,13 @@
|
|
|
93
104
|
});
|
|
94
105
|
</script>
|
|
95
106
|
|
|
96
|
-
<!-- With a name, the whole avatar is one image with that name, and what is inside is not read out
|
|
107
|
+
<!-- With a name, the whole avatar is one image with that name, and what is inside is not read out.
|
|
108
|
+
With `label={null}` it is decoration, beside a name that is read already. -->
|
|
97
109
|
<span
|
|
98
110
|
bind:this={ref}
|
|
99
|
-
role={
|
|
100
|
-
aria-label={
|
|
111
|
+
role={spoken ? 'img' : undefined}
|
|
112
|
+
aria-label={spoken}
|
|
113
|
+
aria-hidden={label === null || undefined}
|
|
101
114
|
data-slot="avatar"
|
|
102
115
|
data-status={status}
|
|
103
116
|
{...rest}
|
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
2
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
3
|
import { type Sx } from '../../internal/sx.js';
|
|
4
|
-
|
|
4
|
+
/** 20, 24, 28, 36 and 56px. */
|
|
5
|
+
export type AvatarSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
5
6
|
export type AvatarRootProps = Omit<HTMLAttributes<HTMLSpanElement>, 'children'> & {
|
|
6
7
|
/**
|
|
7
|
-
* The person's name. It
|
|
8
|
-
*
|
|
8
|
+
* The person's name. It picks the colour behind the initials, so each person keeps
|
|
9
|
+
* theirs, and is the avatar's accessible name unless `label` says otherwise.
|
|
9
10
|
*/
|
|
10
11
|
name?: string | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* The accessible name, in place of `name`: "Ada, the thread's owner". `null` where the
|
|
14
|
+
* name is written beside the avatar, so it is not read twice: the avatar is then hidden
|
|
15
|
+
* from assistive technology.
|
|
16
|
+
*/
|
|
17
|
+
label?: string | null | undefined;
|
|
11
18
|
size?: AvatarSize | undefined;
|
|
12
19
|
sx?: Sx | undefined;
|
|
13
20
|
ref?: HTMLSpanElement | null | undefined;
|
|
@@ -44,6 +44,13 @@
|
|
|
44
44
|
*/
|
|
45
45
|
loadingLabel?: string | undefined;
|
|
46
46
|
disabled?: boolean | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* Makes it a toggle button (`aria-pressed`), held in its open look while true: a
|
|
49
|
+
* toolbar's button that shows or hides something. `secondary` and `ghost` take the fill
|
|
50
|
+
* of what is chosen, `floating` its stronger edge, `bare` its full ink. For a toggle lit
|
|
51
|
+
* in the accent, use Toggle.
|
|
52
|
+
*/
|
|
53
|
+
pressed?: boolean | undefined;
|
|
47
54
|
/** Square button for a single icon. Give it an `aria-label`. */
|
|
48
55
|
iconOnly?: boolean | undefined;
|
|
49
56
|
/** Renders a link styled as a button. */
|
|
@@ -58,7 +65,9 @@
|
|
|
58
65
|
// The trigger of a menu, a popover or a select while what it opened is showing. bits-ui
|
|
59
66
|
// marks it with `aria-expanded`, which a disclosure's trigger carries too: only a popup's
|
|
60
67
|
// (`aria-haspopup`) is held in its open look.
|
|
61
|
-
|
|
68
|
+
// A toggle button that is pressed holds the same look.
|
|
69
|
+
const OPEN =
|
|
70
|
+
':is([aria-haspopup]:not([aria-haspopup="false"])[aria-expanded="true"], [aria-pressed="true"])';
|
|
62
71
|
|
|
63
72
|
const styles = stylex.create({
|
|
64
73
|
base: {
|
|
@@ -444,6 +453,7 @@
|
|
|
444
453
|
loading = false,
|
|
445
454
|
loadingLabel,
|
|
446
455
|
disabled = false,
|
|
456
|
+
pressed,
|
|
447
457
|
iconOnly = false,
|
|
448
458
|
href,
|
|
449
459
|
type = 'button',
|
|
@@ -511,6 +521,7 @@
|
|
|
511
521
|
data-icons
|
|
512
522
|
{type}
|
|
513
523
|
disabled={disabled || undefined}
|
|
524
|
+
aria-pressed={pressed}
|
|
514
525
|
aria-disabled={loading ? true : undefined}
|
|
515
526
|
aria-busy={loading ? true : undefined}
|
|
516
527
|
{...rest}
|
|
@@ -24,6 +24,13 @@ export type ButtonProps = Omit<HTMLButtonAttributes & HTMLAnchorAttributes, 'chi
|
|
|
24
24
|
*/
|
|
25
25
|
loadingLabel?: string | undefined;
|
|
26
26
|
disabled?: boolean | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Makes it a toggle button (`aria-pressed`), held in its open look while true: a
|
|
29
|
+
* toolbar's button that shows or hides something. `secondary` and `ghost` take the fill
|
|
30
|
+
* of what is chosen, `floating` its stronger edge, `bare` its full ink. For a toggle lit
|
|
31
|
+
* in the accent, use Toggle.
|
|
32
|
+
*/
|
|
33
|
+
pressed?: boolean | undefined;
|
|
27
34
|
/** Square button for a single icon. Give it an `aria-label`. */
|
|
28
35
|
iconOnly?: boolean | undefined;
|
|
29
36
|
/** Renders a link styled as a button. */
|
|
@@ -23,7 +23,10 @@
|
|
|
23
23
|
disabled?: boolean | undefined;
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
-
export type SegmentedControlProps = Omit<
|
|
26
|
+
export type SegmentedControlProps = Omit<
|
|
27
|
+
HTMLAttributes<HTMLDivElement>,
|
|
28
|
+
'children' | 'onchange'
|
|
29
|
+
> & {
|
|
27
30
|
/** The choices, in order. Two to five read best. */
|
|
28
31
|
options: SegmentedOption[];
|
|
29
32
|
/** The selected option's value. Bindable. */
|
|
@@ -31,6 +34,8 @@
|
|
|
31
34
|
/** Form field name. Generated when omitted. */
|
|
32
35
|
name?: string | undefined;
|
|
33
36
|
disabled?: boolean | undefined;
|
|
37
|
+
/** Called when the person picks an option, with its value: not when `value` is set. */
|
|
38
|
+
onchange?: ((value: string) => void) | undefined;
|
|
34
39
|
sx?: Sx | undefined;
|
|
35
40
|
};
|
|
36
41
|
|
|
@@ -139,6 +144,7 @@
|
|
|
139
144
|
value = $bindable(),
|
|
140
145
|
name,
|
|
141
146
|
disabled = false,
|
|
147
|
+
onchange,
|
|
142
148
|
sx,
|
|
143
149
|
class: className,
|
|
144
150
|
...rest
|
|
@@ -181,6 +187,11 @@
|
|
|
181
187
|
name={name ?? uid}
|
|
182
188
|
value={option.value}
|
|
183
189
|
bind:group={value}
|
|
190
|
+
onchange={() => {
|
|
191
|
+
// The binding may not have run yet: the value is set before the callback reads it
|
|
192
|
+
value = option.value;
|
|
193
|
+
onchange?.(option.value);
|
|
194
|
+
}}
|
|
184
195
|
disabled={off}
|
|
185
196
|
aria-describedby={titleId}
|
|
186
197
|
{...stylex.attrs(styles.input, segmentedInputMarker)}
|
|
@@ -14,7 +14,7 @@ export type SegmentedOption = {
|
|
|
14
14
|
icon?: IconComponent | undefined;
|
|
15
15
|
disabled?: boolean | undefined;
|
|
16
16
|
};
|
|
17
|
-
export type SegmentedControlProps = Omit<HTMLAttributes<HTMLDivElement>, 'children'> & {
|
|
17
|
+
export type SegmentedControlProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'onchange'> & {
|
|
18
18
|
/** The choices, in order. Two to five read best. */
|
|
19
19
|
options: SegmentedOption[];
|
|
20
20
|
/** The selected option's value. Bindable. */
|
|
@@ -22,6 +22,8 @@ export type SegmentedControlProps = Omit<HTMLAttributes<HTMLDivElement>, 'childr
|
|
|
22
22
|
/** Form field name. Generated when omitted. */
|
|
23
23
|
name?: string | undefined;
|
|
24
24
|
disabled?: boolean | undefined;
|
|
25
|
+
/** Called when the person picks an option, with its value: not when `value` is set. */
|
|
26
|
+
onchange?: ((value: string) => void) | undefined;
|
|
25
27
|
sx?: Sx | undefined;
|
|
26
28
|
};
|
|
27
29
|
declare const SegmentedControl: import("svelte").Component<SegmentedControlProps, {}, "value">;
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
import { control, type ControlSize } from '../../internal/control.js';
|
|
12
12
|
import { layer } from '../../internal/layer.js';
|
|
13
13
|
import { attrs, type Sx } from '../../internal/sx.js';
|
|
14
|
-
import { colors } from '../../tokens.stylex.js';
|
|
14
|
+
import { colors, font } from '../../tokens.stylex.js';
|
|
15
15
|
import { getFieldContext } from '../field/context.js';
|
|
16
16
|
|
|
17
17
|
export type SelectOption = {
|
|
@@ -22,6 +22,13 @@
|
|
|
22
22
|
* component such as a Lucide icon, which is sized to fit.
|
|
23
23
|
*/
|
|
24
24
|
icon?: IconComponent | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* More about the option, at the end of its row in the list and muted: a commit's short
|
|
27
|
+
* hash, a device's size, a count. It is not shown on the trigger.
|
|
28
|
+
*/
|
|
29
|
+
detail?: string | undefined;
|
|
30
|
+
/** Sets `detail` in monospace, for code such as a hash. */
|
|
31
|
+
detailMono?: boolean | undefined;
|
|
25
32
|
/** Options with the same group are listed together under its name. */
|
|
26
33
|
group?: string | undefined;
|
|
27
34
|
disabled?: boolean | undefined;
|
|
@@ -79,9 +86,16 @@
|
|
|
79
86
|
color: colors.textMuted
|
|
80
87
|
},
|
|
81
88
|
selector: { display: 'grid', flexShrink: 0, color: colors.textSubtle },
|
|
82
|
-
check: { display: 'grid', marginInlineStart: 'auto', color: colors.accent }
|
|
89
|
+
check: { display: 'grid', marginInlineStart: 'auto', color: colors.accent },
|
|
90
|
+
// Where options have details, every row keeps the check's room, so the details line up
|
|
91
|
+
unchecked: { visibility: 'hidden' },
|
|
92
|
+
mono: { fontFamily: font.mono }
|
|
83
93
|
});
|
|
84
94
|
|
|
95
|
+
// Made here: the item's `selected` comes through a snippet's argument, which StyleX cannot read
|
|
96
|
+
const check = stylex.attrs(styles.check);
|
|
97
|
+
const checkHidden = stylex.attrs(styles.check, styles.unchecked);
|
|
98
|
+
|
|
85
99
|
type Group = { name: string | undefined; options: SelectOption[] };
|
|
86
100
|
function grouped(options: SelectOption[]): Group[] {
|
|
87
101
|
const groups: Group[] = [];
|
|
@@ -115,6 +129,7 @@
|
|
|
115
129
|
const field = getFieldContext();
|
|
116
130
|
const selected = $derived(options.find((option) => option.value === value));
|
|
117
131
|
const groups = $derived(grouped(options));
|
|
132
|
+
const detailed = $derived(options.some((option) => option.detail));
|
|
118
133
|
</script>
|
|
119
134
|
|
|
120
135
|
<Select.Root
|
|
@@ -172,8 +187,14 @@
|
|
|
172
187
|
>
|
|
173
188
|
{/if}
|
|
174
189
|
<span {...stylex.attrs(layer.label)}>{option.label}</span>
|
|
175
|
-
{#if
|
|
176
|
-
<span {...stylex.attrs(
|
|
190
|
+
{#if option.detail}
|
|
191
|
+
<span {...stylex.attrs(layer.trailing, option.detailMono && styles.mono)}
|
|
192
|
+
>{option.detail}</span
|
|
193
|
+
>
|
|
194
|
+
{/if}
|
|
195
|
+
{#if selected || detailed}
|
|
196
|
+
<span aria-hidden={!selected || undefined} {...selected ? check : checkHidden}
|
|
197
|
+
><Glyph name="check" stroke={1.75} /></span
|
|
177
198
|
>
|
|
178
199
|
{/if}
|
|
179
200
|
{/snippet}
|
|
@@ -11,6 +11,13 @@ export type SelectOption = {
|
|
|
11
11
|
* component such as a Lucide icon, which is sized to fit.
|
|
12
12
|
*/
|
|
13
13
|
icon?: IconComponent | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* More about the option, at the end of its row in the list and muted: a commit's short
|
|
16
|
+
* hash, a device's size, a count. It is not shown on the trigger.
|
|
17
|
+
*/
|
|
18
|
+
detail?: string | undefined;
|
|
19
|
+
/** Sets `detail` in monospace, for code such as a hash. */
|
|
20
|
+
detailMono?: boolean | undefined;
|
|
14
21
|
/** Options with the same group are listed together under its name. */
|
|
15
22
|
group?: string | undefined;
|
|
16
23
|
disabled?: boolean | undefined;
|