@diegopluna/narvi 0.3.5 → 0.3.7

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 (43) hide show
  1. package/dist/components/app-shell/AppShellPanel.svelte +37 -11
  2. package/dist/components/app-shell/AppShellPanel.svelte.d.ts +13 -0
  3. package/dist/components/button/Button.svelte +24 -5
  4. package/dist/components/button/Button.svelte.d.ts +13 -1
  5. package/dist/components/command/CommandDialog.svelte +9 -2
  6. package/dist/components/command/CommandDialog.svelte.d.ts +4 -0
  7. package/dist/components/command/CommandEmpty.svelte +38 -4
  8. package/dist/components/command/CommandEmpty.svelte.d.ts +18 -2
  9. package/dist/components/command/CommandFooter.svelte +5 -7
  10. package/dist/components/command/CommandFooter.svelte.d.ts +4 -1
  11. package/dist/components/command/CommandInput.svelte +13 -1
  12. package/dist/components/command/CommandInput.svelte.d.ts +11 -0
  13. package/dist/components/command/CommandItem.svelte +32 -6
  14. package/dist/components/command/CommandItem.svelte.d.ts +20 -0
  15. package/dist/components/command/CommandRoot.svelte +68 -9
  16. package/dist/components/command/CommandRoot.svelte.d.ts +13 -3
  17. package/dist/components/command/styles.d.ts +50 -8
  18. package/dist/components/command/styles.js +50 -8
  19. package/dist/components/menu/MenuContent.svelte +7 -1
  20. package/dist/components/menu/MenuContent.svelte.d.ts +10 -0
  21. package/dist/components/queued-message/QueuedMessage.svelte +3 -2
  22. package/dist/components/rail/RailRoot.svelte +3 -3
  23. package/dist/components/segmented/SegmentedControl.svelte +2 -1
  24. package/dist/components/settings-row/SettingsRow.svelte +3 -2
  25. package/dist/components/split-button/SplitButton.svelte +58 -16
  26. package/dist/components/split-button/SplitButton.svelte.d.ts +22 -5
  27. package/dist/components/tabs/Tabs.svelte +2 -1
  28. package/dist/components/tooltip/TooltipProvider.svelte +23 -0
  29. package/dist/components/tooltip/TooltipProvider.svelte.d.ts +8 -0
  30. package/dist/components/tooltip/index.d.ts +4 -5
  31. package/dist/components/tooltip/index.js +3 -5
  32. package/dist/index.d.ts +2 -2
  33. package/dist/internal/TooltipScope.svelte +19 -0
  34. package/dist/internal/TooltipScope.svelte.d.ts +7 -0
  35. package/dist/internal/layer.d.ts +6 -3
  36. package/dist/internal/layer.js +13 -6
  37. package/package.json +1 -1
  38. package/skills/building-ui/SKILL.md +32 -32
  39. package/skills/building-ui/references/components.md +71 -32
  40. package/skills/markdown/SKILL.md +1 -1
  41. package/skills/setup/SKILL.md +1 -1
  42. package/skills/styling/SKILL.md +1 -1
  43. package/skills/theming/SKILL.md +1 -1
@@ -1,3 +1,12 @@
1
+ <!--
2
+ A list to search and choose from with the keys: the arrows, Page Up and Page
3
+ Down move the highlight, Home and End reach its ends, and Enter chooses.
4
+
5
+ The keys are the list's only where the person is in it: on the root, or in its
6
+ Command.Input. A button, a field or a form of the caller's own inside the root
7
+ keeps its keys, Enter among them, and the search field keeps Home and End to
8
+ move its caret.
9
+ -->
1
10
  <script lang="ts" module>
2
11
  import type { Loose } from '../../internal/loose.js';
3
12
  import { Command } from 'bits-ui';
@@ -9,7 +18,7 @@
9
18
  Omit<Command.RootProps, 'children' | 'child'> & {
10
19
  /**
11
20
  * The value of the highlighted item. Bindable: set it to move the highlight from
12
- * outside, such as back to the first result as the app's own results change.
21
+ * outside. When the highlighted item goes, the highlight goes back to the first.
13
22
  */
14
23
  value?: string | undefined;
15
24
  /**
@@ -17,6 +26,11 @@
17
26
  * to rank them yourself and list only those that match: results from a server, say.
18
27
  */
19
28
  shouldFilter?: boolean | undefined;
29
+ /**
30
+ * Whether Ctrl with J and N, or K and P, moves the highlight too, as in Vim and Emacs.
31
+ * Off, those keys are left to the app's own shortcuts.
32
+ */
33
+ vimBindings?: boolean | undefined;
20
34
  sx?: Sx | undefined;
21
35
  /** A Command.Input, a Command.List and, if you like, a Command.Footer. */
22
36
  children?: Snippet | undefined;
@@ -25,12 +39,17 @@
25
39
 
26
40
  // Page Up and Page Down move the highlight this many items
27
41
  const PAGE = 8;
42
+
43
+ // What a caret moves through, where Home and End are the field's
44
+ const FIELD = '[data-command-input]';
28
45
  </script>
29
46
 
30
47
  <script lang="ts">
31
48
  let {
32
49
  value = $bindable(''),
50
+ ref = $bindable(null),
33
51
  loop = true,
52
+ vimBindings = false,
34
53
  sx,
35
54
  class: className,
36
55
  children,
@@ -57,22 +76,62 @@
57
76
  const at = items.findIndex((item) => item.hasAttribute('data-selected'));
58
77
  highlight(Math.min(Math.max((at === -1 ? 0 : at) + step, 0), items.length - 1));
59
78
  }
79
+
80
+ const keydown = (
81
+ event: KeyboardEvent & { currentTarget: HTMLDivElement },
82
+ list: ((event: KeyboardEvent) => void) | undefined
83
+ ) => {
84
+ onkeydown?.(event);
85
+ // A word being composed keeps its keys (229: Safari's Japanese input, which sends no
86
+ // `isComposing`)
87
+ if (event.defaultPrevented || event.isComposing || event.keyCode === 229) return;
88
+ const target = event.target instanceof Element ? event.target : null;
89
+ const inField = !!target?.matches(FIELD);
90
+ if (target !== event.currentTarget && !inField) return;
91
+ if (inField && (event.key === 'Home' || event.key === 'End')) return;
92
+ if (event.key === 'PageDown' || event.key === 'PageUp') {
93
+ event.preventDefault();
94
+ move(event.key === 'PageDown' ? PAGE : -PAGE);
95
+ return;
96
+ }
97
+ list?.(event);
98
+ };
99
+
100
+ // bits-ui means to move the highlight as its item goes, but compares the item's value with
101
+ // the element's id, so it never does. Here, once the items change, a highlight left on one
102
+ // that is gone goes back to the first.
103
+ $effect(() => {
104
+ const node = ref;
105
+ if (!node) return;
106
+ const observer = new MutationObserver(() => {
107
+ const items = getValidItems();
108
+ if (!items.length || items.some((item) => item.dataset.value === value)) return;
109
+ highlight(0);
110
+ });
111
+ observer.observe(node, { childList: true, subtree: true });
112
+ return () => observer.disconnect();
113
+ });
60
114
  </script>
61
115
 
62
116
  <Command.Root
63
117
  bind:this={root}
64
118
  bind:value
119
+ bind:ref
65
120
  {loop}
121
+ {vimBindings}
66
122
  data-slot="command"
67
123
  {...rest}
68
- onkeydown={(event: KeyboardEvent & { currentTarget: HTMLDivElement }) => {
69
- onkeydown?.(event);
70
- if (event.defaultPrevented || event.isComposing) return;
71
- if (event.key !== 'PageDown' && event.key !== 'PageUp') return;
72
- event.preventDefault();
73
- move(event.key === 'PageDown' ? PAGE : -PAGE);
74
- }}
75
124
  {...attrs([command.root, sx], className)}
76
125
  >
77
- {@render children?.()}
126
+ {#snippet child({ props })}
127
+ {@const { onkeydown: list, ...own } = props as typeof props & {
128
+ onkeydown?: (event: KeyboardEvent) => void;
129
+ }}
130
+ <div
131
+ {...own}
132
+ onkeydown={(event: KeyboardEvent & { currentTarget: HTMLDivElement }) => keydown(event, list)}
133
+ >
134
+ {@render children?.()}
135
+ </div>
136
+ {/snippet}
78
137
  </Command.Root>
@@ -5,7 +5,7 @@ import { type Sx } from '../../internal/sx.js';
5
5
  export type CommandRootProps = Loose<Omit<Command.RootProps, 'children' | 'child'> & {
6
6
  /**
7
7
  * The value of the highlighted item. Bindable: set it to move the highlight from
8
- * outside, such as back to the first result as the app's own results change.
8
+ * outside. When the highlighted item goes, the highlight goes back to the first.
9
9
  */
10
10
  value?: string | undefined;
11
11
  /**
@@ -13,6 +13,11 @@ export type CommandRootProps = Loose<Omit<Command.RootProps, 'children' | 'child
13
13
  * to rank them yourself and list only those that match: results from a server, say.
14
14
  */
15
15
  shouldFilter?: boolean | undefined;
16
+ /**
17
+ * Whether Ctrl with J and N, or K and P, moves the highlight too, as in Vim and Emacs.
18
+ * Off, those keys are left to the app's own shortcuts.
19
+ */
20
+ vimBindings?: boolean | undefined;
16
21
  sx?: Sx | undefined;
17
22
  /** A Command.Input, a Command.List and, if you like, a Command.Footer. */
18
23
  children?: Snippet | undefined;
@@ -20,7 +25,7 @@ export type CommandRootProps = Loose<Omit<Command.RootProps, 'children' | 'child
20
25
  declare const CommandRoot: import("svelte").Component<Loose<Omit<Command.RootProps, "children" | "child"> & {
21
26
  /**
22
27
  * The value of the highlighted item. Bindable: set it to move the highlight from
23
- * outside, such as back to the first result as the app's own results change.
28
+ * outside. When the highlighted item goes, the highlight goes back to the first.
24
29
  */
25
30
  value?: string | undefined;
26
31
  /**
@@ -28,6 +33,11 @@ declare const CommandRoot: import("svelte").Component<Loose<Omit<Command.RootPro
28
33
  * to rank them yourself and list only those that match: results from a server, say.
29
34
  */
30
35
  shouldFilter?: boolean | undefined;
36
+ /**
37
+ * Whether Ctrl with J and N, or K and P, moves the highlight too, as in Vim and Emacs.
38
+ * Off, those keys are left to the app's own shortcuts.
39
+ */
40
+ vimBindings?: boolean | undefined;
31
41
  sx?: Sx | undefined;
32
42
  /** A Command.Input, a Command.List and, if you like, a Command.Footer. */
33
43
  children?: Snippet | undefined;
@@ -35,6 +45,6 @@ declare const CommandRoot: import("svelte").Component<Loose<Omit<Command.RootPro
35
45
  getValidItems: () => HTMLElement[];
36
46
  highlight: (index: number) => void;
37
47
  move: (step: number) => void;
38
- }, "value">;
48
+ }, "ref" | "value">;
39
49
  type CommandRoot = ReturnType<typeof CommandRoot>;
40
50
  export default CommandRoot;
@@ -65,11 +65,61 @@ export declare const command: Readonly<{
65
65
  readonly textOverflow: stylex.StyleXClassNameFor<"textOverflow", "ellipsis">;
66
66
  readonly whiteSpace: stylex.StyleXClassNameFor<"whiteSpace", "nowrap">;
67
67
  }>;
68
+ readonly end: Readonly<{
69
+ readonly display: stylex.StyleXClassNameFor<"display", "flex">;
70
+ readonly alignItems: stylex.StyleXClassNameFor<"alignItems", "center">;
71
+ readonly gap: stylex.StyleXClassNameFor<"gap", "0.125rem">;
72
+ readonly flexShrink: stylex.StyleXClassNameFor<"flexShrink", 0>;
73
+ readonly marginInlineEnd: stylex.StyleXClassNameFor<"marginInlineEnd", "-0.5rem">;
74
+ }>;
75
+ readonly badge: Readonly<{
76
+ readonly '--narvi-icon-size': stylex.StyleXClassNameFor<"--narvi-icon-size", "0.875rem">;
77
+ readonly display: stylex.StyleXClassNameFor<"display", "inline-flex">;
78
+ readonly alignItems: stylex.StyleXClassNameFor<"alignItems", "center">;
79
+ readonly marginInlineStart: stylex.StyleXClassNameFor<"marginInlineStart", string>;
80
+ readonly verticalAlign: stylex.StyleXClassNameFor<"verticalAlign", "middle">;
81
+ readonly color: stylex.StyleXClassNameFor<"color", string>;
82
+ }>;
83
+ readonly wrapRow: Readonly<{
84
+ readonly flexGrow: stylex.StyleXClassNameFor<"flexGrow", 1>;
85
+ readonly display: stylex.StyleXClassNameFor<"display", "flex">;
86
+ readonly alignItems: stylex.StyleXClassNameFor<"alignItems", "center">;
87
+ readonly gap: stylex.StyleXClassNameFor<"gap", string>;
88
+ readonly minWidth: stylex.StyleXClassNameFor<"minWidth", 0>;
89
+ readonly paddingBlock: stylex.StyleXClassNameFor<"paddingBlock", "0.375rem">;
90
+ }>;
91
+ readonly wrapLabel: Readonly<{
92
+ readonly minWidth: stylex.StyleXClassNameFor<"minWidth", 0>;
93
+ readonly overflow: stylex.StyleXClassNameFor<"overflow", "hidden">;
94
+ readonly textOverflow: stylex.StyleXClassNameFor<"textOverflow", "ellipsis">;
95
+ readonly whiteSpace: stylex.StyleXClassNameFor<"whiteSpace", "nowrap">;
96
+ }>;
97
+ readonly wrapped: Readonly<{
98
+ readonly display: stylex.StyleXClassNameFor<"display", "-webkit-box">;
99
+ readonly flexShrink: stylex.StyleXClassNameFor<"flexShrink", 1000>;
100
+ readonly minWidth: stylex.StyleXClassNameFor<"minWidth", 0>;
101
+ readonly overflow: stylex.StyleXClassNameFor<"overflow", "hidden">;
102
+ readonly overflowWrap: stylex.StyleXClassNameFor<"overflowWrap", "anywhere">;
103
+ readonly color: stylex.StyleXClassNameFor<"color", string>;
104
+ readonly fontSize: stylex.StyleXClassNameFor<"fontSize", string>;
105
+ readonly WebkitBoxOrient: stylex.StyleXClassNameFor<"WebkitBoxOrient", "vertical">;
106
+ readonly WebkitLineClamp: stylex.StyleXClassNameFor<"WebkitLineClamp", 2>;
107
+ }>;
68
108
  readonly empty: Readonly<{
69
109
  readonly paddingBlock: stylex.StyleXClassNameFor<"paddingBlock", string>;
110
+ readonly paddingInline: stylex.StyleXClassNameFor<"paddingInline", string>;
70
111
  readonly color: stylex.StyleXClassNameFor<"color", string>;
71
112
  readonly textAlign: stylex.StyleXClassNameFor<"textAlign", "center">;
72
113
  }>;
114
+ readonly emptyLoading: Readonly<{
115
+ readonly display: stylex.StyleXClassNameFor<"display", "flex">;
116
+ readonly alignItems: stylex.StyleXClassNameFor<"alignItems", "center">;
117
+ readonly justifyContent: stylex.StyleXClassNameFor<"justifyContent", "center">;
118
+ readonly gap: stylex.StyleXClassNameFor<"gap", string>;
119
+ }>;
120
+ readonly emptyError: Readonly<{
121
+ readonly color: stylex.StyleXClassNameFor<"color", string>;
122
+ }>;
73
123
  readonly footer: Readonly<{
74
124
  readonly display: stylex.StyleXClassNameFor<"display", "flex">;
75
125
  readonly alignItems: stylex.StyleXClassNameFor<"alignItems", "center">;
@@ -107,12 +157,4 @@ export declare const command: Readonly<{
107
157
  readonly zIndex: stylex.StyleXClassNameFor<"zIndex", 50>;
108
158
  readonly backgroundColor: stylex.StyleXClassNameFor<"backgroundColor", `color-mix(in oklab, ${stylex.StyleXVar<string>} 70%, transparent)`>;
109
159
  }>;
110
- readonly hidden: Readonly<{
111
- readonly position: stylex.StyleXClassNameFor<"position", "absolute">;
112
- readonly width: stylex.StyleXClassNameFor<"width", "1px">;
113
- readonly height: stylex.StyleXClassNameFor<"height", "1px">;
114
- readonly overflow: stylex.StyleXClassNameFor<"overflow", "hidden">;
115
- readonly clipPath: stylex.StyleXClassNameFor<"clipPath", "inset(50%)">;
116
- readonly whiteSpace: stylex.StyleXClassNameFor<"whiteSpace", "nowrap">;
117
- }>;
118
160
  }>;
@@ -69,11 +69,61 @@ export const command = stylex.create({
69
69
  textOverflow: 'ellipsis',
70
70
  whiteSpace: 'nowrap'
71
71
  },
72
+ // Controls after the field, a little nearer the edge than the words start
73
+ end: {
74
+ display: 'flex',
75
+ alignItems: 'center',
76
+ gap: '0.125rem',
77
+ flexShrink: 0,
78
+ marginInlineEnd: '-0.5rem'
79
+ },
80
+ badge: {
81
+ '--narvi-icon-size': '0.875rem',
82
+ display: 'inline-flex',
83
+ alignItems: 'center',
84
+ marginInlineStart: space.x2,
85
+ verticalAlign: 'middle',
86
+ color: colors.textMuted
87
+ },
88
+ // A detail that wraps: beside the label, up to two lines, and the first to give way
89
+ wrapRow: {
90
+ flexGrow: 1,
91
+ display: 'flex',
92
+ alignItems: 'center',
93
+ gap: space.x2,
94
+ minWidth: 0,
95
+ paddingBlock: '0.375rem'
96
+ },
97
+ wrapLabel: {
98
+ minWidth: 0,
99
+ overflow: 'hidden',
100
+ textOverflow: 'ellipsis',
101
+ whiteSpace: 'nowrap'
102
+ },
103
+ wrapped: {
104
+ display: '-webkit-box',
105
+ flexShrink: 1000,
106
+ minWidth: 0,
107
+ overflow: 'hidden',
108
+ overflowWrap: 'anywhere',
109
+ color: colors.textSubtle,
110
+ fontSize: font.sizeMeta,
111
+ WebkitBoxOrient: 'vertical',
112
+ WebkitLineClamp: 2
113
+ },
72
114
  empty: {
73
115
  paddingBlock: space.x8,
116
+ paddingInline: space.x4,
74
117
  color: colors.textMuted,
75
118
  textAlign: 'center'
76
119
  },
120
+ emptyLoading: {
121
+ display: 'flex',
122
+ alignItems: 'center',
123
+ justifyContent: 'center',
124
+ gap: space.x2
125
+ },
126
+ emptyError: { color: colors.dangerText },
77
127
  footer: {
78
128
  display: 'flex',
79
129
  alignItems: 'center',
@@ -112,13 +162,5 @@ export const command = stylex.create({
112
162
  zIndex: 50,
113
163
  // Lighter than a dialog's: the page behind is what is being searched
114
164
  backgroundColor: `color-mix(in oklab, ${colors.scrim} 70%, transparent)`
115
- },
116
- hidden: {
117
- position: 'absolute',
118
- width: '1px',
119
- height: '1px',
120
- overflow: 'hidden',
121
- clipPath: 'inset(50%)',
122
- whiteSpace: 'nowrap'
123
165
  }
124
166
  });
@@ -12,6 +12,11 @@
12
12
  * the trigger's width, up to 22rem). It is still no wider than the window has room for.
13
13
  */
14
14
  width?: string | undefined;
15
+ /**
16
+ * How wide it is at least, such as `16rem`, in place of 12rem: it still fits its items,
17
+ * up to 22rem, and is at least as wide as its trigger.
18
+ */
19
+ minWidth?: string | undefined;
15
20
  sx?: Sx | undefined;
16
21
  children?: Snippet | undefined;
17
22
  }
@@ -23,6 +28,7 @@
23
28
  sideOffset = 6,
24
29
  collisionPadding = 8,
25
30
  width,
31
+ minWidth,
26
32
  style,
27
33
  align = 'start',
28
34
  sx,
@@ -39,7 +45,7 @@
39
45
  {align}
40
46
  data-slot="menu-content"
41
47
  {...rest}
42
- style={widthStyle(width, style)}
48
+ style={widthStyle(width, style, minWidth)}
43
49
  {...attrs([layer.surface, !!width && layer.sized, sx], className)}
44
50
  >
45
51
  {@render children?.()}
@@ -8,6 +8,11 @@ export type MenuContentProps = Loose<Omit<DropdownMenu.ContentProps, 'children'
8
8
  * the trigger's width, up to 22rem). It is still no wider than the window has room for.
9
9
  */
10
10
  width?: string | undefined;
11
+ /**
12
+ * How wide it is at least, such as `16rem`, in place of 12rem: it still fits its items,
13
+ * up to 22rem, and is at least as wide as its trigger.
14
+ */
15
+ minWidth?: string | undefined;
11
16
  sx?: Sx | undefined;
12
17
  children?: Snippet | undefined;
13
18
  }>;
@@ -17,6 +22,11 @@ declare const MenuContent: import("svelte").Component<Loose<Omit<DropdownMenu.Co
17
22
  * the trigger's width, up to 22rem). It is still no wider than the window has room for.
18
23
  */
19
24
  width?: string | undefined;
25
+ /**
26
+ * How wide it is at least, such as `16rem`, in place of 12rem: it still fits its items,
27
+ * up to 22rem, and is at least as wide as its trigger.
28
+ */
29
+ minWidth?: string | undefined;
20
30
  sx?: Sx | undefined;
21
31
  children?: Snippet | undefined;
22
32
  }>, {}, "">;
@@ -12,6 +12,7 @@
12
12
  import Button from '../button/Button.svelte';
13
13
  import { text, type MessageTextSize } from '../message/styles.js';
14
14
  import * as Tooltip from '../tooltip/index.js';
15
+ import TooltipScope from '../../internal/TooltipScope.svelte';
15
16
 
16
17
  export type QueuedMessageStatus = 'queued' | 'editing' | 'unsent';
17
18
 
@@ -151,7 +152,7 @@
151
152
  {...stylex.attrs(styles.status, status === 'unsent' && styles.unsent)}
152
153
  >{statusText ?? STATUS[status]}</span
153
154
  >
154
- <Tooltip.Provider delayDuration={400}>
155
+ <TooltipScope>
155
156
  {#each actions as [key, handler, icon, fallback] (key)}
156
157
  {@const label = labels?.[key] ?? fallback}
157
158
  <Tooltip.Root>
@@ -173,6 +174,6 @@
173
174
  <Tooltip.Content>{label}</Tooltip.Content>
174
175
  </Tooltip.Root>
175
176
  {/each}
176
- </Tooltip.Provider>
177
+ </TooltipScope>
177
178
  </div>
178
179
  </div>
@@ -11,7 +11,7 @@
11
11
  import type { HTMLAttributes } from 'svelte/elements';
12
12
  import { roving } from '../../internal/roving.js';
13
13
  import { attrs, type Sx } from '../../internal/sx.js';
14
- import * as Tooltip from '../tooltip/index.js';
14
+ import TooltipScope from '../../internal/TooltipScope.svelte';
15
15
 
16
16
  export type RailRootProps = Omit<HTMLAttributes<HTMLElement>, 'children'> & {
17
17
  /** Names it for assistive technology: "Workspaces". */
@@ -54,7 +54,7 @@
54
54
  {...attrs([styles.rail, sx], className)}
55
55
  {@attach roving({ selector: '[data-rail-item]' })}
56
56
  >
57
- <Tooltip.Provider delayDuration={400}>
57
+ <TooltipScope>
58
58
  {@render children?.()}
59
- </Tooltip.Provider>
59
+ </TooltipScope>
60
60
  </nav>
@@ -9,6 +9,7 @@
9
9
  import '../../internal/icons.css';
10
10
  import { groupTrigger } from '../../internal/tooltip-trigger.js';
11
11
  import * as Tooltip from '../tooltip/index.js';
12
+ import TooltipScope from '../../internal/TooltipScope.svelte';
12
13
 
13
14
  export type SegmentedOption = {
14
15
  value: string;
@@ -217,7 +218,7 @@
217
218
  {/each}
218
219
  {/snippet}
219
220
  {#if titled}
220
- <Tooltip.Provider delayDuration={400}>{@render segments()}</Tooltip.Provider>
221
+ <TooltipScope>{@render segments()}</TooltipScope>
221
222
  {:else}
222
223
  {@render segments()}
223
224
  {/if}
@@ -15,6 +15,7 @@
15
15
  import { media } from '../../media.stylex.js';
16
16
  import { typography } from '../../typography.js';
17
17
  import * as Tooltip from '../tooltip/index.js';
18
+ import TooltipScope from '../../internal/TooltipScope.svelte';
18
19
  import { getSettingsGroupContext } from '../settings-group/context.js';
19
20
  import '../../internal/icons.css';
20
21
 
@@ -222,7 +223,7 @@
222
223
  <span id={control.labelId} {...stylex.attrs(...labelStyles)}>{label}</span>
223
224
  {/if}
224
225
  {#if about}
225
- <Tooltip.Provider delayDuration={400}>
226
+ <TooltipScope>
226
227
  <Tooltip.Root>
227
228
  <Tooltip.Trigger>
228
229
  {#snippet child({ props })}
@@ -238,7 +239,7 @@
238
239
  </Tooltip.Trigger>
239
240
  <Tooltip.Content side="top">{about}</Tooltip.Content>
240
241
  </Tooltip.Root>
241
- </Tooltip.Provider>
242
+ </TooltipScope>
242
243
  {/if}
243
244
  </span>
244
245
  {#if description}
@@ -1,23 +1,37 @@
1
1
  <!--
2
2
  A button and, joined to its end, a second that opens a menu of how to do it, or
3
3
  of what else there is to do: Merge, and the ways to merge. The two are one
4
- group, disabled together. Without a menu the button stands alone, rounded at
5
- both ends, so a menu that is offered only sometimes does not change the markup.
4
+ group, disabled together, or with `mainDisabled` only the main one, so the
5
+ menu's other ways stay in reach. Without a menu the button stands alone,
6
+ rounded at both ends, so a menu that is offered only sometimes does not change
7
+ the markup.
6
8
  -->
7
9
  <script lang="ts" module>
8
10
  import * as stylex from '@stylexjs/stylex';
9
11
  import type { Snippet } from 'svelte';
10
12
  import Glyph from '../../internal/Glyph.svelte';
11
13
  import { attrs, type Sx } from '../../internal/sx.js';
12
- import Button, { type ButtonProps } from '../button/Button.svelte';
14
+ import Button, { type ButtonProps, type ButtonShape } from '../button/Button.svelte';
15
+ import { colors, space } from '../../tokens.stylex.js';
13
16
  import * as Menu from '../menu/index.js';
14
17
 
15
18
  export type SplitButtonProps = Omit<
16
19
  ButtonProps,
17
- 'variant' | 'iconOnly' | 'href' | 'shape' | 'pressed' | 'sx'
20
+ 'variant' | 'iconOnly' | 'href' | 'pressed' | 'sx' | 'justify'
18
21
  > & {
19
- /** `secondary`, an edge round both halves; `primary`, the one solid, with a line between them. */
20
- variant?: 'primary' | 'secondary' | undefined;
22
+ /**
23
+ * `secondary`, an edge round both halves; `primary`, the one solid, with a line between
24
+ * them; `ghost`, quiet, for a bar of them: no edge, a fill only under the pointer, and a
25
+ * short line between the halves. Give a ghost pair a fill of its own with `sx`.
26
+ */
27
+ variant?: 'primary' | 'secondary' | 'ghost' | undefined;
28
+ /** `pill` rounds the pair's two outer ends fully. */
29
+ shape?: ButtonShape | undefined;
30
+ /**
31
+ * Disables the main button alone. The menu stays open to the person: its other ways may
32
+ * still apply, or it may say why the main one cannot.
33
+ */
34
+ mainDisabled?: boolean | undefined;
21
35
  /** Names the pair as a group, where the button's own words do not say it all: "Merge". */
22
36
  label?: string | undefined;
23
37
  /** Names the button that opens the menu: "Choose how to merge", "More for GitHub". */
@@ -31,17 +45,23 @@
31
45
  align?: 'start' | 'center' | 'end' | undefined;
32
46
  /** A width of its own for the menu, such as `16rem`. */
33
47
  menuWidth?: string | undefined;
48
+ /** How wide the menu is at least, such as `16rem`; it still fits its items. */
49
+ menuMinWidth?: string | undefined;
34
50
  /** Whether the menu is open. Bindable. */
35
51
  open?: boolean | undefined;
36
52
  /** Called as the menu opens or closes: to fetch what it lists as it opens, say. */
37
53
  onopenchange?: ((open: boolean) => void) | undefined;
38
54
  /**
39
55
  * A tooltip on the button that opens the menu, as `tooltip` is on the main one: words, or a
40
- * snippet with a shortcut.
56
+ * snippet with a shortcut. It opens on the side `tooltipSide` names, as the main one's does.
41
57
  */
42
58
  menuTooltip?: string | Snippet | undefined;
43
59
  /** On the group, which holds both halves. */
44
60
  sx?: Sx | undefined;
61
+ /** On the main button, after the pair's own styles. */
62
+ mainSx?: Sx | undefined;
63
+ /** On the button that opens the menu, after the pair's own styles. */
64
+ menuSx?: Sx | undefined;
45
65
  /** The main button's label, and its icon if it has one. */
46
66
  children?: Snippet | undefined;
47
67
  };
@@ -71,6 +91,18 @@
71
91
  pointerEvents: 'none'
72
92
  }
73
93
  },
94
+ // Quiet halves are divided by a short hairline, inset from the pair's ends
95
+ moreGhost: {
96
+ '::before': {
97
+ content: '""',
98
+ position: 'absolute',
99
+ insetInlineStart: 0,
100
+ insetBlock: space.x1_5,
101
+ width: '1px',
102
+ backgroundColor: colors.border,
103
+ pointerEvents: 'none'
104
+ }
105
+ },
74
106
  // The chevron's button is a little narrower than a square: it is the lesser half
75
107
  moreWidth: { paddingInline: '0.375rem' }
76
108
  });
@@ -85,12 +117,18 @@
85
117
  menu,
86
118
  align = 'end',
87
119
  menuWidth,
120
+ menuMinWidth,
121
+ shape = 'default',
122
+ mainDisabled = false,
88
123
  open = $bindable(false),
89
124
  onopenchange,
90
125
  menuTooltip,
126
+ tooltipSide,
91
127
  disabled = false,
92
128
  loading = false,
93
129
  sx,
130
+ mainSx,
131
+ menuSx,
94
132
  class: className,
95
133
  ref = $bindable(null),
96
134
  children,
@@ -98,6 +136,11 @@
98
136
  }: SplitButtonProps = $props();
99
137
 
100
138
  const glyph = { micro: 10, xs: 12, sm: 12, md: 14, lg: 16 } as const;
139
+ const divider = {
140
+ primary: styles.morePrimary,
141
+ secondary: styles.moreSecondary,
142
+ ghost: styles.moreGhost
143
+ } as const;
101
144
  </script>
102
145
 
103
146
  <div
@@ -111,9 +154,11 @@
111
154
  {...rest}
112
155
  {variant}
113
156
  {size}
114
- {disabled}
157
+ {shape}
158
+ disabled={disabled || mainDisabled}
115
159
  {loading}
116
- sx={[styles.half, menu && styles.main]}
160
+ {tooltipSide}
161
+ sx={[styles.half, menu && styles.main, mainSx]}
117
162
  >
118
163
  {@render children?.()}
119
164
  </Button>
@@ -125,21 +170,18 @@
125
170
  {...props}
126
171
  {variant}
127
172
  {size}
173
+ {shape}
128
174
  disabled={disabled || loading}
129
175
  aria-label={menuLabel}
130
176
  tooltip={menuTooltip}
131
- sx={[
132
- styles.half,
133
- styles.more,
134
- styles.moreWidth,
135
- variant === 'primary' ? styles.morePrimary : styles.moreSecondary
136
- ]}
177
+ {tooltipSide}
178
+ sx={[styles.half, styles.more, styles.moreWidth, divider[variant], menuSx]}
137
179
  >
138
180
  <Glyph name="chevron" size={glyph[size]} />
139
181
  </Button>
140
182
  {/snippet}
141
183
  </Menu.Trigger>
142
- <Menu.Content {align} width={menuWidth}>
184
+ <Menu.Content {align} width={menuWidth} minWidth={menuMinWidth}>
143
185
  {@render menu()}
144
186
  </Menu.Content>
145
187
  </Menu.Root>
@@ -1,9 +1,20 @@
1
1
  import type { Snippet } from 'svelte';
2
2
  import { type Sx } from '../../internal/sx.js';
3
- import { type ButtonProps } from '../button/Button.svelte';
4
- export type SplitButtonProps = Omit<ButtonProps, 'variant' | 'iconOnly' | 'href' | 'shape' | 'pressed' | 'sx'> & {
5
- /** `secondary`, an edge round both halves; `primary`, the one solid, with a line between them. */
6
- variant?: 'primary' | 'secondary' | undefined;
3
+ import { type ButtonProps, type ButtonShape } from '../button/Button.svelte';
4
+ export type SplitButtonProps = Omit<ButtonProps, 'variant' | 'iconOnly' | 'href' | 'pressed' | 'sx' | 'justify'> & {
5
+ /**
6
+ * `secondary`, an edge round both halves; `primary`, the one solid, with a line between
7
+ * them; `ghost`, quiet, for a bar of them: no edge, a fill only under the pointer, and a
8
+ * short line between the halves. Give a ghost pair a fill of its own with `sx`.
9
+ */
10
+ variant?: 'primary' | 'secondary' | 'ghost' | undefined;
11
+ /** `pill` rounds the pair's two outer ends fully. */
12
+ shape?: ButtonShape | undefined;
13
+ /**
14
+ * Disables the main button alone. The menu stays open to the person: its other ways may
15
+ * still apply, or it may say why the main one cannot.
16
+ */
17
+ mainDisabled?: boolean | undefined;
7
18
  /** Names the pair as a group, where the button's own words do not say it all: "Merge". */
8
19
  label?: string | undefined;
9
20
  /** Names the button that opens the menu: "Choose how to merge", "More for GitHub". */
@@ -17,17 +28,23 @@ export type SplitButtonProps = Omit<ButtonProps, 'variant' | 'iconOnly' | 'href'
17
28
  align?: 'start' | 'center' | 'end' | undefined;
18
29
  /** A width of its own for the menu, such as `16rem`. */
19
30
  menuWidth?: string | undefined;
31
+ /** How wide the menu is at least, such as `16rem`; it still fits its items. */
32
+ menuMinWidth?: string | undefined;
20
33
  /** Whether the menu is open. Bindable. */
21
34
  open?: boolean | undefined;
22
35
  /** Called as the menu opens or closes: to fetch what it lists as it opens, say. */
23
36
  onopenchange?: ((open: boolean) => void) | undefined;
24
37
  /**
25
38
  * A tooltip on the button that opens the menu, as `tooltip` is on the main one: words, or a
26
- * snippet with a shortcut.
39
+ * snippet with a shortcut. It opens on the side `tooltipSide` names, as the main one's does.
27
40
  */
28
41
  menuTooltip?: string | Snippet | undefined;
29
42
  /** On the group, which holds both halves. */
30
43
  sx?: Sx | undefined;
44
+ /** On the main button, after the pair's own styles. */
45
+ mainSx?: Sx | undefined;
46
+ /** On the button that opens the menu, after the pair's own styles. */
47
+ menuSx?: Sx | undefined;
31
48
  /** The main button's label, and its icon if it has one. */
32
49
  children?: Snippet | undefined;
33
50
  };