viewkitjs 0.24.0 → 0.25.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 (82) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/fields/dist/creatable.d.ts +9 -5
  3. package/fields/dist/creatable.js +8 -1
  4. package/fields/dist/messages.d.ts +19 -1
  5. package/fields/dist/messages.js +75 -0
  6. package/fields/dist/registry.js +4 -7
  7. package/fields/dist/types.d.ts +4 -2
  8. package/fields/dist/zod.d.ts +58 -0
  9. package/fields/dist/zod.js +430 -2
  10. package/fields/docs/guides/checking-definitions.md +6 -1
  11. package/fields/docs/guides/field-types.md +5 -1
  12. package/fields/docs/reference/definitions.md +1 -2
  13. package/fields/docs/reference/types.md +2 -1
  14. package/fields/skills/viewkit/SKILL.md +2 -2
  15. package/package.json +1 -1
  16. package/views/dist/controls/avatar/avatar.d.ts +58 -0
  17. package/views/dist/controls/avatar/avatar.js +54 -0
  18. package/views/dist/controls/avatar/looks.d.ts +4 -0
  19. package/views/dist/controls/avatar/looks.js +5 -0
  20. package/views/dist/controls/avatar/tokens.d.ts +131 -0
  21. package/views/dist/controls/avatar/tokens.js +35 -0
  22. package/views/dist/controls/avatar.css +163 -0
  23. package/views/dist/controls/controls.d.ts +2 -0
  24. package/views/dist/controls/controls.js +2 -0
  25. package/views/dist/controls/index.d.ts +12 -0
  26. package/views/dist/controls/index.js +12 -0
  27. package/views/dist/controls/internal/phone.d.ts +9 -0
  28. package/views/dist/controls/internal/phone.js +15 -0
  29. package/views/dist/controls/internal/read-token.d.ts +2 -1
  30. package/views/dist/controls/internal/read-token.js +1 -1
  31. package/views/dist/controls/internal/scroll.d.ts +38 -0
  32. package/views/dist/controls/internal/scroll.js +126 -0
  33. package/views/dist/controls/list/looks.d.ts +4 -0
  34. package/views/dist/controls/list/looks.js +12 -0
  35. package/views/dist/controls/list.css +17 -13
  36. package/views/dist/controls/menu/map-menu.d.ts +11 -0
  37. package/views/dist/controls/menu/map-menu.js +47 -0
  38. package/views/dist/controls/menu/menu.d.ts +75 -0
  39. package/views/dist/controls/menu/menu.js +105 -0
  40. package/views/dist/controls/menu/tokens.d.ts +23 -0
  41. package/views/dist/controls/menu/tokens.js +8 -0
  42. package/views/dist/controls/menu-list/looks.d.ts +5 -1
  43. package/views/dist/controls/menu-list/looks.js +6 -4
  44. package/views/dist/controls/menu-list/menu-list.js +3 -1
  45. package/views/dist/controls/menu-list.css +39 -31
  46. package/views/dist/controls/menu.css +25 -0
  47. package/views/dist/controls/picker/looks.d.ts +19 -0
  48. package/views/dist/controls/picker/looks.js +32 -0
  49. package/views/dist/controls/picker/picker.d.ts +153 -0
  50. package/views/dist/controls/picker/picker.js +773 -0
  51. package/views/dist/controls/picker/rows.d.ts +129 -0
  52. package/views/dist/controls/picker/rows.js +90 -0
  53. package/views/dist/controls/picker/tokens.d.ts +147 -0
  54. package/views/dist/controls/picker/tokens.js +39 -0
  55. package/views/dist/controls/picker.css +237 -0
  56. package/views/dist/controls/popup-line/tokens.d.ts +23 -0
  57. package/views/dist/controls/popup-line/tokens.js +8 -0
  58. package/views/dist/controls/popup-line.css +44 -0
  59. package/views/dist/controls/select/filled.d.ts +7 -0
  60. package/views/dist/controls/select/filled.js +5 -0
  61. package/views/dist/controls/select/fit.d.ts +9 -0
  62. package/views/dist/controls/select/fit.js +11 -0
  63. package/views/dist/controls/select/select.d.ts +131 -0
  64. package/views/dist/controls/select/select.js +227 -0
  65. package/views/dist/controls/select/side.d.ts +3 -0
  66. package/views/dist/controls/select/side.js +4 -0
  67. package/views/dist/controls/select/tokens.d.ts +27 -0
  68. package/views/dist/controls/select/tokens.js +9 -0
  69. package/views/dist/controls/select.css +91 -0
  70. package/views/dist/controls/tokens.js +10 -0
  71. package/views/dist/looks/index.d.ts +4 -0
  72. package/views/dist/looks/index.js +4 -0
  73. package/views/dist/looks/pieces.js +6 -0
  74. package/views/dist/styles.css +586 -62
  75. package/views/dist/styles.unlayered.css +586 -62
  76. package/views/docs/controls/avatar.md +38 -0
  77. package/views/docs/controls/menu.md +11 -0
  78. package/views/docs/controls/picker.md +42 -0
  79. package/views/docs/controls/popup-line.md +11 -0
  80. package/views/docs/controls/select.md +12 -0
  81. package/views/docs/reference/controls.md +86 -0
  82. package/views/docs/reference/looks.md +8 -0
@@ -0,0 +1,227 @@
1
+ "use client";
2
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import * as React from "react";
4
+ import { Combobox as BaseCombobox } from "@base-ui/react/combobox";
5
+ import { Field as BaseField } from "@base-ui/react/field";
6
+ import { Avatar } from "../avatar/avatar.js";
7
+ import { Button } from "../button/button.js";
8
+ import { Field } from "../field/field.js";
9
+ import { Input, InputGroupAddon } from "../input/input.js";
10
+ import { Option, Options } from "../option/option.js";
11
+ import { cx } from "../../internal/cx.js";
12
+ import { usePopupHost as usePickHost } from "../internal/popup-host.js";
13
+ import { PhoneHost, usePhone } from "../internal/phone.js";
14
+ import { drawnAt, holdsThePage } from "../internal/scroll.js";
15
+ import { spacingPx } from "../internal/read-token.js";
16
+ import { Picker, PickerUnder, usePicker } from "../picker/picker.js";
17
+ import { findItem, itemLabel } from "../picker/rows.js";
18
+ import { Sheet, SheetBody, SheetHead } from "../sheet/bottom-sheet.js";
19
+ import { listSide } from "./side.js";
20
+ import { chipsThatFit } from "./fit.js";
21
+ import { filledMatch } from "./filled.js";
22
+ const glyph = (paths, className, strokeWidth = 2) => (_jsx("svg", { className: className, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: strokeWidth, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: paths.map((d) => _jsx("path", { d: d }, d)) }));
23
+ const CHEVRON = ["M6 9l6 6l6 -6"], PLUS = ["M12 5v14", "M5 12h14"], X = ["M18 6l-12 12", "M6 6l12 12"];
24
+ const SEARCH = ["M10 10m-7 0a7 7 0 1 0 14 0a7 7 0 1 0 -14 0", "M21 21l-6 -6"];
25
+ function Value({ chosen, multiple, chips, placeholder }) {
26
+ if (!chosen.length)
27
+ return _jsx("span", { className: "o-select-value o-select-placeholder", children: placeholder });
28
+ return _jsx("span", { className: "o-select-value", children: valueBody(chosen, multiple, chips) });
29
+ }
30
+ const valueBody = (chosen, multiple, chips) => {
31
+ if (multiple)
32
+ return chosen.length <= 2 ? _jsx(Options, { values: chosen.map((i) => i.label) }) : `${chosen.length} chosen`;
33
+ const [i] = chosen;
34
+ return chips ? _jsx(Option, { children: i.label }) : _jsxs(_Fragment, { children: [i.mark, _jsx("span", { className: "o-list-main", children: i.label })] });
35
+ };
36
+ export function Select(props) {
37
+ const sheet = useSheetSelect();
38
+ if (props.opens)
39
+ return _jsx(AloneSelect, { ...props });
40
+ if (sheet)
41
+ return _jsx(SheetSelect, { ...props });
42
+ return _jsx(PickerSelect, { ...props });
43
+ }
44
+ const chipMark = (mark) => React.isValidElement(mark) && mark.type === Avatar ? React.cloneElement(mark, { size: 16 }) : mark;
45
+ export const toPickerItems = (items, chips) => items.map((i) => ({ value: i.value, label: i.label, line: i.line, you: i.you, group: i.group, disabled: i.disabled, divider: i.divider,
46
+ as: chips ? { option: true } : i.mark ? { mark: i.mark } : undefined, ...(i.level ? { level: toPickerItems(i.level, chips) } : {}) }));
47
+ const titleOf = (p) => (typeof p.label === "string" ? p.label : p["aria-label"] ?? p.placeholder ?? "Choose");
48
+ function usePickerOf(p, f, close) {
49
+ const [naming, setNaming] = React.useState(null);
50
+ const make = (typed) => { const it = { value: `new-${Date.now()}`, label: typed }; f.add(it); return it.value; };
51
+ const first = () => { const it = { value: "first", label: p.empty.first }; f.add(it); f.setValue(p.multiple ? [it.value] : it.value); close(); };
52
+ const actions = p.footer
53
+ ? [{ id: "footer", label: p.footer, icon: glyph(PLUS, ""), onSelect: () => setNaming(`Name the ${p.footer.replace(/^New /, "new ").toLowerCase()}`) }] : undefined;
54
+ return {
55
+ reset: () => setNaming(null),
56
+ props: {
57
+ label: titleOf(p), items: toPickerItems(f.items, p.chips), multiple: p.multiple, value: f.value, onValueChange: (v) => f.setValue(v),
58
+ onDone: close, readOnly: p.readOnly, empty: p.multiple ? undefined : p.clear, onCreate: p.create ? make : undefined, onSearch: p.onSearch,
59
+ doing: p.loading ? "searching" : undefined, none: p.none, actions,
60
+ nothingYet: p.empty && !f.items.length ? { text: p.empty.text, action: p.empty.action, onAction: first } : undefined,
61
+ },
62
+ words: naming ?? undefined,
63
+ };
64
+ }
65
+ function PickerSelect(p) {
66
+ const { placeholder = "Choose", multiple, chips, disabled } = p;
67
+ const typed = p.searchIn === "field", field = React.useRef(null);
68
+ const f = useField(p), trigger = React.useRef(null), host = usePickHost(trigger), popup = React.useRef(null);
69
+ const [ownOpen, setOwnOpen] = React.useState(false), open = p.open ?? ownOpen;
70
+ const shut = React.useRef(() => { });
71
+ const picker = usePickerOf(p, f, () => shut.current());
72
+ const setOpen = (o) => { setOwnOpen(o); if (!o)
73
+ picker.reset(); p.onOpenChange?.(o); };
74
+ React.useLayoutEffect(() => { shut.current = () => setOpen(false); });
75
+ React.useEffect(() => (open ? holdsThePage(trigger.current?.ownerDocument ?? document, () => popup.current) : undefined), [open]);
76
+ const [placed, setPlaced] = React.useState({ open: false, side: p.side ?? "bottom" });
77
+ const [box, setBox] = React.useState(null);
78
+ React.useLayoutEffect(() => { setBox(typed ? field.current : trigger.current); }, [typed]);
79
+ if (placed.open !== open)
80
+ setPlaced({ open, side: open ? sideAsItOpens(p, f, box) : p.side ?? "bottom" });
81
+ const side = placed.side;
82
+ return (_jsxs(Labelled, { ...p, id: f.id, typed: typed, children: [_jsx(PickerUnder, { ...picker.props, empty: typed ? undefined : picker.props.empty, search: picker.words ?? p.search ?? (p.create || p.onSearch || p.footer ? "Search" : undefined), searchShown: typed || !!(p.search || p.create || p.onSearch || p.footer), searchIn: typed ? "box" : "list", open: open, onOpenChange: setOpen, disabled: disabled, box: typed ? (search) => _jsx(TypedBox, { p: p, f: f, trigger: trigger, field: field, hint: picker.words ?? p.search ?? placeholder, search: search }) : (_jsxs(BaseCombobox.Trigger, { ref: trigger, className: cx("o-input o-select-field o-smooth o-smooth-ease", sized(p.size)), "data-force": p["data-force"], "data-kit": "select", ...fieldAria(p, f.id), children: [_jsx("span", { id: `${f.id}-value`, className: "contents", children: _jsx(Value, { chosen: f.chosen, multiple: multiple, chips: chips, placeholder: placeholder }) }), _jsx(BaseCombobox.Icon, { className: "o-select-chevron", children: glyph(CHEVRON, "") })] })), panel: (list) => (_jsx(BaseCombobox.Portal, { container: host, children: _jsx(BaseCombobox.Positioner, { className: "o-list-positioner", side: side, sideOffset: gapOf(box ?? host), collisionPadding: edgeOf(box ?? host), align: p.align ?? "start", collisionAvoidance: { side: "none" }, anchor: typed ? field : undefined, children: _jsx(BaseCombobox.Popup, { ref: popup, className: "o-list o-select-list o-smooth o-smooth-ease", "data-list-width": p.listWidth === "rows" ? "rows" : undefined, "aria-label": titleOf(p), children: list }) }, side) })) }), _jsx(FormValue, { p: p, f: f, focusBox: () => (typed ? field.current?.querySelector("input") : trigger.current)?.focus() })] }));
83
+ }
84
+ function TypedBox({ p, f, trigger, field, hint, search }) {
85
+ const { multiple, disabled } = p, q = search.typed;
86
+ const input = React.useRef(null), chipsBox = React.useRef(null), measure = React.useRef(null);
87
+ const keep = (e) => { const t = e.target; if (t.closest(".o-tag-remove, .o-select-clear, .o-tag-count") || t === field.current || t.classList.contains("o-select-chips")) {
88
+ e.preventDefault();
89
+ input.current?.focus();
90
+ } };
91
+ const [fit, setFit] = React.useState(Number.POSITIVE_INFINITY);
92
+ const several = !!multiple, names = f.chosen.map((i) => i.label).join("\u0000"), n = f.chosen.length;
93
+ React.useLayoutEffect(() => {
94
+ const row = chipsBox.current, copy = measure.current, typing = row?.querySelector(".o-select-typed-input");
95
+ if (!several || !row || !copy || !typing)
96
+ return;
97
+ const count = () => {
98
+ const widths = [...copy.children].map((c) => c.offsetWidth), gap = parseFloat(getComputedStyle(row).columnGap) || 0;
99
+ const words = widths[n + 1] ?? 0, more = widths[n] ?? 0;
100
+ row.style.setProperty("--select-typed", `${q ? words + 4 : 0}px`);
101
+ setFit(chipsThatFit({ chips: widths.slice(0, n), more, words, gap, row: row.clientWidth, least: parseFloat(getComputedStyle(typing).minWidth) || 0, typed: !!q }));
102
+ };
103
+ const watch = new ResizeObserver(count);
104
+ watch.observe(row);
105
+ return () => watch.disconnect();
106
+ }, [several, names, n, q]);
107
+ const small = p.size === "2xs" || p.size === "xs";
108
+ const one = !multiple && f.chosen.length === 1 ? f.chosen[0] : undefined;
109
+ const slot = one?.mark != null && (_jsxs(InputGroupAddon, { side: "start", className: "o-select-mark", "aria-hidden": "true", "data-searching": q !== one.label ? "" : undefined, children: [_jsx("span", { className: "o-select-mark-own", children: one.mark }), glyph(SEARCH, "o-select-mark-search")] }));
110
+ const box = (_jsx(Input, { combobox: true, chrome: "bare", ref: input, className: "o-select-typed-input", placeholder: multiple && f.chosen.length ? undefined : hint, onKeyDown: search.onKeyDown, ...search.attrs, ...(p.label != null ? {} : { "aria-label": p["aria-label"] }) }));
111
+ return (_jsxs(BaseCombobox.InputGroup, { ref: field, className: cx("o-input o-input-group o-select-field o-select-typed o-smooth o-smooth-ease", sized(p.size)), "data-force": p["data-force"], "data-kit": "select", onMouseDown: keep, children: [slot, multiple ? (_jsxs(_Fragment, { children: [_jsx("span", { className: "o-select-measure", "aria-hidden": "true", inert: true, children: _jsxs("span", { ref: measure, children: [f.chosen.map((i) => _jsx(Option, { icon: chipMark(i.mark), onRemove: () => { }, children: i.label }, i.value)), _jsx(Option, { count: n }), _jsx("span", { className: "o-select-measure-words", children: q })] }) }), _jsxs(BaseCombobox.Chips, { ref: chipsBox, className: "o-select-chips", children: [f.chosen.map((i, at) => _jsx(BaseCombobox.Chip, { "data-over": at >= fit ? "" : undefined, render: _jsx(Option, { icon: chipMark(i.mark), onRemove: () => f.setValue(f.value.filter((v) => v !== i.value)) }), children: i.label }, i.value)), fit < n && _jsx(Option, { count: n - fit }), box] })] })) : box, !small && !disabled && !p.readOnly && f.chosen.length > 0 && (_jsx(BaseCombobox.Clear, { render: (props) => _jsx(Button, { ...props, kind: "quiet", size: "2xs", shape: "icon", className: "o-select-clear", "aria-label": "Clear", icon: glyph(X, ""), children: null }) })), _jsx(BaseCombobox.Trigger, { ref: trigger, className: "o-select-chevron o-select-typed-trigger", tabIndex: -1, "aria-label": `Show every ${typeof p.label === "string" ? p.label.toLowerCase() : "choice"}`, children: glyph(CHEVRON, "") })] }));
112
+ }
113
+ const gapOf = (at) => spacingPx(1, at), edgeOf = (at) => spacingPx(1.25, at);
114
+ function listNeed(at, rows, lines) {
115
+ const probe = at.ownerDocument.createElement("div");
116
+ probe.style.cssText = "position:absolute;visibility:hidden;pointer-events:none;height:var(--list-row-h, calc(var(--vk-spacing) * 8));padding-top:var(--list-pad, calc(var(--vk-spacing) * 1.5));margin-top:calc(var(--vk-spacing) * 11)";
117
+ at.parentElement?.append(probe);
118
+ const s = getComputedStyle(probe), most = parseFloat(getComputedStyle(at).getPropertyValue("--list-rows")) || 8.5;
119
+ const need = Math.min(rows, most) * parseFloat(s.height) + 2 * parseFloat(s.paddingTop) + lines * parseFloat(s.marginTop);
120
+ probe.remove();
121
+ return need * drawnAt(at);
122
+ }
123
+ function sideAsItOpens(p, f, at) {
124
+ const typed = p.searchIn === "field";
125
+ const asked = p.side ?? "bottom";
126
+ if (!at)
127
+ return asked;
128
+ const groups = new Set(f.items.map((i) => i.group).filter(Boolean)).size;
129
+ const rows = f.items.length ? f.items.length + groups + (!typed && p.clear && !p.multiple && f.value != null ? 1 : 0) + (p.footer ? 1 : 0) : p.empty ? 2 : 1;
130
+ const lines = (!typed && (p.search || p.create || p.onSearch || p.footer) ? 1 : 0) + (p.footer ? 1 : 0);
131
+ const b = at.getBoundingClientRect(), height = at.ownerDocument.documentElement.clientHeight;
132
+ const keep = gapOf(at) + edgeOf(at);
133
+ return listSide(asked, listNeed(at, rows, lines), height - b.bottom - keep, b.top - keep);
134
+ }
135
+ const useSheetSelect = () => { const phone = usePhone(), screen = React.useContext(PhoneHost); return phone || !!screen; };
136
+ function SheetSelect(p) {
137
+ const { placeholder = "Choose", multiple, chips } = p;
138
+ const f = useField(p), screen = React.useContext(PhoneHost), box = React.useRef(null), host = usePickHost(box);
139
+ const [ownOpen, setOwnOpen] = React.useState(false), open = p.open ?? ownOpen;
140
+ const shut = React.useRef(() => { });
141
+ const picker = usePickerOf(p, f, () => shut.current());
142
+ const setOpen = (o) => { setOwnOpen(o); if (!o)
143
+ picker.reset(); p.onOpenChange?.(o); };
144
+ React.useLayoutEffect(() => { shut.current = () => setOpen(false); });
145
+ const title = titleOf(p), typed = p.searchIn === "field";
146
+ const parts = usePicker({ ...picker.props, form: "phone", search: picker.words ?? p.search ?? (typed ? placeholder : p.create || p.onSearch || p.footer ? "Search" : undefined), searchShown: !!(p.search || p.create || p.onSearch || p.footer) || typed });
147
+ const { opens: _o, items: _i, ...field } = { ...p, opens: undefined };
148
+ void _o;
149
+ void _i;
150
+ return (_jsxs(_Fragment, { children: [_jsx("span", { ref: box, hidden: true }), _jsx(AloneSelect, { ...field, opens: "dialog", open: open, onOpenChange: setOpen, placeholder: placeholder, shown: f.chosen.length ? valueBody(f.chosen, multiple, chips) : undefined }), _jsx(FormValue, { p: p, f: f, focusBox: () => box.current?.nextElementSibling?.querySelector(".o-select-field")?.focus() }), _jsxs(Sheet, { open: open, onOpenChange: setOpen, label: title, form: "full", container: screen ?? host, standing: !!screen, children: [_jsx(SheetHead, { title: title, ...parts.head }), _jsx(SheetBody, { children: parts.body })] })] }));
151
+ }
152
+ function FormValue({ p, f, focusBox }) {
153
+ if (!p.name && !p.required && !p.autoComplete)
154
+ return null;
155
+ const values = valuesOf(f.value);
156
+ const own = { tabIndex: -1, "aria-hidden": true, disabled: p.disabled, onFocus: focusBox };
157
+ if (p.multiple && values.length > 1)
158
+ return _jsx(_Fragment, { children: values.map((v, k) => _jsx("input", { className: "o-select-form sr-only", ...own, name: p.name, value: v, required: p.required && k === 0, readOnly: true }, v)) });
159
+ const filled = (e) => {
160
+ const it = filledMatch(f.items, e.target.value);
161
+ if (it && !p.readOnly)
162
+ f.setValue(p.multiple ? [it.value] : it.value);
163
+ };
164
+ return _jsx("input", { className: "o-select-form sr-only", ...own, name: p.multiple && !values.length ? undefined : p.name, required: p.required, autoComplete: p.autoComplete, value: values[0] ?? "", onChange: filled });
165
+ }
166
+ const valuesOf = (v) => (Array.isArray(v) ? v : v != null ? [v] : []);
167
+ function useField({ multiple, defaultValue, value: outside, onValueChange, items: given }) {
168
+ const [made, setMade] = React.useState([]);
169
+ const items = [...given, ...made.filter((m) => !given.some((g) => g.value === m.value))];
170
+ const [named, setNamed] = React.useState(() => new Map(valuesOf(outside !== undefined ? outside : defaultValue).flatMap((v) => given.filter((i) => i.value === v).map((i) => [v, i]))));
171
+ const add = (it) => { setMade((xs) => [...xs, it]); setNamed((n) => new Map(n).set(it.value, it)); };
172
+ const lookUp = (x) => {
173
+ const top = items.find((i) => i.value === x);
174
+ if (top)
175
+ return top;
176
+ const f = findItem(items, x);
177
+ return f ? { ...f.item, label: itemLabel(items, x) } : undefined;
178
+ };
179
+ const [own, setOwn] = React.useState(defaultValue ?? (multiple ? [] : null));
180
+ const value = outside !== undefined ? outside ?? (multiple ? [] : null) : own;
181
+ const setValue = (v) => {
182
+ const picked = valuesOf(v).flatMap((x) => lookUp(x) ?? []);
183
+ if (picked.length)
184
+ setNamed((n) => { const next = new Map(n); for (const i of picked)
185
+ next.set(i.value, i); return next; });
186
+ if (outside === undefined)
187
+ setOwn(v);
188
+ onValueChange?.(v);
189
+ };
190
+ const chosen = valuesOf(value).map((v) => lookUp(v) ?? named.get(v)).filter(Boolean);
191
+ return { items, add, value, setValue, chosen, id: React.useId() };
192
+ }
193
+ const sized = (size) => size && size !== "md" && `o-input-${size}`;
194
+ function Labelled({ label, note, error, id, size, typed, disabled, className, children }) {
195
+ const cls = cx("o-select", size && size !== "md" && `o-select-${size}`, className);
196
+ return label != null || note != null || (error != null && error !== "")
197
+ ? _jsx(Field, { label: label, note: note, error: error, disabled: disabled, nativeLabel: !!typed, labelId: `${id}-label`, className: cls, children: children })
198
+ : _jsx("div", { className: cls, children: children });
199
+ }
200
+ const fieldAria = (p, id) => (p.label != null ? { "aria-labelledby": `${id}-label ${id}-value` } : { "aria-label": p["aria-label"] });
201
+ const ARROWS = { down: CHEVRON, right: ["M9 6l6 6l-6 6"] };
202
+ function AloneSelect({ opens, shown, open = false, onOpenChange, placeholder = "Choose", arrow = "down", ...p }) {
203
+ const id = React.useId(), own = React.useRef(null), pressedOpen = React.useRef(false);
204
+ React.useEffect(() => {
205
+ if (!open)
206
+ return;
207
+ const press = (e) => { pressedOpen.current = e.target instanceof Node && !!own.current?.contains(e.target); };
208
+ window.addEventListener("pointerdown", press, true);
209
+ return () => window.removeEventListener("pointerdown", press, true);
210
+ }, [open]);
211
+ const press = () => { const was = pressedOpen.current; pressedOpen.current = false; if (!was)
212
+ onOpenChange?.(!open);
213
+ else if (open)
214
+ onOpenChange?.(false); };
215
+ const keys = (e) => { pressedOpen.current = false; if (!open && (e.key === "ArrowDown" || e.key === "ArrowUp")) {
216
+ e.preventDefault();
217
+ onOpenChange?.(true);
218
+ } };
219
+ const empty = shown == null || shown === "" || shown === false;
220
+ return (_jsx(Labelled, { ...p, id: id, children: _jsxs(BaseField.Control, { render: _jsx("button", { type: "button" }), ref: own, disabled: p.disabled, className: cx("o-input o-select-field o-smooth o-smooth-ease", sized(p.size)), "data-force": p["data-force"], "data-kit": "select", ...fieldAria(p, id), "aria-haspopup": opens, "aria-expanded": open, "data-popup-open": open ? "" : undefined, onClick: press, onKeyDown: keys, children: [_jsx("span", { id: `${id}-value`, className: "contents", children: empty ? _jsx("span", { className: "o-select-value o-select-placeholder", children: placeholder })
221
+ : _jsx("span", { className: "o-select-value", children: typeof shown === "string" ? _jsx("span", { className: "o-list-main", children: shown }) : shown }) }), arrow !== "none" && _jsx("span", { className: "o-select-chevron", "data-arrow": arrow, "aria-hidden": "true", children: glyph(ARROWS[arrow], "") })] }) }));
222
+ }
223
+ export function SelectShown({ items, defaultValue, multiple, chips, search, none, placeholder = "Choose", "aria-label": name }) {
224
+ const [value, setValue] = React.useState(defaultValue ?? (multiple ? [] : null));
225
+ const chosen = items.filter((i) => valuesOf(value).includes(i.value));
226
+ return (_jsxs("div", { className: "o-select o-select-shown", "data-kit": "select", children: [_jsxs("div", { className: "o-input o-select-field o-smooth o-smooth-ease", "data-popup-open": "", children: [_jsx(Value, { chosen: chosen, multiple: multiple, chips: chips, placeholder: placeholder }), _jsx("span", { className: "o-select-chevron", children: glyph(CHEVRON, "") })] }), _jsx("div", { className: "o-list o-select-list o-smooth o-smooth-ease", children: _jsx(Picker, { label: name, items: toPickerItems(items, chips), multiple: multiple, value: value, onValueChange: setValue, search: search, searchShown: !!search, none: none, form: "computer", standing: true }) })] }));
227
+ }
@@ -0,0 +1,3 @@
1
+ export type ListSide = "bottom" | "top";
2
+ /** The side a list of `need` pixels opens on: the one asked for, unless it doesn't fit there and the other side has more room. */
3
+ export declare function listSide(asked: ListSide, need: number, under: number, over: number): ListSide;
@@ -0,0 +1,4 @@
1
+ export function listSide(asked, need, under, over) {
2
+ const room = asked === "bottom" ? under : over, other = asked === "bottom" ? over : under;
3
+ return need > room && other > room ? (asked === "bottom" ? "top" : "bottom") : asked;
4
+ }
@@ -0,0 +1,27 @@
1
+ export declare const SELECT_TOKENS: readonly [{
2
+ readonly name: "--vk-fg-disabled";
3
+ readonly kind: "colour";
4
+ readonly outright: "--text-disabled";
5
+ }, {
6
+ readonly name: "--vk-fg-subtlest";
7
+ readonly kind: "colour";
8
+ readonly outright: "--text-subtlest";
9
+ }, {
10
+ readonly name: "--vk-font-size-base";
11
+ readonly kind: "size";
12
+ readonly outright: "--text-base";
13
+ }, {
14
+ readonly name: "--vk-spacing";
15
+ readonly kind: "size";
16
+ readonly outright: "--spacing";
17
+ }, {
18
+ readonly name: "--vk-duration-fast";
19
+ readonly kind: "motion";
20
+ readonly outright: "--duration-fast";
21
+ }, {
22
+ readonly name: "--vk-ease-out";
23
+ readonly kind: "motion";
24
+ readonly outright: "--ease-out";
25
+ }];
26
+ /** The Select's own machinery: what is typed into it. */
27
+ export declare const SELECT_PRIVATE: readonly ["--select-"];
@@ -0,0 +1,9 @@
1
+ export const SELECT_TOKENS = [
2
+ { name: "--vk-fg-disabled", kind: "colour", outright: "--text-disabled" },
3
+ { name: "--vk-fg-subtlest", kind: "colour", outright: "--text-subtlest" },
4
+ { name: "--vk-font-size-base", kind: "size", outright: "--text-base" },
5
+ { name: "--vk-spacing", kind: "size", outright: "--spacing" },
6
+ { name: "--vk-duration-fast", kind: "motion", outright: "--duration-fast" },
7
+ { name: "--vk-ease-out", kind: "motion", outright: "--ease-out" },
8
+ ];
9
+ export const SELECT_PRIVATE = ["--select-"];
@@ -0,0 +1,91 @@
1
+ /* The Select. Its field is the Input's own
2
+ (.o-input, and .o-input-group when typed into): input.css draws its edge, fill, lift, size and every state
3
+ and option, its open list being its focus. This file says only what is the Select's: its words and chevron
4
+ in a row, the chevron turning over while the list is open (alone, a right arrow never turns: it points to a step), and the chips of a field typed into; the list's
5
+ panel and rows are list.css. Every value it draws with is a token (control tokens).
6
+
7
+ The rules sit in the components layer, so a utility class on a select still wins. */
8
+ @layer components {
9
+
10
+ /* ── The field: its value, then the chevron ────────────────────────────────────────────────────────── */
11
+ .o-select { position: relative; }
12
+ .o-select-field { display: flex; align-items: center; gap: calc(var(--vk-spacing) * 2); text-align: left; cursor: pointer; }
13
+ .o-select-value { flex: 1; min-width: 0; display: flex; align-items: center; gap: calc(var(--vk-spacing) * 2); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
14
+ .o-select-placeholder { color: var(--vk-fg-subtlest); }
15
+ .o-select-field:is([data-disabled], :disabled) .o-select-placeholder { color: var(--vk-fg-disabled); }
16
+ .o-select-chevron { flex: none; display: grid; place-items: center; transition: rotate var(--vk-duration-fast) var(--vk-ease-out); }
17
+ .o-select-chevron svg { width: calc(var(--vk-spacing) * 4); height: calc(var(--vk-spacing) * 4); fill: none; stroke: var(--vk-fg-subtlest); stroke-linecap: round; stroke-linejoin: round; }
18
+ /* The smallest, in dense rows: its words and chevron closer, the chevron 14px; on the phone 16px, as the
19
+ field is 44px there. */
20
+ .o-select-2xs .o-select-field { gap: calc(var(--vk-spacing) * 1.5); }
21
+ .o-select-2xs .o-select-chevron svg { width: calc(var(--vk-spacing) * 3.5); height: calc(var(--vk-spacing) * 3.5); }
22
+ @media (width < 640px) { .o-select-2xs .o-select-chevron svg:where(:not([data-computer-host], [data-computer-host] *)) { width: calc(var(--vk-spacing) * 4); height: calc(var(--vk-spacing) * 4); } }
23
+ @container o-phone (width < 640px) { .o-select-2xs .o-select-chevron svg { width: calc(var(--vk-spacing) * 4); height: calc(var(--vk-spacing) * 4); } }
24
+ .o-select-field[data-popup-open] .o-select-chevron:not([data-arrow="right"]) { rotate: 180deg; }
25
+
26
+ /* ── Typed into: the field holds the box you type in (the group's bare control), and with several, their
27
+ chips first, each the Option with its own ×, wrapping onto more lines as they grow; from 32px up a quiet ×
28
+ clears it; the chevron shows every choice ───────────────────────────────────────────────────────── */
29
+ .o-select-field.o-select-typed { gap: calc(var(--vk-spacing) * 2); cursor: text; }
30
+ .o-select-chips { flex: 1; min-width: 0; display: flex; align-items: center; gap: calc(var(--vk-spacing) * 1); overflow: hidden; }
31
+ /* Several stay one line, the field's own height: the chips that fit, the first shrinking to "…" if it must, the count for the rest
32
+ (the Option's "+1"), then the box to type in, which keeps room for what is typed (--select-typed, set as it is typed). */
33
+ .o-select-chips > .o-option { flex: none; }
34
+ .o-select-chips > .o-option:first-child { flex: 0 1 auto; min-width: 0; }
35
+ .o-select-chips > [data-over] { display: none; }
36
+ .o-select-chips > .o-input-control.o-select-typed-input { flex: 1 1 0; min-width: max(calc(var(--vk-spacing) * 6), var(--select-typed, 0px)); }
37
+ /* The copy the chips are measured by: out of sight, taking no room, never focused or read. */
38
+ .o-select-measure { position: absolute; width: 0; height: 0; overflow: hidden; visibility: hidden; pointer-events: none; }
39
+ .o-select-measure > span { display: flex; width: max-content; gap: calc(var(--vk-spacing) * 1); white-space: pre; }
40
+ .o-select-measure > span > * { flex: none; }
41
+ .o-input-control.o-select-typed-input { min-width: calc(var(--vk-spacing) * 16); text-overflow: ellipsis; }
42
+ .o-select-typed-input:disabled::placeholder { color: var(--vk-fg-disabled); }
43
+ .o-select-typed-trigger { margin: 0; padding: 0; border: 0; background: none; color: inherit; cursor: pointer; outline: none; }
44
+ .o-select-typed-trigger:disabled { cursor: not-allowed; }
45
+ .o-select-typed > .o-select-clear { flex: none; }
46
+ /* One chosen, its mark before its name: the Input's own start addon, the field's 8px before the
47
+ words; the search glyph, the addon's own 16px icon (14 at 24px, input.css), stands over the mark's centre and shows while the
48
+ words are a search, the mark hidden, so the slot keeps the mark's width and the words never move. */
49
+ .o-select-typed > .o-select-mark { position: relative; }
50
+ .o-select-mark-own { display: flex; }
51
+ .o-select-mark > .o-select-mark-search { position: absolute; inset: 50% auto auto 50%; translate: -50% -50%; visibility: hidden; }
52
+ .o-select-mark[data-searching] > .o-select-mark-own { visibility: hidden; }
53
+ .o-select-mark[data-searching] > .o-select-mark-search { visibility: visible; }
54
+
55
+ /* ── The list (the Picker's panel, a typed-into field's too): 4px under the field, exactly as wide as it (a long name ends in "…"), never taller than the room its side
56
+ has. It stands still: its search on top (a pressed one's; typed into, the field is its search), under it its rows, the only part that scrolls, its actions at its foot (the Picker's),
57
+ 8½ rows at most (--list-rows), the half row saying there is more; a row brought into view stands a row clear of the edge.
58
+ ──────────────────────────────────────────────────────────────────── */
59
+ .o-select-list { display: flex; flex-direction: column; width: var(--anchor-width); max-width: var(--available-width); max-height: var(--available-height); overflow: hidden; }
60
+ /* Where its place asks for its rows' width (listWidth: the filter editor's and the
61
+ sort editor's boxes): as wide as its widest row needs, never narrower than its box nor 192, unless the room on screen is less; never past that room or the 288 a Picker stands in a Popover (popover.css),
62
+ a longer name then ending in "…"; its search counts as a row does, so a list with a search is never narrower than it (as the
63
+ Picker in a Popover handed its own width), and its foot takes the width the rows give it. */
64
+ .o-select-list[data-list-width="rows"] {
65
+ width: max-content; min-width: min(max(var(--anchor-width), calc(var(--vk-spacing) * 48)), var(--available-width));
66
+ max-width: min(var(--available-width), calc(var(--vk-spacing) * 72));
67
+ }
68
+ .o-select-list[data-list-width="rows"] .o-picker-foot { contain: inline-size; }
69
+ /* Under the list's Smooth its edge is a layer reaching over its border, which hiding what overflows would cut: the kit's
70
+ outline cuts the panel instead, and its rows scroll inside it (the Picker's rows). */
71
+ @supports (clip-path: shape(evenodd from 0 0, curve by 1px 1px with 1px 0 / 1px 0, close, move to 0 0, hline to 1px, close)) and (width: calc(tan(atan2(1px, 1px)) * 1px)) {
72
+ .o-select-list:not([data-list-smoothing="round"] *) { overflow: visible; }
73
+ }
74
+ /* While a list is open the page behind it never moves (scroll.ts, holdsThePage). A finger that lands outside it lands on Base
75
+ UI's backdrop, drawn just before the list's positioner, which closes the list and turns inert at once, so no script sees that
76
+ finger again: it may never pan, read by the browser as the finger lands. */
77
+ [data-base-ui-inert]:has(+ .o-list-positioner > .o-select-list) { touch-action: none; }
78
+ /* The box's form input: out of sight and out of the tab order, but a box all the same, so at 16px on a phone, as every
79
+ box is, and iOS never zooms if something hands it the focus. */
80
+ @media (width < 640px) { .o-select-form:where(:not([data-computer-host], [data-computer-host] *)) { font-size: var(--vk-font-size-base); } }
81
+ @container o-phone (width < 640px) { .o-select-form { font-size: var(--vk-font-size-base); } }
82
+
83
+ /* ── Shown open, standing in the page: the list under its field, in the flow, the Picker standing: its held row lit at
84
+ rest by picker.css's standing rule, the one under the pointer by Base UI, in the list's Highlight and its intensity. ─── */
85
+ .o-select-shown { display: grid; gap: calc(var(--vk-spacing) * 1); min-width: 0; }
86
+ .o-select-shown .o-select-list { position: relative; width: auto; max-width: none; max-height: none; }
87
+ /* The list stands over its field's focus glow, as it did before the field stood its smooth layers in a stacking context of its
88
+ own, which lifts the field over what follows it unless that is lifted too. */
89
+
90
+ @media (prefers-reduced-motion: reduce) { .o-select-chevron { transition: none; } }
91
+ }
@@ -19,6 +19,11 @@ import { SWITCH_PRIVATE, SWITCH_TOKENS } from "./switch/tokens.js";
19
19
  import { TAG_PRIVATE, TAG_TOKENS } from "./tag/tokens.js";
20
20
  import { LIST_PRIVATE, LIST_TOKENS } from "./list/tokens.js";
21
21
  import { MENU_LIST_PRIVATE, MENU_LIST_TOKENS } from "./menu-list/tokens.js";
22
+ import { MENU_PRIVATE, MENU_TOKENS } from "./menu/tokens.js";
23
+ import { SELECT_PRIVATE, SELECT_TOKENS } from "./select/tokens.js";
24
+ import { PICKER_PRIVATE, PICKER_TOKENS } from "./picker/tokens.js";
25
+ import { AVATAR_PRIVATE, AVATAR_TOKENS } from "./avatar/tokens.js";
26
+ import { POPUP_LINE_PRIVATE, POPUP_LINE_TOKENS } from "./popup-line/tokens.js";
22
27
  const CONTROLS_OWN = {
23
28
  button: { tokens: BUTTON_TOKENS, private: BUTTON_PRIVATE },
24
29
  spinner: { tokens: SPINNER_TOKENS, private: SPINNER_PRIVATE },
@@ -41,6 +46,11 @@ const CONTROLS_OWN = {
41
46
  switch: { tokens: SWITCH_TOKENS, private: SWITCH_PRIVATE },
42
47
  list: { tokens: LIST_TOKENS, private: LIST_PRIVATE },
43
48
  "menu-list": { tokens: MENU_LIST_TOKENS, private: MENU_LIST_PRIVATE },
49
+ "popup-line": { tokens: POPUP_LINE_TOKENS, private: POPUP_LINE_PRIVATE },
50
+ menu: { tokens: MENU_TOKENS, private: MENU_PRIVATE },
51
+ select: { tokens: SELECT_TOKENS, private: SELECT_PRIVATE },
52
+ picker: { tokens: PICKER_TOKENS, private: PICKER_PRIVATE },
53
+ avatar: { tokens: AVATAR_TOKENS, private: AVATAR_PRIVATE },
44
54
  };
45
55
  export const VK_CONTROL_TOKENS_BY_PIECE = Object.fromEntries(Object.entries(CONTROLS_OWN).map(([piece, own]) => [piece, own.tokens]));
46
56
  export const VK_CONTROL_TOKENS = Object.entries(VK_CONTROL_TOKENS_BY_PIECE)
@@ -23,3 +23,7 @@ export { STATUS_LOOKS, type StatusLookOptionId } from "../controls/status/looks.
23
23
  export { SWITCH_LOOKS, type SwitchLookOptionId } from "../controls/switch/looks.js";
24
24
  export { TAG_LOOKS, type TagLookOptionId } from "../controls/tag/looks.js";
25
25
  export { MENU_LIST_LOOKS, type MenuListLookOptionId } from "../controls/menu-list/looks.js";
26
+ export { LIST_LOOKS, type ListOptionId } from "../controls/list/looks.js";
27
+ export { PICKER_LOOKS, type PickerOptionId } from "../controls/picker/looks.js";
28
+ export { AVATAR_LOOKS, type AvatarLookOptionId } from "../controls/avatar/looks.js";
29
+ export { MENU_LIST_CARD_FRAME } from "../controls/menu-list/looks.js";
@@ -19,3 +19,7 @@ export { STATUS_LOOKS } from "../controls/status/looks.js";
19
19
  export { SWITCH_LOOKS } from "../controls/switch/looks.js";
20
20
  export { TAG_LOOKS } from "../controls/tag/looks.js";
21
21
  export { MENU_LIST_LOOKS } from "../controls/menu-list/looks.js";
22
+ export { LIST_LOOKS } from "../controls/list/looks.js";
23
+ export { PICKER_LOOKS } from "../controls/picker/looks.js";
24
+ export { AVATAR_LOOKS } from "../controls/avatar/looks.js";
25
+ export { MENU_LIST_CARD_FRAME } from "../controls/menu-list/looks.js";
@@ -17,6 +17,9 @@ import { STATUS_LOOKS } from "../controls/status/looks.js";
17
17
  import { SWITCH_LOOKS } from "../controls/switch/looks.js";
18
18
  import { TAG_LOOKS } from "../controls/tag/looks.js";
19
19
  import { MENU_LIST_LOOKS } from "../controls/menu-list/looks.js";
20
+ import { AVATAR_LOOKS } from "../controls/avatar/looks.js";
21
+ import { LIST_LOOKS } from "../controls/list/looks.js";
22
+ import { PICKER_LOOKS } from "../controls/picker/looks.js";
20
23
  export const LOOKS = [
21
24
  GRID_LOOKS,
22
25
  BUTTON_LOOKS,
@@ -37,4 +40,7 @@ export const LOOKS = [
37
40
  STATUS_LOOKS,
38
41
  SWITCH_LOOKS,
39
42
  MENU_LIST_LOOKS,
43
+ LIST_LOOKS,
44
+ PICKER_LOOKS,
45
+ AVATAR_LOOKS,
40
46
  ];