@diegopluna/narvi 0.3.3 → 0.3.5

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.
Files changed (66) hide show
  1. package/dist/components/app-shell/AppShellMain.svelte +14 -2
  2. package/dist/components/app-shell/AppShellPanel.svelte +108 -12
  3. package/dist/components/app-shell/AppShellPanel.svelte.d.ts +11 -1
  4. package/dist/components/app-shell/AppShellSheet.svelte +11 -1
  5. package/dist/components/app-shell/context.d.ts +8 -0
  6. package/dist/components/app-shell/context.js +7 -0
  7. package/dist/components/avatar/AvatarRoot.svelte +20 -7
  8. package/dist/components/avatar/AvatarRoot.svelte.d.ts +10 -3
  9. package/dist/components/badge/Badge.svelte +13 -1
  10. package/dist/components/badge/Badge.svelte.d.ts +6 -0
  11. package/dist/components/button/Button.svelte +71 -32
  12. package/dist/components/button/Button.svelte.d.ts +13 -0
  13. package/dist/components/command/CommandDialog.svelte +24 -2
  14. package/dist/components/command/CommandDialog.svelte.d.ts +12 -0
  15. package/dist/components/command/CommandItem.svelte +15 -4
  16. package/dist/components/command/CommandItem.svelte.d.ts +20 -4
  17. package/dist/components/command/CommandRoot.svelte +57 -2
  18. package/dist/components/command/CommandRoot.svelte.d.ts +25 -1
  19. package/dist/components/composer/ComposerModelPicker.svelte +608 -53
  20. package/dist/components/composer/ComposerModelPicker.svelte.d.ts +56 -1
  21. package/dist/components/composer/ComposerRoot.svelte.d.ts +1 -1
  22. package/dist/components/composer/ComposerSubmit.svelte +12 -2
  23. package/dist/components/composer/ComposerSubmit.svelte.d.ts +6 -0
  24. package/dist/components/composer/index.d.ts +1 -1
  25. package/dist/components/input/Input.svelte.d.ts +1 -1
  26. package/dist/components/menu/MenuCheckboxItem.svelte +14 -5
  27. package/dist/components/menu/MenuCheckboxItem.svelte.d.ts +15 -4
  28. package/dist/components/menu/MenuItem.svelte +9 -3
  29. package/dist/components/menu/MenuItem.svelte.d.ts +11 -4
  30. package/dist/components/menu/MenuRadioItem.svelte +18 -9
  31. package/dist/components/menu/MenuRadioItem.svelte.d.ts +15 -4
  32. package/dist/components/menu/MenuSubTrigger.svelte +9 -3
  33. package/dist/components/menu/MenuSubTrigger.svelte.d.ts +11 -4
  34. package/dist/components/questionnaire/Questionnaire.svelte +100 -9
  35. package/dist/components/questionnaire/Questionnaire.svelte.d.ts +11 -0
  36. package/dist/components/segmented/SegmentedControl.svelte +12 -1
  37. package/dist/components/segmented/SegmentedControl.svelte.d.ts +3 -1
  38. package/dist/components/select/Select.svelte +36 -5
  39. package/dist/components/select/Select.svelte.d.ts +12 -0
  40. package/dist/components/settings-row/SettingsRow.svelte +87 -37
  41. package/dist/components/settings-row/SettingsRow.svelte.d.ts +13 -0
  42. package/dist/components/slider/Slider.svelte.d.ts +2 -2
  43. package/dist/components/split-button/SplitButton.svelte +147 -0
  44. package/dist/components/split-button/SplitButton.svelte.d.ts +36 -0
  45. package/dist/components/tab-strip/TabStrip.svelte +410 -109
  46. package/dist/components/tab-strip/TabStrip.svelte.d.ts +51 -3
  47. package/dist/components/tab-strip/drag.svelte.d.ts +31 -0
  48. package/dist/components/tab-strip/drag.svelte.js +148 -0
  49. package/dist/components/textarea/Textarea.svelte.d.ts +1 -1
  50. package/dist/components/toggle-group/ToggleGroupRoot.svelte.d.ts +1 -1
  51. package/dist/index.d.ts +3 -1
  52. package/dist/index.js +1 -0
  53. package/dist/internal/ItemDescription.svelte +34 -0
  54. package/dist/internal/ItemDescription.svelte.d.ts +10 -0
  55. package/dist/internal/roving.d.ts +3 -1
  56. package/dist/internal/roving.js +6 -3
  57. package/dist/media.stylex.d.ts +6 -0
  58. package/dist/media.stylex.js +6 -0
  59. package/dist/vite.js +4 -0
  60. package/package.json +20 -1
  61. package/skills/building-ui/SKILL.md +48 -20
  62. package/skills/building-ui/references/components.md +43 -42
  63. package/skills/markdown/SKILL.md +1 -1
  64. package/skills/setup/SKILL.md +1 -1
  65. package/skills/styling/SKILL.md +11 -2
  66. 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 data-slot="app-shell-main" {...rest} {...attrs([styles.main, sx], className)}>
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,15 @@
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.
8
+
9
+ It can also stand in a row of your own inside AppShell.Main, beside a thread
10
+ rather than beside the page: a flex row with `position: relative`. It then
11
+ measures that row, and narrow or maximized it lies over the row, whose other
12
+ children are inert underneath.
4
13
  -->
5
14
  <script lang="ts" module>
6
15
  import * as stylex from '@stylexjs/stylex';
@@ -9,7 +18,7 @@
9
18
  import { attrs, type Sx } from '../../internal/sx.js';
10
19
  import { colors } from '../../tokens.stylex.js';
11
20
  import ResizeHandle from '../resize-handle/ResizeHandle.svelte';
12
- import { useAppShell } from './context.js';
21
+ import { getAppShellSheetContext, useAppShell } from './context.js';
13
22
 
14
23
  export type AppShellPanelProps = Omit<HTMLAttributes<HTMLElement>, 'children'> & {
15
24
  /** Names the region: "Changes", "Files". */
@@ -18,8 +27,18 @@
18
27
  width?: number | undefined;
19
28
  minWidth?: number | undefined;
20
29
  defaultWidth?: number | undefined;
21
- /** How much room it always leaves the main area, in pixels. */
30
+ /**
31
+ * How much room it always leaves the main area, in pixels. Where the row has less than
32
+ * this and `minWidth` together, the panel takes the page's place under its header.
33
+ */
22
34
  mainMinWidth?: number | undefined;
35
+ /**
36
+ * Fills the row in the page's place, over its header too, with no handle. The page
37
+ * stays as it was underneath, out of sight and out of reach, until it is restored. Give
38
+ * the panel a header of its own: with `AppShell.Toggle when="closed"` in it, the sidebar
39
+ * stays in reach.
40
+ */
41
+ maximized?: boolean | undefined;
23
42
  sx?: Sx | undefined;
24
43
  children?: Snippet | undefined;
25
44
  };
@@ -38,20 +57,29 @@
38
57
  borderInlineStartWidth: '1px',
39
58
  borderInlineStartStyle: 'solid',
40
59
  borderInlineStartColor: colors.border,
41
- // The traffic lights are never over a panel, so a header inside one keeps no room for them
60
+ // The traffic lights are never over a panel beside the page, so a header inside one
61
+ // keeps no room for them
42
62
  '--narvi-inset-page': '0px'
43
63
  },
44
- // On a narrow window the panel takes the place of the page, under its
45
- // header, which stays in reach with the sidebar's toggle
46
- narrow: {
64
+ // In the page's place: from the sidebar's end (none on a narrow window, where the
65
+ // sidebar is a drawer) to the sheet's
66
+ over: {
47
67
  position: 'absolute',
48
- inset: 0,
49
- top: '3rem',
68
+ insetBlockEnd: 0,
69
+ insetInlineStart: 'var(--narvi-panel-start, 0px)',
70
+ insetInlineEnd: 0,
50
71
  zIndex: 5,
51
72
  width: 'auto',
52
73
  borderInlineStartWidth: 0,
53
74
  backgroundColor: colors.bgRaised
54
75
  },
76
+ // Under the page's header, which stays in reach with the sidebar's toggle
77
+ narrow: { insetBlockStart: '3rem' },
78
+ // In a row of the caller's own, over the whole row: its header is the panel's
79
+ inRow: { insetBlockStart: 0, insetInlineStart: 0 },
80
+ // Over all of the page. Where the page's header kept room for the traffic lights, the
81
+ // panel's own header keeps it now.
82
+ maximized: { insetBlockStart: 0, '--narvi-inset-page': 'inherit' },
55
83
  handle: { position: 'relative', alignSelf: 'stretch' }
56
84
  });
57
85
  </script>
@@ -63,6 +91,7 @@
63
91
  minWidth = 320,
64
92
  defaultWidth = 560,
65
93
  mainMinWidth = 352,
94
+ maximized = false,
66
95
  sx,
67
96
  class: className,
68
97
  children,
@@ -70,21 +99,76 @@
70
99
  }: AppShellPanelProps = $props();
71
100
 
72
101
  const shell = useAppShell('Panel');
102
+ const sheetContext = getAppShellSheetContext();
73
103
  let element = $state<HTMLElement | null>(null);
104
+ // The room the row gives the page and the panel together, and where that room starts
105
+ let row = $state(Infinity);
106
+ let start = $state(0);
107
+ // Placed straight in the sheet, beside the page; otherwise in a row of the caller's own
108
+ let inSheet = $state(true);
109
+
110
+ const sidebarOf = (sheet: Element | null | undefined) =>
111
+ sheet?.querySelector<HTMLElement>(':scope > [data-slot="app-shell-sidebar"]') ?? null;
112
+
113
+ // The row is measured, not the window: a sheet among several panes is narrower than it
114
+ $effect(() => {
115
+ const sheet = element?.parentElement;
116
+ if (!sheet) return;
117
+ inSheet = sheet.dataset.slot === 'app-shell-sheet';
118
+ const measure = () => {
119
+ const sidebar = sidebarOf(sheet);
120
+ // A drawer is over the page, not beside it
121
+ const beside = shell.narrow && inSheet ? 0 : (sidebar?.offsetWidth ?? 0);
122
+ row = sheet.clientWidth - beside;
123
+ start = beside;
124
+ };
125
+ measure();
126
+ const observer = new ResizeObserver(measure);
127
+ observer.observe(sheet);
128
+ const sidebar = sidebarOf(sheet);
129
+ if (sidebar) observer.observe(sidebar);
130
+ return () => observer.disconnect();
131
+ });
132
+
133
+ const narrow = $derived((inSheet && shell.narrow) || row < minWidth + Math.max(mainMinWidth, 0));
134
+ const over = $derived(maximized || narrow);
135
+
136
+ // The page steps out of view under a maximized panel
137
+ $effect(() => {
138
+ if (!sheetContext || !maximized || !inSheet) return;
139
+ sheetContext.setCovered(true);
140
+ return () => sheetContext.setCovered(false);
141
+ });
142
+
143
+ // In a row of the caller's own, what the panel lies over is out of reach underneath:
144
+ // its siblings are inert, and come back as they were
145
+ $effect(() => {
146
+ const parent = element?.parentElement;
147
+ if (inSheet || !over || !parent || !element) return;
148
+ const covered = [...parent.children].filter(
149
+ (child): child is HTMLElement =>
150
+ child instanceof HTMLElement && child !== element && !child.inert
151
+ );
152
+ for (const child of covered) child.inert = true;
153
+ return () => {
154
+ for (const child of covered) child.inert = false;
155
+ };
156
+ });
74
157
 
75
158
  // It never takes so much that the main area falls below its minimum
76
159
  const largest = () => {
77
160
  // On the server there is no window to measure: no limit yet
78
161
  if (typeof window === 'undefined') return Infinity;
79
162
  const sheet = element?.parentElement;
80
- const sidebar = sheet?.querySelector<HTMLElement>(':scope > [data-slot="app-shell-sidebar"]');
81
163
  return (
82
- (sheet?.clientWidth ?? innerWidth) - (sidebar?.offsetWidth ?? 0) - Math.max(mainMinWidth, 0)
164
+ (sheet?.clientWidth ?? innerWidth) -
165
+ (sidebarOf(sheet)?.offsetWidth ?? 0) -
166
+ Math.max(mainMinWidth, 0)
83
167
  );
84
168
  };
85
169
  </script>
86
170
 
87
- {#if !shell.narrow}
171
+ {#if !over}
88
172
  <ResizeHandle
89
173
  bind:value={width}
90
174
  min={minWidth}
@@ -101,9 +185,21 @@
101
185
  bind:this={element}
102
186
  aria-label={label}
103
187
  data-slot="app-shell-panel"
188
+ data-maximized={maximized || undefined}
189
+ data-narrow={(narrow && !maximized) || undefined}
104
190
  style:--narvi-panel-width="{width}px"
191
+ style:--narvi-panel-start="{start}px"
105
192
  {...rest}
106
- {...attrs([styles.panel, shell.narrow && styles.narrow, sx], className)}
193
+ {...attrs(
194
+ [
195
+ styles.panel,
196
+ over && styles.over,
197
+ maximized ? styles.maximized : narrow && styles.narrow,
198
+ over && !inSheet && styles.inRow,
199
+ sx
200
+ ],
201
+ className
202
+ )}
107
203
  >
108
204
  {@render children?.()}
109
205
  </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
- /** How much room it always leaves the main area, in pixels. */
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
- export type AvatarSize = 'sm' | 'md' | 'lg' | 'xl';
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 becomes the avatar's accessible name and picks the
14
- * colour behind the initials, so each person keeps theirs.
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: '0.6875rem' },
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={name ? 'img' : undefined}
100
- aria-label={name}
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
- export type AvatarSize = 'sm' | 'md' | 'lg' | 'xl';
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 becomes the avatar's accessible name and picks the
8
- * colour behind the initials, so each person keeps theirs.
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;
@@ -12,6 +12,12 @@
12
12
  export type BadgeProps = Omit<HTMLAttributes<HTMLSpanElement>, 'children'> & {
13
13
  /** Colour of the dot. The words stay in the text colour, so they are always readable. */
14
14
  tone?: BadgeTone | undefined;
15
+ /**
16
+ * The dot in a colour of its own, any CSS colour, in place of a tone's: a label's colour
17
+ * as its owner chose it, such as a GitHub label's `#d73a4a`. Only the dot takes it, so the
18
+ * words stay readable whatever the colour.
19
+ */
20
+ color?: string | undefined;
15
21
  /**
16
22
  * Hides the dot, for a plain label or a count. A tone then colours the words, in its
17
23
  * text colour, which holds its contrast on a badge's own surface.
@@ -79,6 +85,7 @@
79
85
  <script lang="ts">
80
86
  let {
81
87
  tone = 'neutral',
88
+ color,
82
89
  plain = false,
83
90
  size = 'md',
84
91
  sx,
@@ -104,7 +111,12 @@
104
111
  )}
105
112
  >
106
113
  {#if !plain}
107
- <span aria-hidden="true" {...stylex.attrs(styles.dot, dots[tone])}></span>
114
+ <!-- A colour of the caller's own is set on the dot itself; forced colours keep it, as a tone's -->
115
+ <span
116
+ aria-hidden="true"
117
+ {...stylex.attrs(styles.dot, !color && dots[tone])}
118
+ style:background-color={color}
119
+ ></span>
108
120
  {/if}
109
121
  {@render children?.()}
110
122
  </span>
@@ -6,6 +6,12 @@ export type BadgeTone = 'neutral' | 'accent' | 'info' | 'success' | 'warning' |
6
6
  export type BadgeProps = Omit<HTMLAttributes<HTMLSpanElement>, 'children'> & {
7
7
  /** Colour of the dot. The words stay in the text colour, so they are always readable. */
8
8
  tone?: BadgeTone | undefined;
9
+ /**
10
+ * The dot in a colour of its own, any CSS colour, in place of a tone's: a label's colour
11
+ * as its owner chose it, such as a GitHub label's `#d73a4a`. Only the dot takes it, so the
12
+ * words stay readable whatever the colour.
13
+ */
14
+ color?: string | undefined;
9
15
  /**
10
16
  * Hides the dot, for a plain label or a count. A tone then colours the words, in its
11
17
  * text colour, which holds its contrast on a badge's own surface.
@@ -7,6 +7,8 @@
7
7
  import { colors, font, motion, radius } from '../../tokens.stylex.js';
8
8
  import { media } from '../../media.stylex.js';
9
9
  import Spinner from '../spinner/Spinner.svelte';
10
+ import * as Tooltip from '../tooltip/index.js';
11
+ import { mergeProps } from 'bits-ui';
10
12
  import '../../internal/icons.css';
11
13
 
12
14
  /**
@@ -44,8 +46,21 @@
44
46
  */
45
47
  loadingLabel?: string | undefined;
46
48
  disabled?: boolean | undefined;
49
+ /**
50
+ * Makes it a toggle button (`aria-pressed`), held in its open look while true: a
51
+ * toolbar's button that shows or hides something. `secondary` and `ghost` take the fill
52
+ * of what is chosen, `floating` its stronger edge, `bare` its full ink. For a toggle lit
53
+ * in the accent, use Toggle.
54
+ */
55
+ pressed?: boolean | undefined;
47
56
  /** Square button for a single icon. Give it an `aria-label`. */
48
57
  iconOnly?: boolean | undefined;
58
+ /**
59
+ * A tooltip, shown as the pointer rests on it or the keyboard reaches it: words, or a
60
+ * snippet for words with a shortcut. It says more than the button's name, which stays as
61
+ * it is. It waits 400ms, as Narvi's other parts' tooltips do.
62
+ */
63
+ tooltip?: string | Snippet | undefined;
49
64
  /** Renders a link styled as a button. */
50
65
  href?: string | undefined;
51
66
  sx?: Sx | undefined;
@@ -58,7 +73,9 @@
58
73
  // The trigger of a menu, a popover or a select while what it opened is showing. bits-ui
59
74
  // marks it with `aria-expanded`, which a disclosure's trigger carries too: only a popup's
60
75
  // (`aria-haspopup`) is held in its open look.
61
- const OPEN = ':is([aria-haspopup]:not([aria-haspopup="false"])[aria-expanded="true"])';
76
+ // A toggle button that is pressed holds the same look.
77
+ const OPEN =
78
+ ':is([aria-haspopup]:not([aria-haspopup="false"])[aria-expanded="true"], [aria-pressed="true"])';
62
79
 
63
80
  const styles = stylex.create({
64
81
  base: {
@@ -444,7 +461,9 @@
444
461
  loading = false,
445
462
  loadingLabel,
446
463
  disabled = false,
464
+ pressed,
447
465
  iconOnly = false,
466
+ tooltip,
448
467
  href,
449
468
  type = 'button',
450
469
  sx,
@@ -492,36 +511,56 @@
492
511
  {/if}
493
512
  {/snippet}
494
513
 
495
- {#if href !== undefined}
496
- <a
497
- bind:this={ref}
498
- data-icons
499
- href={inert ? undefined : href}
500
- role={inert ? 'link' : undefined}
501
- aria-disabled={inert ? true : undefined}
502
- aria-busy={loading ? true : undefined}
503
- {...rest}
504
- {...rootAttrs}
505
- >
506
- {@render content()}
507
- </a>
514
+ <!-- The element, with a tooltip trigger's props when it has a tooltip -->
515
+ {#snippet control(trigger: Record<string, unknown>)}
516
+ {@const own = Object.keys(trigger).length ? mergeProps(rest, trigger) : rest}
517
+ {#if href !== undefined}
518
+ <a
519
+ bind:this={ref}
520
+ data-icons
521
+ href={inert ? undefined : href}
522
+ role={inert ? 'link' : undefined}
523
+ aria-disabled={inert ? true : undefined}
524
+ aria-busy={loading ? true : undefined}
525
+ {...own}
526
+ {...rootAttrs}
527
+ >
528
+ {@render content()}
529
+ </a>
530
+ {:else}
531
+ <button
532
+ bind:this={ref}
533
+ data-icons
534
+ {type}
535
+ disabled={disabled || undefined}
536
+ aria-pressed={pressed}
537
+ aria-disabled={loading ? true : undefined}
538
+ aria-busy={loading ? true : undefined}
539
+ {...own}
540
+ {...rootAttrs}
541
+ onclick={loading
542
+ ? (event: MouseEvent) => {
543
+ event.preventDefault();
544
+ event.stopPropagation();
545
+ }
546
+ : (own.onclick as HTMLButtonAttributes['onclick'])}
547
+ >
548
+ {@render content()}
549
+ </button>
550
+ {/if}
551
+ {/snippet}
552
+
553
+ {#if tooltip}
554
+ <Tooltip.Provider delayDuration={400}>
555
+ <Tooltip.Root>
556
+ <Tooltip.Trigger>
557
+ {#snippet child({ props })}{@render control(props)}{/snippet}
558
+ </Tooltip.Trigger>
559
+ <Tooltip.Content>
560
+ {#if typeof tooltip === 'function'}{@render tooltip()}{:else}{tooltip}{/if}
561
+ </Tooltip.Content>
562
+ </Tooltip.Root>
563
+ </Tooltip.Provider>
508
564
  {:else}
509
- <button
510
- bind:this={ref}
511
- data-icons
512
- {type}
513
- disabled={disabled || undefined}
514
- aria-disabled={loading ? true : undefined}
515
- aria-busy={loading ? true : undefined}
516
- {...rest}
517
- {...rootAttrs}
518
- onclick={loading
519
- ? (event) => {
520
- event.preventDefault();
521
- event.stopPropagation();
522
- }
523
- : rest.onclick}
524
- >
525
- {@render content()}
526
- </button>
565
+ {@render control({})}
527
566
  {/if}
@@ -24,8 +24,21 @@ 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;
36
+ /**
37
+ * A tooltip, shown as the pointer rests on it or the keyboard reaches it: words, or a
38
+ * snippet for words with a shortcut. It says more than the button's name, which stays as
39
+ * it is. It waits 400ms, as Narvi's other parts' tooltips do.
40
+ */
41
+ tooltip?: string | Snippet | undefined;
29
42
  /** Renders a link styled as a button. */
30
43
  href?: string | undefined;
31
44
  sx?: Sx | undefined;
@@ -11,6 +11,18 @@
11
11
  export type CommandDialogProps = {
12
12
  /** Whether it is open. Bindable. */
13
13
  open?: boolean | undefined;
14
+ /** Called as it opens or closes. */
15
+ onopenchange?: ((open: boolean) => void) | undefined;
16
+ /**
17
+ * Called as Escape is pressed. Call `event.preventDefault()` to keep it open: to go back
18
+ * a step of a palette that has several, or to wait while something is on its way.
19
+ */
20
+ onescape?: ((event: KeyboardEvent) => void) | undefined;
21
+ /**
22
+ * Whether focus goes back where it was as it closes. Pass `false` after a command that
23
+ * put the focus somewhere of its own, such as a thread it opened.
24
+ */
25
+ restoreFocus?: boolean | undefined;
14
26
  /** What the palette is, for assistive technology. */
15
27
  label?: string | undefined;
16
28
  /** A Command.Root with its Input, List and Footer. */
@@ -22,14 +34,24 @@
22
34
  let {
23
35
  open = $bindable(false),
24
36
  label = 'Command palette',
37
+ onopenchange,
38
+ onescape,
39
+ restoreFocus = true,
25
40
  children
26
41
  }: CommandDialogProps = $props();
27
42
  </script>
28
43
 
29
- <Dialog.Root bind:open>
44
+ <Dialog.Root bind:open onOpenChange={onopenchange}>
30
45
  <Dialog.Portal>
31
46
  <Dialog.Overlay {...stylex.attrs(command.overlay)} />
32
- <Dialog.Content data-slot="command-dialog" {...stylex.attrs(command.dialog)}>
47
+ <Dialog.Content
48
+ data-slot="command-dialog"
49
+ onEscapeKeydown={onescape}
50
+ onCloseAutoFocus={(event) => {
51
+ if (!restoreFocus) event.preventDefault();
52
+ }}
53
+ {...stylex.attrs(command.dialog)}
54
+ >
33
55
  <Dialog.Title {...stylex.attrs(command.hidden)}>{label}</Dialog.Title>
34
56
  {@render children?.()}
35
57
  </Dialog.Content>
@@ -2,6 +2,18 @@ import type { Snippet } from 'svelte';
2
2
  export type CommandDialogProps = {
3
3
  /** Whether it is open. Bindable. */
4
4
  open?: boolean | undefined;
5
+ /** Called as it opens or closes. */
6
+ onopenchange?: ((open: boolean) => void) | undefined;
7
+ /**
8
+ * Called as Escape is pressed. Call `event.preventDefault()` to keep it open: to go back
9
+ * a step of a palette that has several, or to wait while something is on its way.
10
+ */
11
+ onescape?: ((event: KeyboardEvent) => void) | undefined;
12
+ /**
13
+ * Whether focus goes back where it was as it closes. Pass `false` after a command that
14
+ * put the focus somewhere of its own, such as a thread it opened.
15
+ */
16
+ restoreFocus?: boolean | undefined;
5
17
  /** What the palette is, for assistive technology. */
6
18
  label?: string | undefined;
7
19
  /** A Command.Root with its Input, List and Footer. */