@opencode/ui 2.2.5 → 2.2.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.
- package/dist/actions/button/button.d.ts +2 -2
- package/dist/actions/icon-button/icon-button.d.ts +1 -1
- package/dist/components/animated-number-machine.d.ts +95 -0
- package/dist/components/file-icon-machine.d.ts +40 -0
- package/dist/components/file-icon.d.ts +0 -2
- package/dist/components/file-icons/choose-icon-name.d.ts +2 -0
- package/dist/components/image-flight-machine.d.ts +135 -0
- package/dist/components/image-zoom-machine.d.ts +95 -0
- package/dist/components/image-zoom.d.ts +6 -3
- package/dist/components/list.d.ts +2 -6
- package/dist/components/menu-scroll.d.ts +9 -3
- package/dist/components/popover-machine.d.ts +96 -0
- package/dist/components/popover.d.ts +2 -2
- package/dist/components/resize-handle-machine.d.ts +71 -0
- package/dist/components/resize-handle.d.ts +2 -0
- package/dist/components/scroll-view-machine.d.ts +68 -0
- package/dist/components/scroll-view.d.ts +2 -2
- package/dist/components/spinner.d.ts +11 -3
- package/dist/components/text-field-machine.d.ts +62 -0
- package/dist/components/text-reveal-machine.d.ts +90 -0
- package/dist/components/typewriter-machine.d.ts +62 -0
- package/dist/context/dialog-machine.d.ts +125 -0
- package/dist/context/dialog.d.ts +17 -16
- package/dist/data-display/line-comment/machine.d.ts +157 -0
- package/dist/data-display/project-avatar/animation-machine.d.ts +62 -0
- package/dist/data-display/project-avatar/animation.d.ts +1 -1
- package/dist/feedback/activity-ring/activity-ring.d.ts +2 -1
- package/dist/feedback/toast/machine.d.ts +57 -0
- package/dist/feedback/toast/toast.d.ts +1 -1
- package/dist/forms/checkbox/checkbox.d.ts +6 -1
- package/dist/forms/select/machine.d.ts +45 -0
- package/dist/forms/select/select.d.ts +4 -0
- package/dist/forms/typeahead/machine.d.ts +85 -0
- package/dist/hooks/auto-scroll-machine.d.ts +89 -0
- package/dist/hooks/create-auto-scroll.d.ts +1 -1
- package/dist/hooks/list-machine.d.ts +150 -0
- package/dist/hooks/use-filtered-list.d.ts +21 -35
- package/dist/i18n/en.d.ts +5 -0
- package/dist/icons/catalog.d.ts +8 -0
- package/dist/navigation/menu/machine.d.ts +49 -0
- package/dist/navigation/menu/menu.d.ts +5 -3
- package/dist/navigation/segmented-control/machine.d.ts +46 -0
- package/dist/overlays/mcp-sign-in/machine.d.ts +184 -0
- package/dist/overlays/mcp-sign-in/mcp-sign-in.d.ts +40 -0
- package/dist/overlays/tooltip/machine.d.ts +146 -0
- package/dist/theme/context.d.ts +38 -14
- package/dist/theme/machine.d.ts +174 -0
- package/dist/typography/text-shimmer/machine.d.ts +48 -0
- package/package.json +128 -111
- package/src/actions/button/button.tsx +11 -6
- package/src/actions/icon-button/icon-button.tsx +17 -4
- package/src/components/animated-number-machine.ts +214 -0
- package/src/components/animated-number.tsx +134 -83
- package/src/components/file-icon-machine.ts +78 -0
- package/src/components/file-icon.tsx +96 -579
- package/src/components/file-icons/choose-icon-name.ts +574 -0
- package/src/components/image-flight-machine.ts +247 -0
- package/src/components/image-preview.css +5 -2
- package/src/components/image-preview.tsx +390 -252
- package/src/components/image-zoom-machine.ts +191 -0
- package/src/components/image-zoom.ts +22 -14
- package/src/components/list.tsx +46 -137
- package/src/components/menu-scroll.css +19 -8
- package/src/components/menu-scroll.tsx +111 -34
- package/src/components/popover-machine.ts +198 -0
- package/src/components/popover.tsx +157 -89
- package/src/components/resize-handle-machine.ts +174 -0
- package/src/components/resize-handle.tsx +116 -67
- package/src/components/scroll-view-machine.ts +244 -0
- package/src/components/scroll-view.tsx +163 -116
- package/src/components/spinner.css +18 -5
- package/src/components/spinner.tsx +28 -14
- package/src/components/text-field-machine.ts +102 -0
- package/src/components/text-field.tsx +78 -24
- package/src/components/text-reveal-machine.ts +184 -0
- package/src/components/text-reveal.tsx +96 -93
- package/src/components/typewriter-machine.ts +134 -0
- package/src/components/typewriter.tsx +50 -39
- package/src/context/dialog-machine.ts +280 -0
- package/src/context/dialog.tsx +168 -177
- package/src/data-display/line-comment/line-comment.tsx +157 -178
- package/src/data-display/line-comment/machine.ts +391 -0
- package/src/data-display/project-avatar/animation-machine.ts +182 -0
- package/src/data-display/project-avatar/animation.ts +67 -38
- package/src/feedback/activity-ring/activity-ring.tsx +1 -1
- package/src/feedback/toast/machine.ts +115 -0
- package/src/feedback/toast/toast.tsx +59 -59
- package/src/forms/checkbox/checkbox-compact.css +169 -0
- package/src/forms/checkbox/checkbox.tsx +93 -31
- package/src/forms/inline-input/inline-input.css +0 -1
- package/src/forms/search-list/search-list.css +5 -1
- package/src/forms/search-list/search-list.tsx +18 -10
- package/src/forms/select/machine.ts +81 -0
- package/src/forms/select/select.css +59 -17
- package/src/forms/select/select.tsx +74 -32
- package/src/forms/typeahead/machine.ts +253 -0
- package/src/forms/typeahead/typeahead.tsx +70 -62
- package/src/hooks/auto-scroll-machine.ts +261 -0
- package/src/hooks/create-auto-scroll.tsx +110 -205
- package/src/hooks/list-machine.ts +359 -0
- package/src/hooks/use-filtered-list.tsx +101 -112
- package/src/i18n/en.ts +6 -1
- package/src/i18n/uk.ts +3 -3
- package/src/icons/catalog.ts +8 -0
- package/src/navigation/menu/machine.ts +109 -0
- package/src/navigation/menu/menu.tsx +133 -22
- package/src/navigation/segmented-control/machine.ts +72 -0
- package/src/navigation/segmented-control/segmented-control.tsx +46 -46
- package/src/overlays/dialog/dialog.tsx +7 -1
- package/src/overlays/mcp-sign-in/machine.ts +343 -0
- package/src/overlays/mcp-sign-in/mcp-sign-in.ts +159 -0
- package/src/overlays/tooltip/machine.ts +303 -0
- package/src/overlays/tooltip/tooltip.tsx +159 -92
- package/src/styles/theme.css +10 -2
- package/src/theme/context.tsx +192 -269
- package/src/theme/machine.ts +508 -0
- package/src/typography/text-shimmer/machine.ts +90 -0
- package/src/typography/text-shimmer/text-shimmer.css +71 -39
- package/src/typography/text-shimmer/text-shimmer.tsx +41 -24
|
@@ -1,44 +1,106 @@
|
|
|
1
1
|
import { Control, Description, ErrorMessage, Indicator, Input, Label, Root } from "@kobalte/core/checkbox"
|
|
2
|
-
import { Show, splitProps } from "solid-js"
|
|
2
|
+
import { Match, Show, Switch, splitProps } from "solid-js"
|
|
3
3
|
import type { ComponentProps, JSX, ParentProps } from "solid-js"
|
|
4
|
+
import "./checkbox-compact.css"
|
|
4
5
|
|
|
5
6
|
export interface CheckboxProps extends ParentProps<ComponentProps<typeof Root>> {
|
|
7
|
+
/** `compact` is the design system checkbox; `standard` keeps the legacy look. */
|
|
8
|
+
appearance?: "standard" | "compact"
|
|
9
|
+
/** Background of the compact control. */
|
|
10
|
+
surface?: "base" | "layer-1"
|
|
6
11
|
hideLabel?: boolean
|
|
7
|
-
description?:
|
|
12
|
+
description?: JSX.Element
|
|
8
13
|
icon?: JSX.Element
|
|
9
14
|
}
|
|
10
15
|
|
|
11
16
|
export function Checkbox(props: CheckboxProps) {
|
|
12
|
-
const [local, others] = splitProps(props, [
|
|
17
|
+
const [local, others] = splitProps(props, [
|
|
18
|
+
"children",
|
|
19
|
+
"class",
|
|
20
|
+
"label",
|
|
21
|
+
"appearance",
|
|
22
|
+
"surface",
|
|
23
|
+
"hideLabel",
|
|
24
|
+
"description",
|
|
25
|
+
"icon",
|
|
26
|
+
])
|
|
13
27
|
|
|
14
28
|
return (
|
|
15
|
-
<
|
|
16
|
-
<
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
<
|
|
21
|
-
<
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
29
|
+
<Switch>
|
|
30
|
+
<Match when={local.appearance === "compact"}>
|
|
31
|
+
<Root {...others} class={local.class} data-slot="checkbox-v2" data-surface={local.surface ?? "base"}>
|
|
32
|
+
<div data-slot="checkbox-v2-row">
|
|
33
|
+
<Input data-slot="checkbox-v2-input" />
|
|
34
|
+
<div data-slot="checkbox-v2-control-stack">
|
|
35
|
+
<Control data-slot="checkbox-v2-control">
|
|
36
|
+
<Indicator data-slot="checkbox-v2-indicator">
|
|
37
|
+
<svg
|
|
38
|
+
class="checkbox-v2-icon checkbox-v2-icon--check"
|
|
39
|
+
width="16"
|
|
40
|
+
height="16"
|
|
41
|
+
viewBox="0 0 16 16"
|
|
42
|
+
fill="none"
|
|
43
|
+
aria-hidden="true"
|
|
44
|
+
>
|
|
45
|
+
<path d="M3.53564 8.17857L6.39279 11.75L12.4642 4.25" stroke="currentColor" stroke-width="1" />
|
|
46
|
+
</svg>
|
|
47
|
+
<svg
|
|
48
|
+
class="checkbox-v2-icon checkbox-v2-icon--minus"
|
|
49
|
+
width="16"
|
|
50
|
+
height="16"
|
|
51
|
+
viewBox="0 0 16 16"
|
|
52
|
+
fill="none"
|
|
53
|
+
aria-hidden="true"
|
|
54
|
+
>
|
|
55
|
+
<path d="M12.75 8H3.25" stroke="currentColor" stroke-linejoin="round" stroke-width="1" />
|
|
56
|
+
</svg>
|
|
57
|
+
</Indicator>
|
|
58
|
+
</Control>
|
|
59
|
+
</div>
|
|
60
|
+
<div data-slot="checkbox-v2-text">
|
|
61
|
+
<Show when={local.children}>
|
|
62
|
+
<Label data-slot="checkbox-v2-label" classList={{ "sr-only": local.hideLabel }}>
|
|
63
|
+
{local.children}
|
|
64
|
+
</Label>
|
|
65
|
+
</Show>
|
|
66
|
+
<Show when={local.description}>
|
|
67
|
+
<Description data-slot="checkbox-v2-description">{local.description}</Description>
|
|
68
|
+
</Show>
|
|
69
|
+
</div>
|
|
70
|
+
</div>
|
|
71
|
+
<ErrorMessage data-slot="checkbox-v2-error" />
|
|
72
|
+
</Root>
|
|
73
|
+
</Match>
|
|
74
|
+
<Match when={true}>
|
|
75
|
+
<Root {...others} class={local.class} data-component="checkbox">
|
|
76
|
+
<Input data-slot="checkbox-checkbox-input" />
|
|
77
|
+
<Control data-slot="checkbox-checkbox-control">
|
|
78
|
+
<Indicator data-slot="checkbox-checkbox-indicator">
|
|
79
|
+
{local.icon || (
|
|
80
|
+
<svg viewBox="0 0 12 12" fill="none" width="10" height="10" xmlns="http://www.w3.org/2000/svg">
|
|
81
|
+
<path
|
|
82
|
+
d="M3 7.17905L5.02703 8.85135L9 3.5"
|
|
83
|
+
stroke="currentColor"
|
|
84
|
+
stroke-width="1.5"
|
|
85
|
+
stroke-linecap="square"
|
|
86
|
+
/>
|
|
87
|
+
</svg>
|
|
88
|
+
)}
|
|
89
|
+
</Indicator>
|
|
90
|
+
</Control>
|
|
91
|
+
<div data-slot="checkbox-checkbox-content">
|
|
92
|
+
<Show when={props.children}>
|
|
93
|
+
<Label data-slot="checkbox-checkbox-label" classList={{ "sr-only": local.hideLabel }}>
|
|
94
|
+
{props.children}
|
|
95
|
+
</Label>
|
|
96
|
+
</Show>
|
|
97
|
+
<Show when={local.description}>
|
|
98
|
+
<Description data-slot="checkbox-checkbox-description">{local.description}</Description>
|
|
99
|
+
</Show>
|
|
100
|
+
<ErrorMessage data-slot="checkbox-checkbox-error" />
|
|
101
|
+
</div>
|
|
102
|
+
</Root>
|
|
103
|
+
</Match>
|
|
104
|
+
</Switch>
|
|
43
105
|
)
|
|
44
106
|
}
|
|
@@ -56,11 +56,14 @@
|
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
[data-slot="search-list-body"] > [data-component="menu-scroll"] {
|
|
60
|
+
flex: 1;
|
|
61
|
+
}
|
|
62
|
+
|
|
59
63
|
/* Arrow keys scroll the active row clear of the sticky header. Rows fade out past the bottom edge while more follow. */
|
|
60
64
|
[data-slot="search-list-scroll"] {
|
|
61
65
|
min-height: 0;
|
|
62
66
|
flex: 1;
|
|
63
|
-
overflow-y: auto;
|
|
64
67
|
--search-list-edge: linear-gradient(
|
|
65
68
|
to bottom,
|
|
66
69
|
#000 calc(100% - 24px),
|
|
@@ -209,6 +212,7 @@
|
|
|
209
212
|
box-shadow: var(--v2-elevation-floating);
|
|
210
213
|
}
|
|
211
214
|
|
|
215
|
+
[data-slot="search-list-body"] > [data-component="menu-scroll"],
|
|
212
216
|
[data-slot="search-list-scroll"] {
|
|
213
217
|
flex: 0 1 auto;
|
|
214
218
|
}
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
} from "solid-js"
|
|
13
13
|
import { createResizeObserver } from "@solid-primitives/resize-observer"
|
|
14
14
|
import { Icon } from "@opencode/ui/icon"
|
|
15
|
+
import { MenuScroll } from "../../components/menu-scroll"
|
|
15
16
|
import { TextInput } from "../text-input/text-input"
|
|
16
17
|
import { createTypeahead } from "../typeahead/controller"
|
|
17
18
|
import { searchListMove, searchListTarget } from "./navigation"
|
|
@@ -186,8 +187,9 @@ export function SearchList<T>(props: {
|
|
|
186
187
|
createEffect(() => props.onActive?.(typeahead.activeItem()))
|
|
187
188
|
|
|
188
189
|
// A new query starts from the top. Results that arrive later for the same query bring a chosen row back into view,
|
|
189
|
-
// but leave the list where the wheel put it while the first row is still the default.
|
|
190
|
+
// but leave the list where the wheel put it while the first row is still the default or the pointer took the row.
|
|
190
191
|
let revealed = props.query
|
|
192
|
+
let pointed: string | undefined
|
|
191
193
|
|
|
192
194
|
createEffect(
|
|
193
195
|
on(
|
|
@@ -196,7 +198,7 @@ export function SearchList<T>(props: {
|
|
|
196
198
|
const fresh = props.query !== revealed
|
|
197
199
|
revealed = props.query
|
|
198
200
|
|
|
199
|
-
if (!fresh && typeahead.activeItem() === all[0]) return
|
|
201
|
+
if (!fresh && (typeahead.activeItem() === all[0] || activeKey() === pointed)) return
|
|
200
202
|
const frame = requestAnimationFrame(reveal)
|
|
201
203
|
onCleanup(() => cancelAnimationFrame(frame))
|
|
202
204
|
},
|
|
@@ -204,7 +206,12 @@ export function SearchList<T>(props: {
|
|
|
204
206
|
),
|
|
205
207
|
)
|
|
206
208
|
|
|
207
|
-
|
|
209
|
+
const choose = (key: string | undefined) => {
|
|
210
|
+
pointed = undefined
|
|
211
|
+
typeahead.setActive(key)
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
props.ref?.({ active: typeahead.activeItem, setActive: choose })
|
|
208
215
|
|
|
209
216
|
const onKeyDown = (event: KeyboardEvent) => {
|
|
210
217
|
if (event.isComposing) return
|
|
@@ -231,7 +238,7 @@ export function SearchList<T>(props: {
|
|
|
231
238
|
const target = all[step(from)]
|
|
232
239
|
|
|
233
240
|
if (target === undefined) return
|
|
234
|
-
|
|
241
|
+
choose(props.key(target))
|
|
235
242
|
reveal()
|
|
236
243
|
}
|
|
237
244
|
|
|
@@ -253,7 +260,7 @@ export function SearchList<T>(props: {
|
|
|
253
260
|
},
|
|
254
261
|
onInput: (event) => {
|
|
255
262
|
// A new query starts again from its first row.
|
|
256
|
-
|
|
263
|
+
choose(undefined)
|
|
257
264
|
props.onQuery(event.currentTarget.value)
|
|
258
265
|
},
|
|
259
266
|
onKeyDown,
|
|
@@ -273,7 +280,9 @@ export function SearchList<T>(props: {
|
|
|
273
280
|
},
|
|
274
281
|
onMouseMove: (event) => {
|
|
275
282
|
// A static cursor must not take the active row while the keyboard scrolls rows beneath it.
|
|
276
|
-
if (event.movementX
|
|
283
|
+
if (event.movementX === 0 && event.movementY === 0) return
|
|
284
|
+
pointed = key
|
|
285
|
+
typeahead.setActive(key)
|
|
277
286
|
},
|
|
278
287
|
// Focus stays in the field.
|
|
279
288
|
onMouseDown: (event) => event.preventDefault(),
|
|
@@ -307,10 +316,9 @@ export function SearchList<T>(props: {
|
|
|
307
316
|
{(custom) => custom()(field)}
|
|
308
317
|
</Show>
|
|
309
318
|
<div data-slot="search-list-body" hidden={!open()}>
|
|
310
|
-
<
|
|
319
|
+
<MenuScroll
|
|
311
320
|
data-slot="search-list-scroll"
|
|
312
|
-
|
|
313
|
-
ref={(element) => (viewport = element)}
|
|
321
|
+
viewportRef={(element) => (viewport = element)}
|
|
314
322
|
onScroll={(event) => {
|
|
315
323
|
edges()
|
|
316
324
|
props.onScroll?.(event.currentTarget.scrollTop)
|
|
@@ -364,7 +372,7 @@ export function SearchList<T>(props: {
|
|
|
364
372
|
<Show when={rows().length === 0}>
|
|
365
373
|
<div data-slot="search-list-empty">{props.empty}</div>
|
|
366
374
|
</Show>
|
|
367
|
-
</
|
|
375
|
+
</MenuScroll>
|
|
368
376
|
<Show when={props.footer}>
|
|
369
377
|
<div data-slot="search-list-footer">{props.footer}</div>
|
|
370
378
|
</Show>
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The preview a `<Select>` shows for its highlighted option (`onHighlight`, which may return an undo). Unlike a one-shot
|
|
3
|
+
* palette, a select opens and closes repeatedly: choosing the previewed option keeps its preview, choosing another
|
|
4
|
+
* reverts it first, and closing without a choice reverts it. Nothing previews while the menu is closed or closing.
|
|
5
|
+
*/
|
|
6
|
+
export type SelectHighlightState =
|
|
7
|
+
| { readonly status: "closed" }
|
|
8
|
+
| { readonly status: "idle" }
|
|
9
|
+
| { readonly status: "previewing"; readonly key: string }
|
|
10
|
+
| { readonly status: "committed" }
|
|
11
|
+
| { readonly status: "disposed" }
|
|
12
|
+
|
|
13
|
+
export type SelectHighlightEvent =
|
|
14
|
+
| { readonly type: "open.changed"; readonly open: boolean }
|
|
15
|
+
| { readonly type: "highlight.changed"; readonly key: string; readonly previewable: boolean }
|
|
16
|
+
/** `closing` is whether the menu closes on this choice (`closeOnSelection`). */
|
|
17
|
+
| { readonly type: "option.selected"; readonly key: string | undefined; readonly closing: boolean }
|
|
18
|
+
| { readonly type: "disposed" }
|
|
19
|
+
|
|
20
|
+
export type SelectHighlightEffect =
|
|
21
|
+
| { readonly type: "preview.apply"; readonly key: string }
|
|
22
|
+
| { readonly type: "preview.revert" }
|
|
23
|
+
|
|
24
|
+
export type SelectHighlightTransition = {
|
|
25
|
+
readonly state: SelectHighlightState
|
|
26
|
+
readonly effects: readonly SelectHighlightEffect[]
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const CLOSED: SelectHighlightState = Object.freeze({ status: "closed" })
|
|
30
|
+
|
|
31
|
+
const IDLE: SelectHighlightState = Object.freeze({ status: "idle" })
|
|
32
|
+
|
|
33
|
+
const COMMITTED: SelectHighlightState = Object.freeze({ status: "committed" })
|
|
34
|
+
|
|
35
|
+
const DISPOSED: SelectHighlightState = Object.freeze({ status: "disposed" })
|
|
36
|
+
|
|
37
|
+
const NONE: readonly SelectHighlightEffect[] = Object.freeze([])
|
|
38
|
+
|
|
39
|
+
const REVERT: readonly SelectHighlightEffect[] = Object.freeze([{ type: "preview.revert" }])
|
|
40
|
+
|
|
41
|
+
export function createSelectHighlightState(open: boolean): SelectHighlightState {
|
|
42
|
+
return open ? IDLE : CLOSED
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function transitionSelectHighlight(
|
|
46
|
+
state: SelectHighlightState,
|
|
47
|
+
event: SelectHighlightEvent,
|
|
48
|
+
): SelectHighlightTransition {
|
|
49
|
+
if (state.status === "disposed") return { state, effects: NONE }
|
|
50
|
+
const previewing = state.status === "previewing"
|
|
51
|
+
|
|
52
|
+
if (event.type === "disposed") return { state: DISPOSED, effects: previewing ? REVERT : NONE }
|
|
53
|
+
|
|
54
|
+
if (event.type === "open.changed") {
|
|
55
|
+
if (event.open)
|
|
56
|
+
return { state: state.status === "closed" || state.status === "committed" ? IDLE : state, effects: NONE }
|
|
57
|
+
|
|
58
|
+
return { state: CLOSED, effects: previewing ? REVERT : NONE }
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (event.type === "option.selected") {
|
|
62
|
+
// The chosen option's preview is the committed value; any other preview reverts before the caller commits.
|
|
63
|
+
const effects = previewing && (event.key === undefined || state.key !== event.key) ? REVERT : NONE
|
|
64
|
+
|
|
65
|
+
if (!event.closing) return { state: IDLE, effects }
|
|
66
|
+
|
|
67
|
+
return { state: state.status === "closed" ? CLOSED : COMMITTED, effects }
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// A closed or closing menu still delivers focus and pointer events to its items (forceMount, exit animation).
|
|
71
|
+
if (state.status === "closed" || state.status === "committed") return { state, effects: NONE }
|
|
72
|
+
|
|
73
|
+
if (!event.previewable) return previewing ? { state: IDLE, effects: REVERT } : { state, effects: NONE }
|
|
74
|
+
|
|
75
|
+
if (previewing && state.key === event.key) return { state, effects: NONE }
|
|
76
|
+
|
|
77
|
+
return {
|
|
78
|
+
state: { status: "previewing", key: event.key },
|
|
79
|
+
effects: [...(previewing ? REVERT : NONE), { type: "preview.apply", key: event.key }],
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -32,10 +32,9 @@
|
|
|
32
32
|
border: 0;
|
|
33
33
|
border-radius: 6px;
|
|
34
34
|
outline: 1px solid transparent;
|
|
35
|
-
outline-offset:
|
|
36
|
-
background:
|
|
37
|
-
|
|
38
|
-
box-shadow: var(--v2-elevation-button-neutral);
|
|
35
|
+
outline-offset: -1px;
|
|
36
|
+
background: var(--v2-background-bg-base);
|
|
37
|
+
box-shadow: var(--v2-elevation-input);
|
|
39
38
|
flex: none;
|
|
40
39
|
align-self: stretch;
|
|
41
40
|
user-select: none;
|
|
@@ -45,21 +44,59 @@
|
|
|
45
44
|
box-shadow 85ms ease-out;
|
|
46
45
|
}
|
|
47
46
|
|
|
48
|
-
[data-component="select-v2"]
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
47
|
+
[data-component="select-v2"][data-appearance="small"] {
|
|
48
|
+
height: 24px;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
[data-component="select-v2"][data-appearance="large"] {
|
|
52
|
+
height: 32px;
|
|
53
|
+
padding-inline: 0 8px;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
[data-component="select-v2"][data-surface="layer-1"] {
|
|
57
|
+
background: var(--v2-background-bg-layer-01);
|
|
54
58
|
}
|
|
55
59
|
|
|
56
|
-
[data-component="select-v2"]
|
|
57
|
-
background:
|
|
58
|
-
|
|
59
|
-
|
|
60
|
+
[data-component="select-v2"][data-surface="invisible"] {
|
|
61
|
+
background: transparent;
|
|
62
|
+
box-shadow: none;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/* An inset overlay keeps the surface colour underneath, the same hover the text input uses. */
|
|
66
|
+
@media (hover: hover) {
|
|
67
|
+
[data-component="select-v2"]:where(:hover):not(
|
|
68
|
+
[data-disabled],
|
|
69
|
+
[data-invalid],
|
|
70
|
+
[data-expanded],
|
|
71
|
+
[data-appearance="inline"],
|
|
72
|
+
[data-surface="invisible"]
|
|
73
|
+
):not(:focus-within) {
|
|
74
|
+
box-shadow:
|
|
75
|
+
inset 0 0 0 100vmax var(--v2-overlay-simple-overlay-hover),
|
|
76
|
+
var(--v2-elevation-input);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
[data-component="select-v2"][data-surface="invisible"]:where(:hover):not(
|
|
80
|
+
[data-disabled],
|
|
81
|
+
[data-invalid],
|
|
82
|
+
[data-expanded]
|
|
83
|
+
):not(:focus-within) {
|
|
84
|
+
background: var(--v2-overlay-simple-overlay-hover);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
[data-component="select-v2"]:where([data-expanded]):not([data-disabled], [data-invalid], [data-appearance="inline"]) {
|
|
89
|
+
box-shadow:
|
|
90
|
+
inset 0 0 0 100vmax var(--v2-overlay-simple-overlay-hover),
|
|
91
|
+
var(--v2-elevation-input);
|
|
60
92
|
outline-color: transparent;
|
|
61
93
|
}
|
|
62
94
|
|
|
95
|
+
[data-component="select-v2"][data-surface="invisible"]:where([data-expanded]):not([data-disabled], [data-invalid]) {
|
|
96
|
+
background: var(--v2-overlay-simple-overlay-hover);
|
|
97
|
+
box-shadow: none;
|
|
98
|
+
}
|
|
99
|
+
|
|
63
100
|
[data-component="select-v2"]:where(:focus-within):not([data-disabled], [data-invalid]):not([data-expanded]) {
|
|
64
101
|
outline-color: var(--v2-border-border-focus);
|
|
65
102
|
box-shadow: none;
|
|
@@ -196,6 +233,14 @@
|
|
|
196
233
|
padding: 0;
|
|
197
234
|
}
|
|
198
235
|
|
|
236
|
+
[data-component="menu-v2-content"][data-slot="select-v2-content"] > [data-component="menu-scroll"] {
|
|
237
|
+
max-height: 12rem;
|
|
238
|
+
|
|
239
|
+
> [data-scrollable] {
|
|
240
|
+
overflow-x: hidden;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
199
244
|
/* Listbox inside menu surface */
|
|
200
245
|
[data-component="menu-v2-content"][data-slot="select-v2-content"] [data-slot="select-v2-listbox"] {
|
|
201
246
|
box-sizing: border-box;
|
|
@@ -207,9 +252,6 @@
|
|
|
207
252
|
list-style: none;
|
|
208
253
|
min-width: 0;
|
|
209
254
|
width: 100%;
|
|
210
|
-
max-height: 12rem;
|
|
211
|
-
overflow-x: hidden;
|
|
212
|
-
overflow-y: auto;
|
|
213
255
|
outline: none;
|
|
214
256
|
white-space: nowrap;
|
|
215
257
|
|
|
@@ -10,7 +10,19 @@ import {
|
|
|
10
10
|
Trigger,
|
|
11
11
|
Value,
|
|
12
12
|
} from "@kobalte/core/select"
|
|
13
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
Show,
|
|
15
|
+
createComputed,
|
|
16
|
+
createMemo,
|
|
17
|
+
on,
|
|
18
|
+
onCleanup,
|
|
19
|
+
splitProps,
|
|
20
|
+
untrack,
|
|
21
|
+
type ComponentProps,
|
|
22
|
+
type JSX,
|
|
23
|
+
} from "solid-js"
|
|
24
|
+
import { MenuScroll } from "../../components/menu-scroll"
|
|
25
|
+
import { createSelectHighlightState, transitionSelectHighlight, type SelectHighlightEvent } from "./machine"
|
|
14
26
|
import "./select.css"
|
|
15
27
|
|
|
16
28
|
function groupOptions<T>(options: T[], groupBy?: (x: T) => string): { category: string; options: T[] }[] {
|
|
@@ -70,6 +82,10 @@ export type SelectProps<T> = Omit<
|
|
|
70
82
|
onHighlight?: (value: T | undefined) => void | (() => void)
|
|
71
83
|
invalid?: boolean
|
|
72
84
|
numeric?: boolean
|
|
85
|
+
/** `inline` is the borderless settings trigger; `small`, `base` and `large` are 24px, 28px and 32px input fields. */
|
|
86
|
+
appearance?: "inline" | "small" | "base" | "large"
|
|
87
|
+
/** Background surface of an input field; invisible gains a fill on hover. */
|
|
88
|
+
surface?: "base" | "layer-1" | "invisible"
|
|
73
89
|
children?: (item: T) => JSX.Element
|
|
74
90
|
valueClass?: string
|
|
75
91
|
contentClass?: string
|
|
@@ -91,6 +107,8 @@ export function Select<T>(props: SelectProps<T>) {
|
|
|
91
107
|
"children",
|
|
92
108
|
"invalid",
|
|
93
109
|
"numeric",
|
|
110
|
+
"appearance",
|
|
111
|
+
"surface",
|
|
94
112
|
"disabled",
|
|
95
113
|
"valueClass",
|
|
96
114
|
"contentClass",
|
|
@@ -102,34 +120,46 @@ export function Select<T>(props: SelectProps<T>) {
|
|
|
102
120
|
"fitViewport",
|
|
103
121
|
])
|
|
104
122
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
state.cleanup = undefined
|
|
110
|
-
state.key = undefined
|
|
111
|
-
}
|
|
123
|
+
let highlight = createSelectHighlightState(untrack(() => others.open ?? others.defaultOpen ?? false))
|
|
124
|
+
// The highlighted item and the undo its preview returned; the machine decides when each runs.
|
|
125
|
+
let highlighted: T | undefined
|
|
126
|
+
let revert: void | (() => void)
|
|
112
127
|
|
|
113
|
-
|
|
128
|
+
let scroller: HTMLDivElement | undefined
|
|
114
129
|
|
|
115
|
-
const
|
|
116
|
-
|
|
130
|
+
const dispatch = (event: SelectHighlightEvent) => {
|
|
131
|
+
const next = transitionSelectHighlight(highlight, event)
|
|
132
|
+
highlight = next.state
|
|
133
|
+
next.effects.forEach((effect) => {
|
|
134
|
+
if (effect.type === "preview.revert") {
|
|
135
|
+
const undo = revert
|
|
136
|
+
revert = undefined
|
|
117
137
|
|
|
118
|
-
|
|
119
|
-
|
|
138
|
+
return undo?.()
|
|
139
|
+
}
|
|
120
140
|
|
|
121
|
-
|
|
122
|
-
}
|
|
141
|
+
revert = highlighted === undefined ? undefined : local.onHighlight?.(highlighted)
|
|
142
|
+
})
|
|
143
|
+
}
|
|
123
144
|
|
|
124
|
-
|
|
145
|
+
const keyFor = (item: T) => (local.value ? local.value(item) : String(item))
|
|
125
146
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
state.key = key
|
|
147
|
+
const move = (item: T) => {
|
|
148
|
+
highlighted = item
|
|
149
|
+
dispatch({ type: "highlight.changed", key: keyFor(item), previewable: !!local.onHighlight })
|
|
130
150
|
}
|
|
131
151
|
|
|
132
|
-
|
|
152
|
+
// A controlled menu closed by its owner does not call onOpenChange.
|
|
153
|
+
createComputed(
|
|
154
|
+
on(
|
|
155
|
+
() => others.open,
|
|
156
|
+
(open) => {
|
|
157
|
+
if (open !== undefined) dispatch({ type: "open.changed", open })
|
|
158
|
+
},
|
|
159
|
+
),
|
|
160
|
+
)
|
|
161
|
+
|
|
162
|
+
onCleanup(() => dispatch({ type: "disposed" }))
|
|
133
163
|
|
|
134
164
|
const grouped = createMemo(() => groupOptions(local.options, local.groupBy))
|
|
135
165
|
|
|
@@ -148,8 +178,8 @@ export function Select<T>(props: SelectProps<T>) {
|
|
|
148
178
|
fitViewport={local.fitViewport ?? false}
|
|
149
179
|
value={local.current}
|
|
150
180
|
options={grouped()}
|
|
151
|
-
optionValue={(x) => (local.value ? local.value(x) : String(x
|
|
152
|
-
optionTextValue={(x) => (local.label ? local.label(x) : String(x
|
|
181
|
+
optionValue={(x) => (local.value ? local.value(x) : String(x))}
|
|
182
|
+
optionTextValue={(x) => (local.label ? local.label(x) : String(x))}
|
|
153
183
|
optionGroupChildren="options"
|
|
154
184
|
placeholder={local.placeholder}
|
|
155
185
|
sectionComponent={(sectionProps) => (
|
|
@@ -172,7 +202,7 @@ export function Select<T>(props: SelectProps<T>) {
|
|
|
172
202
|
? local.children(itemProps.item.rawValue)
|
|
173
203
|
: local.label
|
|
174
204
|
? local.label(itemProps.item.rawValue)
|
|
175
|
-
: String(itemProps.item.rawValue
|
|
205
|
+
: String(itemProps.item.rawValue)}
|
|
176
206
|
</ItemLabel>
|
|
177
207
|
<ItemIndicator data-slot="menu-v2-item-indicator" forceMount>
|
|
178
208
|
<CheckSmall />
|
|
@@ -180,14 +210,17 @@ export function Select<T>(props: SelectProps<T>) {
|
|
|
180
210
|
</Item>
|
|
181
211
|
)}
|
|
182
212
|
onChange={(next) => {
|
|
183
|
-
const v = next == null ? null : Array.isArray(next) ? (
|
|
213
|
+
const v = next == null ? null : Array.isArray(next) ? (next[0] ?? null) : next
|
|
214
|
+
dispatch({
|
|
215
|
+
type: "option.selected",
|
|
216
|
+
key: v === null ? undefined : keyFor(v),
|
|
217
|
+
closing: others.closeOnSelection ?? true,
|
|
218
|
+
})
|
|
184
219
|
local.onSelect?.(v)
|
|
185
|
-
stop()
|
|
186
220
|
}}
|
|
187
221
|
onOpenChange={(open) => {
|
|
222
|
+
if (others.open === undefined) dispatch({ type: "open.changed", open })
|
|
188
223
|
local.onOpenChange?.(open)
|
|
189
|
-
|
|
190
|
-
if (!open) stop()
|
|
191
224
|
}}
|
|
192
225
|
>
|
|
193
226
|
<Trigger
|
|
@@ -195,7 +228,8 @@ export function Select<T>(props: SelectProps<T>) {
|
|
|
195
228
|
aria-label={props["aria-label"]}
|
|
196
229
|
aria-labelledby={props["aria-labelledby"]}
|
|
197
230
|
data-component="select-v2"
|
|
198
|
-
data-appearance="inline"
|
|
231
|
+
data-appearance={local.appearance ?? "inline"}
|
|
232
|
+
data-surface={local.appearance && local.appearance !== "inline" ? (local.surface ?? "base") : undefined}
|
|
199
233
|
data-invalid={local.invalid ? "" : undefined}
|
|
200
234
|
data-numeric={local.numeric ? "" : undefined}
|
|
201
235
|
disabled={local.disabled}
|
|
@@ -212,7 +246,7 @@ export function Select<T>(props: SelectProps<T>) {
|
|
|
212
246
|
|
|
213
247
|
if (local.label && selected != null) return local.label(selected)
|
|
214
248
|
|
|
215
|
-
return selected != null ? (selected
|
|
249
|
+
return selected != null ? String(selected) : ""
|
|
216
250
|
}}
|
|
217
251
|
</Value>
|
|
218
252
|
</div>
|
|
@@ -221,8 +255,16 @@ export function Select<T>(props: SelectProps<T>) {
|
|
|
221
255
|
</span>
|
|
222
256
|
</Trigger>
|
|
223
257
|
<Portal>
|
|
224
|
-
|
|
225
|
-
|
|
258
|
+
{/* A modal dialog hides what's outside it from assistive tech, and this list is portaled outside it. */}
|
|
259
|
+
<Content
|
|
260
|
+
class={local.contentClass}
|
|
261
|
+
data-kb-top-layer=""
|
|
262
|
+
data-component="menu-v2-content"
|
|
263
|
+
data-slot="select-v2-content"
|
|
264
|
+
>
|
|
265
|
+
<MenuScroll viewportRef={(element) => (scroller = element)}>
|
|
266
|
+
<Listbox data-slot="select-v2-listbox" scrollRef={() => scroller} />
|
|
267
|
+
</MenuScroll>
|
|
226
268
|
</Content>
|
|
227
269
|
</Portal>
|
|
228
270
|
</Root>
|