@charcuterie/ui 4.28.4 → 4.30.0

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 (49) hide show
  1. package/dist/CatalogPicker/CatalogPicker.d.ts +110 -0
  2. package/dist/CatalogPicker/CatalogPicker.d.ts.map +1 -0
  3. package/dist/CatalogPicker/CatalogPicker.js +155 -0
  4. package/dist/CatalogPicker/CatalogPicker.js.map +1 -0
  5. package/dist/CatalogPicker/CatalogPickerMark.d.ts +29 -0
  6. package/dist/CatalogPicker/CatalogPickerMark.d.ts.map +1 -0
  7. package/dist/CatalogPicker/CatalogPickerMark.js +35 -0
  8. package/dist/CatalogPicker/CatalogPickerMark.js.map +1 -0
  9. package/dist/CatalogPicker/CatalogPickerOption.d.ts +40 -0
  10. package/dist/CatalogPicker/CatalogPickerOption.d.ts.map +1 -0
  11. package/dist/CatalogPicker/CatalogPickerOption.js +43 -0
  12. package/dist/CatalogPicker/CatalogPickerOption.js.map +1 -0
  13. package/dist/CatalogPicker/CatalogPickerPanel.d.ts +60 -0
  14. package/dist/CatalogPicker/CatalogPickerPanel.d.ts.map +1 -0
  15. package/dist/CatalogPicker/CatalogPickerPanel.js +409 -0
  16. package/dist/CatalogPicker/CatalogPickerPanel.js.map +1 -0
  17. package/dist/CatalogPicker/CatalogPickerRail.d.ts +50 -0
  18. package/dist/CatalogPicker/CatalogPickerRail.d.ts.map +1 -0
  19. package/dist/CatalogPicker/CatalogPickerRail.js +114 -0
  20. package/dist/CatalogPicker/CatalogPickerRail.js.map +1 -0
  21. package/dist/CatalogPicker/catalogPickerDrawings.d.ts +10 -0
  22. package/dist/CatalogPicker/catalogPickerDrawings.d.ts.map +1 -0
  23. package/dist/CatalogPicker/catalogPickerDrawings.js +29 -0
  24. package/dist/CatalogPicker/catalogPickerDrawings.js.map +1 -0
  25. package/dist/CatalogPicker/catalogPickerView.d.ts +185 -0
  26. package/dist/CatalogPicker/catalogPickerView.d.ts.map +1 -0
  27. package/dist/CatalogPicker/catalogPickerView.js +245 -0
  28. package/dist/CatalogPicker/catalogPickerView.js.map +1 -0
  29. package/dist/index.d.ts +2 -0
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +1 -0
  32. package/dist/index.js.map +1 -1
  33. package/package.json +1 -1
  34. package/src/CatalogPicker/CatalogPicker.mdx +192 -0
  35. package/src/CatalogPicker/CatalogPicker.stories.tsx +218 -0
  36. package/src/CatalogPicker/CatalogPicker.test.tsx +1592 -0
  37. package/src/CatalogPicker/CatalogPicker.tsx +387 -0
  38. package/src/CatalogPicker/CatalogPickerMark.tsx +89 -0
  39. package/src/CatalogPicker/CatalogPickerOption.tsx +151 -0
  40. package/src/CatalogPicker/CatalogPickerPanel.tsx +780 -0
  41. package/src/CatalogPicker/CatalogPickerRail.tsx +214 -0
  42. package/src/CatalogPicker/catalogPicker.storyHelpers.tsx +276 -0
  43. package/src/CatalogPicker/catalogPickerDrawings.tsx +51 -0
  44. package/src/CatalogPicker/catalogPickerView.test.ts +365 -0
  45. package/src/CatalogPicker/catalogPickerView.ts +476 -0
  46. package/src/Dialog/Dialog.test.tsx +20 -289
  47. package/src/Field/Field.test.tsx +11 -405
  48. package/src/index.ts +6 -0
  49. package/src/sourceRules.test.ts +5 -1
@@ -0,0 +1,387 @@
1
+ import { useVisibility } from "@charcuterie/logic"
2
+ import type { ControlSize } from "@charcuterie/tokens"
3
+ import type { Placement } from "@floating-ui/react"
4
+ import {
5
+ FloatingFocusManager,
6
+ FloatingPortal,
7
+ } from "@floating-ui/react"
8
+ import type {
9
+ ComponentPropsWithRef,
10
+ ReactNode,
11
+ } from "react"
12
+ import { useEffect, useMemo, useRef, useState } from "react"
13
+
14
+ import { Button } from "../Button/Button.tsx"
15
+ import { PANEL_SURFACE_CLASS } from "../Overlay/overlayPanelClass.ts"
16
+ import { useAnchoredOverlay } from "../Overlay/useAnchoredOverlay.ts"
17
+ import { usePanelItemSize } from "../Overlay/usePanelItemSize.ts"
18
+ import { toClassName } from "../toClassName.ts"
19
+ import { CatalogPickerMark } from "./CatalogPickerMark.tsx"
20
+ import { CatalogPickerPanel } from "./CatalogPickerPanel.tsx"
21
+ import {
22
+ type CatalogPickerGroup,
23
+ type CatalogPickerItem,
24
+ toGroupedName,
25
+ toUniqueCatalog,
26
+ } from "./catalogPickerView.ts"
27
+
28
+ export type {
29
+ CatalogPickerGroup,
30
+ CatalogPickerItem,
31
+ } from "./catalogPickerView.ts"
32
+
33
+ /**
34
+ * A constant element rather than a component, as in `Picker`: a
35
+ * second component in this file trips the house rule, and this never
36
+ * varies.
37
+ */
38
+ const CHEVRON_DOWN = (
39
+ <svg
40
+ aria-hidden="true"
41
+ className="size-4"
42
+ fill="none"
43
+ focusable={false}
44
+ stroke="currentColor"
45
+ strokeLinecap="round"
46
+ strokeLinejoin="round"
47
+ strokeWidth={1.75}
48
+ viewBox="0 0 24 24"
49
+ xmlns="http://www.w3.org/2000/svg"
50
+ >
51
+ <path d="m6 9 6 6 6-6" />
52
+ </svg>
53
+ )
54
+
55
+ export type CatalogPickerProps = Omit<
56
+ ComponentPropsWithRef<"button">,
57
+ "children" | "disabled" | "onChange" | "value"
58
+ > & {
59
+ /**
60
+ * The glyph inside the search field's clear button — the app's own,
61
+ * as for `SearchInput`. Without one there is no clear button, and
62
+ * Escape clears the query.
63
+ */
64
+ clearIcon?: ReactNode
65
+ /** The trigger. As in `Picker`, the outermost box this renders. */
66
+ className?: string
67
+ /** Shown when a search matches nothing. Default "No matches". */
68
+ emptyLabel?: string
69
+ /** Item values, in the order the Favorites tab lists them. No favorites, no Favorites tab. */
70
+ favorites?: readonly string[]
71
+ /** The Favorites tab's accessible name and tooltip. Default "Favorites". */
72
+ favoritesLabel?: string
73
+ /**
74
+ * The rail, top to bottom (after Favorites). A group with no rows is
75
+ * left off. Each `id` must be unique: a repeated one is dropped (the
76
+ * first wins), with a console warning.
77
+ */
78
+ groups: readonly CatalogPickerGroup[]
79
+ isDisabled?: boolean
80
+ /**
81
+ * Everything that can be chosen. A group's rows keep this order. Each
82
+ * `value` must be unique across the catalog: a repeated one is
83
+ * dropped (the first wins), with a console warning.
84
+ */
85
+ items: readonly CatalogPickerItem[]
86
+ /**
87
+ * What the control is FOR — "Agent", "Model". Not the current value.
88
+ * The trigger is named `"<label>: <chosen label>"`, as in `Picker`,
89
+ * then `", <group label>"` when the chosen item's group has a label
90
+ * that is not blank; the
91
+ * search field and the list are named `label`.
92
+ */
93
+ label: string
94
+ onChange: (value: string) => void
95
+ /** The trigger's text when nothing is chosen. */
96
+ placeholder?: string
97
+ /** Where the panel opens against the trigger. Default `bottom-start`. */
98
+ placement?: Placement
99
+ /** The search field's placeholder. Default "Search…". */
100
+ searchPlaceholder?: string
101
+ /** The trigger's size, and the size of every row in the panel. Default `md`. */
102
+ size?: ControlSize
103
+ value?: string
104
+ }
105
+
106
+ /** Tall enough for about nine rows at `md`, and never taller than the window leaves. */
107
+ const PANEL_MAX_HEIGHT_PX = 448
108
+
109
+ /** Wide enough for a rail and a long model name; capped to the window on a phone. */
110
+ const PANEL_MAX_WIDTH_PX = 416
111
+
112
+ /**
113
+ * A picker over a large catalog: browsed by group on a rail, or
114
+ * searched across everything at once.
115
+ *
116
+ * The trigger is a `Picker`-style button showing the chosen item's mark
117
+ * and label. The panel has a vertical rail on the inline start — a
118
+ * Favorites tab, then one tab per group — and, beside it, a search
119
+ * field over the list. Browsing a tab lists that group's rows; typing
120
+ * lists matches from every group, under group headings.
121
+ *
122
+ * ### Why not `Combobox` or `Picker`
123
+ *
124
+ * Both are one flat list. Forty-odd rows that differ only after a
125
+ * shared provider prefix are exactly what neither helps with: `Picker`
126
+ * has no filter, and `Combobox` filters one label string and has no
127
+ * way to browse a part of the list. The rail is the browse half, and
128
+ * the search crosses the rail, because a person who types a model's
129
+ * name should not have to know its provider first.
130
+ *
131
+ * ### The ARIA contract
132
+ *
133
+ * The trigger opens a `role="dialog"` named by the trigger. Inside, the
134
+ * search field is the `role="combobox"` controlling a `role="listbox"`,
135
+ * focus stays in the field, and the arrows move
136
+ * `aria-activedescendant` — the `Combobox` contract. The rail is a
137
+ * vertical `role="toolbar"` of `aria-pressed` buttons, and Tab moves
138
+ * between the field, its clear button and the rail. Escape clears a
139
+ * query, then closes, and focus returns to the trigger. A row is
140
+ * named by its label, its description and then its group's label (when
141
+ * not blank), and the trigger by the chosen row's label and group: the mark is decorative,
142
+ * so two groups' same-label rows must not read alike. The picker
143
+ * consumes every Escape it handles, so one inside a `Dialog` never
144
+ * closes the dialog too.
145
+ *
146
+ * ### Opening
147
+ *
148
+ * Every open is a fresh start: an empty query, and the tab below. The
149
+ * panel lands on Favorites when the chosen value is a favorite or a row
150
+ * listed on every tab (pinned, or in no group), else on the chosen
151
+ * row's group, else on Favorites, else on the first group; and the
152
+ * chosen row is centred in the list, as a `Combobox` opens on its
153
+ * chosen option.
154
+ *
155
+ * ### One value, one row
156
+ *
157
+ * An item's `value` and a group's `id` must each be unique. A repeat is
158
+ * dropped — the first one wins, in the trigger, the list and Favorites
159
+ * alike — and the picker warns in the console.
160
+ *
161
+ * ### Not windowed
162
+ *
163
+ * Every row of the current view is rendered. `Combobox` windows only
164
+ * above 100 rows, and the catalogs this was built for are 40 to 60; a
165
+ * catalog that needs windowing is a change to this component, recorded
166
+ * in its decision.
167
+ */
168
+ export const CatalogPicker = ({
169
+ className,
170
+ clearIcon,
171
+ emptyLabel = "No matches",
172
+ favorites = [],
173
+ favoritesLabel = "Favorites",
174
+ groups: givenGroups,
175
+ isDisabled = false,
176
+ items: givenItems,
177
+ label,
178
+ onChange,
179
+ placeholder,
180
+ placement,
181
+ searchPlaceholder = "Search…",
182
+ size = "md",
183
+ value,
184
+ ...buttonProps
185
+ }: CatalogPickerProps): ReactNode => {
186
+ const {
187
+ duplicateGroupIds,
188
+ duplicateItemValues,
189
+ groups,
190
+ items,
191
+ } = useMemo(
192
+ () =>
193
+ toUniqueCatalog({
194
+ groups: givenGroups,
195
+ items: givenItems,
196
+ }),
197
+ [givenGroups, givenItems],
198
+ )
199
+
200
+ const duplicateWarning = [
201
+ duplicateItemValues.length === 0
202
+ ? ""
203
+ : `item values ${JSON.stringify(duplicateItemValues)}`,
204
+ duplicateGroupIds.length === 0
205
+ ? ""
206
+ : `group ids ${JSON.stringify(duplicateGroupIds)}`,
207
+ ]
208
+ .filter((part) => part !== "")
209
+ .join(" and ")
210
+
211
+ useEffect(() => {
212
+ if (duplicateWarning !== "") {
213
+ console.warn(
214
+ `CatalogPicker: ${duplicateWarning} repeat. A value names one row, so only the first of each is kept.`,
215
+ )
216
+ }
217
+ }, [duplicateWarning])
218
+
219
+ /**
220
+ * Bumped on every open, and the panel's `key`: a panel still fading
221
+ * out when the picker reopens is replaced, not revived, so its old
222
+ * query and tab never come back.
223
+ */
224
+ const [session, setSession] = useState(0)
225
+
226
+ const { hide, isVisible, toggle } = useVisibility({
227
+ onChange: (isNextVisible) => {
228
+ if (isNextVisible) {
229
+ setSession((previous) => previous + 1)
230
+ }
231
+ },
232
+ })
233
+
234
+ const isOpen = isVisible && !isDisabled
235
+
236
+ // Disabling closes the picker for good, rather than hiding it until
237
+ // it is enabled again: re-enabling should not open it unasked.
238
+ useEffect(() => {
239
+ if (isDisabled) {
240
+ hide()
241
+ }
242
+ }, [hide, isDisabled])
243
+
244
+ const itemSize = usePanelItemSize(size)
245
+
246
+ const inputRef = useRef<HTMLInputElement>(null)
247
+
248
+ const chosen =
249
+ value === undefined
250
+ ? undefined
251
+ : items.find((item) => item.value === value)
252
+
253
+ const chosenGroup =
254
+ chosen?.groupId == null
255
+ ? undefined
256
+ : groups.find((group) => group.id === chosen.groupId)
257
+
258
+ const triggerText = chosen?.label ?? placeholder ?? ""
259
+
260
+ const hasChosenMark =
261
+ chosen !== undefined &&
262
+ (chosen.icon !== undefined || chosenGroup !== undefined)
263
+
264
+ const {
265
+ clonedTrigger,
266
+ context,
267
+ floatingStyles,
268
+ getFloatingProps,
269
+ isExiting,
270
+ isMounted,
271
+ motionClassName,
272
+ setFloating,
273
+ triggerId,
274
+ } = useAnchoredOverlay({
275
+ // Escape belongs to the panel: it clears a query before it closes.
276
+ isEscapeDismissable: false,
277
+ isVisible: isOpen,
278
+ maxHeightPx: PANEL_MAX_HEIGHT_PX,
279
+ maxWidthPx: PANEL_MAX_WIDTH_PX,
280
+ offsetValue: 4,
281
+ onDismiss: hide,
282
+ placement,
283
+ role: "dialog",
284
+ trigger: (
285
+ <Button
286
+ {...buttonProps}
287
+ appearance="outline"
288
+ // The chosen row's group in words, as the row says it: the
289
+ // badge beside the text is decorative.
290
+ aria-label={toGroupedName(
291
+ `${label}: ${triggerText}`,
292
+ chosenGroup,
293
+ )}
294
+ className={toClassName(
295
+ "justify-between",
296
+ className,
297
+ )}
298
+ iconEnd={CHEVRON_DOWN}
299
+ intent="neutral"
300
+ isDisabled={isDisabled}
301
+ onClick={(clickEvent) => {
302
+ buttonProps.onClick?.(clickEvent)
303
+
304
+ toggle()
305
+ }}
306
+ size={size}
307
+ type="button"
308
+ >
309
+ {triggerText === "" && !hasChosenMark ? null : (
310
+ <span className="flex min-w-0 grow items-center gap-2">
311
+ {hasChosenMark ? (
312
+ <CatalogPickerMark
313
+ accentColor={chosenGroup?.accentColor}
314
+ icon={chosen?.icon ?? chosenGroup?.icon}
315
+ initialsOf={chosenGroup?.label}
316
+ size="sm"
317
+ />
318
+ ) : null}
319
+
320
+ {/* Not `truncate`, for the reason `Picker` gives: its
321
+ `overflow: hidden` clips glyph edges. */}
322
+ <span className="-mx-1 min-w-0 grow overflow-x-clip px-1 text-start text-ellipsis whitespace-nowrap">
323
+ {triggerText}
324
+ </span>
325
+ </span>
326
+ )}
327
+ </Button>
328
+ ),
329
+ })
330
+
331
+ const choose = (nextValue: string) => {
332
+ onChange(nextValue)
333
+
334
+ hide()
335
+ }
336
+
337
+ return (
338
+ <>
339
+ {clonedTrigger}
340
+
341
+ {isMounted ? (
342
+ <FloatingPortal>
343
+ <FloatingFocusManager
344
+ context={context}
345
+ disabled={isExiting}
346
+ initialFocus={inputRef}
347
+ modal={false}
348
+ >
349
+ <div
350
+ {...getFloatingProps()}
351
+ aria-hidden={isExiting ? true : undefined}
352
+ aria-labelledby={triggerId}
353
+ className={toClassName(
354
+ PANEL_SURFACE_CLASS,
355
+ "z-[var(--layer-modal)] flex h-[28rem] w-[26rem] overflow-hidden",
356
+ motionClassName,
357
+ )}
358
+ inert={isExiting ? true : undefined}
359
+ ref={setFloating}
360
+ // `useRole` already wrote this through the spread; restated
361
+ // so the lint can see the role `aria-labelledby` belongs to.
362
+ role="dialog"
363
+ style={floatingStyles}
364
+ >
365
+ <CatalogPickerPanel
366
+ clearIcon={clearIcon}
367
+ emptyLabel={emptyLabel}
368
+ favorites={favorites}
369
+ favoritesLabel={favoritesLabel}
370
+ groups={groups}
371
+ inputRef={inputRef}
372
+ itemSize={itemSize}
373
+ items={items}
374
+ key={session}
375
+ label={label}
376
+ onDismiss={hide}
377
+ onSelect={choose}
378
+ searchPlaceholder={searchPlaceholder}
379
+ value={value}
380
+ />
381
+ </div>
382
+ </FloatingFocusManager>
383
+ </FloatingPortal>
384
+ ) : null}
385
+ </>
386
+ )
387
+ }
@@ -0,0 +1,89 @@
1
+ import type { ControlSize } from "@charcuterie/tokens"
2
+ import type { CSSProperties, ReactNode } from "react"
3
+
4
+ import { toClassName } from "../toClassName.ts"
5
+ import { toInitials } from "./catalogPickerView.ts"
6
+
7
+ export type CatalogPickerMarkProps = {
8
+ accentColor?: string
9
+ icon?: ReactNode
10
+ /**
11
+ * The group label the badge's initials come from. `undefined` with
12
+ * no `icon` draws an empty slot of the same size, so a row with no
13
+ * group still lines its label up with the rows above it.
14
+ */
15
+ initialsOf?: string
16
+ size: ControlSize
17
+ }
18
+
19
+ const MARK_SIZE_CLASS: Record<ControlSize, string> = {
20
+ lg: "size-7 [&>img]:size-7 [&>svg]:size-5",
21
+ md: "size-6 [&>img]:size-6 [&>svg]:size-4",
22
+ sm: "size-5 [&>img]:size-5 [&>svg]:size-4",
23
+ }
24
+
25
+ /**
26
+ * A group's mark — the app's icon, or the group's initials on a
27
+ * neutral badge — in a fixed square.
28
+ *
29
+ * `accentColor` is drawn as an **outer ring** (`box-shadow`), never as
30
+ * the badge's fill or its text. The initials stay `content-primary` on
31
+ * a neutral surface, which the contrast gate already covers, so a
32
+ * consumer's arbitrary color cannot make the text unreadable. A ring
33
+ * also takes no layout space, so a ringed mark and a plain one are the
34
+ * same size.
35
+ *
36
+ * Decorative throughout (`aria-hidden`): the row, the tab and the
37
+ * trigger all carry the group or item name as text or `aria-label`.
38
+ */
39
+ export const CatalogPickerMark = ({
40
+ accentColor,
41
+ icon,
42
+ initialsOf,
43
+ size,
44
+ }: CatalogPickerMarkProps): ReactNode => {
45
+ const ringStyle: CSSProperties | undefined =
46
+ accentColor === undefined
47
+ ? undefined
48
+ : { boxShadow: `0 0 0 2px ${accentColor}` }
49
+
50
+ if (icon !== undefined && icon !== null) {
51
+ return (
52
+ <span
53
+ aria-hidden="true"
54
+ className={toClassName(
55
+ "flex shrink-0 items-center justify-center overflow-hidden rounded-sm text-content-secondary [&>img]:object-contain",
56
+ MARK_SIZE_CLASS[size],
57
+ )}
58
+ style={ringStyle}
59
+ >
60
+ {icon}
61
+ </span>
62
+ )
63
+ }
64
+
65
+ if (initialsOf === undefined) {
66
+ return (
67
+ <span
68
+ aria-hidden="true"
69
+ className={toClassName(
70
+ "shrink-0",
71
+ MARK_SIZE_CLASS[size],
72
+ )}
73
+ />
74
+ )
75
+ }
76
+
77
+ return (
78
+ <span
79
+ aria-hidden="true"
80
+ className={toClassName(
81
+ "flex shrink-0 items-center justify-center rounded-sm bg-intent-neutral-surface-hover font-semibold text-content-primary text-xs leading-none",
82
+ MARK_SIZE_CLASS[size],
83
+ )}
84
+ style={ringStyle}
85
+ >
86
+ {toInitials(initialsOf)}
87
+ </span>
88
+ )
89
+ }
@@ -0,0 +1,151 @@
1
+ import type { ControlSize } from "@charcuterie/tokens"
2
+ import type { ReactNode } from "react"
3
+
4
+ import { PANEL_ITEM_SIZE_CLASS } from "../controlStyles.ts"
5
+ import { toClassName } from "../toClassName.ts"
6
+ import { CatalogPickerMark } from "./CatalogPickerMark.tsx"
7
+ import {
8
+ CHOSEN_CHECK,
9
+ ROW_FAVORITE_STAR,
10
+ } from "./catalogPickerDrawings.tsx"
11
+ import {
12
+ type CatalogPickerGroup,
13
+ type CatalogPickerItem,
14
+ toGroupedName,
15
+ } from "./catalogPickerView.ts"
16
+
17
+ export type CatalogPickerOptionProps = {
18
+ group: CatalogPickerGroup | undefined
19
+ /** The DOM id the search field's `aria-activedescendant` points at. */
20
+ id: string
21
+ isActive: boolean
22
+ isFavorite: boolean
23
+ isSelected: boolean
24
+ item: CatalogPickerItem
25
+ /** Already stepped down for a short window by `usePanelItemSize`. */
26
+ itemSize: ControlSize
27
+ onChoose: (value: string) => void
28
+ /** The pointer moved over the row. */
29
+ onPoint: () => void
30
+ }
31
+
32
+ /**
33
+ * One row of the catalog's listbox: the mark, the label, the optional
34
+ * description, a star on a favorite, and the check gutter.
35
+ *
36
+ * The contract is `ComboboxOption`'s, for the same reasons: focus stays
37
+ * in the search field, so the row is `role="option"` with
38
+ * `tabIndex={-1}` and the active row is announced by
39
+ * `aria-activedescendant`; `aria-selected` is the chosen value; a
40
+ * mouse press is prevented from moving focus, so the caret stays in the
41
+ * field while the click lands.
42
+ *
43
+ * The pointer moves the active row on `pointermove` (as in
44
+ * `CommandPalette`), so the pointer and the arrow keys share one
45
+ * highlight and Enter's target is never ambiguous. The chosen row keeps
46
+ * its accent tint whenever the highlight is elsewhere.
47
+ *
48
+ * The check is always laid out and only hidden on an unchosen row, so
49
+ * choosing never moves the star or the label. It is drawn, not the
50
+ * `✓` `ComboboxOption` types: that glyph measures blank where the font
51
+ * lacks it.
52
+ */
53
+ export const CatalogPickerOption = ({
54
+ group,
55
+ id,
56
+ isActive,
57
+ isFavorite,
58
+ isSelected,
59
+ item,
60
+ itemSize,
61
+ onChoose,
62
+ onPoint,
63
+ }: CatalogPickerOptionProps): ReactNode => {
64
+ const {
65
+ description,
66
+ icon,
67
+ isDisabled = false,
68
+ label,
69
+ value,
70
+ } = item
71
+
72
+ const hasDescription =
73
+ description !== undefined && description.trim() !== ""
74
+
75
+ return (
76
+ <button
77
+ // The row's text, then its group in words: the badge is
78
+ // decorative, and two groups' "Opus" in Favorites must not read
79
+ // alike. An `aria-label`, not a `VisuallyHidden` suffix: an
80
+ // `sr-only` span is laid out as a block, so Chromium, Playwright,
81
+ // and Testing Library named the row "Opus , Team", with a space
82
+ // before the comma.
83
+ aria-label={toGroupedName(
84
+ `${label}${hasDescription ? ` ${description}` : ""}`,
85
+ group,
86
+ )}
87
+ aria-selected={isSelected}
88
+ className={toClassName(
89
+ "flex w-full cursor-pointer items-center rounded-sm text-start",
90
+ PANEL_ITEM_SIZE_CLASS[itemSize],
91
+ isDisabled
92
+ ? "cursor-not-allowed text-content-disabled"
93
+ : "text-content-primary",
94
+ isActive && "bg-intent-neutral-surface-hover",
95
+ isSelected &&
96
+ !isActive &&
97
+ "bg-intent-accent-surface",
98
+ )}
99
+ disabled={isDisabled}
100
+ id={id}
101
+ onClick={() => {
102
+ onChoose(value)
103
+ }}
104
+ onMouseDown={(mouseEvent) => {
105
+ mouseEvent.preventDefault()
106
+ }}
107
+ onPointerMove={onPoint}
108
+ role="option"
109
+ tabIndex={-1}
110
+ type="button"
111
+ >
112
+ <CatalogPickerMark
113
+ accentColor={group?.accentColor}
114
+ icon={icon ?? group?.icon}
115
+ initialsOf={group?.label}
116
+ size={itemSize}
117
+ />
118
+
119
+ <span className="flex min-w-0 flex-1 flex-wrap items-baseline gap-x-2">
120
+ <span className="min-w-0 wrap-anywhere">
121
+ {label}
122
+ </span>
123
+
124
+ {hasDescription ? (
125
+ <span
126
+ className={toClassName(
127
+ "min-w-0 text-sm wrap-anywhere",
128
+ isDisabled
129
+ ? "text-content-disabled"
130
+ : "text-content-muted",
131
+ )}
132
+ >
133
+ {description}
134
+ </span>
135
+ ) : null}
136
+ </span>
137
+
138
+ {isFavorite ? ROW_FAVORITE_STAR : null}
139
+
140
+ <span
141
+ aria-hidden="true"
142
+ className={toClassName(
143
+ "flex w-4 shrink-0 items-center justify-center text-intent-accent-content",
144
+ !isSelected && "invisible",
145
+ )}
146
+ >
147
+ {CHOSEN_CHECK}
148
+ </span>
149
+ </button>
150
+ )
151
+ }