@tangible/ui 0.2.4 → 0.2.5
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/components/ColorPicker/ColorField.d.ts +31 -2
- package/components/ColorPicker/ColorField.js +100 -8
- package/components/Combobox/Combobox.d.ts +1 -1
- package/components/Combobox/Combobox.js +2 -2
- package/components/Combobox/types.d.ts +5 -0
- package/components/Field/Field.d.ts +13 -1
- package/components/Field/Field.js +5 -3
- package/components/GradientPicker/AngleDial.d.ts +14 -0
- package/components/GradientPicker/AngleDial.js +24 -0
- package/components/GradientPicker/GradientBar.d.ts +38 -0
- package/components/GradientPicker/GradientBar.js +130 -0
- package/components/GradientPicker/GradientPicker.d.ts +32 -0
- package/components/GradientPicker/GradientPicker.js +191 -0
- package/components/GradientPicker/index.d.ts +8 -0
- package/components/GradientPicker/index.js +8 -0
- package/components/GradientPicker/labels.d.ts +42 -0
- package/components/GradientPicker/labels.js +31 -0
- package/components/MultiCombobox/MultiCombobox.d.ts +1 -1
- package/components/MultiCombobox/MultiCombobox.js +2 -2
- package/components/MultiCombobox/types.d.ts +5 -0
- package/components/index.d.ts +2 -0
- package/components/index.js +1 -0
- package/package.json +5 -1
- package/styles/all.css +1 -1
- package/styles/all.expanded.css +241 -16
- package/styles/all.expanded.unlayered.css +241 -16
- package/styles/all.unlayered.css +1 -1
- package/styles/components/_bundle.scss +9 -1
- package/styles/components/button.scss +4 -3
- package/styles/components/color-picker.scss +11 -1
- package/styles/components/gradient-picker.scss +296 -0
- package/styles/components/icon-button.scss +15 -8
- package/styles/system/_checkerboard.scss +24 -0
- package/styles/system/index.scss +2 -1
- package/tui-manifest.json +94 -5
- package/utils/color/gradient.d.ts +42 -0
- package/utils/color/gradient.js +408 -0
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useEffect, useId, useRef, useState } from 'react';
|
|
3
|
+
import { cx } from '../../utils/cx.js';
|
|
4
|
+
import { Button } from '../Button/index.js';
|
|
5
|
+
import { IconButton } from '../IconButton/index.js';
|
|
6
|
+
import { Popover } from '../Popover/index.js';
|
|
7
|
+
import { Select } from '../Select/index.js';
|
|
8
|
+
import { TextInput } from '../TextInput/index.js';
|
|
9
|
+
import { Tooltip } from '../Tooltip/index.js';
|
|
10
|
+
import { ColorPicker } from '../ColorPicker/index.js';
|
|
11
|
+
import { parseGradient, formatGradient, reverseStops, colorAtPosition, DEFAULT_GRADIENT, GRADIENT_TYPES, } from '../../utils/color/gradient.js';
|
|
12
|
+
import { GradientBar } from './GradientBar.js';
|
|
13
|
+
import { AngleDial } from './AngleDial.js';
|
|
14
|
+
import { resolveGradientLabels } from './labels.js';
|
|
15
|
+
const round1 = (n) => Math.round(n * 10) / 10;
|
|
16
|
+
const clampN = (n, min, max) => Math.min(max, Math.max(min, n));
|
|
17
|
+
// -----------------------------------------------------------------------------
|
|
18
|
+
// NumberField — a compact labelled numeric input (spinbutton semantics), used
|
|
19
|
+
// for stop positions and the gradient geometry (angle / size / position).
|
|
20
|
+
// -----------------------------------------------------------------------------
|
|
21
|
+
function NumberField({ label, hideLabel, value, min, max, suffix, disabled, onCommit, className, }) {
|
|
22
|
+
const id = useId();
|
|
23
|
+
// A local draft only while typing, so the round-trip through the gradient
|
|
24
|
+
// string doesn't clobber partial input. Cleared on blur → canonical value.
|
|
25
|
+
const [draft, setDraft] = useState(null);
|
|
26
|
+
const display = draft ?? String(round1(value));
|
|
27
|
+
const commit = (raw) => onCommit(clampN(raw, min, max));
|
|
28
|
+
// Live-commit ONLY values already inside [min, max]. Clamping intermediate
|
|
29
|
+
// keystrokes would be destructive with dynamic bounds: typing "6" on the way
|
|
30
|
+
// to "65" between neighbours at 50 and 70 would collapse the stop onto 50.
|
|
31
|
+
// Out-of-range drafts stay drafts until blur, which clamp-commits.
|
|
32
|
+
const commitLive = (raw) => {
|
|
33
|
+
if (raw >= min && raw <= max)
|
|
34
|
+
onCommit(raw);
|
|
35
|
+
};
|
|
36
|
+
return (_jsxs("span", { className: cx('tui-gradient-picker__field', className), children: [!hideLabel && (_jsx("label", { className: "tui-gradient-picker__label", htmlFor: id, children: label })), _jsx(TextInput, { id: id, size: "sm", inputMode: "decimal", autoComplete: "off", spellCheck: false, value: display, suffix: suffix, disabled: disabled, role: "spinbutton", "aria-label": hideLabel ? label : undefined, "aria-valuenow": round1(value), "aria-valuetext": `${round1(value)}${suffix ?? ''}`, "aria-valuemin": min, "aria-valuemax": max, onChange: (e) => {
|
|
37
|
+
const text = e.target.value;
|
|
38
|
+
setDraft(text);
|
|
39
|
+
const num = parseFloat(text);
|
|
40
|
+
if (!Number.isNaN(num))
|
|
41
|
+
commitLive(num);
|
|
42
|
+
}, onBlur: () => {
|
|
43
|
+
if (draft != null) {
|
|
44
|
+
const num = parseFloat(draft);
|
|
45
|
+
if (!Number.isNaN(num))
|
|
46
|
+
commit(num);
|
|
47
|
+
}
|
|
48
|
+
setDraft(null);
|
|
49
|
+
}, onKeyDown: (e) => {
|
|
50
|
+
if (e.key !== 'ArrowUp' && e.key !== 'ArrowDown')
|
|
51
|
+
return;
|
|
52
|
+
e.preventDefault();
|
|
53
|
+
const delta = (e.shiftKey ? 10 : 1) * (e.key === 'ArrowUp' ? 1 : -1);
|
|
54
|
+
const base = parseFloat(draft ?? String(value));
|
|
55
|
+
const num = clampN((Number.isNaN(base) ? 0 : base) + delta, min, max);
|
|
56
|
+
setDraft(String(round1(num)));
|
|
57
|
+
commit(num);
|
|
58
|
+
} })] }));
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Gradient picker: a stop strip with draggable thumbs, an editable CSS value
|
|
62
|
+
* field, a fully accessible colour-stop list (each stop opens a {@link
|
|
63
|
+
* ColorPicker} in a popover), and per-type geometry controls (linear angle +
|
|
64
|
+
* dial, radial size/position, conic position).
|
|
65
|
+
*
|
|
66
|
+
* The value contract is a CSS gradient string — `linear-gradient(…)`,
|
|
67
|
+
* `radial-gradient(…)` or `conic-gradient(…)` — accepted (pasted or typed)
|
|
68
|
+
* and emitted. Stops keep whatever colour strings the ColorPicker accepts,
|
|
69
|
+
* including `var(--x)` references. An unparseable value falls back to a
|
|
70
|
+
* default gradient in the controls; committing any edit replaces it.
|
|
71
|
+
*/
|
|
72
|
+
export function GradientPicker({ value: controlledValue, defaultValue = formatGradient(DEFAULT_GRADIENT), onValueChange, alpha = true, formats, disabled, labels, 'aria-label': ariaLabel, className, ...rest }) {
|
|
73
|
+
const L = resolveGradientLabels(labels);
|
|
74
|
+
const isControlled = useRef(controlledValue !== undefined).current;
|
|
75
|
+
const [uncontrolledValue, setUncontrolledValue] = useState(defaultValue);
|
|
76
|
+
const value = isControlled ? controlledValue ?? '' : uncontrolledValue;
|
|
77
|
+
const parsed = parseGradient(value);
|
|
78
|
+
const gradient = parsed.kind === 'gradient' ? parsed.gradient : DEFAULT_GRADIENT;
|
|
79
|
+
const { stops } = gradient;
|
|
80
|
+
// Which stop's colour editor popover is open (also the bar's highlight).
|
|
81
|
+
const [openStop, setOpenStop] = useState(null);
|
|
82
|
+
// Focus recovery for row removals: the focused remove button unmounts, so
|
|
83
|
+
// focus the surviving neighbour's remove button (or the add button when the
|
|
84
|
+
// remaining rows can't be removed).
|
|
85
|
+
// HTMLElement because Button/IconButton forward a button/anchor union ref.
|
|
86
|
+
const removeRefs = useRef([]);
|
|
87
|
+
const addRef = useRef(null);
|
|
88
|
+
const pendingRowFocus = useRef(null);
|
|
89
|
+
const prevStopCount = useRef(stops.length);
|
|
90
|
+
useEffect(() => {
|
|
91
|
+
// Consume only on an actual decrease — a controlled parent may drop the
|
|
92
|
+
// update, and a stale ref must not steal focus on a later stop-add.
|
|
93
|
+
const decreased = stops.length < prevStopCount.current;
|
|
94
|
+
prevStopCount.current = stops.length;
|
|
95
|
+
const target = pendingRowFocus.current;
|
|
96
|
+
pendingRowFocus.current = null;
|
|
97
|
+
if (!decreased || target == null)
|
|
98
|
+
return;
|
|
99
|
+
const index = Math.min(target, stops.length - 1);
|
|
100
|
+
const button = removeRefs.current[index];
|
|
101
|
+
if (button instanceof HTMLButtonElement && !button.disabled)
|
|
102
|
+
button.focus();
|
|
103
|
+
else
|
|
104
|
+
addRef.current?.focus();
|
|
105
|
+
}, [stops.length]);
|
|
106
|
+
const commit = useCallback((next) => {
|
|
107
|
+
const nextValue = formatGradient(next);
|
|
108
|
+
if (!isControlled)
|
|
109
|
+
setUncontrolledValue(nextValue);
|
|
110
|
+
onValueChange?.(nextValue);
|
|
111
|
+
}, [isControlled, onValueChange]);
|
|
112
|
+
const patch = (partial) => commit({ ...gradient, ...partial });
|
|
113
|
+
// Stops stay sorted by position at all times (indices are stable for the
|
|
114
|
+
// bar, the list, and assistive tech). Dragging clamps at the neighbours
|
|
115
|
+
// instead of crossing them.
|
|
116
|
+
const clampStopPosition = (index, position) => clampN(position, stops[index - 1]?.position ?? 0, stops[index + 1]?.position ?? 100);
|
|
117
|
+
const updateStop = (index, partial) => patch({ stops: stops.map((s, i) => (i === index ? { ...s, ...partial } : s)) });
|
|
118
|
+
const moveStop = (index, position) => updateStop(index, { position: round1(clampStopPosition(index, position)) });
|
|
119
|
+
/** Insert a stop at `position` (default: the middle of the largest gap). */
|
|
120
|
+
const addStop = (position) => {
|
|
121
|
+
let at = position;
|
|
122
|
+
if (at == null) {
|
|
123
|
+
let gapStart = 0;
|
|
124
|
+
let gapSize = -1;
|
|
125
|
+
for (let i = 0; i <= stops.length; i++) {
|
|
126
|
+
const from = i === 0 ? 0 : stops[i - 1].position;
|
|
127
|
+
const to = i === stops.length ? 100 : stops[i].position;
|
|
128
|
+
if (to - from > gapSize) {
|
|
129
|
+
gapSize = to - from;
|
|
130
|
+
gapStart = from;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
at = gapStart + gapSize / 2;
|
|
134
|
+
}
|
|
135
|
+
at = round1(clampN(at, 0, 100));
|
|
136
|
+
const stop = { color: colorAtPosition(stops, at), position: at };
|
|
137
|
+
const index = stops.findIndex((s) => s.position > at);
|
|
138
|
+
const insertAt = index === -1 ? stops.length : index;
|
|
139
|
+
patch({ stops: [...stops.slice(0, insertAt), stop, ...stops.slice(insertAt)] });
|
|
140
|
+
setOpenStop(null);
|
|
141
|
+
};
|
|
142
|
+
const removeStop = (index, recoverFocus = false) => {
|
|
143
|
+
if (stops.length <= 2)
|
|
144
|
+
return;
|
|
145
|
+
if (recoverFocus)
|
|
146
|
+
pendingRowFocus.current = index > 0 ? index - 1 : 0;
|
|
147
|
+
if (openStop != null && openStop >= index)
|
|
148
|
+
setOpenStop(null);
|
|
149
|
+
patch({ stops: stops.filter((_, i) => i !== index) });
|
|
150
|
+
};
|
|
151
|
+
// Editable value field: local draft, parsed on commit, reverted if invalid.
|
|
152
|
+
const [draft, setDraft] = useState(null);
|
|
153
|
+
const emitted = formatGradient(gradient);
|
|
154
|
+
const fieldText = draft ?? emitted;
|
|
155
|
+
const commitText = () => {
|
|
156
|
+
if (draft == null)
|
|
157
|
+
return;
|
|
158
|
+
const p = parseGradient(draft.trim());
|
|
159
|
+
if (p.kind === 'gradient')
|
|
160
|
+
commit(p.gradient);
|
|
161
|
+
// invalid → revert (drop the draft)
|
|
162
|
+
setDraft(null);
|
|
163
|
+
};
|
|
164
|
+
// Transient "Copied" confirmation (tooltip label + SR live announcement).
|
|
165
|
+
const [copied, setCopied] = useState(false);
|
|
166
|
+
const copyTimer = useRef(null);
|
|
167
|
+
useEffect(() => () => void (copyTimer.current && clearTimeout(copyTimer.current)), []);
|
|
168
|
+
const handleCopy = () => {
|
|
169
|
+
navigator.clipboard?.writeText(emitted);
|
|
170
|
+
setCopied(true);
|
|
171
|
+
if (copyTimer.current)
|
|
172
|
+
clearTimeout(copyTimer.current);
|
|
173
|
+
copyTimer.current = setTimeout(() => setCopied(false), 1200);
|
|
174
|
+
};
|
|
175
|
+
const typeLabelId = useId();
|
|
176
|
+
return (_jsxs("div", { className: cx('tui-gradient-picker', disabled && 'is-disabled', className), role: "group", "aria-label": ariaLabel ?? L.group, ...rest, children: [_jsx(GradientBar, { stops: stops, activeIndex: openStop, onStopPositionChange: moveStop, onStopAdd: (position) => addStop(position), onStopRemove: (index) => removeStop(index), onStopActivate: (index) => setOpenStop(index), labels: { stop: L.stop, stopValueText: L.stopValueText }, disabled: disabled, "aria-label": L.bar }), _jsxs("div", { className: "tui-gradient-picker__value", children: [_jsx("input", { className: "tui-gradient-picker__value-input", type: "text", autoComplete: "off", spellCheck: false, value: fieldText, onChange: (e) => setDraft(e.target.value), onBlur: commitText, onKeyDown: (e) => {
|
|
177
|
+
if (e.key === 'Enter')
|
|
178
|
+
commitText();
|
|
179
|
+
}, "aria-label": L.value, disabled: disabled }), _jsxs(Tooltip, { children: [_jsx(Tooltip.Trigger, { asChild: true, children: _jsx(IconButton, { icon: "system/reverse", label: L.reverse, variant: "ghost", size: "sm", disabled: disabled, onClick: () => {
|
|
180
|
+
// An open editor's index would silently point at the mirrored
|
|
181
|
+
// stop after the reorder — close it instead.
|
|
182
|
+
setOpenStop(null);
|
|
183
|
+
patch({ stops: reverseStops(stops) });
|
|
184
|
+
} }) }), _jsx(Tooltip.Content, { children: L.reverse })] }), _jsxs(Tooltip, { children: [_jsx(Tooltip.Trigger, { asChild: true, children: _jsx(IconButton, { icon: "system/copy", label: L.copy, variant: "ghost", size: "sm", disabled: disabled, onClick: handleCopy }) }), _jsx(Tooltip.Content, { children: copied ? L.copied : L.copy })] })] }), _jsxs("div", { className: "tui-gradient-picker__stops", children: [_jsx("span", { className: "tui-gradient-picker__label", children: L.stopsHeading }), stops.map((stop, i) => (_jsxs("div", { className: "tui-gradient-picker__stop", children: [_jsxs(Popover, { open: openStop === i, onOpenChange: (open) => setOpenStop(open ? i : null), children: [_jsx(Popover.Trigger, { asChild: true, children: _jsx("button", { type: "button", className: "tui-gradient-picker__swatch", "aria-label": L.editStop(i + 1), disabled: disabled, children: _jsx("span", { className: "tui-gradient-picker__swatch-fill", "aria-hidden": "true", style: { '--_swatch': stop.color } }) }) }), _jsx(Popover.Content, { side: "bottom", align: "start", modal: true, "aria-label": L.editStop(i + 1), className: "tui-gradient-picker__stop-popover", children: _jsx(ColorPicker, { value: stop.color, onValueChange: (color) => updateStop(i, { color }), alpha: alpha, formats: formats }) })] }), _jsx(NumberField, { label: L.stopPosition(i + 1), hideLabel: true, value: stop.position, min: stops[i - 1]?.position ?? 0, max: stops[i + 1]?.position ?? 100, suffix: "%", disabled: disabled, onCommit: (position) => updateStop(i, { position: round1(position) }), className: "tui-gradient-picker__stop-position" }), _jsx(IconButton, { ref: (el) => {
|
|
185
|
+
removeRefs.current[i] = el;
|
|
186
|
+
}, icon: "system/trash", label: L.removeStop(i + 1), variant: "ghost", theme: "danger", size: "sm", disabled: disabled || stops.length <= 2, onClick: () => removeStop(i, true) })] }, i))), _jsx(Button, { ref: (el) => {
|
|
187
|
+
addRef.current = el;
|
|
188
|
+
}, variant: "outline", size: "sm", disabled: disabled, onClick: () => addStop(), className: "tui-gradient-picker__add", children: L.addStop })] }), _jsxs("div", { className: cx('tui-gradient-picker__geometry', gradient.type === 'linear' && 'is-linear'), children: [_jsxs("span", { className: "tui-gradient-picker__field tui-gradient-picker__type-field", children: [_jsx("span", { className: "tui-gradient-picker__label", id: typeLabelId, children: L.type }), _jsxs(Select, { value: gradient.type, onValueChange: (t) => patch({ type: t }), disabled: disabled, size: "sm", "aria-labelledby": typeLabelId, children: [_jsx(Select.Trigger, { className: "tui-gradient-picker__type" }), _jsx(Select.Content, { children: GRADIENT_TYPES.map((t) => (_jsx(Select.Option, { value: t, children: L.types[t] }, t))) })] })] }), gradient.type === 'linear' && (_jsxs("span", { className: "tui-gradient-picker__angle", children: [_jsx(NumberField, { label: L.angle, value: gradient.angle, min: 0, max: 360, suffix: "\u00B0", disabled: disabled,
|
|
189
|
+
// mod 360 so a committed 360 doesn't flip to 0 on blur.
|
|
190
|
+
onCommit: (angle) => patch({ angle: round1(angle) % 360 }) }), _jsx(AngleDial, { angle: gradient.angle, onAngleChange: (angle) => patch({ angle }), disabled: disabled })] })), gradient.type === 'radial' && (_jsxs(_Fragment, { children: [_jsx(NumberField, { label: L.sizeX, value: gradient.sizeX, min: 0, max: 1000, suffix: "%", disabled: disabled, onCommit: (sizeX) => patch({ sizeX: round1(sizeX) }) }), _jsx(NumberField, { label: L.sizeY, value: gradient.sizeY, min: 0, max: 1000, suffix: "%", disabled: disabled, onCommit: (sizeY) => patch({ sizeY: round1(sizeY) }) })] })), (gradient.type === 'radial' || gradient.type === 'conic') && (_jsxs(_Fragment, { children: [_jsx(NumberField, { label: L.posX, value: gradient.posX, min: 0, max: 100, suffix: "%", disabled: disabled, onCommit: (posX) => patch({ posX: round1(posX) }) }), _jsx(NumberField, { label: L.posY, value: gradient.posY, min: 0, max: 100, suffix: "%", disabled: disabled, onCommit: (posY) => patch({ posY: round1(posY) }) })] }))] }), _jsx("span", { className: "tui-visually-hidden", role: "status", "aria-live": "polite", children: copied ? L.copied : '' })] }));
|
|
191
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { GradientPicker } from './GradientPicker';
|
|
2
|
+
export type { GradientPickerProps } from './GradientPicker';
|
|
3
|
+
export { GradientBar } from './GradientBar';
|
|
4
|
+
export type { GradientBarProps, GradientBarLabels } from './GradientBar';
|
|
5
|
+
export { defaultGradientPickerLabels } from './labels';
|
|
6
|
+
export type { GradientPickerLabels } from './labels';
|
|
7
|
+
export { parseGradient, formatGradient, formatStops, reverseStops, colorAtPosition, DEFAULT_GRADIENT, GRADIENT_TYPES, } from '../../utils/color/gradient';
|
|
8
|
+
export type { Gradient, GradientType, GradientStop, ParsedGradient, } from '../../utils/color/gradient';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { GradientPicker } from './GradientPicker.js';
|
|
2
|
+
export { GradientBar } from './GradientBar.js';
|
|
3
|
+
// AngleDial is deliberately NOT exported: it is aria-hidden and pointer-only
|
|
4
|
+
// by design — usable only beside an accessible input editing the same value,
|
|
5
|
+
// which GradientPicker provides. Standalone use would ship an inaccessible
|
|
6
|
+
// control.
|
|
7
|
+
export { defaultGradientPickerLabels } from './labels.js';
|
|
8
|
+
export { parseGradient, formatGradient, formatStops, reverseStops, colorAtPosition, DEFAULT_GRADIENT, GRADIENT_TYPES, } from '../../utils/color/gradient.js';
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { GradientType } from '../../utils/color/gradient';
|
|
2
|
+
export type GradientPickerLabels = {
|
|
3
|
+
/** Accessible name for the whole picker group. */
|
|
4
|
+
group?: string;
|
|
5
|
+
/** Accessible name for the stop strip. */
|
|
6
|
+
bar?: string;
|
|
7
|
+
/** Accessible name for a stop thumb on the strip. */
|
|
8
|
+
stop?: (index: number, total: number, color: string) => string;
|
|
9
|
+
/** Value text for a stop thumb's position. */
|
|
10
|
+
stopValueText?: (percent: number) => string;
|
|
11
|
+
/** Accessible name for the gradient value text field. */
|
|
12
|
+
value?: string;
|
|
13
|
+
/** Copy button label + idle tooltip. */
|
|
14
|
+
copy?: string;
|
|
15
|
+
/** Tooltip + SR announcement shown briefly after a successful copy. */
|
|
16
|
+
copied?: string;
|
|
17
|
+
/** Reverse button label + tooltip. */
|
|
18
|
+
reverse?: string;
|
|
19
|
+
/** Visible heading of the stop list. */
|
|
20
|
+
stopsHeading?: string;
|
|
21
|
+
/** The add-stop button's text. */
|
|
22
|
+
addStop?: string;
|
|
23
|
+
/** Accessible name for a stop row's swatch (opens the colour editor). */
|
|
24
|
+
editStop?: (index: number) => string;
|
|
25
|
+
/** Accessible name for a stop row's position input. */
|
|
26
|
+
stopPosition?: (index: number) => string;
|
|
27
|
+
/** Accessible name for a stop row's remove button. */
|
|
28
|
+
removeStop?: (index: number) => string;
|
|
29
|
+
/** Visible label of the gradient type selector. */
|
|
30
|
+
type?: string;
|
|
31
|
+
/** Display names per gradient type. */
|
|
32
|
+
types?: Partial<Record<GradientType, string>>;
|
|
33
|
+
/** Visible labels of the geometry fields. */
|
|
34
|
+
angle?: string;
|
|
35
|
+
sizeX?: string;
|
|
36
|
+
sizeY?: string;
|
|
37
|
+
posX?: string;
|
|
38
|
+
posY?: string;
|
|
39
|
+
};
|
|
40
|
+
export declare const defaultGradientPickerLabels: Required<GradientPickerLabels>;
|
|
41
|
+
/** Merge consumer overrides over the defaults (shallow, plus the nested map). */
|
|
42
|
+
export declare function resolveGradientLabels(labels?: GradientPickerLabels): Required<GradientPickerLabels>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export const defaultGradientPickerLabels = {
|
|
2
|
+
group: 'Gradient picker',
|
|
3
|
+
bar: 'Gradient stops',
|
|
4
|
+
stop: (index, total, color) => `Color stop ${index + 1} of ${total}: ${color}`,
|
|
5
|
+
stopValueText: (percent) => `${percent}%`,
|
|
6
|
+
value: 'Gradient value',
|
|
7
|
+
copy: 'Copy gradient value',
|
|
8
|
+
copied: 'Copied',
|
|
9
|
+
reverse: 'Reverse gradient',
|
|
10
|
+
stopsHeading: 'Color stops',
|
|
11
|
+
addStop: 'Add color stop',
|
|
12
|
+
editStop: (index) => `Edit color stop ${index}`,
|
|
13
|
+
stopPosition: (index) => `Position of color stop ${index}`,
|
|
14
|
+
removeStop: (index) => `Remove color stop ${index}`,
|
|
15
|
+
type: 'Type',
|
|
16
|
+
types: { linear: 'Linear', radial: 'Radial', conic: 'Conic' },
|
|
17
|
+
angle: 'Angle',
|
|
18
|
+
sizeX: 'Shape size X',
|
|
19
|
+
sizeY: 'Shape size Y',
|
|
20
|
+
posX: 'Shape position X',
|
|
21
|
+
posY: 'Shape position Y',
|
|
22
|
+
};
|
|
23
|
+
/** Merge consumer overrides over the defaults (shallow, plus the nested map). */
|
|
24
|
+
export function resolveGradientLabels(labels) {
|
|
25
|
+
const d = defaultGradientPickerLabels;
|
|
26
|
+
return {
|
|
27
|
+
...d,
|
|
28
|
+
...labels,
|
|
29
|
+
types: { ...d.types, ...labels?.types },
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { MultiComboboxProps, MultiComboboxContentProps, MultiComboboxOptionProps, MultiComboboxGroupProps, MultiComboboxLabelProps } from './types';
|
|
2
|
-
declare function MultiComboboxRoot({ value: controlledValue, defaultValue, onValueChange, inputValue: controlledInputValue, onInputChange, open: controlledOpen, defaultOpen, onOpenChange, disabled, placeholder, size, overflow, openOnFocus, filterMode, onQueryChange, max, onMaxReached, clearable, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, 'aria-describedby': ariaDescribedBy, 'aria-invalid': ariaInvalid, 'aria-required': ariaRequired, inputClassName, labels: labelsProp, children, }: MultiComboboxProps): import("react/jsx-runtime").JSX.Element;
|
|
2
|
+
declare function MultiComboboxRoot({ value: controlledValue, defaultValue, onValueChange, inputValue: controlledInputValue, onInputChange, open: controlledOpen, defaultOpen, onOpenChange, disabled, placeholder, size, overflow, openOnFocus, filterMode, onQueryChange, max, onMaxReached, clearable, 'aria-label': ariaLabel, id: inputIdProp, 'aria-labelledby': ariaLabelledBy, 'aria-describedby': ariaDescribedBy, 'aria-invalid': ariaInvalid, 'aria-required': ariaRequired, inputClassName, labels: labelsProp, children, }: MultiComboboxProps): import("react/jsx-runtime").JSX.Element;
|
|
3
3
|
declare namespace MultiComboboxRoot {
|
|
4
4
|
var displayName: string;
|
|
5
5
|
}
|
|
@@ -17,7 +17,7 @@ const EMPTY_VALUE = [];
|
|
|
17
17
|
// =============================================================================
|
|
18
18
|
// MultiCombobox Root
|
|
19
19
|
// =============================================================================
|
|
20
|
-
function MultiComboboxRoot({ value: controlledValue, defaultValue, onValueChange, inputValue: controlledInputValue, onInputChange, open: controlledOpen, defaultOpen, onOpenChange, disabled = false, placeholder = '', size = 'md', overflow = 'trim', openOnFocus = true, filterMode = 'always', onQueryChange, max, onMaxReached, clearable = true, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, 'aria-describedby': ariaDescribedBy, 'aria-invalid': ariaInvalid, 'aria-required': ariaRequired, inputClassName, labels: labelsProp, children, }) {
|
|
20
|
+
function MultiComboboxRoot({ value: controlledValue, defaultValue, onValueChange, inputValue: controlledInputValue, onInputChange, open: controlledOpen, defaultOpen, onOpenChange, disabled = false, placeholder = '', size = 'md', overflow = 'trim', openOnFocus = true, filterMode = 'always', onQueryChange, max, onMaxReached, clearable = true, 'aria-label': ariaLabel, id: inputIdProp, 'aria-labelledby': ariaLabelledBy, 'aria-describedby': ariaDescribedBy, 'aria-invalid': ariaInvalid, 'aria-required': ariaRequired, inputClassName, labels: labelsProp, children, }) {
|
|
21
21
|
const labels = { ...defaultMultiComboboxLabels, ...labelsProp };
|
|
22
22
|
// Controlled/uncontrolled value (initialize from defaultValue)
|
|
23
23
|
const [uncontrolledValue, setUncontrolledValue] = useState(defaultValue ?? []);
|
|
@@ -58,7 +58,7 @@ function MultiComboboxRoot({ value: controlledValue, defaultValue, onValueChange
|
|
|
58
58
|
openRef.current = open;
|
|
59
59
|
// IDs
|
|
60
60
|
const baseId = useId();
|
|
61
|
-
const inputId = `${baseId}-input`;
|
|
61
|
+
const inputId = inputIdProp ?? `${baseId}-input`;
|
|
62
62
|
const listboxId = `${baseId}-listbox`;
|
|
63
63
|
// Refs
|
|
64
64
|
const inputRef = useRef(null);
|
|
@@ -110,6 +110,11 @@ export type MultiComboboxProps = {
|
|
|
110
110
|
* Callback when max selections is reached.
|
|
111
111
|
*/
|
|
112
112
|
onMaxReached?: () => void;
|
|
113
|
+
/**
|
|
114
|
+
* Optional input ID override, applied to the inner `<input>`.
|
|
115
|
+
* Useful for Field integration via htmlFor — Field.Control injects this.
|
|
116
|
+
*/
|
|
117
|
+
id?: string;
|
|
113
118
|
/**
|
|
114
119
|
* Accessible name for the combobox.
|
|
115
120
|
*/
|
package/components/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export { Chip } from './Chip';
|
|
|
10
10
|
export { ChipGroup } from './ChipGroup';
|
|
11
11
|
export { Chips } from './Chips';
|
|
12
12
|
export { ColorPicker, ColorField, ColorArea, ColorSlider, defaultColorPickerLabels } from './ColorPicker';
|
|
13
|
+
export { GradientPicker, GradientBar, defaultGradientPickerLabels } from './GradientPicker';
|
|
13
14
|
export { ContentIndicator } from './ContentIndicator';
|
|
14
15
|
export { Calendar, DatePicker, DateRangePicker, defaultDateRangePresets, defaultCalendarLabels, defaultDatePickerLabels, defaultDateRangePickerLabels, } from './DatePicker';
|
|
15
16
|
export { Combobox, ComboboxContent, ComboboxOption, ComboboxGroup, ComboboxLabel, useCombobox } from './Combobox';
|
|
@@ -52,6 +53,7 @@ export type { ChipGroupProps, ChipGroupSingleProps, ChipGroupMultipleProps } fro
|
|
|
52
53
|
export type { ChipsProps, ChipOption } from './Chips';
|
|
53
54
|
export type { ColorPickerProps, ColorPickerLabels, ColorFieldProps, ColorFieldLabels, ColorAreaProps, ColorSliderProps } from './ColorPicker';
|
|
54
55
|
export type { ColorFormat, Hsva as ColorHsva } from './ColorPicker';
|
|
56
|
+
export type { GradientPickerProps, GradientPickerLabels, GradientBarProps, GradientBarLabels, Gradient, GradientType, GradientStop, } from './GradientPicker';
|
|
55
57
|
export type { ContentIndicatorProps } from './ContentIndicator';
|
|
56
58
|
export type { DropdownProps, DropdownTriggerProps, DropdownContentProps, DropdownItemProps, DropdownSeparatorProps, DropdownHeaderProps, } from './Dropdown';
|
|
57
59
|
export type { ComboboxProps, ComboboxContentProps, ComboboxOptionProps, ComboboxGroupProps, ComboboxLabelProps, ComboboxRegisteredOption, } from './Combobox';
|
package/components/index.js
CHANGED
|
@@ -8,6 +8,7 @@ export { Chip } from './Chip/index.js';
|
|
|
8
8
|
export { ChipGroup } from './ChipGroup/index.js';
|
|
9
9
|
export { Chips } from './Chips/index.js';
|
|
10
10
|
export { ColorPicker, ColorField, ColorArea, ColorSlider, defaultColorPickerLabels } from './ColorPicker/index.js';
|
|
11
|
+
export { GradientPicker, GradientBar, defaultGradientPickerLabels } from './GradientPicker/index.js';
|
|
11
12
|
export { ContentIndicator } from './ContentIndicator/index.js';
|
|
12
13
|
export { Calendar, DatePicker, DateRangePicker, defaultDateRangePresets, defaultCalendarLabels, defaultDatePickerLabels, defaultDateRangePickerLabels, } from './DatePicker/index.js';
|
|
13
14
|
export { Combobox, ComboboxContent, ComboboxOption, ComboboxGroup, ComboboxLabel, useCombobox } from './Combobox/index.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tangible/ui",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
4
4
|
"description": "Tangible Design System",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./components/index.js",
|
|
@@ -104,6 +104,10 @@
|
|
|
104
104
|
"import": "./components/Field/index.js",
|
|
105
105
|
"types": "./components/Field/index.d.ts"
|
|
106
106
|
},
|
|
107
|
+
"./components/GradientPicker": {
|
|
108
|
+
"import": "./components/GradientPicker/index.js",
|
|
109
|
+
"types": "./components/GradientPicker/index.d.ts"
|
|
110
|
+
},
|
|
107
111
|
"./components/Icon": {
|
|
108
112
|
"import": "./components/Icon/index.js",
|
|
109
113
|
"types": "./components/Icon/index.d.ts"
|