@tangible/ui 0.2.6 → 0.2.8
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.js +33 -10
- package/components/MultiCombobox/MultiCombobox.js +4 -3
- package/components/MultiSelect/MultiSelect.js +4 -3
- package/components/Tabs/Tabs.js +16 -1
- package/package.json +1 -1
- package/styles/all.css +1 -1
- package/styles/all.expanded.css +64 -36
- package/styles/all.expanded.unlayered.css +64 -36
- package/styles/all.unlayered.css +1 -1
- package/styles/components/combobox.scss +29 -6
- package/styles/components/date-picker.scss +9 -3
- package/styles/components/multi-combobox.scss +18 -3
- package/styles/components/multi-select.scss +28 -9
- package/styles/components/notice.scss +28 -7
- package/styles/components/segmented-control.scss +10 -5
- package/styles/components/select.scss +16 -7
- package/styles/components/sidebar.scss +31 -22
- package/styles/components/tabs.scss +26 -15
- package/tui-manifest.json +3 -2
- package/utils/color/color.js +14 -2
|
@@ -8,26 +8,44 @@ import { Tabs } from '../Tabs/index.js';
|
|
|
8
8
|
import { ColorPicker } from './ColorPicker.js';
|
|
9
9
|
import { GradientPicker } from '../GradientPicker/index.js';
|
|
10
10
|
import { resolveLabels } from './labels.js';
|
|
11
|
-
import { parseColor, resolveVarColor, formatColor, } from '../../utils/color/color.js';
|
|
11
|
+
import { parseColor, resolveVarColor, formatColor, hsvToRgb, rgbToHex, } from '../../utils/color/color.js';
|
|
12
12
|
import { parseGradient, formatGradient, colorAtPosition, } from '../../utils/color/gradient.js';
|
|
13
13
|
import { getContrastForeground } from '../../utils/color/contrast.js';
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
15
|
+
* Resolve any colour string to an Hsva — `var()` opportunistically via the
|
|
16
|
+
* live element; anything unresolvable returns null. The single resolved value
|
|
17
|
+
* feeds two consumers with DIFFERENT needs: the swatch background (which must
|
|
18
|
+
* keep alpha, or the checkerboard underneath stops showing through) and the
|
|
19
|
+
* icon-contrast probe (which must composite alpha away — see below).
|
|
17
20
|
*/
|
|
18
|
-
function
|
|
21
|
+
function resolveTriggerHsva(color, el) {
|
|
19
22
|
const p = parseColor(color);
|
|
20
23
|
if (p.kind === 'color')
|
|
21
|
-
return
|
|
24
|
+
return p.hsva;
|
|
22
25
|
if (p.kind === 'var') {
|
|
23
26
|
const resolved = resolveVarColor(p, el);
|
|
24
27
|
if (resolved) {
|
|
25
28
|
const rp = parseColor(resolved);
|
|
26
29
|
if (rp.kind === 'color')
|
|
27
|
-
return
|
|
30
|
+
return rp.hsva;
|
|
28
31
|
}
|
|
29
32
|
}
|
|
30
|
-
return
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Contrast-probe hex ONLY: alpha is composited over white (the checkerboard's
|
|
37
|
+
* dominant tone) — getContrastForeground ignores alpha, so a low-alpha dark
|
|
38
|
+
* colour would otherwise read as dark and get an invisible white icon on what
|
|
39
|
+
* actually renders as a light swatch. Never paint the swatch with this.
|
|
40
|
+
*/
|
|
41
|
+
function compositeOverWhiteHex(hsva) {
|
|
42
|
+
const { r, g, b } = hsvToRgb(hsva);
|
|
43
|
+
const a = hsva.a;
|
|
44
|
+
return rgbToHex({
|
|
45
|
+
r: r * a + (1 - a),
|
|
46
|
+
g: g * a + (1 - a),
|
|
47
|
+
b: b * a + (1 - a),
|
|
48
|
+
}).toUpperCase();
|
|
31
49
|
}
|
|
32
50
|
/** Best-effort text extraction from a ReactNode, for the accessible name. */
|
|
33
51
|
function nodeToText(node) {
|
|
@@ -93,12 +111,17 @@ export function ColorField({ value: controlledValue, defaultValue = '#000000', o
|
|
|
93
111
|
// Contrast for the swatch icon: a gradient has no single colour, so sample
|
|
94
112
|
// the midpoint — where the icon actually sits (best effort; an unresolvable
|
|
95
113
|
// var() falls back to black).
|
|
96
|
-
const
|
|
114
|
+
const resolvedHsva = resolveTriggerHsva(isGradient ? colorAtPosition(parsedGradient.gradient.stops, 50) : value, triggerRef.current);
|
|
115
|
+
// Alpha-preserving hex (8-digit when a < 1) — the swatch paints over the
|
|
116
|
+
// checkerboard, so compositing here would kill the transparency indicator.
|
|
117
|
+
const swatchHex = resolvedHsva ? formatColor(resolvedHsva, 'hex') : '#000000';
|
|
97
118
|
// Dynamic values get a neutral swatch + bolt; concrete colours get the colour
|
|
98
119
|
// + an edit affordance. Icon colour is contrast-picked so it stays legible.
|
|
99
|
-
const swatchBg = dynamic ? 'var(--tui-color-fg, #111)' :
|
|
120
|
+
const swatchBg = dynamic ? 'var(--tui-color-fg, #111)' : swatchHex;
|
|
100
121
|
const swatchIcon = icon ?? (dynamic ? 'system/bolt-fill' : 'system/edit-small');
|
|
101
|
-
const iconColor = dynamic
|
|
122
|
+
const iconColor = dynamic
|
|
123
|
+
? '#fff'
|
|
124
|
+
: getContrastForeground(resolvedHsva ? compositeOverWhiteHex(resolvedHsva) : '#000000');
|
|
102
125
|
// Trigger text: explicit label wins, else the variable name or the value.
|
|
103
126
|
// Gradients get a compact summary — the raw CSS string would be spelled out
|
|
104
127
|
// hex-by-hex in the accessible name (and overflow the pill).
|
|
@@ -468,11 +468,12 @@ function MultiComboboxRoot({ value: controlledValue, defaultValue, onValueChange
|
|
|
468
468
|
onKeyDown: handleInputKeyDown,
|
|
469
469
|
});
|
|
470
470
|
const hasValue = value.length > 0;
|
|
471
|
-
//
|
|
472
|
-
|
|
471
|
+
// Note: chips carry no size prop — token-field chips size em-relative to
|
|
472
|
+
// the host control (0.875em in styles.scss), which outranks Chip's
|
|
473
|
+
// font-size presets, so a size here would be dead code.
|
|
473
474
|
return (_jsx(MultiComboboxActionsContext.Provider, { value: actionsValue, children: _jsx(MultiComboboxStateContext.Provider, { value: stateValue, children: _jsxs("div", { className: "tui-multicombobox", children: [_jsxs("div", { ref: refs.setReference, className: cx('tui-multicombobox__control', size !== 'md' && `is-size-${size}`, overflow === 'trim' && 'is-overflow-trim'), "data-overflow-start": overflow === 'trim' && overflowStart ? '' : undefined, onMouseDown: handleWrapperMouseDown, children: [_jsxs("div", { ref: tokensRef, className: "tui-multicombobox__tokens", onScroll: overflow === 'trim' ? handleTokensScroll : undefined, children: [value.map((v) => {
|
|
474
475
|
const label = labelFor(v);
|
|
475
|
-
return (_jsx(Chip, {
|
|
476
|
+
return (_jsx(Chip, { className: "tui-multicombobox__chip", disabled: disabled, removeLabel: labels.remove(label), onRemove: () => removeValue(v), children: label }, toKey(v)));
|
|
476
477
|
}), _jsx("input", { ref: (node) => {
|
|
477
478
|
inputRef.current = node;
|
|
478
479
|
}, type: "text", id: inputId, className: cx('tui-multicombobox__input', inputClassName), role: "combobox", "aria-expanded": open, "aria-controls": open ? listboxId : undefined, "aria-autocomplete": "list", "aria-activedescendant": activeOptionId, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, "aria-invalid": ariaInvalid, "aria-required": ariaRequired, disabled: disabled, placeholder: hasValue ? undefined : placeholder, value: inputValue, autoComplete: "off", ...referenceProps, onChange: handleInputChange })] }), clearable && hasValue && !disabled && (_jsx("button", { type: "button", className: "tui-multicombobox__clear", onClick: handleClear, onMouseDown: (e) => e.preventDefault(), "aria-label": labels.clear, tabIndex: -1, children: _jsx(Icon, { name: "system/close" }) })), _jsx("span", { className: "tui-multicombobox__icon", "aria-hidden": "true", children: _jsx(Icon, { name: "system/chevron-down" }) })] }), children, _jsx("div", { className: "tui-visually-hidden", role: "status", children: labels.status(value.length, max) })] }) }) }));
|
|
@@ -466,9 +466,10 @@ function MultiSelectTriggerComponent({ asChild = false, className, children, })
|
|
|
466
466
|
// + "+N more") can't offer a per-chip × for the collapsed items anyway.
|
|
467
467
|
const visibleChips = selectedOptions.slice(0, maxChips);
|
|
468
468
|
const overflow = selectedOptions.length - maxChips;
|
|
469
|
-
//
|
|
470
|
-
|
|
471
|
-
|
|
469
|
+
// No size prop: token-field chips size em-relative to the host control
|
|
470
|
+
// (0.875em in styles.scss), which outranks Chip's font-size presets — a
|
|
471
|
+
// size here would be dead code that reads as if it did something.
|
|
472
|
+
return (_jsxs("span", { className: "tui-multiselect__chips", children: [visibleChips.map((opt) => (_jsx(Chip, { className: "tui-multiselect__chip", children: opt.textValue }, toKey(opt.value)))), overflow > 0 && (_jsx("span", { className: "tui-multiselect__more", children: labels.more(overflow) }))] }));
|
|
472
473
|
};
|
|
473
474
|
// Default trigger content (when not using asChild or custom children)
|
|
474
475
|
const defaultTriggerContent = (_jsxs(_Fragment, { children: [_jsx("span", { className: "tui-multiselect__value", children: renderTriggerContent() }), hasSelection && (_jsx("span", { className: "tui-multiselect__clear", onClick: handleClearClick, "aria-hidden": "true", children: _jsx(Icon, { name: "system/close" }) })), _jsx(Icon, { name: "system/chevron-down", className: "tui-multiselect__icon", "aria-hidden": "true" })] }));
|
package/components/Tabs/Tabs.js
CHANGED
|
@@ -239,7 +239,22 @@ function TabsList({ 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy,
|
|
|
239
239
|
// Focus event handler will update focusedValue and (in auto mode) call onSelect
|
|
240
240
|
}
|
|
241
241
|
};
|
|
242
|
-
|
|
242
|
+
// Reset the roving tab stop when focus LEAVES the tablist: in manual mode a
|
|
243
|
+
// user can arrow to a tab without committing, and `focusedValue ?? activeValue`
|
|
244
|
+
// would otherwise park the tab stop on that browsed, unselected tab — APG
|
|
245
|
+
// expects re-entry to land on the SELECTED tab.
|
|
246
|
+
const handleBlur = (event) => {
|
|
247
|
+
// relatedTarget is also null on window blur (alt-tab), where DOM focus
|
|
248
|
+
// stays on the browsed tab and the browser restores it on return — resetting
|
|
249
|
+
// there would desync the roving stop from the actually-focused tab.
|
|
250
|
+
if (!event.relatedTarget && event.currentTarget.contains(document.activeElement)) {
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
if (!event.currentTarget.contains(event.relatedTarget)) {
|
|
254
|
+
setFocusedValue(undefined);
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
return (_jsx("div", { role: "tablist", className: cx('tui-tabs__list', className), "aria-orientation": orientation, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, onKeyDown: handleKeyDown, onFocusCapture: handleFocusIn, onBlur: handleBlur, children: children }));
|
|
243
258
|
}
|
|
244
259
|
// =============================================================================
|
|
245
260
|
// Tabs.Tab
|