@opencode/ui 0.0.0-dev-21922 → 0.0.0-dev-51

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.
@@ -0,0 +1,6 @@
1
+ import { type DurationOptions } from "../motion";
2
+ export declare function RollingNumber(props: {
3
+ value: number;
4
+ spring?: DurationOptions;
5
+ class?: string;
6
+ }): import("solid-js").JSX.Element;
@@ -11,6 +11,18 @@ export type SearchListRow = {
11
11
  onMouseDown: (event: MouseEvent) => void;
12
12
  onClick: () => void;
13
13
  };
14
+ /** Attributes for the input of a field passed as `field`: spread them onto it. */
15
+ export type SearchListField = {
16
+ role: "combobox";
17
+ "aria-expanded": boolean;
18
+ "aria-autocomplete": "list";
19
+ "aria-controls": string | undefined;
20
+ "aria-activedescendant": string | undefined;
21
+ onInput: (event: InputEvent & {
22
+ currentTarget: HTMLInputElement;
23
+ }) => void;
24
+ onKeyDown: (event: KeyboardEvent) => void;
25
+ };
14
26
  export type SearchListHandle<T> = {
15
27
  active: () => T | undefined;
16
28
  setActive: (key: string | undefined) => void;
@@ -19,13 +31,22 @@ export type SearchListHandle<T> = {
19
31
  * A search field over sectioned results. Rows that share a `section` key list together under one header, which sticks
20
32
  * while its rows scroll beneath it until the next header pushes it away. The first row is active until the user picks
21
33
  * another: ↑/↓ wrap, ⌘ or ⌥ with ↑/↓ jump between sections, Home/End go to the ends, Enter selects and Escape closes.
34
+ * A page can keep its own field through `field` and float the results beneath it with `popover`.
22
35
  */
23
36
  export declare function SearchList<T>(props: {
24
37
  query: string;
25
38
  onQuery: (query: string) => void;
26
39
  placeholder: string;
40
+ /** The results' accessible name; the placeholder by default. */
41
+ label?: string;
27
42
  /** Controls after the field, such as icon buttons. */
28
43
  trailing?: JSX.Element;
44
+ /** A search field of the page's own in place of the built-in one. */
45
+ field?: (field: SearchListField) => JSX.Element;
46
+ /** Whether the results show. Closed, only the field remains and the list leaves keys to the page. On by default. */
47
+ open?: boolean;
48
+ /** Float the results beneath the field on a raised surface, over what follows it. */
49
+ popover?: boolean;
29
50
  items: T[];
30
51
  key: (item: T) => string;
31
52
  section?: (item: T) => string;
@@ -35,6 +56,11 @@ export declare function SearchList<T>(props: {
35
56
  header?: (item: T) => JSX.Element;
36
57
  /** Shown in place of the rows when there are none. */
37
58
  empty: JSX.Element;
59
+ /** A note beneath the rows, such as a hint that more results are hidden. */
60
+ footer?: JSX.Element;
61
+ /** Where the results start scrolled each time they mount, such as a position kept from an earlier visit. */
62
+ scrollTop?: number;
63
+ onScroll?: (scrollTop: number) => void;
38
64
  onSelect: (item: T) => void;
39
65
  onActive?: (item: T | undefined) => void;
40
66
  /** Runs before the list's own keys; call `preventDefault` to claim one. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opencode/ui",
3
- "version": "0.0.0-dev-21922",
3
+ "version": "0.0.0-dev-51",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -35,233 +35,234 @@
35
35
  "exports": {
36
36
  "./package.json": "./package.json",
37
37
  "./accordion": {
38
- "types": "./dist/data-display/accordion/accordion.d.ts",
39
- "import": "./src/data-display/accordion/accordion.tsx"
38
+ "import": "./src/data-display/accordion/accordion.tsx",
39
+ "types": "./dist/data-display/accordion/accordion.d.ts"
40
40
  },
41
41
  "./activity-ring": {
42
- "types": "./dist/feedback/activity-ring/activity-ring.d.ts",
43
- "import": "./src/feedback/activity-ring/activity-ring.tsx"
42
+ "import": "./src/feedback/activity-ring/activity-ring.tsx",
43
+ "types": "./dist/feedback/activity-ring/activity-ring.d.ts"
44
44
  },
45
45
  "./avatar": {
46
- "types": "./dist/data-display/avatar/avatar.d.ts",
47
- "import": "./src/data-display/avatar/avatar.tsx"
46
+ "import": "./src/data-display/avatar/avatar.tsx",
47
+ "types": "./dist/data-display/avatar/avatar.d.ts"
48
48
  },
49
49
  "./badge": {
50
- "types": "./dist/data-display/badge/badge.d.ts",
51
- "import": "./src/data-display/badge/badge.tsx"
50
+ "import": "./src/data-display/badge/badge.tsx",
51
+ "types": "./dist/data-display/badge/badge.d.ts"
52
52
  },
53
53
  "./button": {
54
- "types": "./dist/actions/button/button.d.ts",
55
- "import": "./src/actions/button/button.tsx"
54
+ "import": "./src/actions/button/button.tsx",
55
+ "types": "./dist/actions/button/button.d.ts"
56
56
  },
57
57
  "./button.css": "./src/actions/button/button.css",
58
58
  "./checkbox": {
59
- "types": "./dist/forms/checkbox/checkbox.d.ts",
60
- "import": "./src/forms/checkbox/checkbox.tsx"
59
+ "import": "./src/forms/checkbox/checkbox.tsx",
60
+ "types": "./dist/forms/checkbox/checkbox.d.ts"
61
61
  },
62
62
  "./dialog": {
63
- "types": "./dist/overlays/dialog/dialog.d.ts",
64
- "import": "./src/overlays/dialog/dialog.tsx"
63
+ "import": "./src/overlays/dialog/dialog.tsx",
64
+ "types": "./dist/overlays/dialog/dialog.d.ts"
65
65
  },
66
66
  "./diff-changes": {
67
- "types": "./dist/data-display/diff-changes/diff-changes.d.ts",
68
- "import": "./src/data-display/diff-changes/diff-changes.tsx"
67
+ "import": "./src/data-display/diff-changes/diff-changes.tsx",
68
+ "types": "./dist/data-display/diff-changes/diff-changes.d.ts"
69
69
  },
70
70
  "./divider": {
71
- "types": "./dist/layout/divider/divider.d.ts",
72
- "import": "./src/layout/divider/divider.tsx"
71
+ "import": "./src/layout/divider/divider.tsx",
72
+ "types": "./dist/layout/divider/divider.d.ts"
73
73
  },
74
74
  "./field": {
75
- "types": "./dist/forms/field/field.d.ts",
76
- "import": "./src/forms/field/field.tsx"
75
+ "import": "./src/forms/field/field.tsx",
76
+ "types": "./dist/forms/field/field.d.ts"
77
77
  },
78
78
  "./file-tree.css": "./src/styles/file-tree.css",
79
79
  "./icon": {
80
- "types": "./dist/icons/icon/icon.d.ts",
81
- "import": "./src/icons/icon/icon.tsx"
80
+ "import": "./src/icons/icon/icon.tsx",
81
+ "types": "./dist/icons/icon/icon.d.ts"
82
82
  },
83
83
  "./icons/catalog": {
84
- "types": "./dist/icons/catalog.d.ts",
85
- "import": "./src/icons/catalog.ts"
84
+ "import": "./src/icons/catalog.ts",
85
+ "types": "./dist/icons/catalog.d.ts"
86
86
  },
87
87
  "./icon-button": {
88
- "types": "./dist/actions/icon-button/icon-button.d.ts",
89
- "import": "./src/actions/icon-button/icon-button.tsx"
88
+ "import": "./src/actions/icon-button/icon-button.tsx",
89
+ "types": "./dist/actions/icon-button/icon-button.d.ts"
90
90
  },
91
91
  "./inline-input": {
92
- "types": "./dist/forms/inline-input/inline-input.d.ts",
93
- "import": "./src/forms/inline-input/inline-input.tsx"
92
+ "import": "./src/forms/inline-input/inline-input.tsx",
93
+ "types": "./dist/forms/inline-input/inline-input.d.ts"
94
94
  },
95
95
  "./keybind": {
96
- "types": "./dist/data-display/keybind/keybind.d.ts",
97
- "import": "./src/data-display/keybind/keybind.tsx"
96
+ "import": "./src/data-display/keybind/keybind.tsx",
97
+ "types": "./dist/data-display/keybind/keybind.d.ts"
98
98
  },
99
99
  "./line-comment": {
100
- "types": "./dist/data-display/line-comment/line-comment.d.ts",
101
- "import": "./src/data-display/line-comment/line-comment.tsx"
100
+ "import": "./src/data-display/line-comment/line-comment.tsx",
101
+ "types": "./dist/data-display/line-comment/line-comment.d.ts"
102
102
  },
103
103
  "./loader": {
104
- "types": "./dist/feedback/loader/loader.d.ts",
105
- "import": "./src/feedback/loader/loader.tsx"
104
+ "import": "./src/feedback/loader/loader.tsx",
105
+ "types": "./dist/feedback/loader/loader.d.ts"
106
106
  },
107
107
  "./menu": {
108
- "types": "./dist/navigation/menu/menu.d.ts",
109
- "import": "./src/navigation/menu/menu.tsx"
108
+ "import": "./src/navigation/menu/menu.tsx",
109
+ "types": "./dist/navigation/menu/menu.d.ts"
110
110
  },
111
111
  "./motion": {
112
- "types": "./dist/motion/index.d.ts",
113
- "import": "./src/motion/index.ts"
112
+ "import": "./src/motion/index.ts",
113
+ "types": "./dist/motion/index.d.ts"
114
114
  },
115
115
  "./motion/solid": {
116
- "types": "./dist/motion/solid.d.ts",
117
- "import": "./src/motion/solid.ts"
116
+ "import": "./src/motion/solid.ts",
117
+ "types": "./dist/motion/solid.d.ts"
118
118
  },
119
119
  "./motion-tuning": {
120
- "types": "./dist/motion-tuning.d.ts",
121
- "import": "./src/motion-tuning.ts"
120
+ "import": "./src/motion-tuning.ts",
121
+ "types": "./dist/motion-tuning.d.ts"
122
122
  },
123
123
  "./motion-tuning-features": {
124
- "types": "./dist/motion-tuning-features.d.ts",
125
- "import": "./src/motion-tuning-features.ts"
124
+ "import": "./src/motion-tuning-features.ts",
125
+ "types": "./dist/motion-tuning-features.d.ts"
126
126
  },
127
127
  "./motion-tuning-fields": {
128
- "types": "./dist/motion-tuning-fields.d.ts",
129
- "import": "./src/motion-tuning-fields.ts"
128
+ "import": "./src/motion-tuning-fields.ts",
129
+ "types": "./dist/motion-tuning-fields.d.ts"
130
130
  },
131
131
  "./progress-circle": {
132
- "types": "./dist/feedback/progress-circle/progress-circle.d.ts",
133
- "import": "./src/feedback/progress-circle/progress-circle.tsx"
132
+ "import": "./src/feedback/progress-circle/progress-circle.tsx",
133
+ "types": "./dist/feedback/progress-circle/progress-circle.d.ts"
134
134
  },
135
135
  "./project-avatar": {
136
- "types": "./dist/data-display/project-avatar/project-avatar.d.ts",
137
- "import": "./src/data-display/project-avatar/project-avatar.tsx"
136
+ "import": "./src/data-display/project-avatar/project-avatar.tsx",
137
+ "types": "./dist/data-display/project-avatar/project-avatar.d.ts"
138
138
  },
139
139
  "./radio": {
140
- "types": "./dist/forms/radio/radio.d.ts",
141
- "import": "./src/forms/radio/radio.tsx"
140
+ "import": "./src/forms/radio/radio.tsx",
141
+ "types": "./dist/forms/radio/radio.d.ts"
142
142
  },
143
143
  "./search-list": {
144
- "types": "./dist/forms/search-list/search-list.d.ts",
145
- "import": "./src/forms/search-list/search-list.tsx"
144
+ "import": "./src/forms/search-list/search-list.tsx",
145
+ "types": "./dist/forms/search-list/search-list.d.ts"
146
146
  },
147
147
  "./segmented-control": {
148
- "types": "./dist/navigation/segmented-control/segmented-control.d.ts",
149
- "import": "./src/navigation/segmented-control/segmented-control.tsx"
148
+ "import": "./src/navigation/segmented-control/segmented-control.tsx",
149
+ "types": "./dist/navigation/segmented-control/segmented-control.d.ts"
150
150
  },
151
151
  "./select": {
152
- "types": "./dist/forms/select/select.d.ts",
153
- "import": "./src/forms/select/select.tsx"
152
+ "import": "./src/forms/select/select.tsx",
153
+ "types": "./dist/forms/select/select.d.ts"
154
154
  },
155
155
  "./split-button": {
156
- "types": "./dist/actions/split-button/split-button.d.ts",
157
- "import": "./src/actions/split-button/split-button.tsx"
156
+ "import": "./src/actions/split-button/split-button.tsx",
157
+ "types": "./dist/actions/split-button/split-button.d.ts"
158
158
  },
159
159
  "./switch": {
160
- "types": "./dist/forms/switch/switch.d.ts",
161
- "import": "./src/forms/switch/switch.tsx"
160
+ "import": "./src/forms/switch/switch.tsx",
161
+ "types": "./dist/forms/switch/switch.d.ts"
162
162
  },
163
163
  "./tab-state-indicator": {
164
- "types": "./dist/navigation/tab-state-indicator.d.ts",
165
- "import": "./src/navigation/tab-state-indicator.tsx"
164
+ "import": "./src/navigation/tab-state-indicator.tsx",
165
+ "types": "./dist/navigation/tab-state-indicator.d.ts"
166
166
  },
167
167
  "./tabs": {
168
- "types": "./dist/navigation/tabs/tabs.d.ts",
169
- "import": "./src/navigation/tabs/tabs.tsx"
168
+ "import": "./src/navigation/tabs/tabs.tsx",
169
+ "types": "./dist/navigation/tabs/tabs.d.ts"
170
170
  },
171
171
  "./text-input": {
172
- "types": "./dist/forms/text-input/text-input.d.ts",
173
- "import": "./src/forms/text-input/text-input.tsx"
172
+ "import": "./src/forms/text-input/text-input.tsx",
173
+ "types": "./dist/forms/text-input/text-input.d.ts"
174
174
  },
175
175
  "./text-input.css": "./src/forms/text-input/text-input.css",
176
176
  "./textarea": {
177
- "types": "./dist/forms/textarea/textarea.d.ts",
178
- "import": "./src/forms/textarea/textarea.tsx"
177
+ "import": "./src/forms/textarea/textarea.tsx",
178
+ "types": "./dist/forms/textarea/textarea.d.ts"
179
179
  },
180
180
  "./typeahead": {
181
- "types": "./dist/forms/typeahead/typeahead.d.ts",
182
- "import": "./src/forms/typeahead/typeahead.tsx"
181
+ "import": "./src/forms/typeahead/typeahead.tsx",
182
+ "types": "./dist/forms/typeahead/typeahead.d.ts"
183
183
  },
184
184
  "./slash": {
185
- "types": "./dist/typography/slash/slash.d.ts",
186
- "import": "./src/typography/slash/slash.tsx"
185
+ "import": "./src/typography/slash/slash.tsx",
186
+ "types": "./dist/typography/slash/slash.d.ts"
187
187
  },
188
188
  "./text-shimmer": {
189
- "types": "./dist/typography/text-shimmer/text-shimmer.d.ts",
190
- "import": "./src/typography/text-shimmer/text-shimmer.tsx"
189
+ "import": "./src/typography/text-shimmer/text-shimmer.tsx",
190
+ "types": "./dist/typography/text-shimmer/text-shimmer.d.ts"
191
191
  },
192
192
  "./toast": {
193
- "types": "./dist/feedback/toast/toast.d.ts",
194
- "import": "./src/feedback/toast/toast.tsx"
193
+ "import": "./src/feedback/toast/toast.tsx",
194
+ "types": "./dist/feedback/toast/toast.d.ts"
195
195
  },
196
196
  "./tooltip": {
197
- "types": "./dist/overlays/tooltip/tooltip.d.ts",
198
- "import": "./src/overlays/tooltip/tooltip.tsx"
197
+ "import": "./src/overlays/tooltip/tooltip.tsx",
198
+ "types": "./dist/overlays/tooltip/tooltip.d.ts"
199
199
  },
200
200
  "./wordmark": {
201
- "types": "./dist/typography/wordmark/wordmark.d.ts",
202
- "import": "./src/typography/wordmark/wordmark.tsx"
201
+ "import": "./src/typography/wordmark/wordmark.tsx",
202
+ "types": "./dist/typography/wordmark/wordmark.d.ts"
203
203
  },
204
204
  "./*": {
205
- "types": "./dist/components/*.d.ts",
206
- "import": "./src/components/*.tsx"
205
+ "import": "./src/components/*.tsx",
206
+ "types": "./dist/components/*.d.ts"
207
207
  },
208
208
  "./i18n/*": {
209
- "types": "./dist/i18n/*.d.ts",
210
- "import": "./src/i18n/*.ts"
209
+ "import": "./src/i18n/*.ts",
210
+ "types": "./dist/i18n/*.d.ts"
211
211
  },
212
212
  "./hooks": {
213
- "types": "./dist/hooks/index.d.ts",
214
- "import": "./src/hooks/index.ts"
213
+ "import": "./src/hooks/index.ts",
214
+ "types": "./dist/hooks/index.d.ts"
215
215
  },
216
216
  "./context": {
217
- "types": "./dist/context/index.d.ts",
218
- "import": "./src/context/index.ts"
217
+ "import": "./src/context/index.ts",
218
+ "types": "./dist/context/index.d.ts"
219
219
  },
220
220
  "./context/*": {
221
- "types": "./dist/context/*.d.ts",
222
- "import": "./src/context/*.tsx"
221
+ "import": "./src/context/*.tsx",
222
+ "types": "./dist/context/*.d.ts"
223
223
  },
224
224
  "./storybook/scaffold": {
225
- "types": "./dist/storybook/scaffold.d.ts",
226
- "import": "./src/storybook/scaffold.tsx"
225
+ "import": "./src/storybook/scaffold.tsx",
226
+ "types": "./dist/storybook/scaffold.d.ts"
227
227
  },
228
228
  "./storybook/fixtures": {
229
- "types": "./dist/storybook/fixtures.d.ts",
230
- "import": "./src/storybook/fixtures.ts"
229
+ "import": "./src/storybook/fixtures.ts",
230
+ "types": "./dist/storybook/fixtures.d.ts"
231
231
  },
232
232
  "./styles": "./src/styles/index.css",
233
233
  "./styles/tokens": "./src/styles/tokens/index.css",
234
234
  "./styles/tokens/*": "./src/styles/tokens/*",
235
235
  "./styles/tailwind": "./src/styles/tailwind/index.css",
236
236
  "./theme": {
237
- "types": "./dist/theme/index.d.ts",
238
- "import": "./src/theme/index.ts"
237
+ "import": "./src/theme/index.ts",
238
+ "types": "./dist/theme/index.d.ts"
239
239
  },
240
240
  "./theme/*": {
241
- "types": "./dist/theme/*.d.ts",
242
- "import": "./src/theme/*.ts"
241
+ "import": "./src/theme/*.ts",
242
+ "types": "./dist/theme/*.d.ts"
243
243
  },
244
244
  "./theme/context": {
245
- "types": "./dist/theme/context.d.ts",
246
- "import": "./src/theme/context.tsx"
245
+ "import": "./src/theme/context.tsx",
246
+ "types": "./dist/theme/context.d.ts"
247
247
  },
248
248
  "./icons/provider": {
249
- "types": "./dist/components/provider-icons/types.d.ts",
250
- "import": "./src/components/provider-icons/types.ts"
249
+ "import": "./src/components/provider-icons/types.ts",
250
+ "types": "./dist/components/provider-icons/types.d.ts"
251
251
  },
252
252
  "./icons/file-type": {
253
- "types": "./dist/components/file-icons/types.d.ts",
254
- "import": "./src/components/file-icons/types.ts"
253
+ "import": "./src/components/file-icons/types.ts",
254
+ "types": "./dist/components/file-icons/types.d.ts"
255
255
  },
256
256
  "./icons/app": {
257
- "types": "./dist/components/app-icons/types.d.ts",
258
- "import": "./src/components/app-icons/types.ts"
257
+ "import": "./src/components/app-icons/types.ts",
258
+ "types": "./dist/components/app-icons/types.d.ts"
259
259
  },
260
260
  "./fonts/*": "./src/assets/fonts/*",
261
261
  "./audio/*": "./src/assets/audio/*"
262
262
  },
263
263
  "scripts": {
264
264
  "build": "rm -rf dist && tsc -p tsconfig.build.json",
265
+ "pack": "bun run script/pack.ts",
265
266
  "typecheck": "bun check --no-script",
266
267
  "typecheck:tsc": "tsc --noEmit",
267
268
  "test": "bun test src --only-failures",
@@ -285,7 +286,7 @@
285
286
  "dependencies": {
286
287
  "@kitlangton/solid-motion": "0.2.2",
287
288
  "@kobalte/core": "0.13.13",
288
- "@opencode/util": "0.0.0-dev-21922",
289
+ "@opencode/util": "0.0.0-dev-51",
289
290
  "@pierre/diffs": "1.6.1",
290
291
  "@pierre/highlights": "0.2.0",
291
292
  "@solid-primitives/event-listener": "2.4.6",
@@ -0,0 +1,24 @@
1
+ [data-component="rolling-number"] {
2
+ display: inline-flex;
3
+ /* Digits keep numeric order in RTL documents. */
4
+ direction: ltr;
5
+ unicode-bidi: isolate;
6
+ font-variant-numeric: tabular-nums;
7
+
8
+ [data-slot="rolling-number-digit"] {
9
+ display: inline-grid;
10
+ overflow-y: clip;
11
+ }
12
+
13
+ [data-slot="rolling-number-glyph"] {
14
+ grid-area: 1 / 1;
15
+ }
16
+
17
+ [data-slot="rolling-number-glyph"][data-leaving] {
18
+ pointer-events: none;
19
+
20
+ &::before {
21
+ content: attr(data-leaving);
22
+ }
23
+ }
24
+ }
@@ -0,0 +1,135 @@
1
+ import { For, createEffect, createMemo, on, onCleanup } from "solid-js"
2
+ import { frameLoop, prefersReducedMotion, Spring, type DurationOptions } from "../motion"
3
+
4
+ const settle: DurationOptions = { duration: 0.375, bounce: 0 }
5
+
6
+ // A whole number whose changed digits roll: up when it grows, down when it shrinks. Each digit rolls inside its own
7
+ // box on a bounce-free spring, by transform and opacity only, and swaps at once under reduced motion. Digits are
8
+ // tabular, so the width holds while they roll.
9
+ export function RollingNumber(props: { value: number; spring?: DurationOptions; class?: string }) {
10
+ const shown = createMemo<{ text: string; dir: number }>(
11
+ (last) => {
12
+ const value = Number.isFinite(props.value) ? Math.max(0, Math.round(props.value)) : 0
13
+
14
+ return { text: String(value), dir: value < Number(last.text) ? -1 : 1 }
15
+ },
16
+ { text: "", dir: 1 },
17
+ )
18
+
19
+ // Place values, most significant first, so each place keeps its digit box as digits appear and leave.
20
+ const places = createMemo(() =>
21
+ Array.from({ length: shown().text.length }, (_, index) => shown().text.length - 1 - index),
22
+ )
23
+
24
+ return (
25
+ <span data-component="rolling-number" class={props.class}>
26
+ <For each={places()}>
27
+ {(place) => (
28
+ <Digit
29
+ digit={shown().text[shown().text.length - 1 - place] ?? ""}
30
+ dir={shown().dir}
31
+ spring={props.spring ?? settle}
32
+ />
33
+ )}
34
+ </For>
35
+ </span>
36
+ )
37
+ }
38
+
39
+ function Digit(props: { digit: string; dir: number; spring: DurationOptions }) {
40
+ let incoming: HTMLSpanElement | undefined
41
+ let outgoing: HTMLSpanElement | undefined
42
+ let spring: Spring | undefined
43
+ let stop: VoidFunction | undefined
44
+ // Offsets in digit heights, down positive: the new digit enters from `enter`, the old one leaves from `from` to `to`.
45
+ let enter = 0
46
+ let from = 0
47
+ let to = 0
48
+
49
+ const progress = () => (spring ? Math.max(0, Math.min(1, spring.value)) : 1)
50
+
51
+ const paint = () => {
52
+ const p = progress()
53
+ roll(incoming, enter * (1 - p))
54
+ roll(outgoing, from + (to - from) * p)
55
+
56
+ if (!spring && outgoing) outgoing.dataset.leaving = ""
57
+ }
58
+
59
+ const tick = (dt: number) => {
60
+ spring?.step(dt)
61
+
62
+ if (spring?.resting) spring = undefined
63
+ paint()
64
+
65
+ if (spring) return true
66
+ stop = undefined
67
+
68
+ return false
69
+ }
70
+
71
+ let last = props.digit
72
+
73
+ createEffect(
74
+ on(
75
+ () => props.digit,
76
+ (next) => {
77
+ const prev = last
78
+ last = next
79
+
80
+ if (!incoming || !outgoing || next === prev) return
81
+
82
+ if (prefersReducedMotion() || !incoming.isConnected) {
83
+ incoming.textContent = next
84
+ spring = undefined
85
+ paint()
86
+
87
+ return
88
+ }
89
+
90
+ // A change mid-roll carries on from where both digits are, so together they never show less than one digit.
91
+ // Going back to the digit still leaving brings it back from where it is, and the arriving one leaves the way it
92
+ // came. Otherwise the digit nearer the middle leaves from there, and the new one comes in as far out as the
93
+ // other was, so a digit that had barely appeared never crosses the middle.
94
+ const p = progress()
95
+ const now = { in: enter * (1 - p), out: from + (to - from) * p }
96
+ const back = !!spring && next === outgoing.dataset.leaving
97
+ const near = back || Math.abs(now.in) <= Math.abs(now.out)
98
+ const far = !spring ? 1 : Math.min(1, Math.abs(near ? now.out : now.in))
99
+
100
+ if (near) outgoing.dataset.leaving = prev
101
+ from = near ? now.in : now.out
102
+ to = -props.dir
103
+ enter = back ? now.out : props.dir * far
104
+ incoming.textContent = next
105
+ spring = Spring.fromDuration(0, props.spring).set(1)
106
+ paint()
107
+ stop ??= frameLoop.add(tick)
108
+ },
109
+ { defer: true },
110
+ ),
111
+ )
112
+
113
+ onCleanup(() => stop?.())
114
+
115
+ return (
116
+ <span data-slot="rolling-number-digit">
117
+ <span
118
+ data-slot="rolling-number-glyph"
119
+ ref={(el) => {
120
+ incoming = el
121
+ el.textContent = props.digit
122
+ }}
123
+ />
124
+ {/* The leaving digit is drawn from its attribute, so the number's text is only ever the value it shows. */}
125
+ <span data-slot="rolling-number-glyph" data-leaving="" aria-hidden="true" ref={(el) => (outgoing = el)} />
126
+ </span>
127
+ )
128
+ }
129
+
130
+ function roll(el: HTMLElement | undefined, offset: number) {
131
+ if (!el) return
132
+ const still = Math.abs(offset) < 0.001
133
+ el.style.transform = still ? "" : `translate3d(0,${(offset * 100).toFixed(2)}%,0)`
134
+ el.style.opacity = still ? "" : (1 - Math.min(1, Math.abs(offset))).toFixed(4)
135
+ }
@@ -1,4 +1,7 @@
1
1
  [data-component="search-list"] {
2
+ /* Sticky headers and the top fade paint this, so rows scroll under an opaque band. */
3
+ --search-list-surface: var(--v2-background-bg-base);
4
+
2
5
  display: flex;
3
6
  min-height: 0;
4
7
  flex: 1;
@@ -42,6 +45,17 @@
42
45
  }
43
46
  }
44
47
 
48
+ [data-slot="search-list-body"] {
49
+ display: flex;
50
+ min-height: 0;
51
+ flex: 1;
52
+ flex-direction: column;
53
+
54
+ &[hidden] {
55
+ display: none;
56
+ }
57
+ }
58
+
45
59
  /* Arrow keys scroll the active row clear of the sticky header. Rows fade out past the bottom edge while more follow. */
46
60
  [data-slot="search-list-scroll"] {
47
61
  min-height: 0;
@@ -69,7 +83,7 @@
69
83
  position: absolute;
70
84
  inset: var(--search-list-fade-offset, 0px) 0 auto;
71
85
  height: 24px;
72
- background: linear-gradient(var(--v2-background-bg-base), transparent);
86
+ background: linear-gradient(var(--search-list-surface), transparent);
73
87
  content: "";
74
88
  opacity: var(--search-list-fade-top, 0);
75
89
  }
@@ -79,6 +93,11 @@
79
93
  display: flex;
80
94
  flex-direction: column;
81
95
  padding: 6px 6px 8px;
96
+
97
+ /* Its padding would sit above the empty state and push it below the centre. */
98
+ &[hidden] {
99
+ display: none;
100
+ }
82
101
  }
83
102
 
84
103
  [data-slot="search-list-section"] {
@@ -104,7 +123,7 @@
104
123
  height: 28px;
105
124
  margin-inline: -6px;
106
125
  padding-inline: 18px;
107
- background: var(--v2-background-bg-base);
126
+ background: var(--search-list-surface);
108
127
  color: var(--v2-text-text-muted);
109
128
  font-size: 13px;
110
129
  font-weight: 440;
@@ -160,6 +179,40 @@
160
179
  line-height: var(--line-height-compact);
161
180
  letter-spacing: -0.04px;
162
181
  }
182
+
183
+ /* On the rows' text spine, under the bottom fade rather than inside it. */
184
+ [data-slot="search-list-footer"] {
185
+ flex-shrink: 0;
186
+ padding: 4px 18px 12px;
187
+ color: var(--v2-text-text-muted);
188
+ font-size: 13px;
189
+ font-weight: 440;
190
+ line-height: var(--line-height-compact);
191
+ letter-spacing: -0.04px;
192
+ }
193
+
194
+ &[data-popover] {
195
+ --search-list-surface: var(--v2-background-bg-layer-01);
196
+
197
+ position: relative;
198
+ flex: none;
199
+
200
+ [data-slot="search-list-body"] {
201
+ position: absolute;
202
+ inset-block-start: calc(100% + 4px);
203
+ inset-inline: 0;
204
+ z-index: 12;
205
+ max-height: min(45vh, 480px);
206
+ overflow: hidden;
207
+ border-radius: 8px;
208
+ background: var(--search-list-surface);
209
+ box-shadow: var(--v2-elevation-floating);
210
+ }
211
+
212
+ [data-slot="search-list-scroll"] {
213
+ flex: 0 1 auto;
214
+ }
215
+ }
163
216
  }
164
217
 
165
218
  [data-color-scheme="dark"] [data-component="search-list"] [data-slot="search-list-row"][data-active] {
@@ -1,4 +1,15 @@
1
- import { createContext, createEffect, createMemo, For, type JSX, on, onCleanup, Show, useContext } from "solid-js"
1
+ import {
2
+ createContext,
3
+ createEffect,
4
+ createMemo,
5
+ For,
6
+ type JSX,
7
+ on,
8
+ onCleanup,
9
+ onMount,
10
+ Show,
11
+ useContext,
12
+ } from "solid-js"
2
13
  import { createResizeObserver } from "@solid-primitives/resize-observer"
3
14
  import { Icon } from "@opencode/ui/icon"
4
15
  import { TextInput } from "../text-input/text-input"
@@ -18,6 +29,17 @@ export type SearchListRow = {
18
29
  onClick: () => void
19
30
  }
20
31
 
32
+ /** Attributes for the input of a field passed as `field`: spread them onto it. */
33
+ export type SearchListField = {
34
+ role: "combobox"
35
+ "aria-expanded": boolean
36
+ "aria-autocomplete": "list"
37
+ "aria-controls": string | undefined
38
+ "aria-activedescendant": string | undefined
39
+ onInput: (event: InputEvent & { currentTarget: HTMLInputElement }) => void
40
+ onKeyDown: (event: KeyboardEvent) => void
41
+ }
42
+
21
43
  export type SearchListHandle<T> = {
22
44
  active: () => T | undefined
23
45
  setActive: (key: string | undefined) => void
@@ -29,13 +51,22 @@ const QueryContext = createContext<() => string>(() => "")
29
51
  * A search field over sectioned results. Rows that share a `section` key list together under one header, which sticks
30
52
  * while its rows scroll beneath it until the next header pushes it away. The first row is active until the user picks
31
53
  * another: ↑/↓ wrap, ⌘ or ⌥ with ↑/↓ jump between sections, Home/End go to the ends, Enter selects and Escape closes.
54
+ * A page can keep its own field through `field` and float the results beneath it with `popover`.
32
55
  */
33
56
  export function SearchList<T>(props: {
34
57
  query: string
35
58
  onQuery: (query: string) => void
36
59
  placeholder: string
60
+ /** The results' accessible name; the placeholder by default. */
61
+ label?: string
37
62
  /** Controls after the field, such as icon buttons. */
38
63
  trailing?: JSX.Element
64
+ /** A search field of the page's own in place of the built-in one. */
65
+ field?: (field: SearchListField) => JSX.Element
66
+ /** Whether the results show. Closed, only the field remains and the list leaves keys to the page. On by default. */
67
+ open?: boolean
68
+ /** Float the results beneath the field on a raised surface, over what follows it. */
69
+ popover?: boolean
39
70
  items: T[]
40
71
  key: (item: T) => string
41
72
  section?: (item: T) => string
@@ -45,6 +76,11 @@ export function SearchList<T>(props: {
45
76
  header?: (item: T) => JSX.Element
46
77
  /** Shown in place of the rows when there are none. */
47
78
  empty: JSX.Element
79
+ /** A note beneath the rows, such as a hint that more results are hidden. */
80
+ footer?: JSX.Element
81
+ /** Where the results start scrolled each time they mount, such as a position kept from an earlier visit. */
82
+ scrollTop?: number
83
+ onScroll?: (scrollTop: number) => void
48
84
  onSelect: (item: T) => void
49
85
  onActive?: (item: T | undefined) => void
50
86
  /** Runs before the list's own keys; call `preventDefault` to claim one. */
@@ -59,6 +95,7 @@ export function SearchList<T>(props: {
59
95
  let results: HTMLDivElement | undefined
60
96
 
61
97
  const sectionOf = (item: T) => props.section?.(item) ?? ""
98
+ const open = () => props.open ?? true
62
99
 
63
100
  // Sections in the order their first row arrives; rows then list section by section, which is also the arrow order.
64
101
  const groups = createMemo(() => {
@@ -173,7 +210,7 @@ export function SearchList<T>(props: {
173
210
  if (event.isComposing) return
174
211
  props.onKeyDown?.(event, typeahead.activeItem())
175
212
 
176
- if (event.defaultPrevented) return
213
+ if (event.defaultPrevented || !open()) return
177
214
  const move = searchListMove(event)
178
215
 
179
216
  if (!move) return typeahead.onKeyDown(event)
@@ -198,6 +235,30 @@ export function SearchList<T>(props: {
198
235
  reveal()
199
236
  }
200
237
 
238
+ onMount(() => {
239
+ if (viewport && props.scrollTop) viewport.scrollTop = props.scrollTop
240
+ })
241
+
242
+ const field: SearchListField = {
243
+ role: "combobox",
244
+ get "aria-expanded"() {
245
+ return open()
246
+ },
247
+ "aria-autocomplete": "list",
248
+ get "aria-controls"() {
249
+ return open() ? typeahead.listID : undefined
250
+ },
251
+ get "aria-activedescendant"() {
252
+ return open() ? typeahead.activeID() : undefined
253
+ },
254
+ onInput: (event) => {
255
+ // A new query starts again from its first row.
256
+ typeahead.setActive(undefined)
257
+ props.onQuery(event.currentTarget.value)
258
+ },
259
+ onKeyDown,
260
+ }
261
+
201
262
  const row = (key: string, item: () => T): SearchListRow => ({
202
263
  get id() {
203
264
  return typeahead.optionID(item())
@@ -221,80 +282,91 @@ export function SearchList<T>(props: {
221
282
 
222
283
  return (
223
284
  <QueryContext.Provider value={() => props.query}>
224
- <div data-component="search-list" class={props.class}>
225
- <div data-slot="search-list-search">
226
- <TextInput
227
- value={props.query}
228
- autofocus
229
- autocomplete="off"
230
- autocorrect="off"
231
- autocapitalize="off"
232
- spellcheck={false}
233
- appearance="large"
234
- placeholder={props.placeholder}
235
- aria-label={props.placeholder}
236
- leadingIcon={<Icon name="magnifying-glass" />}
237
- trailing={props.trailing}
238
- role="combobox"
239
- aria-expanded="true"
240
- aria-autocomplete="list"
241
- aria-controls={typeahead.listID}
242
- aria-activedescendant={typeahead.activeID()}
243
- onInput={(event) => {
244
- // A new query starts again from its first row.
245
- typeahead.setActive(undefined)
246
- props.onQuery(event.currentTarget.value)
247
- }}
248
- onKeyDown={onKeyDown}
249
- />
250
- </div>
251
- <div data-slot="search-list-scroll" data-scrollable ref={(element) => (viewport = element)} onScroll={edges}>
252
- <div data-slot="search-list-fade" aria-hidden="true" />
285
+ <div data-component="search-list" data-popover={props.popover ? "" : undefined} class={props.class}>
286
+ <Show
287
+ when={props.field}
288
+ fallback={
289
+ <div data-slot="search-list-search">
290
+ <TextInput
291
+ {...field}
292
+ value={props.query}
293
+ autofocus
294
+ autocomplete="off"
295
+ autocorrect="off"
296
+ autocapitalize="off"
297
+ spellcheck={false}
298
+ appearance="large"
299
+ placeholder={props.placeholder}
300
+ aria-label={props.placeholder}
301
+ leadingIcon={<Icon name="magnifying-glass" />}
302
+ trailing={props.trailing}
303
+ />
304
+ </div>
305
+ }
306
+ >
307
+ {(custom) => custom()(field)}
308
+ </Show>
309
+ <div data-slot="search-list-body" hidden={!open()}>
253
310
  <div
254
- ref={results}
255
- id={typeahead.listID}
256
- data-slot="search-list-results"
257
- role="listbox"
258
- aria-label={props.placeholder}
311
+ data-slot="search-list-scroll"
312
+ data-scrollable
313
+ ref={(element) => (viewport = element)}
314
+ onScroll={(event) => {
315
+ edges()
316
+ props.onScroll?.(event.currentTarget.scrollTop)
317
+ }}
259
318
  >
260
- <For each={sectionKeys()}>
261
- {(section) => {
262
- const keys = createMemo<string[]>((previous) =>
263
- stable(previous, (groups().get(section) ?? []).map(props.key)),
264
- )
265
-
266
- const first = () => byKey().get(keys()[0] ?? "")
267
-
268
- const header = createMemo(() =>
269
- props.header && first() !== undefined ? props.header(first()!) : undefined,
270
- )
271
-
272
- const id = `${typeahead.listID}-section-${encodeURIComponent(section)}`
273
-
274
- return (
275
- <div data-slot="search-list-section" role="group" aria-labelledby={header() ? id : undefined}>
276
- <Show when={header()}>
277
- {(content) => (
278
- <div id={id} data-slot="search-list-header">
279
- {content()}
280
- </div>
281
- )}
282
- </Show>
283
- <For each={keys()}>
284
- {(key) => {
285
- // A row that is leaving keeps its last item until it is removed.
286
- const item = createMemo<T>((previous) => byKey().get(key) ?? previous, byKey().get(key)!)
287
-
288
- return props.children(item, row(key, item))
289
- }}
290
- </For>
291
- </div>
292
- )
293
- }}
294
- </For>
319
+ <div data-slot="search-list-fade" aria-hidden="true" />
320
+ <div
321
+ ref={results}
322
+ id={typeahead.listID}
323
+ data-slot="search-list-results"
324
+ role="listbox"
325
+ hidden={rows().length === 0}
326
+ aria-label={props.label ?? props.placeholder}
327
+ >
328
+ <For each={sectionKeys()}>
329
+ {(section) => {
330
+ const keys = createMemo<string[]>((previous) =>
331
+ stable(previous, (groups().get(section) ?? []).map(props.key)),
332
+ )
333
+
334
+ const first = () => byKey().get(keys()[0] ?? "")
335
+
336
+ const header = createMemo(() =>
337
+ props.header && first() !== undefined ? props.header(first()!) : undefined,
338
+ )
339
+
340
+ const id = `${typeahead.listID}-section-${encodeURIComponent(section)}`
341
+
342
+ return (
343
+ <div data-slot="search-list-section" role="group" aria-labelledby={header() ? id : undefined}>
344
+ <Show when={header()}>
345
+ {(content) => (
346
+ <div id={id} data-slot="search-list-header">
347
+ {content()}
348
+ </div>
349
+ )}
350
+ </Show>
351
+ <For each={keys()}>
352
+ {(key) => {
353
+ // A row that is leaving keeps its last item until it is removed.
354
+ const item = createMemo<T>((previous) => byKey().get(key) ?? previous, byKey().get(key)!)
355
+
356
+ return props.children(item, row(key, item))
357
+ }}
358
+ </For>
359
+ </div>
360
+ )
361
+ }}
362
+ </For>
363
+ </div>
364
+ <Show when={rows().length === 0}>
365
+ <div data-slot="search-list-empty">{props.empty}</div>
366
+ </Show>
295
367
  </div>
296
- <Show when={rows().length === 0}>
297
- <div data-slot="search-list-empty">{props.empty}</div>
368
+ <Show when={props.footer}>
369
+ <div data-slot="search-list-footer">{props.footer}</div>
298
370
  </Show>
299
371
  </div>
300
372
  </div>
@@ -35,7 +35,9 @@ export function createTypeahead<T>(props: {
35
35
  onKeyDown: (event: KeyboardEvent) => {
36
36
  if (event.isComposing) return
37
37
  const items = props.items()
38
- const delta = event.key === "ArrowDown" ? 1 : event.key === "ArrowUp" ? -1 : 0
38
+ // Modified arrows belong to the input: Shift selects text, Ctrl and the rest are the platform's.
39
+ const plain = !event.shiftKey && !event.ctrlKey && !event.altKey && !event.metaKey
40
+ const delta = !plain ? 0 : event.key === "ArrowDown" ? 1 : event.key === "ArrowUp" ? -1 : 0
39
41
 
40
42
  if (delta !== 0 || event.key === "Enter" || (event.key === "Escape" && props.onClose)) {
41
43
  event.preventDefault()
@@ -9,6 +9,7 @@
9
9
 
10
10
  @import "../data-display/accordion/accordion.css" layer(components);
11
11
  @import "../components/animated-number.css" layer(components);
12
+ @import "../components/rolling-number.css" layer(components);
12
13
  @import "../components/app-icon.css" layer(components);
13
14
  @import "../components/card.css" layer(components);
14
15
  @import "../forms/checkbox/checkbox.css" layer(components);