viewkitjs 0.26.0 → 0.27.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 (94) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/MIGRATION.md +84 -6
  3. package/package.json +1 -1
  4. package/views/dist/contract.d.ts +171 -1
  5. package/views/dist/contract.js +162 -0
  6. package/views/dist/controls/compound-editor/map-parts-body.js +2 -1
  7. package/views/dist/controls/compound-editor/name-parts.js +10 -2
  8. package/views/dist/controls/compound-editor/place.d.ts +2 -1
  9. package/views/dist/controls/compound-editor/place.js +2 -0
  10. package/views/dist/controls/controls.d.ts +8 -0
  11. package/views/dist/controls/controls.js +8 -0
  12. package/views/dist/controls/index.d.ts +16 -0
  13. package/views/dist/controls/index.js +16 -0
  14. package/views/dist/controls/internal/editor-parts.d.ts +40 -0
  15. package/views/dist/controls/internal/editor-parts.js +43 -0
  16. package/views/dist/controls/links-editor/links-editor.d.ts +78 -0
  17. package/views/dist/controls/links-editor/links-editor.js +308 -0
  18. package/views/dist/controls/links-editor/links.d.ts +62 -0
  19. package/views/dist/controls/links-editor/links.js +50 -0
  20. package/views/dist/controls/links-editor/map-links-body.d.ts +10 -0
  21. package/views/dist/controls/links-editor/map-links-body.js +71 -0
  22. package/views/dist/controls/links-editor/tokens.d.ts +71 -0
  23. package/views/dist/controls/links-editor/tokens.js +20 -0
  24. package/views/dist/controls/links-editor/words.d.ts +56 -0
  25. package/views/dist/controls/links-editor/words.js +33 -0
  26. package/views/dist/controls/links-editor.css +132 -0
  27. package/views/dist/controls/number-editor/format.d.ts +31 -0
  28. package/views/dist/controls/number-editor/format.js +79 -0
  29. package/views/dist/controls/number-editor/looks.d.ts +14 -0
  30. package/views/dist/controls/number-editor/looks.js +17 -0
  31. package/views/dist/controls/number-editor/map-number-body.d.ts +16 -0
  32. package/views/dist/controls/number-editor/map-number-body.js +57 -0
  33. package/views/dist/controls/number-editor/number-editor.d.ts +72 -0
  34. package/views/dist/controls/number-editor/number-editor.js +202 -0
  35. package/views/dist/controls/number-editor/tokens.d.ts +28 -0
  36. package/views/dist/controls/number-editor/tokens.js +9 -0
  37. package/views/dist/controls/number-editor/words.d.ts +23 -0
  38. package/views/dist/controls/number-editor/words.js +13 -0
  39. package/views/dist/controls/number-editor.css +37 -0
  40. package/views/dist/controls/number-field/number-field.js +57 -5
  41. package/views/dist/controls/radio/radio.d.ts +33 -0
  42. package/views/dist/controls/radio/radio.js +19 -0
  43. package/views/dist/controls/radio/tokens.d.ts +127 -0
  44. package/views/dist/controls/radio/tokens.js +34 -0
  45. package/views/dist/controls/radio.css +104 -0
  46. package/views/dist/controls/text-editor/phone-number.d.ts +4 -0
  47. package/views/dist/controls/text-editor/phone-number.js +20 -0
  48. package/views/dist/controls/text-editor/text-editor.js +2 -19
  49. package/views/dist/controls/tokens.js +10 -0
  50. package/views/dist/controls/values-editor/looks.d.ts +16 -0
  51. package/views/dist/controls/values-editor/looks.js +19 -0
  52. package/views/dist/controls/values-editor/map-values-body.d.ts +12 -0
  53. package/views/dist/controls/values-editor/map-values-body.js +71 -0
  54. package/views/dist/controls/values-editor/tokens.d.ts +132 -0
  55. package/views/dist/controls/values-editor/tokens.js +35 -0
  56. package/views/dist/controls/values-editor/values-editor.d.ts +62 -0
  57. package/views/dist/controls/values-editor/values-editor.js +435 -0
  58. package/views/dist/controls/values-editor/values.d.ts +71 -0
  59. package/views/dist/controls/values-editor/values.js +59 -0
  60. package/views/dist/controls/values-editor/words.d.ts +50 -0
  61. package/views/dist/controls/values-editor/words.js +29 -0
  62. package/views/dist/controls/values-editor.css +207 -0
  63. package/views/dist/controls/views-list/looks.d.ts +13 -0
  64. package/views/dist/controls/views-list/looks.js +12 -0
  65. package/views/dist/controls/views-list/map-views-list-body.d.ts +19 -0
  66. package/views/dist/controls/views-list/map-views-list-body.js +65 -0
  67. package/views/dist/controls/views-list/rules.d.ts +72 -0
  68. package/views/dist/controls/views-list/rules.js +4 -0
  69. package/views/dist/controls/views-list/tokens.d.ts +11 -0
  70. package/views/dist/controls/views-list/tokens.js +5 -0
  71. package/views/dist/controls/views-list/views-list.d.ts +44 -0
  72. package/views/dist/controls/views-list/views-list.js +57 -0
  73. package/views/dist/controls/views-list/words.d.ts +22 -0
  74. package/views/dist/controls/views-list/words.js +3 -0
  75. package/views/dist/controls/views-list.css +8 -0
  76. package/views/dist/editors/NumberEditor.js +3 -1
  77. package/views/dist/grid/chrome/GridCellEditors.js +1 -1
  78. package/views/dist/grid/chrome/GridDateEditor.d.ts +3 -1
  79. package/views/dist/grid/chrome/GridDateEditor.js +2 -1
  80. package/views/dist/looks/index.d.ts +3 -0
  81. package/views/dist/looks/index.js +3 -0
  82. package/views/dist/looks/pieces.js +6 -0
  83. package/views/dist/provider/components.d.ts +4 -0
  84. package/views/dist/styles.css +432 -2
  85. package/views/dist/styles.unlayered.css +432 -2
  86. package/views/docs/contract.md +10 -8
  87. package/views/docs/controls/links-editor.md +25 -0
  88. package/views/docs/controls/number-editor.md +12 -0
  89. package/views/docs/controls/radio.md +39 -0
  90. package/views/docs/controls/values-editor.md +40 -0
  91. package/views/docs/controls/views-list.md +8 -0
  92. package/views/docs/reference/controls.md +117 -5
  93. package/views/docs/reference/looks.md +9 -2
  94. package/views/docs/reference/react.md +2 -2
@@ -0,0 +1,202 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import * as React from "react";
4
+ import { Button } from "../button/button.js";
5
+ import { InputGroupButton } from "../input/input.js";
6
+ import { PhoneHost, phoneMark, usePhone, usePhoneForm } from "../internal/phone.js";
7
+ import { NumberField } from "../number-field/number-field.js";
8
+ import { Picker, usePicker } from "../picker/picker.js";
9
+ import { Popover } from "../popover/popover.js";
10
+ import { SheetButton } from "../sheet/bottom-sheet.js";
11
+ import { boxLocale, readTyped } from "./format.js";
12
+ import { NUMBER_EDITOR_ATTRS, numberEditorWornOf } from "./looks.js";
13
+ import { numberWords } from "./words.js";
14
+ const glyph = (paths, className) => (_jsx("svg", { className: className, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: paths.map((d) => _jsx("path", { d: d }, d)) }));
15
+ const X = ["M18 6l-12 12", "M6 6l12 12"], TICK = ["M5 12l5 5l10 -10"], DOWN = ["M6 9l6 6l6 -6"];
16
+ const ATTIO = numberEditorWornOf(null);
17
+ export function useNumberEditorWorn() {
18
+ const [el, setEl] = React.useState(null), [worn, setWorn] = React.useState(ATTIO);
19
+ React.useLayoutEffect(() => {
20
+ if (!el)
21
+ return;
22
+ const read = () => setWorn((now) => { const next = numberEditorWornOf(el); return Object.keys(next).every((k) => now[k] === next[k]) ? now : next; });
23
+ read();
24
+ const watch = new MutationObserver(read);
25
+ watch.observe(document.documentElement, { attributes: true, subtree: true, attributeFilter: NUMBER_EDITOR_ATTRS });
26
+ return () => watch.disconnect();
27
+ }, [el]);
28
+ return [setEl, worn];
29
+ }
30
+ const bare = (decimals) => ({ useGrouping: false, maximumFractionDigits: decimals });
31
+ const setText = typeof HTMLInputElement === "undefined" ? undefined : Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value")?.set;
32
+ function useKeeping({ form, autoFocus = true }) {
33
+ const host = React.useContext(PhoneHost), small = usePhone();
34
+ const focusOnce = React.useRef(autoFocus), latest = React.useRef(null);
35
+ const box = React.useCallback((el) => {
36
+ if (!el)
37
+ return;
38
+ const asked = !!latest.current;
39
+ latest.current = el;
40
+ if (focusOnce.current && !asked)
41
+ requestAnimationFrame(() => {
42
+ if (!focusOnce.current)
43
+ return;
44
+ focusOnce.current = false;
45
+ if (latest.current?.isConnected)
46
+ latest.current.focus({ preventScroll: true });
47
+ });
48
+ }, []);
49
+ return { phone: (form ?? (host || small ? "phone" : "computer")) === "phone", box };
50
+ }
51
+ function homeOrEnd(e) {
52
+ if ((e.key !== "Home" && e.key !== "End") || e.altKey || e.ctrlKey || e.metaKey)
53
+ return false;
54
+ e.preventBaseUIHandler?.();
55
+ return true;
56
+ }
57
+ export function useNumberEditor(props) {
58
+ const { label, kind = "number", value, currency, currencies = [], unit, units = [], onValueChange, onDone, min, max, step = 1, decimals = 2, locale, decimal, align = "end", typed, popupData } = props;
59
+ const shell = props.draft === "shell";
60
+ const { phone, box } = useKeeping(props);
61
+ const settled = React.useRef(false);
62
+ const [wornAt, worn] = useNumberEditorWorn();
63
+ const money = kind === "money";
64
+ const list = money ? currencies : kind === "number" ? units : [], held = money ? currency : kind === "number" ? unit : undefined;
65
+ const [draft, setDraft] = React.useState(value), [ownCode, setCode] = React.useState(held);
66
+ const code = shell ? held : ownCode;
67
+ const [choosing, setChoosing] = React.useState(false), [chip, setChip] = React.useState(null);
68
+ const input = React.useRef(null);
69
+ const pickable = list.length > 1;
70
+ const now = list.find((c) => c.code === code) ?? list[0];
71
+ const w = numberWords(props.words);
72
+ const words = money ? { name: w.currency, find: w.findCurrency, search: w.searchCurrency } : { name: w.unit, find: w.findUnit, search: w.searchUnit };
73
+ const named = now ? w.named(words.name, now.name) : undefined;
74
+ const steps = { increase: w.increase, decrease: w.decrease, field: w.numberField };
75
+ const device = phoneMark(usePhoneForm());
76
+ const keep = () => {
77
+ settled.current = true;
78
+ if (draft !== value || code !== held)
79
+ onValueChange(draft, money || list.length ? code : undefined);
80
+ onDone?.();
81
+ };
82
+ const leave = () => { settled.current = true; setDraft(value); setCode(held); onDone?.(); };
83
+ const pick = (c) => { if (shell)
84
+ onValueChange(value, c);
85
+ else
86
+ setCode(c); };
87
+ const was = React.useRef({ value, currency: held });
88
+ React.useLayoutEffect(() => { was.current = { value, currency: held }; });
89
+ const placeRoot = React.useCallback((el) => { wornAt(el); if (!el) {
90
+ setDraft(was.current.value);
91
+ setCode(was.current.currency);
92
+ setChoosing(false);
93
+ settled.current = false;
94
+ } }, [wornAt, setDraft, setCode, setChoosing]);
95
+ const items = list.map((c) => ({ value: c.code, label: c.name, ...(c.sign ? { as: { sign: c.sign } } : {}) }));
96
+ const back = () => { setChoosing(false); requestAnimationFrame(() => input.current?.focus({ preventScroll: true })); };
97
+ const picker = usePicker({ label: words.name, items, value: code ?? null, onValueChange: (c) => { if (typeof c === "string")
98
+ pick(c); }, onDone: back, search: phone ? words.search : words.find, form: phone ? "phone" : "computer", fromHeld: true, ...(w.picker ? { words: w.picker } : {}) });
99
+ const onKeyDown = (e) => {
100
+ if (homeOrEnd(e))
101
+ return;
102
+ if (e.nativeEvent.isComposing)
103
+ return;
104
+ if (shell) {
105
+ if (e.key === "Enter") {
106
+ e.preventDefault();
107
+ onDone?.();
108
+ }
109
+ return;
110
+ }
111
+ if (e.key === "Escape") {
112
+ e.preventDefault();
113
+ leave();
114
+ }
115
+ else if (e.key === "Enter") {
116
+ e.preventDefault();
117
+ input.current?.blur();
118
+ }
119
+ };
120
+ const readChange = shell ? (e) => {
121
+ const el = input.current, t = el?.value ?? "";
122
+ if (!el || e.target !== el || !t.trim() || (/\p{Nd}/u.test(t) && /[^\x00-\x7f\s\u00a0\u202f\u2212\u2012-\u2015]/.test(t)))
123
+ return;
124
+ onValueChange(readTyped(t, decimal));
125
+ } : undefined;
126
+ const seeded = React.useRef(false), opening = React.useRef({ shell, typed });
127
+ const refs = React.useCallback((el) => {
128
+ input.current = el;
129
+ box(el);
130
+ if (!el || !opening.current.shell)
131
+ return;
132
+ const t = opening.current.typed;
133
+ if (t != null && !seeded.current && setText) {
134
+ seeded.current = true;
135
+ queueMicrotask(() => { const now = input.current; if (!now?.isConnected)
136
+ return; setText.call(now, t); now.dispatchEvent(new Event("input", { bubbles: true })); });
137
+ }
138
+ }, [box]);
139
+ const field = React.useCallback((el) => refs(inputOf(el)), [refs]);
140
+ const format = React.useMemo(() => bare(decimals), [decimals]);
141
+ const shared = {
142
+ value: shell ? (value == null || Number.isNaN(value) ? null : value) : draft,
143
+ onValueChange: (v, d) => { if (!shell)
144
+ setDraft(v);
145
+ else if (d?.reason !== "input-blur")
146
+ onValueChange(v); },
147
+ min, max, step, largeStep: step * 10, format, locale: boxLocale(locale, decimal),
148
+ onFocus: shell ? (e) => { const t = e.currentTarget, n = t.value.length; try {
149
+ t.setSelectionRange(n, n);
150
+ }
151
+ catch { } } : undefined,
152
+ };
153
+ if (phone) {
154
+ const codes = worn.units === "code", choose = () => setChoosing(true);
155
+ const enter = (e) => { if (homeOrEnd(e))
156
+ return; if (e.key === "Enter" && !e.nativeEvent.isComposing) {
157
+ e.preventDefault();
158
+ if (shell)
159
+ onDone?.();
160
+ else
161
+ keep();
162
+ } };
163
+ const sign = now?.sign ?? now?.code;
164
+ const fieldStart = now ? (pickable
165
+ ? _jsx(InputGroupButton, { "aria-label": named, iconEnd: glyph(DOWN), onClick: choose, children: codes || !now.sign ? now.code : `${now.sign} ${now.code}` })
166
+ : codes ? _jsx("span", { className: "o-number-editor-code", children: now.code }) : _jsx("span", { className: "o-number-editor-sign", children: sign })) : undefined;
167
+ const boxStart = now ? (pickable
168
+ ? _jsx(Button, { kind: "quiet", size: "sm", className: "o-number-editor-code", look: SHEET_CODE, "aria-label": named, iconEnd: glyph(DOWN), onClick: choose, children: codes || !now.sign ? now.code : `${now.sign} ${now.code}` })
169
+ : _jsx("span", { className: codes ? "o-number-editor-code" : "o-number-editor-sign", children: codes ? now.code : sign })) : undefined;
170
+ const amount = worn.sheet === "field"
171
+ ? _jsx(PhoneField, { ...shared, words: steps, label: label, before: fieldStart, after: kind === "percent" ? "%" : undefined, onKeyDown: enter, box: refs })
172
+ : _jsx(NumberField, { ref: field, size: "lg", steppers: false, words: steps, className: "o-number-editor-sheet", before: boxStart, after: kind === "percent" ? _jsx("span", { className: "o-number-editor-unit", children: "%" }) : undefined, ...shared, "aria-label": label, autofill: false, onKeyDown: enter });
173
+ const body = (_jsx("div", { ref: placeRoot, className: "o-number-editor", "data-kit": "number-editor", ...device, "data-number-form": "phone", onChange: readChange, "data-number-kind": kind, "data-number-step": choosing ? "currency" : undefined, children: choosing ? picker.body : amount }));
174
+ if (choosing)
175
+ return { body, head: { onBack: () => setChoosing(false), close: false }, title: words.name };
176
+ if (shell)
177
+ return { body, head: {} };
178
+ return { body, head: { left: _jsx(SheetButton, { "aria-label": "Close", icon: glyph(X), onClick: leave }), right: _jsx(SheetButton, { kind: "primary", "aria-label": "Save", icon: glyph(TICK), onClick: keep }) } };
179
+ }
180
+ const onBlur = (e) => {
181
+ if (shell || settled.current || choosing || (e.relatedTarget instanceof Node && e.currentTarget.contains(e.relatedTarget)))
182
+ return;
183
+ keep();
184
+ };
185
+ const start = !now ? null : worn.units === "code"
186
+ ? (pickable ? _jsx(Button, { ref: setChip, kind: "quiet", size: "xs", className: "o-number-editor-code", "aria-label": named, "aria-expanded": choosing, iconEnd: glyph(DOWN), onClick: () => setChoosing(true), children: now.code }) : null)
187
+ : (pickable ? _jsx(Button, { ref: setChip, kind: "soft", size: "2xs", className: "o-number-editor-currency", "aria-label": named, iconEnd: glyph(DOWN), onClick: () => setChoosing(true), children: now.sign ?? now.code })
188
+ : _jsx("span", { className: "o-number-editor-sign", children: now.sign ?? now.code }));
189
+ const body = (_jsxs("div", { ref: wornAt, className: "o-number-editor", "data-kit": "number-editor", ...device, "data-number-form": "computer", "data-number-kind": kind, onChange: readChange, onBlur: onBlur, onFocus: () => { settled.current = false; }, children: [_jsx(NumberField, { ref: field, chrome: "inline", align: align, words: steps, steppers: worn.arrows === "editing" ? "arrows" : false, before: start ?? undefined, after: kind === "percent" ? _jsx("span", { className: "o-number-editor-unit", children: "%" }) : undefined, ...shared, "aria-label": label, autofill: false, onKeyDown: onKeyDown, className: "o-number-editor-field" }), pickable && chip && (_jsx(Popover, { open: choosing, onOpenChange: (o) => { if (!o)
190
+ back(); }, anchor: chip, "aria-label": words.name, popupData: popupData, children: _jsx(Picker, { label: words.name, items: items, value: code ?? null, onValueChange: (c) => { if (typeof c === "string")
191
+ pick(c); }, onDone: back, search: words.find, form: "computer", fromHeld: true, ...(w.picker ? { words: w.picker } : {}) }) }))] }));
192
+ return { body, head: {} };
193
+ }
194
+ const SHEET_CODE = { radius: "lg" };
195
+ const inputOf = (el) => el?.querySelector("input.o-input-control") ?? null;
196
+ function PhoneField({ label, before, after, onKeyDown, box, ...field }) {
197
+ const root = React.useCallback((el) => box(inputOf(el)), [box]);
198
+ return _jsx(NumberField, { ref: root, size: "lg", steppers: false, "aria-label": label, before: before, after: after, autofill: false, onKeyDown: onKeyDown, ...field });
199
+ }
200
+ export function NumberEditor(props) {
201
+ return _jsx(_Fragment, { children: useNumberEditor(props).body });
202
+ }
@@ -0,0 +1,28 @@
1
+ export declare const NUMBER_EDITOR_TOKENS: readonly [{
2
+ readonly name: "--vk-border-width";
3
+ readonly kind: "size";
4
+ readonly outright: "--border-width";
5
+ }, {
6
+ readonly name: "--vk-fg";
7
+ readonly kind: "colour";
8
+ readonly outright: "--text";
9
+ }, {
10
+ readonly name: "--vk-fg-subtle";
11
+ readonly kind: "colour";
12
+ readonly outright: "--text-subtle";
13
+ }, {
14
+ readonly name: "--vk-font-size-base";
15
+ readonly kind: "size";
16
+ readonly outright: "--text-base";
17
+ }, {
18
+ readonly name: "--vk-font-size-sm";
19
+ readonly kind: "size";
20
+ readonly outright: "--text-sm";
21
+ }, {
22
+ readonly name: "--vk-spacing";
23
+ readonly kind: "size";
24
+ readonly outright: "--spacing";
25
+ }];
26
+ /** The prefixes of the Number editor's own machinery, set and read by it alone: not public. It reads none yet; the family is
27
+ * reserved for it. */
28
+ export declare const NUMBER_EDITOR_PRIVATE: readonly ["--number-editor-"];
@@ -0,0 +1,9 @@
1
+ export const NUMBER_EDITOR_TOKENS = [
2
+ { name: "--vk-border-width", kind: "size", outright: "--border-width" },
3
+ { name: "--vk-fg", kind: "colour", outright: "--text" },
4
+ { name: "--vk-fg-subtle", kind: "colour", outright: "--text-subtle" },
5
+ { name: "--vk-font-size-base", kind: "size", outright: "--text-base" },
6
+ { name: "--vk-font-size-sm", kind: "size", outright: "--text-sm" },
7
+ { name: "--vk-spacing", kind: "size", outright: "--spacing" },
8
+ ];
9
+ export const NUMBER_EDITOR_PRIVATE = ["--number-editor-"];
@@ -0,0 +1,23 @@
1
+ import type { PickerWords } from "../picker/picker.js";
2
+ export interface NumberEditorWords {
3
+ /** Money's currencies: the list's name, its title as a phone's step, and the code button's name before the currency's. */
4
+ currency: string;
5
+ /** A number's units, the same. */
6
+ unit: string;
7
+ /** The lists' searches: on a computer (find) and on a phone (search). */
8
+ findCurrency: string;
9
+ searchCurrency: string;
10
+ findUnit: string;
11
+ searchUnit: string;
12
+ /** The code button's name: the list's name and the currency's or the unit's ("Currency: Euro"). */
13
+ named: (unit: string, name: string) => string;
14
+ /** The number field's two steps, and what a screen reader calls it. */
15
+ increase: string;
16
+ decrease: string;
17
+ numberField: string;
18
+ /** The words of its lists. */
19
+ picker?: Partial<PickerWords>;
20
+ }
21
+ export declare const NUMBER_EDITOR_WORDS: NumberEditorWords;
22
+ /** The words handed over the English. */
23
+ export declare const numberWords: (given?: Partial<NumberEditorWords>) => NumberEditorWords;
@@ -0,0 +1,13 @@
1
+ export const NUMBER_EDITOR_WORDS = {
2
+ currency: "Currency",
3
+ unit: "Unit",
4
+ findCurrency: "Find a currency",
5
+ searchCurrency: "Search for a currency",
6
+ findUnit: "Find a unit",
7
+ searchUnit: "Search for a unit",
8
+ named: (unit, name) => `${unit}: ${name}`,
9
+ increase: "Increase",
10
+ decrease: "Decrease",
11
+ numberField: "Number field",
12
+ };
13
+ export const numberWords = (given) => (given ? { ...NUMBER_EDITOR_WORDS, ...given } : NUMBER_EDITOR_WORDS);
@@ -0,0 +1,37 @@
1
+ /* The Number editor: what a person types a number into, with its unit. Every value is a public name (number-editor/tokens.ts).
2
+ Two looks (looks.ts), their options data attributes on the frame around it: Attio's where nothing is picked, Mihai's under
3
+ its options; its box, line or ring, is the inline input's. On a computer a number fills its cell, the number on the right,
4
+ money's currency at its start, a percent's % after it: in Attio's look a line of the focus colour standing over the cell, as
5
+ the Text editor's does, its up and down arrows at its end; in Mihai's the cell's ring. Its box is the number field inline, and
6
+ on a phone the number field in its quiet box, its own look, or in the Input's look (number-field.css). A range is the
7
+ Compound editor's.
8
+
9
+ The rules sit in the components layer, so a utility class still wins. */
10
+ @layer components {
11
+
12
+ /* ── A number in its cell: Attio's line of the focus colour, Mihai's ring: the kit's Number field in a cell, filling it ── */
13
+ .o-number-editor[data-number-form="computer"] { box-sizing: border-box; width: 100%; height: 100%; min-width: 0; color: var(--vk-fg); }
14
+ .o-number-editor .o-number-editor-field, .o-number-editor .o-number-editor-field > .o-inline-input-group { height: 100%; }
15
+ /* Where a shell stands it: over its cell, the cell's lines under its edge, as Attio's editor stands; in the ring, the cell. */
16
+ .o-number-editor-place { position: absolute; inset: calc(var(--vk-border-width) * -1) 0 calc(var(--vk-border-width) * -1) calc(var(--vk-border-width) * -1); }
17
+ [data-inline-input-edge="ring"] .o-number-editor-place { inset: 0; }
18
+
19
+ /* Money's currency at the box's start, a press away; a field with one currency, its sign alone. A percent's % after it. */
20
+ .o-number-editor-currency { flex: none; margin-right: auto; }
21
+ /* Attio's: the code, a quiet press away from the currencies, or the code alone where nothing can be pressed. */
22
+ .o-number-editor-code { flex: none; margin-right: auto; }
23
+ span.o-number-editor-code { color: var(--vk-fg-subtle); }
24
+ .o-number-editor-sign, .o-number-editor-unit { flex: none; color: var(--vk-fg-subtle); }
25
+ .o-number-editor[data-number-form="computer"] .o-number-editor-sign { margin-right: auto; }
26
+
27
+ /* ── On a phone: the box and what is under it ───────────────────────────────────────────────────────────────────── */
28
+ .o-number-editor[data-number-form="phone"] { display: grid; gap: calc(var(--vk-spacing) * 2); }
29
+
30
+ }
31
+
32
+ /* ── On the phone every box typed into is 16px, so iOS never zooms in: the in-cell box by itself, and the field form's the
33
+ Input's. What stands beside the value (money's code, sign and currency, a percent's %) is the value's size there, Mihai's
34
+ currency chip a step under, as it stands a step under the value on a computer. In the phone's form (`data-vk-phone`, by the
35
+ app's line). ── */
36
+ .o-number-editor :is(.o-number-editor-code, .o-number-editor-sign, .o-number-editor-unit, .o-input-addon > .o-button):where([data-vk-phone], [data-vk-phone] *) { font-size: var(--vk-font-size-base); }
37
+ .o-number-editor .o-input-addon > .o-button.o-number-editor-currency:where([data-vk-phone], [data-vk-phone] *) { font-size: var(--vk-font-size-sm); }
@@ -17,19 +17,71 @@ function pageKeys(e, on) {
17
17
  e.currentTarget.dispatchEvent(new KeyboardEvent("keydown", { key: e.key === "PageUp" ? "ArrowUp" : "ArrowDown", shiftKey: true, bubbles: true, cancelable: true }));
18
18
  }
19
19
  const UP_MARK = _jsx("svg", { viewBox: "0 0 8 5", "aria-hidden": "true", children: _jsx("path", { d: "M0 5h8l-4-5z" }) }), DOWN_MARK = _jsx("svg", { viewBox: "0 0 8 5", "aria-hidden": "true", children: _jsx("path", { d: "M0 0h8l-4 5z" }) });
20
+ const TYPED = new Set(["input-change", "input-clear"]);
21
+ function useTypedRun(hold, inputRef) {
22
+ const typing = React.useRef(false), focused = React.useRef(false), pending = React.useRef(null);
23
+ const node = React.useRef(null), write = React.useRef(null);
24
+ const flush = React.useCallback(() => {
25
+ typing.current = false;
26
+ const v = pending.current;
27
+ pending.current = null;
28
+ if (v != null)
29
+ write.current?.(v);
30
+ }, []);
31
+ const formInput = React.useCallback((el) => {
32
+ if (typeof inputRef === "function")
33
+ inputRef(el);
34
+ else if (inputRef)
35
+ inputRef.current = el;
36
+ if (el === node.current)
37
+ return;
38
+ node.current = el;
39
+ write.current = null;
40
+ pending.current = null;
41
+ if (!el)
42
+ return;
43
+ const own = Object.getOwnPropertyDescriptor(el, "value") ?? Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value");
44
+ write.current = (v) => own.set.call(el, v);
45
+ own.set.call(el, own.get.call(el));
46
+ Object.defineProperty(el, "value", {
47
+ configurable: true,
48
+ get() { return own.get.call(this); },
49
+ set(v) { if (typing.current) {
50
+ pending.current = String(v);
51
+ return;
52
+ } pending.current = null; own.set.call(this, v); },
53
+ });
54
+ }, [inputRef]);
55
+ const seen = (reason) => { if (!hold)
56
+ return; if (TYPED.has(reason) && focused.current)
57
+ typing.current = true;
58
+ else
59
+ flush(); };
60
+ const focus = () => { focused.current = true; };
61
+ const leave = () => { focused.current = false; flush(); };
62
+ const enter = (e) => { if (e.key === "Enter" && !e.nativeEvent.isComposing)
63
+ flush(); };
64
+ return { formInput, seen, focus, leave, enter };
65
+ }
20
66
  const DRAG = _jsx("svg", { viewBox: "0 0 24 24", "aria-hidden": "true", children: _jsx("path", { d: "M8 7l-5 5l5 5M16 7l5 5l-5 5M3 12h18" }) });
21
- export const NumberField = React.forwardRef(function NumberField({ size = "md", before, after, steppers, align = "start", scrub = false, placeholder, "aria-label": label, "aria-labelledby": labelledBy, "aria-describedby": describedBy, onKeyDown, onFocus, onBlur, autoFocus, autofill = true, look, chrome, className, style, disabled, readOnly, words, ...root }, ref) {
67
+ export const NumberField = React.forwardRef(function NumberField({ size = "md", before, after, steppers, align = "start", scrub = false, placeholder, "aria-label": label, "aria-labelledby": labelledBy, "aria-describedby": describedBy, onKeyDown, onFocus, onBlur, autoFocus, autofill = true, look, chrome, className, style, disabled, readOnly, words, value, onValueChange, inputRef, ...root }, ref) {
22
68
  const fill = useAutofill(), phone = usePhoneForm();
69
+ const typed = useTypedRun(root.name == null, inputRef);
70
+ const values = {
71
+ ...(value !== undefined ? { value } : {}),
72
+ onValueChange: ((next, details) => { typed.seen(details.reason); onValueChange?.(next, details); }),
73
+ inputRef: typed.formInput,
74
+ };
23
75
  const arrows = steppers === "arrows" && !readOnly;
24
76
  const stepped = steppers !== "arrows" && (steppers ?? (size !== "2xs" && size !== "xs" && !readOnly && chrome !== "inline"));
25
77
  const side = (where, what) => what == null ? null : scrub
26
78
  ? _jsxs(BaseNumberField.ScrubArea, { className: "o-number-scrub", render: (props) => _jsx(InputGroupAddon, { side: where, ...props, children: props.children }), children: [what, _jsx(BaseNumberField.ScrubAreaCursor, { className: "o-number-cursor", children: DRAG })] }, where)
27
79
  : _jsx(InputGroupAddon, { side: where, children: what }, where);
28
- const input = (_jsx(BaseNumberField.Input, { className: cx("o-input-control o-input-num", align === "end" && "o-number-end"), ...fill(autofill), placeholder: placeholder, "aria-label": label, "aria-labelledby": labelledBy, "aria-describedby": describedBy, autoFocus: autoFocus, ...(words?.field ? { "aria-roledescription": words.field } : {}), onKeyDown: (e) => { onKeyDown?.(e); if (!e.defaultPrevented)
29
- pageKeys(e, !disabled && !readOnly); }, onFocus: onFocus, onBlur: onBlur }));
80
+ const input = (_jsx(BaseNumberField.Input, { className: cx("o-input-control o-input-num", align === "end" && "o-number-end"), ...fill(autofill), placeholder: placeholder, "aria-label": label, "aria-labelledby": labelledBy, "aria-describedby": describedBy, autoFocus: autoFocus, ...(words?.field ? { "aria-roledescription": words.field } : {}), onKeyDown: (e) => { typed.enter(e); onKeyDown?.(e); if (!e.defaultPrevented)
81
+ pageKeys(e, !disabled && !readOnly); }, onFocus: (e) => { typed.focus(); onFocus?.(e); }, onBlur: (e) => { typed.leave(); onBlur?.(e); } }));
30
82
  if (chrome === "bare")
31
- return (_jsx(BaseNumberField.Root, { ref: ref, className: cx("o-number o-number-bare", className), style: style, disabled: disabled, readOnly: readOnly, "data-kit": "number-field", ...phoneMark(phone), ...root, children: input }));
32
- return (_jsx(BaseNumberField.Root, { ref: ref, className: cx("o-number", className), style: style, disabled: disabled, readOnly: readOnly, "data-kit": "number-field", ...phoneMark(phone), ...root, children: _jsxs(BaseNumberField.Group, { render: (props) => chrome === "inline"
83
+ return (_jsx(BaseNumberField.Root, { ref: ref, className: cx("o-number o-number-bare", className), style: style, disabled: disabled, readOnly: readOnly, "data-kit": "number-field", ...phoneMark(phone), ...root, ...values, children: input }));
84
+ return (_jsx(BaseNumberField.Root, { ref: ref, className: cx("o-number", className), style: style, disabled: disabled, readOnly: readOnly, "data-kit": "number-field", ...phoneMark(phone), ...root, ...values, children: _jsxs(BaseNumberField.Group, { render: (props) => chrome === "inline"
33
85
  ? _jsx(InlineInputGroup, { ...props, children: props.children })
34
86
  : _jsx(InputGroup, { size: size, look: look, chrome: chrome === "soft" ? "soft" : undefined, ...props, children: props.children }), children: [side("start", before), input, side("end", after), stepped && (_jsxs(InputGroupAddon, { side: "end", className: "o-number-steps", children: [_jsx(BaseNumberField.Decrement, { ...(words?.decrease ? { "aria-label": words.decrease } : {}), render: _jsx(InputGroupButton, { icon: _jsx(Mark, { paths: MINUS }) }) }), _jsx(BaseNumberField.Increment, { ...(words?.increase ? { "aria-label": words.increase } : {}), render: _jsx(InputGroupButton, { icon: _jsx(Mark, { paths: PLUS }) }) })] })), arrows && (_jsxs(InputGroupAddon, { side: "end", className: "o-number-arrows", children: [_jsx(BaseNumberField.Increment, { className: "o-number-arrow", "aria-label": words?.increase ?? "Increase", children: UP_MARK }), _jsx(BaseNumberField.Decrement, { className: "o-number-arrow", "aria-label": words?.decrease ?? "Decrease", children: DOWN_MARK })] }))] }) }));
35
87
  });
@@ -0,0 +1,33 @@
1
+ import * as React from "react";
2
+ import { Radio as BaseRadio } from "@base-ui/react/radio";
3
+ import { RadioGroup as BaseRadioGroup } from "@base-ui/react/radio-group";
4
+ export interface RadioGroupProps extends Omit<React.ComponentProps<typeof BaseRadioGroup>, "className"> {
5
+ /** The group's name, above its choices ("Who can see this deal"). Without one, give it an aria-label. */
6
+ label?: React.ReactNode;
7
+ /** Two to four short choices side by side, instead of one under another. Marked cards stand two across, and one under
8
+ * another on a phone. */
9
+ row?: boolean;
10
+ /** Its marked cards as tiles: three across, each its mark over its name, centred; on a phone on one card (Customize's
11
+ * Layout). */
12
+ tiles?: boolean;
13
+ className?: string;
14
+ children: React.ReactNode;
15
+ }
16
+ /** Exactly one of a few choices, all of them in sight: its name, then its Radios. With a name, the group is a
17
+ * FieldSet, its name the legend (Base UI names the radio group by it). */
18
+ export declare function RadioGroup({ label, row, tiles, className, children, ...props }: RadioGroupProps): import("react/jsx-runtime").JSX.Element;
19
+ export interface RadioProps extends Omit<React.ComponentProps<typeof BaseRadio.Root>, "className"> {
20
+ /** The choice. Without one, give it an aria-label. */
21
+ label?: React.ReactNode;
22
+ /** A line under the label that explains it, or says why it is locked. */
23
+ note?: React.ReactNode;
24
+ /** Drawn as a card: an edge round the ring and its words, the whole card pressing it, the chosen one in
25
+ * the selected colours. For a few choices that each need their line read (a pipeline's start). */
26
+ card?: boolean;
27
+ /** A mark in place of the ring (a layout's icon): a card, the mark over its name and its line, the chosen one ringed in
28
+ * the brand. Disabled, it stands dashed and greyed, with no line, and the arrows pass it by. */
29
+ mark?: React.ReactNode;
30
+ className?: string;
31
+ }
32
+ /** One choice of a RadioGroup: a ring that fills with the brand and a dot when it is the one chosen. */
33
+ export declare const Radio: React.ForwardRefExoticComponent<Omit<RadioProps, "ref"> & React.RefAttributes<HTMLElement>>;
@@ -0,0 +1,19 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import * as React from "react";
4
+ import { Radio as BaseRadio } from "@base-ui/react/radio";
5
+ import { RadioGroup as BaseRadioGroup } from "@base-ui/react/radio-group";
6
+ import { cx } from "../../internal/cx.js";
7
+ import { FieldSet } from "../field/field.js";
8
+ import { phoneMark, usePhoneForm } from "../internal/phone.js";
9
+ export function RadioGroup({ label, row = false, tiles = false, className, children, ...props }) {
10
+ const phone = usePhoneForm();
11
+ const group = (_jsx(BaseRadioGroup, { className: cx("o-radio-group", row && "o-radio-row", tiles && "o-radio-tiles", label == null && className), ...phoneMark(phone), ...props, children: children }));
12
+ return label != null ? _jsx(FieldSet, { legend: label, disabled: props.disabled, className: className, children: group }) : group;
13
+ }
14
+ export const Radio = React.forwardRef(function Radio({ label, note, card = false, mark, className, ...props }, ref) {
15
+ const marked = mark != null;
16
+ return (_jsxs("label", { className: cx("o-radio", (card || marked) && "o-choice-card", marked && "o-radio-marked", className), "data-kit": "radio", children: [marked
17
+ ? _jsx(BaseRadio.Root, { ref: ref, className: "o-radio-mark", ...props, children: mark })
18
+ : _jsx(BaseRadio.Root, { ref: ref, className: "o-radio-ring", ...props, children: _jsx(BaseRadio.Indicator, { keepMounted: true, className: "o-radio-dot" }) }), (label != null || note != null) && (_jsxs("span", { className: "o-choice-text", children: [label != null && _jsx("span", { className: "o-choice-label", children: label }), note != null && _jsx("span", { className: "o-choice-note", children: note })] }))] }));
19
+ });
@@ -0,0 +1,127 @@
1
+ export declare const RADIO_TOKENS: readonly [{
2
+ readonly name: "--vk-border-brand";
3
+ readonly kind: "colour";
4
+ readonly outright: "--border-focused";
5
+ }, {
6
+ readonly name: "--vk-border-danger";
7
+ readonly kind: "colour";
8
+ readonly outright: "--border-danger";
9
+ }, {
10
+ readonly name: "--vk-border-input";
11
+ readonly kind: "colour";
12
+ readonly outright: "--border-input";
13
+ }, {
14
+ readonly name: "--vk-border-input-hovered";
15
+ readonly kind: "colour";
16
+ readonly outright: "--border-input-hovered";
17
+ }, {
18
+ readonly name: "--vk-border-selected";
19
+ readonly kind: "colour";
20
+ readonly outright: "--border-selected";
21
+ }, {
22
+ readonly name: "--vk-border-subtle";
23
+ readonly kind: "colour";
24
+ readonly outright: "--border-subtle";
25
+ }, {
26
+ readonly name: "--vk-border-width";
27
+ readonly kind: "size";
28
+ readonly outright: "--border-width";
29
+ }, {
30
+ readonly name: "--vk-brand";
31
+ readonly kind: "colour";
32
+ readonly outright: "--background-brand-bold";
33
+ }, {
34
+ readonly name: "--vk-brand-hovered";
35
+ readonly kind: "colour";
36
+ readonly outright: "--background-brand-bold-hovered";
37
+ }, {
38
+ readonly name: "--vk-danger-bold";
39
+ readonly kind: "colour";
40
+ readonly outright: "--background-danger-bold";
41
+ }, {
42
+ readonly name: "--vk-danger-bold-hovered";
43
+ readonly kind: "colour";
44
+ readonly outright: "--background-danger-bold-hovered";
45
+ }, {
46
+ readonly name: "--vk-duration-base";
47
+ readonly kind: "motion";
48
+ readonly outright: "--duration-base";
49
+ }, {
50
+ readonly name: "--vk-duration-fast";
51
+ readonly kind: "motion";
52
+ readonly outright: "--duration-fast";
53
+ }, {
54
+ readonly name: "--vk-ease-out";
55
+ readonly kind: "motion";
56
+ readonly outright: "--ease-out";
57
+ }, {
58
+ readonly name: "--vk-fg-accent";
59
+ readonly kind: "colour";
60
+ readonly outright: "--text-brand";
61
+ }, {
62
+ readonly name: "--vk-fg-disabled";
63
+ readonly kind: "colour";
64
+ readonly outright: "--text-disabled";
65
+ }, {
66
+ readonly name: "--vk-fg-inverse";
67
+ readonly kind: "colour";
68
+ readonly outright: "--text-inverse";
69
+ }, {
70
+ readonly name: "--vk-fg-on-brand";
71
+ readonly kind: "colour";
72
+ readonly outright: "--text-brand-inverse";
73
+ }, {
74
+ readonly name: "--vk-fg-subtle";
75
+ readonly kind: "colour";
76
+ readonly outright: "--text-subtle";
77
+ }, {
78
+ readonly name: "--vk-focus-offset";
79
+ readonly kind: "size";
80
+ readonly outright: "--focus-offset";
81
+ }, {
82
+ readonly name: "--vk-focus-width";
83
+ readonly kind: "size";
84
+ readonly outright: "--focus-width";
85
+ }, {
86
+ readonly name: "--vk-font-weight-normal";
87
+ readonly kind: "size";
88
+ readonly outright: "--font-weight-normal";
89
+ }, {
90
+ readonly name: "--vk-ground";
91
+ readonly kind: "colour";
92
+ readonly outright: "--surface";
93
+ }, {
94
+ readonly name: "--vk-hovered";
95
+ readonly kind: "colour";
96
+ readonly outright: "--surface-hovered";
97
+ }, {
98
+ readonly name: "--vk-input";
99
+ readonly kind: "colour";
100
+ readonly outright: "--background-input";
101
+ }, {
102
+ readonly name: "--vk-neutral";
103
+ readonly kind: "colour";
104
+ readonly outright: "--background-neutral";
105
+ }, {
106
+ readonly name: "--vk-overlay-card";
107
+ readonly kind: "colour";
108
+ readonly outright: "--surface-overlay-card";
109
+ }, {
110
+ readonly name: "--vk-radius-full";
111
+ readonly kind: "size";
112
+ readonly outright: "--radius-full";
113
+ }, {
114
+ readonly name: "--vk-radius-lg";
115
+ readonly kind: "size";
116
+ readonly outright: "--radius-lg";
117
+ }, {
118
+ readonly name: "--vk-radius-xl";
119
+ readonly kind: "size";
120
+ readonly outright: "--radius-xl";
121
+ }, {
122
+ readonly name: "--vk-spacing";
123
+ readonly kind: "size";
124
+ readonly outright: "--spacing";
125
+ }];
126
+ /** The Radio has no machinery of its own. */
127
+ export declare const RADIO_PRIVATE: readonly [];
@@ -0,0 +1,34 @@
1
+ export const RADIO_TOKENS = [
2
+ { name: "--vk-border-brand", kind: "colour", outright: "--border-focused" },
3
+ { name: "--vk-border-danger", kind: "colour", outright: "--border-danger" },
4
+ { name: "--vk-border-input", kind: "colour", outright: "--border-input" },
5
+ { name: "--vk-border-input-hovered", kind: "colour", outright: "--border-input-hovered" },
6
+ { name: "--vk-border-selected", kind: "colour", outright: "--border-selected" },
7
+ { name: "--vk-border-subtle", kind: "colour", outright: "--border-subtle" },
8
+ { name: "--vk-border-width", kind: "size", outright: "--border-width" },
9
+ { name: "--vk-brand", kind: "colour", outright: "--background-brand-bold" },
10
+ { name: "--vk-brand-hovered", kind: "colour", outright: "--background-brand-bold-hovered" },
11
+ { name: "--vk-danger-bold", kind: "colour", outright: "--background-danger-bold" },
12
+ { name: "--vk-danger-bold-hovered", kind: "colour", outright: "--background-danger-bold-hovered" },
13
+ { name: "--vk-duration-base", kind: "motion", outright: "--duration-base" },
14
+ { name: "--vk-duration-fast", kind: "motion", outright: "--duration-fast" },
15
+ { name: "--vk-ease-out", kind: "motion", outright: "--ease-out" },
16
+ { name: "--vk-fg-accent", kind: "colour", outright: "--text-brand" },
17
+ { name: "--vk-fg-disabled", kind: "colour", outright: "--text-disabled" },
18
+ { name: "--vk-fg-inverse", kind: "colour", outright: "--text-inverse" },
19
+ { name: "--vk-fg-on-brand", kind: "colour", outright: "--text-brand-inverse" },
20
+ { name: "--vk-fg-subtle", kind: "colour", outright: "--text-subtle" },
21
+ { name: "--vk-focus-offset", kind: "size", outright: "--focus-offset" },
22
+ { name: "--vk-focus-width", kind: "size", outright: "--focus-width" },
23
+ { name: "--vk-font-weight-normal", kind: "size", outright: "--font-weight-normal" },
24
+ { name: "--vk-ground", kind: "colour", outright: "--surface" },
25
+ { name: "--vk-hovered", kind: "colour", outright: "--surface-hovered" },
26
+ { name: "--vk-input", kind: "colour", outright: "--background-input" },
27
+ { name: "--vk-neutral", kind: "colour", outright: "--background-neutral" },
28
+ { name: "--vk-overlay-card", kind: "colour", outright: "--surface-overlay-card" },
29
+ { name: "--vk-radius-full", kind: "size", outright: "--radius-full" },
30
+ { name: "--vk-radius-lg", kind: "size", outright: "--radius-lg" },
31
+ { name: "--vk-radius-xl", kind: "size", outright: "--radius-xl" },
32
+ { name: "--vk-spacing", kind: "size", outright: "--spacing" },
33
+ ];
34
+ export const RADIO_PRIVATE = [];