@charcuterie/ui 4.28.4 → 4.29.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.
- package/dist/CatalogPicker/CatalogPicker.d.ts +105 -0
- package/dist/CatalogPicker/CatalogPicker.d.ts.map +1 -0
- package/dist/CatalogPicker/CatalogPicker.js +152 -0
- package/dist/CatalogPicker/CatalogPicker.js.map +1 -0
- package/dist/CatalogPicker/CatalogPickerMark.d.ts +29 -0
- package/dist/CatalogPicker/CatalogPickerMark.d.ts.map +1 -0
- package/dist/CatalogPicker/CatalogPickerMark.js +35 -0
- package/dist/CatalogPicker/CatalogPickerMark.js.map +1 -0
- package/dist/CatalogPicker/CatalogPickerOption.d.ts +40 -0
- package/dist/CatalogPicker/CatalogPickerOption.d.ts.map +1 -0
- package/dist/CatalogPicker/CatalogPickerOption.js +42 -0
- package/dist/CatalogPicker/CatalogPickerOption.js.map +1 -0
- package/dist/CatalogPicker/CatalogPickerPanel.d.ts +60 -0
- package/dist/CatalogPicker/CatalogPickerPanel.d.ts.map +1 -0
- package/dist/CatalogPicker/CatalogPickerPanel.js +409 -0
- package/dist/CatalogPicker/CatalogPickerPanel.js.map +1 -0
- package/dist/CatalogPicker/CatalogPickerRail.d.ts +50 -0
- package/dist/CatalogPicker/CatalogPickerRail.d.ts.map +1 -0
- package/dist/CatalogPicker/CatalogPickerRail.js +114 -0
- package/dist/CatalogPicker/CatalogPickerRail.js.map +1 -0
- package/dist/CatalogPicker/catalogPickerDrawings.d.ts +10 -0
- package/dist/CatalogPicker/catalogPickerDrawings.d.ts.map +1 -0
- package/dist/CatalogPicker/catalogPickerDrawings.js +29 -0
- package/dist/CatalogPicker/catalogPickerDrawings.js.map +1 -0
- package/dist/CatalogPicker/catalogPickerView.d.ts +173 -0
- package/dist/CatalogPicker/catalogPickerView.d.ts.map +1 -0
- package/dist/CatalogPicker/catalogPickerView.js +235 -0
- package/dist/CatalogPicker/catalogPickerView.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/CatalogPicker/CatalogPicker.mdx +157 -0
- package/src/CatalogPicker/CatalogPicker.stories.tsx +218 -0
- package/src/CatalogPicker/CatalogPicker.test.tsx +1352 -0
- package/src/CatalogPicker/CatalogPicker.tsx +376 -0
- package/src/CatalogPicker/CatalogPickerMark.tsx +89 -0
- package/src/CatalogPicker/CatalogPickerOption.tsx +138 -0
- package/src/CatalogPicker/CatalogPickerPanel.tsx +780 -0
- package/src/CatalogPicker/CatalogPickerRail.tsx +214 -0
- package/src/CatalogPicker/catalogPicker.storyHelpers.tsx +276 -0
- package/src/CatalogPicker/catalogPickerDrawings.tsx +51 -0
- package/src/CatalogPicker/catalogPickerView.test.ts +346 -0
- package/src/CatalogPicker/catalogPickerView.ts +457 -0
- package/src/Dialog/Dialog.test.tsx +20 -289
- package/src/Field/Field.test.tsx +11 -405
- package/src/index.ts +6 -0
- package/src/sourceRules.test.ts +5 -1
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type { ControlSize } from "@charcuterie/tokens";
|
|
2
|
+
import type { Placement } from "@floating-ui/react";
|
|
3
|
+
import type { ComponentPropsWithRef, ReactNode } from "react";
|
|
4
|
+
import { type CatalogPickerGroup, type CatalogPickerItem } from "./catalogPickerView.ts";
|
|
5
|
+
export type { CatalogPickerGroup, CatalogPickerItem, } from "./catalogPickerView.ts";
|
|
6
|
+
export type CatalogPickerProps = Omit<ComponentPropsWithRef<"button">, "children" | "disabled" | "onChange" | "value"> & {
|
|
7
|
+
/**
|
|
8
|
+
* The glyph inside the search field's clear button — the app's own,
|
|
9
|
+
* as for `SearchInput`. Without one there is no clear button, and
|
|
10
|
+
* Escape clears the query.
|
|
11
|
+
*/
|
|
12
|
+
clearIcon?: ReactNode;
|
|
13
|
+
/** The trigger. As in `Picker`, the outermost box this renders. */
|
|
14
|
+
className?: string;
|
|
15
|
+
/** Shown when a search matches nothing. Default "No matches". */
|
|
16
|
+
emptyLabel?: string;
|
|
17
|
+
/** Item values, in the order the Favorites tab lists them. No favorites, no Favorites tab. */
|
|
18
|
+
favorites?: readonly string[];
|
|
19
|
+
/** The Favorites tab's accessible name and tooltip. Default "Favorites". */
|
|
20
|
+
favoritesLabel?: string;
|
|
21
|
+
/**
|
|
22
|
+
* The rail, top to bottom (after Favorites). A group with no rows is
|
|
23
|
+
* left off. Each `id` must be unique: a repeated one is dropped (the
|
|
24
|
+
* first wins), with a console warning.
|
|
25
|
+
*/
|
|
26
|
+
groups: readonly CatalogPickerGroup[];
|
|
27
|
+
isDisabled?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Everything that can be chosen. A group's rows keep this order. Each
|
|
30
|
+
* `value` must be unique across the catalog: a repeated one is
|
|
31
|
+
* dropped (the first wins), with a console warning.
|
|
32
|
+
*/
|
|
33
|
+
items: readonly CatalogPickerItem[];
|
|
34
|
+
/**
|
|
35
|
+
* What the control is FOR — "Agent", "Model". Not the current value.
|
|
36
|
+
* The trigger is named `"<label>: <chosen label>"`, as in `Picker`,
|
|
37
|
+
* and the search field and the list are named `label`.
|
|
38
|
+
*/
|
|
39
|
+
label: string;
|
|
40
|
+
onChange: (value: string) => void;
|
|
41
|
+
/** The trigger's text when nothing is chosen. */
|
|
42
|
+
placeholder?: string;
|
|
43
|
+
/** Where the panel opens against the trigger. Default `bottom-start`. */
|
|
44
|
+
placement?: Placement;
|
|
45
|
+
/** The search field's placeholder. Default "Search…". */
|
|
46
|
+
searchPlaceholder?: string;
|
|
47
|
+
/** The trigger's size, and the size of every row in the panel. Default `md`. */
|
|
48
|
+
size?: ControlSize;
|
|
49
|
+
value?: string;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* A picker over a large catalog: browsed by group on a rail, or
|
|
53
|
+
* searched across everything at once.
|
|
54
|
+
*
|
|
55
|
+
* The trigger is a `Picker`-style button showing the chosen item's mark
|
|
56
|
+
* and label. The panel has a vertical rail on the inline start — a
|
|
57
|
+
* Favorites tab, then one tab per group — and, beside it, a search
|
|
58
|
+
* field over the list. Browsing a tab lists that group's rows; typing
|
|
59
|
+
* lists matches from every group, under group headings.
|
|
60
|
+
*
|
|
61
|
+
* ### Why not `Combobox` or `Picker`
|
|
62
|
+
*
|
|
63
|
+
* Both are one flat list. Forty-odd rows that differ only after a
|
|
64
|
+
* shared provider prefix are exactly what neither helps with: `Picker`
|
|
65
|
+
* has no filter, and `Combobox` filters one label string and has no
|
|
66
|
+
* way to browse a part of the list. The rail is the browse half, and
|
|
67
|
+
* the search crosses the rail, because a person who types a model's
|
|
68
|
+
* name should not have to know its provider first.
|
|
69
|
+
*
|
|
70
|
+
* ### The ARIA contract
|
|
71
|
+
*
|
|
72
|
+
* The trigger opens a `role="dialog"` named by the trigger. Inside, the
|
|
73
|
+
* search field is the `role="combobox"` controlling a `role="listbox"`,
|
|
74
|
+
* focus stays in the field, and the arrows move
|
|
75
|
+
* `aria-activedescendant` — the `Combobox` contract. The rail is a
|
|
76
|
+
* vertical `role="toolbar"` of `aria-pressed` buttons, and Tab moves
|
|
77
|
+
* between the field, its clear button and the rail. Escape clears a
|
|
78
|
+
* query, then closes, and focus returns to the trigger. The picker
|
|
79
|
+
* consumes every Escape it handles, so one inside a `Dialog` never
|
|
80
|
+
* closes the dialog too.
|
|
81
|
+
*
|
|
82
|
+
* ### Opening
|
|
83
|
+
*
|
|
84
|
+
* Every open is a fresh start: an empty query, and the tab below. The
|
|
85
|
+
* panel lands on Favorites when the chosen value is a favorite or a row
|
|
86
|
+
* listed on every tab (pinned, or in no group), else on the chosen
|
|
87
|
+
* row's group, else on Favorites, else on the first group; and the
|
|
88
|
+
* chosen row is centred in the list, as a `Combobox` opens on its
|
|
89
|
+
* chosen option.
|
|
90
|
+
*
|
|
91
|
+
* ### One value, one row
|
|
92
|
+
*
|
|
93
|
+
* An item's `value` and a group's `id` must each be unique. A repeat is
|
|
94
|
+
* dropped — the first one wins, in the trigger, the list and Favorites
|
|
95
|
+
* alike — and the picker warns in the console.
|
|
96
|
+
*
|
|
97
|
+
* ### Not windowed
|
|
98
|
+
*
|
|
99
|
+
* Every row of the current view is rendered. `Combobox` windows only
|
|
100
|
+
* above 100 rows, and the catalogs this was built for are 40 to 60; a
|
|
101
|
+
* catalog that needs windowing is a change to this component, recorded
|
|
102
|
+
* in its decision.
|
|
103
|
+
*/
|
|
104
|
+
export declare const CatalogPicker: ({ className, clearIcon, emptyLabel, favorites, favoritesLabel, groups: givenGroups, isDisabled, items: givenItems, label, onChange, placeholder, placement, searchPlaceholder, size, value, ...buttonProps }: CatalogPickerProps) => ReactNode;
|
|
105
|
+
//# sourceMappingURL=CatalogPicker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CatalogPicker.d.ts","sourceRoot":"","sources":["../../src/CatalogPicker/CatalogPicker.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAKnD,OAAO,KAAK,EACV,qBAAqB,EACrB,SAAS,EACV,MAAM,OAAO,CAAA;AAUd,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EAEvB,MAAM,wBAAwB,CAAA;AAE/B,YAAY,EACV,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,wBAAwB,CAAA;AAwB/B,MAAM,MAAM,kBAAkB,GAAG,IAAI,CACnC,qBAAqB,CAAC,QAAQ,CAAC,EAC/B,UAAU,GAAG,UAAU,GAAG,UAAU,GAAG,OAAO,CAC/C,GAAG;IACF;;;;OAIG;IACH,SAAS,CAAC,EAAE,SAAS,CAAA;IACrB,mEAAmE;IACnE,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,iEAAiE;IACjE,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,8FAA8F;IAC9F,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;IAC7B,4EAA4E;IAC5E,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB;;;;OAIG;IACH,MAAM,EAAE,SAAS,kBAAkB,EAAE,CAAA;IACrC,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB;;;;OAIG;IACH,KAAK,EAAE,SAAS,iBAAiB,EAAE,CAAA;IACnC;;;;OAIG;IACH,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IACjC,iDAAiD;IACjD,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,yEAAyE;IACzE,SAAS,CAAC,EAAE,SAAS,CAAA;IACrB,yDAAyD;IACzD,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,gFAAgF;IAChF,IAAI,CAAC,EAAE,WAAW,CAAA;IAClB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAQD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AACH,eAAO,MAAM,aAAa,GAAI,8MAiB3B,kBAAkB,KAAG,SAqMvB,CAAA"}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useVisibility } from "@charcuterie/logic";
|
|
3
|
+
import { FloatingFocusManager, FloatingPortal, } from "@floating-ui/react";
|
|
4
|
+
import { useEffect, useMemo, useRef, useState } from "react";
|
|
5
|
+
import { Button } from "../Button/Button.js";
|
|
6
|
+
import { PANEL_SURFACE_CLASS } from "../Overlay/overlayPanelClass.js";
|
|
7
|
+
import { useAnchoredOverlay } from "../Overlay/useAnchoredOverlay.js";
|
|
8
|
+
import { usePanelItemSize } from "../Overlay/usePanelItemSize.js";
|
|
9
|
+
import { toClassName } from "../toClassName.js";
|
|
10
|
+
import { CatalogPickerMark } from "./CatalogPickerMark.js";
|
|
11
|
+
import { CatalogPickerPanel } from "./CatalogPickerPanel.js";
|
|
12
|
+
import { toUniqueCatalog, } from "./catalogPickerView.js";
|
|
13
|
+
/**
|
|
14
|
+
* A constant element rather than a component, as in `Picker`: a
|
|
15
|
+
* second component in this file trips the house rule, and this never
|
|
16
|
+
* varies.
|
|
17
|
+
*/
|
|
18
|
+
const CHEVRON_DOWN = (_jsx("svg", { "aria-hidden": "true", className: "size-4", fill: "none", focusable: false, stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 1.75, viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg", children: _jsx("path", { d: "m6 9 6 6 6-6" }) }));
|
|
19
|
+
/** Tall enough for about nine rows at `md`, and never taller than the window leaves. */
|
|
20
|
+
const PANEL_MAX_HEIGHT_PX = 448;
|
|
21
|
+
/** Wide enough for a rail and a long model name; capped to the window on a phone. */
|
|
22
|
+
const PANEL_MAX_WIDTH_PX = 416;
|
|
23
|
+
/**
|
|
24
|
+
* A picker over a large catalog: browsed by group on a rail, or
|
|
25
|
+
* searched across everything at once.
|
|
26
|
+
*
|
|
27
|
+
* The trigger is a `Picker`-style button showing the chosen item's mark
|
|
28
|
+
* and label. The panel has a vertical rail on the inline start — a
|
|
29
|
+
* Favorites tab, then one tab per group — and, beside it, a search
|
|
30
|
+
* field over the list. Browsing a tab lists that group's rows; typing
|
|
31
|
+
* lists matches from every group, under group headings.
|
|
32
|
+
*
|
|
33
|
+
* ### Why not `Combobox` or `Picker`
|
|
34
|
+
*
|
|
35
|
+
* Both are one flat list. Forty-odd rows that differ only after a
|
|
36
|
+
* shared provider prefix are exactly what neither helps with: `Picker`
|
|
37
|
+
* has no filter, and `Combobox` filters one label string and has no
|
|
38
|
+
* way to browse a part of the list. The rail is the browse half, and
|
|
39
|
+
* the search crosses the rail, because a person who types a model's
|
|
40
|
+
* name should not have to know its provider first.
|
|
41
|
+
*
|
|
42
|
+
* ### The ARIA contract
|
|
43
|
+
*
|
|
44
|
+
* The trigger opens a `role="dialog"` named by the trigger. Inside, the
|
|
45
|
+
* search field is the `role="combobox"` controlling a `role="listbox"`,
|
|
46
|
+
* focus stays in the field, and the arrows move
|
|
47
|
+
* `aria-activedescendant` — the `Combobox` contract. The rail is a
|
|
48
|
+
* vertical `role="toolbar"` of `aria-pressed` buttons, and Tab moves
|
|
49
|
+
* between the field, its clear button and the rail. Escape clears a
|
|
50
|
+
* query, then closes, and focus returns to the trigger. The picker
|
|
51
|
+
* consumes every Escape it handles, so one inside a `Dialog` never
|
|
52
|
+
* closes the dialog too.
|
|
53
|
+
*
|
|
54
|
+
* ### Opening
|
|
55
|
+
*
|
|
56
|
+
* Every open is a fresh start: an empty query, and the tab below. The
|
|
57
|
+
* panel lands on Favorites when the chosen value is a favorite or a row
|
|
58
|
+
* listed on every tab (pinned, or in no group), else on the chosen
|
|
59
|
+
* row's group, else on Favorites, else on the first group; and the
|
|
60
|
+
* chosen row is centred in the list, as a `Combobox` opens on its
|
|
61
|
+
* chosen option.
|
|
62
|
+
*
|
|
63
|
+
* ### One value, one row
|
|
64
|
+
*
|
|
65
|
+
* An item's `value` and a group's `id` must each be unique. A repeat is
|
|
66
|
+
* dropped — the first one wins, in the trigger, the list and Favorites
|
|
67
|
+
* alike — and the picker warns in the console.
|
|
68
|
+
*
|
|
69
|
+
* ### Not windowed
|
|
70
|
+
*
|
|
71
|
+
* Every row of the current view is rendered. `Combobox` windows only
|
|
72
|
+
* above 100 rows, and the catalogs this was built for are 40 to 60; a
|
|
73
|
+
* catalog that needs windowing is a change to this component, recorded
|
|
74
|
+
* in its decision.
|
|
75
|
+
*/
|
|
76
|
+
export const CatalogPicker = ({ className, clearIcon, emptyLabel = "No matches", favorites = [], favoritesLabel = "Favorites", groups: givenGroups, isDisabled = false, items: givenItems, label, onChange, placeholder, placement, searchPlaceholder = "Search…", size = "md", value, ...buttonProps }) => {
|
|
77
|
+
const { duplicateGroupIds, duplicateItemValues, groups, items, } = useMemo(() => toUniqueCatalog({
|
|
78
|
+
groups: givenGroups,
|
|
79
|
+
items: givenItems,
|
|
80
|
+
}), [givenGroups, givenItems]);
|
|
81
|
+
const duplicateWarning = [
|
|
82
|
+
duplicateItemValues.length === 0
|
|
83
|
+
? ""
|
|
84
|
+
: `item values ${JSON.stringify(duplicateItemValues)}`,
|
|
85
|
+
duplicateGroupIds.length === 0
|
|
86
|
+
? ""
|
|
87
|
+
: `group ids ${JSON.stringify(duplicateGroupIds)}`,
|
|
88
|
+
]
|
|
89
|
+
.filter((part) => part !== "")
|
|
90
|
+
.join(" and ");
|
|
91
|
+
useEffect(() => {
|
|
92
|
+
if (duplicateWarning !== "") {
|
|
93
|
+
console.warn(`CatalogPicker: ${duplicateWarning} repeat. A value names one row, so only the first of each is kept.`);
|
|
94
|
+
}
|
|
95
|
+
}, [duplicateWarning]);
|
|
96
|
+
/**
|
|
97
|
+
* Bumped on every open, and the panel's `key`: a panel still fading
|
|
98
|
+
* out when the picker reopens is replaced, not revived, so its old
|
|
99
|
+
* query and tab never come back.
|
|
100
|
+
*/
|
|
101
|
+
const [session, setSession] = useState(0);
|
|
102
|
+
const { hide, isVisible, toggle } = useVisibility({
|
|
103
|
+
onChange: (isNextVisible) => {
|
|
104
|
+
if (isNextVisible) {
|
|
105
|
+
setSession((previous) => previous + 1);
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
const isOpen = isVisible && !isDisabled;
|
|
110
|
+
// Disabling closes the picker for good, rather than hiding it until
|
|
111
|
+
// it is enabled again: re-enabling should not open it unasked.
|
|
112
|
+
useEffect(() => {
|
|
113
|
+
if (isDisabled) {
|
|
114
|
+
hide();
|
|
115
|
+
}
|
|
116
|
+
}, [hide, isDisabled]);
|
|
117
|
+
const itemSize = usePanelItemSize(size);
|
|
118
|
+
const inputRef = useRef(null);
|
|
119
|
+
const chosen = value === undefined
|
|
120
|
+
? undefined
|
|
121
|
+
: items.find((item) => item.value === value);
|
|
122
|
+
const chosenGroup = chosen?.groupId == null
|
|
123
|
+
? undefined
|
|
124
|
+
: groups.find((group) => group.id === chosen.groupId);
|
|
125
|
+
const triggerText = chosen?.label ?? placeholder ?? "";
|
|
126
|
+
const hasChosenMark = chosen !== undefined &&
|
|
127
|
+
(chosen.icon !== undefined || chosenGroup !== undefined);
|
|
128
|
+
const { clonedTrigger, context, floatingStyles, getFloatingProps, isExiting, isMounted, motionClassName, setFloating, triggerId, } = useAnchoredOverlay({
|
|
129
|
+
// Escape belongs to the panel: it clears a query before it closes.
|
|
130
|
+
isEscapeDismissable: false,
|
|
131
|
+
isVisible: isOpen,
|
|
132
|
+
maxHeightPx: PANEL_MAX_HEIGHT_PX,
|
|
133
|
+
maxWidthPx: PANEL_MAX_WIDTH_PX,
|
|
134
|
+
offsetValue: 4,
|
|
135
|
+
onDismiss: hide,
|
|
136
|
+
placement,
|
|
137
|
+
role: "dialog",
|
|
138
|
+
trigger: (_jsx(Button, { ...buttonProps, appearance: "outline", "aria-label": `${label}: ${triggerText}`, className: toClassName("justify-between", className), iconEnd: CHEVRON_DOWN, intent: "neutral", isDisabled: isDisabled, onClick: (clickEvent) => {
|
|
139
|
+
buttonProps.onClick?.(clickEvent);
|
|
140
|
+
toggle();
|
|
141
|
+
}, size: size, type: "button", children: triggerText === "" && !hasChosenMark ? null : (_jsxs("span", { className: "flex min-w-0 grow items-center gap-2", children: [hasChosenMark ? (_jsx(CatalogPickerMark, { accentColor: chosenGroup?.accentColor, icon: chosen?.icon ?? chosenGroup?.icon, initialsOf: chosenGroup?.label, size: "sm" })) : null, _jsx("span", { className: "-mx-1 min-w-0 grow overflow-x-clip px-1 text-start text-ellipsis whitespace-nowrap", children: triggerText })] })) })),
|
|
142
|
+
});
|
|
143
|
+
const choose = (nextValue) => {
|
|
144
|
+
onChange(nextValue);
|
|
145
|
+
hide();
|
|
146
|
+
};
|
|
147
|
+
return (_jsxs(_Fragment, { children: [clonedTrigger, isMounted ? (_jsx(FloatingPortal, { children: _jsx(FloatingFocusManager, { context: context, disabled: isExiting, initialFocus: inputRef, modal: false, children: _jsx("div", { ...getFloatingProps(), "aria-hidden": isExiting ? true : undefined, "aria-labelledby": triggerId, className: toClassName(PANEL_SURFACE_CLASS, "z-[var(--layer-modal)] flex h-[28rem] w-[26rem] overflow-hidden", motionClassName), inert: isExiting ? true : undefined, ref: setFloating,
|
|
148
|
+
// `useRole` already wrote this through the spread; restated
|
|
149
|
+
// so the lint can see the role `aria-labelledby` belongs to.
|
|
150
|
+
role: "dialog", style: floatingStyles, children: _jsx(CatalogPickerPanel, { clearIcon: clearIcon, emptyLabel: emptyLabel, favorites: favorites, favoritesLabel: favoritesLabel, groups: groups, inputRef: inputRef, itemSize: itemSize, items: items, label: label, onDismiss: hide, onSelect: choose, searchPlaceholder: searchPlaceholder, value: value }, session) }) }) })) : null] }));
|
|
151
|
+
};
|
|
152
|
+
//# sourceMappingURL=CatalogPicker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CatalogPicker.js","sourceRoot":"","sources":["../../src/CatalogPicker/CatalogPicker.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAGlD,OAAO,EACL,oBAAoB,EACpB,cAAc,GACf,MAAM,oBAAoB,CAAA;AAK3B,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAE5D,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAsB,CAAA;AAC7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAA;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAA;AACrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAA;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAyB,CAAA;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAA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,YAErB,KAAC,kBAAkB,IACjB,SAAS,EAAE,SAAS,EACpB,UAAU,EAAE,UAAU,EACtB,SAAS,EAAE,SAAS,EACpB,cAAc,EAAE,cAAc,EAC9B,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,EAClB,KAAK,EAAE,KAAK,EAEZ,KAAK,EAAE,KAAK,EACZ,SAAS,EAAE,IAAI,EACf,QAAQ,EAAE,MAAM,EAChB,iBAAiB,EAAE,iBAAiB,EACpC,KAAK,EAAE,KAAK,IALP,OAAO,CAMZ,GACE,GACe,GACR,CAClB,CAAC,CAAC,CAAC,IAAI,IACP,CACJ,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ControlSize } from "@charcuterie/tokens";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
export type CatalogPickerMarkProps = {
|
|
4
|
+
accentColor?: string;
|
|
5
|
+
icon?: ReactNode;
|
|
6
|
+
/**
|
|
7
|
+
* The group label the badge's initials come from. `undefined` with
|
|
8
|
+
* no `icon` draws an empty slot of the same size, so a row with no
|
|
9
|
+
* group still lines its label up with the rows above it.
|
|
10
|
+
*/
|
|
11
|
+
initialsOf?: string;
|
|
12
|
+
size: ControlSize;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* A group's mark — the app's icon, or the group's initials on a
|
|
16
|
+
* neutral badge — in a fixed square.
|
|
17
|
+
*
|
|
18
|
+
* `accentColor` is drawn as an **outer ring** (`box-shadow`), never as
|
|
19
|
+
* the badge's fill or its text. The initials stay `content-primary` on
|
|
20
|
+
* a neutral surface, which the contrast gate already covers, so a
|
|
21
|
+
* consumer's arbitrary color cannot make the text unreadable. A ring
|
|
22
|
+
* also takes no layout space, so a ringed mark and a plain one are the
|
|
23
|
+
* same size.
|
|
24
|
+
*
|
|
25
|
+
* Decorative throughout (`aria-hidden`): the row, the tab and the
|
|
26
|
+
* trigger all carry the group or item name as text or `aria-label`.
|
|
27
|
+
*/
|
|
28
|
+
export declare const CatalogPickerMark: ({ accentColor, icon, initialsOf, size, }: CatalogPickerMarkProps) => ReactNode;
|
|
29
|
+
//# sourceMappingURL=CatalogPickerMark.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CatalogPickerMark.d.ts","sourceRoot":"","sources":["../../src/CatalogPicker/CatalogPickerMark.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACtD,OAAO,KAAK,EAAiB,SAAS,EAAE,MAAM,OAAO,CAAA;AAKrD,MAAM,MAAM,sBAAsB,GAAG;IACnC,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,IAAI,CAAC,EAAE,SAAS,CAAA;IAChB;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,IAAI,EAAE,WAAW,CAAA;CAClB,CAAA;AAQD;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,iBAAiB,GAAI,0CAK/B,sBAAsB,KAAG,SA6C3B,CAAA"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { toClassName } from "../toClassName.js";
|
|
3
|
+
import { toInitials } from "./catalogPickerView.js";
|
|
4
|
+
const MARK_SIZE_CLASS = {
|
|
5
|
+
lg: "size-7 [&>img]:size-7 [&>svg]:size-5",
|
|
6
|
+
md: "size-6 [&>img]:size-6 [&>svg]:size-4",
|
|
7
|
+
sm: "size-5 [&>img]:size-5 [&>svg]:size-4",
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* A group's mark — the app's icon, or the group's initials on a
|
|
11
|
+
* neutral badge — in a fixed square.
|
|
12
|
+
*
|
|
13
|
+
* `accentColor` is drawn as an **outer ring** (`box-shadow`), never as
|
|
14
|
+
* the badge's fill or its text. The initials stay `content-primary` on
|
|
15
|
+
* a neutral surface, which the contrast gate already covers, so a
|
|
16
|
+
* consumer's arbitrary color cannot make the text unreadable. A ring
|
|
17
|
+
* also takes no layout space, so a ringed mark and a plain one are the
|
|
18
|
+
* same size.
|
|
19
|
+
*
|
|
20
|
+
* Decorative throughout (`aria-hidden`): the row, the tab and the
|
|
21
|
+
* trigger all carry the group or item name as text or `aria-label`.
|
|
22
|
+
*/
|
|
23
|
+
export const CatalogPickerMark = ({ accentColor, icon, initialsOf, size, }) => {
|
|
24
|
+
const ringStyle = accentColor === undefined
|
|
25
|
+
? undefined
|
|
26
|
+
: { boxShadow: `0 0 0 2px ${accentColor}` };
|
|
27
|
+
if (icon !== undefined && icon !== null) {
|
|
28
|
+
return (_jsx("span", { "aria-hidden": "true", className: toClassName("flex shrink-0 items-center justify-center overflow-hidden rounded-sm text-content-secondary [&>img]:object-contain", MARK_SIZE_CLASS[size]), style: ringStyle, children: icon }));
|
|
29
|
+
}
|
|
30
|
+
if (initialsOf === undefined) {
|
|
31
|
+
return (_jsx("span", { "aria-hidden": "true", className: toClassName("shrink-0", MARK_SIZE_CLASS[size]) }));
|
|
32
|
+
}
|
|
33
|
+
return (_jsx("span", { "aria-hidden": "true", className: toClassName("flex shrink-0 items-center justify-center rounded-sm bg-intent-neutral-surface-hover font-semibold text-content-primary text-xs leading-none", MARK_SIZE_CLASS[size]), style: ringStyle, children: toInitials(initialsOf) }));
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=CatalogPickerMark.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CatalogPickerMark.js","sourceRoot":"","sources":["../../src/CatalogPicker/CatalogPickerMark.tsx"],"names":[],"mappings":";AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAcnD,MAAM,eAAe,GAAgC;IACnD,EAAE,EAAE,sCAAsC;IAC1C,EAAE,EAAE,sCAAsC;IAC1C,EAAE,EAAE,sCAAsC;CAC3C,CAAA;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,EAChC,WAAW,EACX,IAAI,EACJ,UAAU,EACV,IAAI,GACmB,EAAa,EAAE;IACtC,MAAM,SAAS,GACb,WAAW,KAAK,SAAS;QACvB,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,EAAE,SAAS,EAAE,aAAa,WAAW,EAAE,EAAE,CAAA;IAE/C,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;QACxC,OAAO,CACL,8BACc,MAAM,EAClB,SAAS,EAAE,WAAW,CACpB,oHAAoH,EACpH,eAAe,CAAC,IAAI,CAAC,CACtB,EACD,KAAK,EAAE,SAAS,YAEf,IAAI,GACA,CACR,CAAA;IACH,CAAC;IAED,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;QAC7B,OAAO,CACL,8BACc,MAAM,EAClB,SAAS,EAAE,WAAW,CACpB,UAAU,EACV,eAAe,CAAC,IAAI,CAAC,CACtB,GACD,CACH,CAAA;IACH,CAAC;IAED,OAAO,CACL,8BACc,MAAM,EAClB,SAAS,EAAE,WAAW,CACpB,8IAA8I,EAC9I,eAAe,CAAC,IAAI,CAAC,CACtB,EACD,KAAK,EAAE,SAAS,YAEf,UAAU,CAAC,UAAU,CAAC,GAClB,CACR,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { ControlSize } from "@charcuterie/tokens";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
import type { CatalogPickerGroup, CatalogPickerItem } from "./catalogPickerView.ts";
|
|
4
|
+
export type CatalogPickerOptionProps = {
|
|
5
|
+
group: CatalogPickerGroup | undefined;
|
|
6
|
+
/** The DOM id the search field's `aria-activedescendant` points at. */
|
|
7
|
+
id: string;
|
|
8
|
+
isActive: boolean;
|
|
9
|
+
isFavorite: boolean;
|
|
10
|
+
isSelected: boolean;
|
|
11
|
+
item: CatalogPickerItem;
|
|
12
|
+
/** Already stepped down for a short window by `usePanelItemSize`. */
|
|
13
|
+
itemSize: ControlSize;
|
|
14
|
+
onChoose: (value: string) => void;
|
|
15
|
+
/** The pointer moved over the row. */
|
|
16
|
+
onPoint: () => void;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* One row of the catalog's listbox: the mark, the label, the optional
|
|
20
|
+
* description, a star on a favorite, and the check gutter.
|
|
21
|
+
*
|
|
22
|
+
* The contract is `ComboboxOption`'s, for the same reasons: focus stays
|
|
23
|
+
* in the search field, so the row is `role="option"` with
|
|
24
|
+
* `tabIndex={-1}` and the active row is announced by
|
|
25
|
+
* `aria-activedescendant`; `aria-selected` is the chosen value; a
|
|
26
|
+
* mouse press is prevented from moving focus, so the caret stays in the
|
|
27
|
+
* field while the click lands.
|
|
28
|
+
*
|
|
29
|
+
* The pointer moves the active row on `pointermove` (as in
|
|
30
|
+
* `CommandPalette`), so the pointer and the arrow keys share one
|
|
31
|
+
* highlight and Enter's target is never ambiguous. The chosen row keeps
|
|
32
|
+
* its accent tint whenever the highlight is elsewhere.
|
|
33
|
+
*
|
|
34
|
+
* The check is always laid out and only hidden on an unchosen row, so
|
|
35
|
+
* choosing never moves the star or the label. It is drawn, not the
|
|
36
|
+
* `✓` `ComboboxOption` types: that glyph measures blank where the font
|
|
37
|
+
* lacks it.
|
|
38
|
+
*/
|
|
39
|
+
export declare const CatalogPickerOption: ({ group, id, isActive, isFavorite, isSelected, item, itemSize, onChoose, onPoint, }: CatalogPickerOptionProps) => ReactNode;
|
|
40
|
+
//# sourceMappingURL=CatalogPickerOption.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CatalogPickerOption.d.ts","sourceRoot":"","sources":["../../src/CatalogPicker/CatalogPickerOption.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAStC,OAAO,KAAK,EACV,kBAAkB,EAClB,iBAAiB,EAClB,MAAM,wBAAwB,CAAA;AAE/B,MAAM,MAAM,wBAAwB,GAAG;IACrC,KAAK,EAAE,kBAAkB,GAAG,SAAS,CAAA;IACrC,uEAAuE;IACvE,EAAE,EAAE,MAAM,CAAA;IACV,QAAQ,EAAE,OAAO,CAAA;IACjB,UAAU,EAAE,OAAO,CAAA;IACnB,UAAU,EAAE,OAAO,CAAA;IACnB,IAAI,EAAE,iBAAiB,CAAA;IACvB,qEAAqE;IACrE,QAAQ,EAAE,WAAW,CAAA;IACrB,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IACjC,sCAAsC;IACtC,OAAO,EAAE,MAAM,IAAI,CAAA;CACpB,CAAA;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,mBAAmB,GAAI,qFAUjC,wBAAwB,KAAG,SA4E7B,CAAA"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { PANEL_ITEM_SIZE_CLASS } from "../controlStyles.js";
|
|
3
|
+
import { toClassName } from "../toClassName.js";
|
|
4
|
+
import { CatalogPickerMark } from "./CatalogPickerMark.js";
|
|
5
|
+
import { CHOSEN_CHECK, ROW_FAVORITE_STAR, } from "./catalogPickerDrawings.js";
|
|
6
|
+
/**
|
|
7
|
+
* One row of the catalog's listbox: the mark, the label, the optional
|
|
8
|
+
* description, a star on a favorite, and the check gutter.
|
|
9
|
+
*
|
|
10
|
+
* The contract is `ComboboxOption`'s, for the same reasons: focus stays
|
|
11
|
+
* in the search field, so the row is `role="option"` with
|
|
12
|
+
* `tabIndex={-1}` and the active row is announced by
|
|
13
|
+
* `aria-activedescendant`; `aria-selected` is the chosen value; a
|
|
14
|
+
* mouse press is prevented from moving focus, so the caret stays in the
|
|
15
|
+
* field while the click lands.
|
|
16
|
+
*
|
|
17
|
+
* The pointer moves the active row on `pointermove` (as in
|
|
18
|
+
* `CommandPalette`), so the pointer and the arrow keys share one
|
|
19
|
+
* highlight and Enter's target is never ambiguous. The chosen row keeps
|
|
20
|
+
* its accent tint whenever the highlight is elsewhere.
|
|
21
|
+
*
|
|
22
|
+
* The check is always laid out and only hidden on an unchosen row, so
|
|
23
|
+
* choosing never moves the star or the label. It is drawn, not the
|
|
24
|
+
* `✓` `ComboboxOption` types: that glyph measures blank where the font
|
|
25
|
+
* lacks it.
|
|
26
|
+
*/
|
|
27
|
+
export const CatalogPickerOption = ({ group, id, isActive, isFavorite, isSelected, item, itemSize, onChoose, onPoint, }) => {
|
|
28
|
+
const { description, icon, isDisabled = false, label, value, } = item;
|
|
29
|
+
return (_jsxs("button", { "aria-selected": isSelected, className: toClassName("flex w-full cursor-pointer items-center rounded-sm text-start", PANEL_ITEM_SIZE_CLASS[itemSize], isDisabled
|
|
30
|
+
? "cursor-not-allowed text-content-disabled"
|
|
31
|
+
: "text-content-primary", isActive && "bg-intent-neutral-surface-hover", isSelected &&
|
|
32
|
+
!isActive &&
|
|
33
|
+
"bg-intent-accent-surface"), disabled: isDisabled, id: id, onClick: () => {
|
|
34
|
+
onChoose(value);
|
|
35
|
+
}, onMouseDown: (mouseEvent) => {
|
|
36
|
+
mouseEvent.preventDefault();
|
|
37
|
+
}, onPointerMove: onPoint, role: "option", tabIndex: -1, type: "button", children: [_jsx(CatalogPickerMark, { accentColor: group?.accentColor, icon: icon ?? group?.icon, initialsOf: group?.label, size: itemSize }), _jsxs("span", { className: "flex min-w-0 flex-1 flex-wrap items-baseline gap-x-2", children: [_jsx("span", { className: "min-w-0 wrap-anywhere", children: label }), description === undefined ||
|
|
38
|
+
description === "" ? null : (_jsx("span", { className: toClassName("min-w-0 text-sm wrap-anywhere", isDisabled
|
|
39
|
+
? "text-content-disabled"
|
|
40
|
+
: "text-content-muted"), children: description }))] }), isFavorite ? ROW_FAVORITE_STAR : null, _jsx("span", { "aria-hidden": "true", className: toClassName("flex w-4 shrink-0 items-center justify-center text-intent-accent-content", !isSelected && "invisible"), children: CHOSEN_CHECK })] }));
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=CatalogPickerOption.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CatalogPickerOption.js","sourceRoot":"","sources":["../../src/CatalogPicker/CatalogPickerOption.tsx"],"names":[],"mappings":";AAGA,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAA;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAyB,CAAA;AAC3D,OAAO,EACL,YAAY,EACZ,iBAAiB,GAClB,MAAM,4BAA6B,CAAA;AAqBpC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,EAClC,KAAK,EACL,EAAE,EACF,QAAQ,EACR,UAAU,EACV,UAAU,EACV,IAAI,EACJ,QAAQ,EACR,QAAQ,EACR,OAAO,GACkB,EAAa,EAAE;IACxC,MAAM,EACJ,WAAW,EACX,IAAI,EACJ,UAAU,GAAG,KAAK,EAClB,KAAK,EACL,KAAK,GACN,GAAG,IAAI,CAAA;IAER,OAAO,CACL,mCACiB,UAAU,EACzB,SAAS,EAAE,WAAW,CACpB,+DAA+D,EAC/D,qBAAqB,CAAC,QAAQ,CAAC,EAC/B,UAAU;YACR,CAAC,CAAC,0CAA0C;YAC5C,CAAC,CAAC,sBAAsB,EAC1B,QAAQ,IAAI,iCAAiC,EAC7C,UAAU;YACR,CAAC,QAAQ;YACT,0BAA0B,CAC7B,EACD,QAAQ,EAAE,UAAU,EACpB,EAAE,EAAE,EAAE,EACN,OAAO,EAAE,GAAG,EAAE;YACZ,QAAQ,CAAC,KAAK,CAAC,CAAA;QACjB,CAAC,EACD,WAAW,EAAE,CAAC,UAAU,EAAE,EAAE;YAC1B,UAAU,CAAC,cAAc,EAAE,CAAA;QAC7B,CAAC,EACD,aAAa,EAAE,OAAO,EACtB,IAAI,EAAC,QAAQ,EACb,QAAQ,EAAE,CAAC,CAAC,EACZ,IAAI,EAAC,QAAQ,aAEb,KAAC,iBAAiB,IAChB,WAAW,EAAE,KAAK,EAAE,WAAW,EAC/B,IAAI,EAAE,IAAI,IAAI,KAAK,EAAE,IAAI,EACzB,UAAU,EAAE,KAAK,EAAE,KAAK,EACxB,IAAI,EAAE,QAAQ,GACd,EAEF,gBAAM,SAAS,EAAC,sDAAsD,aACpE,eAAM,SAAS,EAAC,uBAAuB,YACpC,KAAK,GACD,EAEN,WAAW,KAAK,SAAS;wBAC1B,WAAW,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAC1B,eACE,SAAS,EAAE,WAAW,CACpB,+BAA+B,EAC/B,UAAU;4BACR,CAAC,CAAC,uBAAuB;4BACzB,CAAC,CAAC,oBAAoB,CACzB,YAEA,WAAW,GACP,CACR,IACI,EAEN,UAAU,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,IAAI,EAEtC,8BACc,MAAM,EAClB,SAAS,EAAE,WAAW,CACpB,0EAA0E,EAC1E,CAAC,UAAU,IAAI,WAAW,CAC3B,YAEA,YAAY,GACR,IACA,CACV,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { ControlSize } from "@charcuterie/tokens";
|
|
2
|
+
import type { ReactNode, RefObject } from "react";
|
|
3
|
+
import { type CatalogPickerGroup, type CatalogPickerItem } from "./catalogPickerView.ts";
|
|
4
|
+
export type CatalogPickerPanelProps = {
|
|
5
|
+
/** The glyph inside the search field's clear button. Without one there is no clear button; Escape clears. */
|
|
6
|
+
clearIcon?: ReactNode;
|
|
7
|
+
/** The query the panel opens with. For the stories' boards; `CatalogPicker` always opens empty. */
|
|
8
|
+
defaultQuery?: string;
|
|
9
|
+
emptyLabel: string;
|
|
10
|
+
favorites: readonly string[];
|
|
11
|
+
favoritesLabel: string;
|
|
12
|
+
groups: readonly CatalogPickerGroup[];
|
|
13
|
+
/** The search field, for the overlay's initial focus. */
|
|
14
|
+
inputRef?: RefObject<HTMLInputElement | null>;
|
|
15
|
+
/** Already stepped down for a short window by `usePanelItemSize`. */
|
|
16
|
+
itemSize: ControlSize;
|
|
17
|
+
items: readonly CatalogPickerItem[];
|
|
18
|
+
/** What the picker is for. Names the search field and the list, and (as "<label> groups") the rail. */
|
|
19
|
+
label: string;
|
|
20
|
+
/** Escape on an empty query. The Escape is consumed before this runs, so no enclosing overlay sees it. */
|
|
21
|
+
onDismiss: () => void;
|
|
22
|
+
onSelect: (value: string) => void;
|
|
23
|
+
searchPlaceholder: string;
|
|
24
|
+
value?: string;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* The panel's contents: the rail, the search field, and the grouped
|
|
28
|
+
* listbox. `CatalogPicker` renders it inside its anchored overlay, and
|
|
29
|
+
* it mounts fresh on every open, so the tab, the query and the
|
|
30
|
+
* highlight all start from the chosen value each time.
|
|
31
|
+
*
|
|
32
|
+
* ### The ARIA shape
|
|
33
|
+
*
|
|
34
|
+
* - The **search field** is the `role="combobox"` and keeps focus,
|
|
35
|
+
* exactly as in `Combobox`: arrows move `aria-activedescendant`
|
|
36
|
+
* through the options, Enter chooses, Escape clears a query and then
|
|
37
|
+
* closes.
|
|
38
|
+
* - The **list** is one `role="listbox"`. Search results sit in
|
|
39
|
+
* labelled `role="group"`s, one per group, the APG grouped-listbox
|
|
40
|
+
* shape `CommandPalette` uses.
|
|
41
|
+
* - The **rail** is a vertical `role="toolbar"` of toggle buttons
|
|
42
|
+
* (`aria-pressed`). See `CatalogPickerRail` for why it is not a
|
|
43
|
+
* `tablist`.
|
|
44
|
+
*
|
|
45
|
+
* Tab and Shift+Tab cycle through the search field, its clear button
|
|
46
|
+
* while it shows, and the rail, and nowhere else: the panel is two tab
|
|
47
|
+
* stops (three with a query and a clear button) however long the rail
|
|
48
|
+
* is.
|
|
49
|
+
*
|
|
50
|
+
* ### The highlight follows a value, not a position
|
|
51
|
+
*
|
|
52
|
+
* The active row is remembered by its `value`, so a catalog that
|
|
53
|
+
* refreshes while the panel is open — rows reordered, rows added — keeps
|
|
54
|
+
* the same row highlighted, and Enter chooses what the person saw. Only
|
|
55
|
+
* when that row leaves the view, or becomes disabled, is the highlight
|
|
56
|
+
* reseeded: to the chosen row if the view shows it, else the first
|
|
57
|
+
* enabled row.
|
|
58
|
+
*/
|
|
59
|
+
export declare const CatalogPickerPanel: ({ clearIcon, defaultQuery, emptyLabel, favorites, favoritesLabel, groups, inputRef: externalInputRef, itemSize, items, label, onDismiss, onSelect, searchPlaceholder, value, }: CatalogPickerPanelProps) => ReactNode;
|
|
60
|
+
//# sourceMappingURL=CatalogPickerPanel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CatalogPickerPanel.d.ts","sourceRoot":"","sources":["../../src/CatalogPicker/CatalogPickerPanel.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACtD,OAAO,KAAK,EAEV,SAAS,EACT,SAAS,EACV,MAAM,OAAO,CAAA;AAad,OAAO,EAGL,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EAGvB,MAAM,wBAAwB,CAAA;AAE/B,MAAM,MAAM,uBAAuB,GAAG;IACpC,6GAA6G;IAC7G,SAAS,CAAC,EAAE,SAAS,CAAA;IACrB,mGAAmG;IACnG,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,UAAU,EAAE,MAAM,CAAA;IAClB,SAAS,EAAE,SAAS,MAAM,EAAE,CAAA;IAC5B,cAAc,EAAE,MAAM,CAAA;IACtB,MAAM,EAAE,SAAS,kBAAkB,EAAE,CAAA;IACrC,yDAAyD;IACzD,QAAQ,CAAC,EAAE,SAAS,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAAA;IAC7C,qEAAqE;IACrE,QAAQ,EAAE,WAAW,CAAA;IACrB,KAAK,EAAE,SAAS,iBAAiB,EAAE,CAAA;IACnC,uGAAuG;IACvG,KAAK,EAAE,MAAM,CAAA;IACb,0GAA0G;IAC1G,SAAS,EAAE,MAAM,IAAI,CAAA;IACrB,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IACjC,iBAAiB,EAAE,MAAM,CAAA;IACzB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AA2CD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,eAAO,MAAM,kBAAkB,GAAI,gLAehC,uBAAuB,KAAG,SA+nB5B,CAAA"}
|