@tangible/ui 0.2.52 → 0.2.53
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/Accordion/Accordion.js +10 -4
- package/components/Checkbox/Checkbox.js +2 -0
- package/components/ColorPicker/ColorField.js +15 -4
- package/components/Field/Field.js +19 -0
- package/components/Pager/Pager.d.ts +2 -1
- package/components/Pager/Pager.js +3 -114
- package/components/Switch/Switch.js +2 -0
- package/components/index.d.ts +2 -0
- package/components/index.js +3 -0
- package/figma-tokens.json +1 -1
- package/icons/icons.svg +1 -1
- package/icons/sprite-version.js +1 -1
- package/icons/sprite.php +1 -1
- package/package.json +9 -1
- package/skills/building-with-tui/SKILL.md +48 -2
- package/styles/all.css +1 -1
- package/styles/all.expanded.css +29 -20
- package/styles/all.expanded.unlayered.css +29 -20
- package/styles/all.unlayered.css +1 -1
- package/styles/components/color-picker.scss +4 -1
- package/styles/components/move-handle.scss +17 -5
- package/styles/core.css +1 -1
- package/styles/core.unlayered.css +1 -1
- package/styles/index.scss +14 -0
- package/tui-manifest.json +4 -3
- package/utils/pager.d.ts +49 -0
- package/utils/pager.js +129 -0
- package/utils/self-labelling.d.ts +12 -0
- package/utils/self-labelling.js +18 -0
- package/vanilla/accordion.d.ts +94 -0
- package/vanilla/accordion.js +317 -0
- package/vanilla/accordion.min.js +1 -0
- package/vanilla/styles.css +1 -1
- package/vanilla/styles.unlayered.css +1 -1
|
@@ -116,8 +116,12 @@ function AccordionItem({ value, disabled = false, headingLevel, children, classN
|
|
|
116
116
|
// Accordion Trigger
|
|
117
117
|
// =============================================================================
|
|
118
118
|
function AccordionTrigger({ asChild = false, unstyled = false, 'aria-label': ariaLabel, children, className, }) {
|
|
119
|
-
const { toggle, registerTrigger, getTriggers } = useAccordionContext();
|
|
119
|
+
const { toggle, registerTrigger, getTriggers, collapsible } = useAccordionContext();
|
|
120
120
|
const { value, disabled, headingLevel, triggerId, panelId, isOpen } = useAccordionItemContext();
|
|
121
|
+
// APG: an open header whose panel can't be collapsed (single mode, not
|
|
122
|
+
// collapsible) is aria-disabled. It stays focusable, reachable by arrow keys
|
|
123
|
+
// and unpainted: it isn't disabled, its activation just does nothing.
|
|
124
|
+
const locked = isOpen && !collapsible && !disabled;
|
|
121
125
|
const triggerRef = useRef(null);
|
|
122
126
|
// Register trigger for keyboard navigation
|
|
123
127
|
React.useEffect(() => {
|
|
@@ -182,7 +186,9 @@ function AccordionTrigger({ asChild = false, unstyled = false, 'aria-label': ari
|
|
|
182
186
|
const currentIndex = sortedTriggers.findIndex(([v]) => v === value);
|
|
183
187
|
// Find next/prev non-disabled trigger — check both native disabled (button)
|
|
184
188
|
// and aria-disabled (asChild elements)
|
|
185
|
-
|
|
189
|
+
// data-disabled, not aria-disabled: a locked open header (aria-disabled,
|
|
190
|
+
// see `locked`) must stay reachable.
|
|
191
|
+
const isElementDisabled = (el) => el.disabled || el.hasAttribute('data-disabled');
|
|
186
192
|
const findNextIndex = (start, direction) => {
|
|
187
193
|
let index = start;
|
|
188
194
|
const len = sortedTriggers.length;
|
|
@@ -238,7 +244,7 @@ function AccordionTrigger({ asChild = false, unstyled = false, 'aria-label': ari
|
|
|
238
244
|
tabIndex: disabled ? -1 : 0,
|
|
239
245
|
'aria-expanded': isOpen,
|
|
240
246
|
'aria-controls': panelId,
|
|
241
|
-
'aria-disabled': disabled || undefined,
|
|
247
|
+
'aria-disabled': disabled || locked || undefined,
|
|
242
248
|
'aria-label': ariaLabel,
|
|
243
249
|
'data-state': state,
|
|
244
250
|
'data-disabled': disabled || undefined,
|
|
@@ -262,7 +268,7 @@ function AccordionTrigger({ asChild = false, unstyled = false, 'aria-label': ari
|
|
|
262
268
|
return element;
|
|
263
269
|
}
|
|
264
270
|
// Default: render as button with built-in chevron indicator
|
|
265
|
-
const button = (_jsxs("button", { ref: triggerRef, type: "button", id: triggerId, className: cx('tui-accordion__trigger', className), "aria-expanded": isOpen, "aria-controls": panelId, "aria-label": ariaLabel, disabled: disabled, "data-state": state, "data-disabled": disabled || undefined, "data-tui-accordion-trigger": "", onClick: handleClick, onKeyDown: handleKeyDown, children: [children && _jsx("span", { className: "tui-accordion__trigger-content", children: children }), _jsx(Icon, { name: ChevronDownIcon, className: "tui-accordion__indicator", "aria-hidden": "true" })] }));
|
|
271
|
+
const button = (_jsxs("button", { ref: triggerRef, type: "button", id: triggerId, className: cx('tui-accordion__trigger', className), "aria-expanded": isOpen, "aria-controls": panelId, "aria-label": ariaLabel, "aria-disabled": locked || undefined, disabled: disabled, "data-state": state, "data-disabled": disabled || undefined, "data-tui-accordion-trigger": "", onClick: handleClick, onKeyDown: handleKeyDown, children: [children && _jsx("span", { className: "tui-accordion__trigger-content", children: children }), _jsx(Icon, { name: ChevronDownIcon, className: "tui-accordion__indicator", "aria-hidden": "true" })] }));
|
|
266
272
|
// Wrap in heading if headingLevel is specified
|
|
267
273
|
if (headingLevel) {
|
|
268
274
|
const Heading = `h${headingLevel}`;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { forwardRef, useEffect, useRef } from 'react';
|
|
3
|
+
import { markSelfLabelling } from '../../utils/self-labelling.js';
|
|
3
4
|
import { cx } from '../../utils/cx.js';
|
|
4
5
|
import { composeRefs } from '../../utils/compose-refs.js';
|
|
5
6
|
import { useControllableState } from '../../utils/use-controllable-state.js';
|
|
@@ -125,3 +126,4 @@ export const Checkbox = forwardRef(function Checkbox({ checked: controlledChecke
|
|
|
125
126
|
return (_jsxs("label", { className: cx('tui-inline-choice', disabled && 'is-disabled', className), ...wrapperProps, children: [renderInput(inputProps, 'tui-inline-choice__control'), _jsx("span", { children: label })] }));
|
|
126
127
|
});
|
|
127
128
|
Checkbox.displayName = 'Checkbox';
|
|
129
|
+
markSelfLabelling(Checkbox);
|
|
@@ -10,7 +10,7 @@ import { GradientPicker } from '../GradientPicker/index.js';
|
|
|
10
10
|
import { resolveLabels } from './labels.js';
|
|
11
11
|
import { parseColor, resolveVarColor, formatColor, hsvToRgb, rgbToHex, } from '../../utils/color/color.js';
|
|
12
12
|
import { parseGradient, formatGradient, colorAtPosition, } from '../../utils/color/gradient.js';
|
|
13
|
-
import {
|
|
13
|
+
import { getContrastTone } from '../../utils/color/contrast.js';
|
|
14
14
|
import { BoltFill as BoltFillIcon, EditSmall as EditSmallIcon } from '../../icons/system/index.js';
|
|
15
15
|
/**
|
|
16
16
|
* Resolve any colour string to an Hsva — `var()` opportunistically via the
|
|
@@ -128,9 +128,20 @@ export function ColorField({ value: controlledValue, defaultValue = '#000000', o
|
|
|
128
128
|
// + an edit affordance. Icon colour is contrast-picked so it stays legible.
|
|
129
129
|
const swatchBg = dynamic ? 'var(--tui-color-fg, #111)' : swatchHex;
|
|
130
130
|
const swatchIcon = icon ?? (dynamic ? BoltFillIcon : EditSmallIcon);
|
|
131
|
+
// The foreground tone that reads on the swatch. Published as
|
|
132
|
+
// data-contrast-tone so a consumer can key the swatch's border (or anything
|
|
133
|
+
// else) to it without reading the private --_swatch-icon (#257). A dynamic
|
|
134
|
+
// swatch paints the page fg, which flips with the theme, so it has no fixed
|
|
135
|
+
// tone: no attribute, and its icon is the page bg (it was #fff, which
|
|
136
|
+
// vanished on the light fg of a dark theme).
|
|
137
|
+
const contrastTone = dynamic
|
|
138
|
+
? undefined
|
|
139
|
+
: getContrastTone(resolvedHsva ? compositeOverWhiteHex(resolvedHsva) : '#000000');
|
|
131
140
|
const iconColor = dynamic
|
|
132
|
-
? '#fff'
|
|
133
|
-
:
|
|
141
|
+
? 'var(--tui-color-bg, #fff)'
|
|
142
|
+
: contrastTone === 'light'
|
|
143
|
+
? '#fff'
|
|
144
|
+
: '#000';
|
|
134
145
|
// Trigger text: explicit label wins, else the variable name or the value.
|
|
135
146
|
// Gradients get a compact summary — the raw CSS string would be spelled out
|
|
136
147
|
// hex-by-hex in the accessible name (and overflow the pill).
|
|
@@ -170,7 +181,7 @@ export function ColorField({ value: controlledValue, defaultValue = '#000000', o
|
|
|
170
181
|
if (!next)
|
|
171
182
|
lastGradientRef.current = null;
|
|
172
183
|
onOpenChange?.(next);
|
|
173
|
-
}, children: [_jsx(Popover.Trigger, { asChild: true, children: _jsxs("button", { ref: triggerRef, type: "button", id: id, className: cx('tui-color-field', size !== 'md' && `is-size-${size}`, variant !== 'field' && `is-variant-${variant}`, showSwatch && !hasLabel && 'is-swatch-only', !showSwatch && 'is-label-only', disabled && 'is-disabled', className), disabled: disabled, "aria-label": computedAriaLabel, "aria-labelledby": ariaLabelledby, ...rest, children: [showSwatch && (_jsx("span", { className: "tui-color-field__swatch", "aria-hidden": "true", style: {
|
|
184
|
+
}, children: [_jsx(Popover.Trigger, { asChild: true, children: _jsxs("button", { ref: triggerRef, type: "button", id: id, className: cx('tui-color-field', size !== 'md' && `is-size-${size}`, variant !== 'field' && `is-variant-${variant}`, showSwatch && !hasLabel && 'is-swatch-only', !showSwatch && 'is-label-only', disabled && 'is-disabled', className), disabled: disabled, "aria-label": computedAriaLabel, "aria-labelledby": ariaLabelledby, ...rest, children: [showSwatch && (_jsx("span", { className: "tui-color-field__swatch", "aria-hidden": "true", "data-contrast-tone": contrastTone, style: {
|
|
174
185
|
'--_swatch': swatchBg,
|
|
175
186
|
'--_swatch-icon': iconColor,
|
|
176
187
|
// A gradient paints the whole swatch; solid values keep the
|
|
@@ -2,6 +2,7 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
|
|
|
2
2
|
import React, { forwardRef, useCallback, useEffect, useId, useLayoutEffect, useState, useMemo, useRef, cloneElement, isValidElement, Children, } from 'react';
|
|
3
3
|
import { cx } from '../../utils/cx.js';
|
|
4
4
|
import { isDev } from '../../utils/is-dev.js';
|
|
5
|
+
import { isSelfLabelling } from '../../utils/self-labelling.js';
|
|
5
6
|
import { FieldContext, useFieldContext, defaultFieldLabels } from './FieldContext.js';
|
|
6
7
|
export const Field = forwardRef(function Field({ error = false, required = false, disabled = false, inline = false, labels: labelsProp, className, children, }, ref) {
|
|
7
8
|
const baseId = useId();
|
|
@@ -92,6 +93,24 @@ function FieldControl({ children }) {
|
|
|
92
93
|
}
|
|
93
94
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
94
95
|
}, []);
|
|
96
|
+
// DEV: a self-labelling control (Checkbox, Switch) with its own `label`
|
|
97
|
+
// under a Field.Label: the injected aria-labelledby outranks the control's
|
|
98
|
+
// own <label>, so the text beside the control drops out of its name and a
|
|
99
|
+
// voice command using it misses (WCAG 2.5.3, #259).
|
|
100
|
+
const childSelfLabel = isSelfLabelling(child.type) && childProps.label != null && childProps.label !== false && childProps.label !== '';
|
|
101
|
+
const warnedSelfLabel = useRef(false);
|
|
102
|
+
useEffect(() => {
|
|
103
|
+
if (!isDev() || warnedSelfLabel.current)
|
|
104
|
+
return;
|
|
105
|
+
if (childSelfLabel && injectedLabelledBy && !childLabelledBy) {
|
|
106
|
+
warnedSelfLabel.current = true;
|
|
107
|
+
console.warn('Field: Field.Label replaces the accessible name of a control that labels itself ' +
|
|
108
|
+
'(Checkbox or Switch with a `label`). Its own label text is no longer announced. ' +
|
|
109
|
+
"Pick one name: usually drop the control's `label` and put that text in " +
|
|
110
|
+
'Field.HelperText, so Field.Label names it. Or, if the text beside the control is the ' +
|
|
111
|
+
'name, replace Field.Label with a plain element (keep Field.Control for help and errors).');
|
|
112
|
+
}
|
|
113
|
+
}, [childSelfLabel, injectedLabelledBy, childLabelledBy]);
|
|
95
114
|
// Clone child with a11y props
|
|
96
115
|
// Note: aria-invalid and aria-required must be string "true", not boolean
|
|
97
116
|
return cloneElement(child, {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { SizeStandard } from '../../types/sizes';
|
|
2
2
|
import { type PagerLabels } from './types';
|
|
3
|
-
|
|
3
|
+
import { type PagerMode } from '../../utils/pager';
|
|
4
|
+
export type { PagerMode } from '../../utils/pager';
|
|
4
5
|
/**
|
|
5
6
|
* Relationship between nav segments.
|
|
6
7
|
*
|
|
@@ -4,6 +4,7 @@ import { cx } from '../../utils/cx.js';
|
|
|
4
4
|
import { Button } from '../Button/index.js';
|
|
5
5
|
import { IconButton } from '../IconButton/index.js';
|
|
6
6
|
import { defaultPagerLabels } from './types.js';
|
|
7
|
+
import { getPagerItems, DEFAULT_PAGER_SLOTS } from '../../utils/pager.js';
|
|
7
8
|
import { ChevronLeft as ChevronLeftIcon, ChevronLeftDouble as ChevronLeftDoubleIcon, ChevronRight as ChevronRightIcon, ChevronRightDouble as ChevronRightDoubleIcon } from '../../icons/system/index.js';
|
|
8
9
|
// =============================================================================
|
|
9
10
|
// Pager Component
|
|
@@ -16,7 +17,6 @@ import { ChevronLeft as ChevronLeftIcon, ChevronLeftDouble as ChevronLeftDoubleI
|
|
|
16
17
|
// For TanStack Table integration, use TablePagination which wraps this.
|
|
17
18
|
//
|
|
18
19
|
// =============================================================================
|
|
19
|
-
const DEFAULT_MAX_SLOTS = 7;
|
|
20
20
|
/**
|
|
21
21
|
* Glyphs for `navStyle="icon"`. First/last are double chevrons — the
|
|
22
22
|
* conventional "jump to the end" affordance, and distinguishable from the
|
|
@@ -29,121 +29,10 @@ const NAV_ICONS = {
|
|
|
29
29
|
next: ChevronRightIcon,
|
|
30
30
|
last: ChevronRightDoubleIcon,
|
|
31
31
|
};
|
|
32
|
-
/**
|
|
33
|
-
* Build a stable-width list of page tokens (numbers + ellipses).
|
|
34
|
-
*
|
|
35
|
-
* Always shows: first, last, current, current±1
|
|
36
|
-
* Single-page gaps are filled in (no "1 ... 3" silliness)
|
|
37
|
-
* Expands symmetrically from current, biased toward center
|
|
38
|
-
*/
|
|
39
|
-
function buildNumberTokens(total, current, maxSlots = DEFAULT_MAX_SLOTS) {
|
|
40
|
-
if (total <= 1)
|
|
41
|
-
return [1];
|
|
42
|
-
if (total <= maxSlots)
|
|
43
|
-
return Array.from({ length: total }, (_, i) => i + 1);
|
|
44
|
-
const inRange = (n) => n >= 1 && n <= total;
|
|
45
|
-
// Start with anchors: first, last, current and neighbors
|
|
46
|
-
const chosen = new Set([1, total]);
|
|
47
|
-
if (inRange(current))
|
|
48
|
-
chosen.add(current);
|
|
49
|
-
if (inRange(current - 1))
|
|
50
|
-
chosen.add(current - 1);
|
|
51
|
-
if (inRange(current + 1))
|
|
52
|
-
chosen.add(current + 1);
|
|
53
|
-
/**
|
|
54
|
-
* Convert chosen pages to tokens, inserting ellipses for gaps.
|
|
55
|
-
* Single-page gaps get filled in rather than showing an ellipsis.
|
|
56
|
-
*/
|
|
57
|
-
const materialize = () => {
|
|
58
|
-
const pages = [...chosen].sort((a, b) => a - b);
|
|
59
|
-
const tokens = [];
|
|
60
|
-
for (let i = 0; i < pages.length; i++) {
|
|
61
|
-
tokens.push(pages[i]);
|
|
62
|
-
const next = pages[i + 1];
|
|
63
|
-
if (next == null)
|
|
64
|
-
break;
|
|
65
|
-
const gap = next - pages[i];
|
|
66
|
-
if (gap === 2)
|
|
67
|
-
tokens.push(pages[i] + 1);
|
|
68
|
-
else if (gap > 2)
|
|
69
|
-
tokens.push('...');
|
|
70
|
-
}
|
|
71
|
-
return tokens;
|
|
72
|
-
};
|
|
73
|
-
/** Try adding a page. Returns true if it fit within maxSlots. */
|
|
74
|
-
const tryAdd = (p) => {
|
|
75
|
-
if (!inRange(p) || chosen.has(p))
|
|
76
|
-
return false;
|
|
77
|
-
chosen.add(p);
|
|
78
|
-
if (materialize().length > maxSlots) {
|
|
79
|
-
chosen.delete(p);
|
|
80
|
-
return false;
|
|
81
|
-
}
|
|
82
|
-
return true;
|
|
83
|
-
};
|
|
84
|
-
// Expand symmetrically from current until we fill available slots
|
|
85
|
-
let offset = 2;
|
|
86
|
-
while (materialize().length < maxSlots) {
|
|
87
|
-
const left = current - offset;
|
|
88
|
-
const right = current + offset;
|
|
89
|
-
// Bias toward center: if past halfway, try right first
|
|
90
|
-
const preferRight = current > total / 2;
|
|
91
|
-
const [first, second] = preferRight ? [right, left] : [left, right];
|
|
92
|
-
// Try preferred side, then other side
|
|
93
|
-
const added = tryAdd(first) || tryAdd(second);
|
|
94
|
-
// If neither side worked, try both explicitly (handles edge cases)
|
|
95
|
-
if (!added && !tryAdd(left) && !tryAdd(right))
|
|
96
|
-
break;
|
|
97
|
-
offset++;
|
|
98
|
-
}
|
|
99
|
-
return materialize();
|
|
100
|
-
}
|
|
101
|
-
function buildItems(total, current, mode, maxNumbers, showFirstLast) {
|
|
102
|
-
const items = [];
|
|
103
|
-
// Outside prev/next, not inside: the reading order is
|
|
104
|
-
// « ‹ 1 2 3 › » in every pager that has them.
|
|
105
|
-
if (showFirstLast) {
|
|
106
|
-
items.push({ kind: 'first', disabled: current <= 1, page: 1 });
|
|
107
|
-
}
|
|
108
|
-
items.push({
|
|
109
|
-
kind: 'prev',
|
|
110
|
-
disabled: current <= 1,
|
|
111
|
-
page: Math.max(1, current - 1),
|
|
112
|
-
});
|
|
113
|
-
if (mode === 'full') {
|
|
114
|
-
for (let p = 1; p <= total; p++) {
|
|
115
|
-
items.push({ kind: 'page', page: p, current: p === current });
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
else if (mode === 'ends') {
|
|
119
|
-
const set = new Set([1, current - 1, current, current + 1, total].filter((n) => n >= 1 && n <= total));
|
|
120
|
-
const pages = Array.from(set).sort((a, b) => a - b);
|
|
121
|
-
pages.forEach((p) => items.push({ kind: 'page', page: p, current: p === current }));
|
|
122
|
-
}
|
|
123
|
-
else if (mode === 'smart') {
|
|
124
|
-
const tokens = buildNumberTokens(total, current, maxNumbers);
|
|
125
|
-
tokens.forEach((tok) => {
|
|
126
|
-
if (tok === '...')
|
|
127
|
-
items.push({ kind: 'ellipsis' });
|
|
128
|
-
else
|
|
129
|
-
items.push({ kind: 'page', page: tok, current: tok === current });
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
// mode === 'simple' => no page numbers
|
|
133
|
-
items.push({
|
|
134
|
-
kind: 'next',
|
|
135
|
-
disabled: current >= total,
|
|
136
|
-
page: Math.min(total, current + 1),
|
|
137
|
-
});
|
|
138
|
-
if (showFirstLast) {
|
|
139
|
-
items.push({ kind: 'last', disabled: current >= total, page: total });
|
|
140
|
-
}
|
|
141
|
-
return items;
|
|
142
|
-
}
|
|
143
32
|
// -----------------------------------------------------------------------------
|
|
144
33
|
// Component
|
|
145
34
|
// -----------------------------------------------------------------------------
|
|
146
|
-
export function Pager({ currentPage, totalPages, onPageChange, pageSize, pageSizeOptions, onPageSizeChange, size = 'sm', mode = 'smart', maxNumbers =
|
|
35
|
+
export function Pager({ currentPage, totalPages, onPageChange, pageSize, pageSizeOptions, onPageSizeChange, size = 'sm', mode = 'smart', maxNumbers = DEFAULT_PAGER_SLOTS, navStyle = 'text', variant = 'flush', showInfo = true, showFirstLast = false, showJump = false, hidden = false, className, labels: labelsProp, }) {
|
|
147
36
|
// Size class follows the shared convention: default emits nothing, sm/lg
|
|
148
37
|
// emit `is-size-*`. (Pager's own default is sm, so a stock Pager still gets
|
|
149
38
|
// the class.)
|
|
@@ -157,7 +46,7 @@ export function Pager({ currentPage, totalPages, onPageChange, pageSize, pageSiz
|
|
|
157
46
|
// Normalise inputs
|
|
158
47
|
const total = Math.max(1, totalPages);
|
|
159
48
|
const current = Math.min(total, Math.max(1, currentPage));
|
|
160
|
-
const items = React.useMemo(() =>
|
|
49
|
+
const items = React.useMemo(() => getPagerItems({ totalPages: total, currentPage: current, mode, maxNumbers, showFirstLast }), [total, current, mode, maxNumbers, showFirstLast]);
|
|
161
50
|
// Live-region text: page changes are announced politely. Empty until the
|
|
162
51
|
// first user-driven change so mount announces nothing.
|
|
163
52
|
const [announcement, setAnnouncement] = React.useState('');
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { forwardRef, useEffect, useRef } from 'react';
|
|
3
|
+
import { markSelfLabelling } from '../../utils/self-labelling.js';
|
|
3
4
|
import { cx } from '../../utils/cx.js';
|
|
4
5
|
import { composeRefs } from '../../utils/compose-refs.js';
|
|
5
6
|
import { useControllableState } from '../../utils/use-controllable-state.js';
|
|
@@ -103,3 +104,4 @@ export const Switch = forwardRef(function Switch({ checked: controlledChecked, d
|
|
|
103
104
|
return (_jsxs("label", { className: cx('tui-switch', sizeClass, disabled && 'is-disabled', className), onClick: handleLabelClick, ...wrapperProps, children: [renderButton(buttonProps), _jsx("span", { className: "tui-switch__label", children: label })] }));
|
|
104
105
|
});
|
|
105
106
|
Switch.displayName = 'Switch';
|
|
107
|
+
markSelfLabelling(Switch);
|
package/components/index.d.ts
CHANGED
|
@@ -107,3 +107,5 @@ export type { TooltipProps, TooltipProviderProps, TooltipTriggerProps, TooltipCo
|
|
|
107
107
|
export { GENERATIVE_COLORS, stringToGenerativeColor } from '../utils/generative';
|
|
108
108
|
export type { GenerativeColor } from '../utils/generative';
|
|
109
109
|
export * from '../utils/color-scheme';
|
|
110
|
+
export { getPagerItems, DEFAULT_PAGER_SLOTS } from '../utils/pager';
|
|
111
|
+
export type { PagerItem, PagerNavKind, PagerItemsOptions } from '../utils/pager';
|
package/components/index.js
CHANGED
|
@@ -55,3 +55,6 @@ export { GENERATIVE_COLORS, stringToGenerativeColor } from '../utils/generative.
|
|
|
55
55
|
// Color scheme switching (instant: no controls fading into the new theme)
|
|
56
56
|
// (the module's whole surface: one list, kept in color-scheme.ts)
|
|
57
57
|
export * from '../utils/color-scheme.js';
|
|
58
|
+
// Pager's page numbering without React, for server-rendered or vanilla pagers
|
|
59
|
+
// (also at @tangible/ui/utils/pager, which pulls in nothing else)
|
|
60
|
+
export { getPagerItems, DEFAULT_PAGER_SLOTS } from '../utils/pager.js';
|
package/figma-tokens.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.2.
|
|
2
|
+
"version": "0.2.53",
|
|
3
3
|
"source": "publish/styles/all.expanded.css",
|
|
4
4
|
"prefix": "tui-",
|
|
5
5
|
"note": "Layer 1 primitives only. Component API tokens (--tui-{component}-*) are never defined in CSS — they exist only as fallback reads — so they have no Figma representation. CONTRACT: consumers read TUI defaults from this file at build time (variables[].cssVar, the \"Light\"/\"Dark\" mode names, and alias chains into TUI/Primitives). Renaming a cssVar or a mode is a breaking change to those consumers even when the CSS value is unchanged — a rename silently becomes an undefined default downstream — so treat it as at least a minor bump and call it out in the CHANGELOG.",
|
package/icons/icons.svg
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg" data-tui-icon-sprite="all" data-tui-icon-sprite-version="0.2.
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" data-tui-icon-sprite="all" data-tui-icon-sprite-version="0.2.53" aria-hidden="true" focusable="false" style="position:absolute;width:0;height:0;overflow:hidden">
|
|
2
2
|
<symbol id="tui-cred-badge-check" viewBox="0 0 24 24"><path fill-rule="evenodd" d="M10.893 4.558a1.377 1.377 0 0 1 2.214 0c.381.515 1.068.7 1.656.444a1.377 1.377 0 0 1 1.917 1.106c.072.637.575 1.14 1.212 1.213a1.377 1.377 0 0 1 1.106 1.916 1.38 1.38 0 0 0 .444 1.656c.744.55.744 1.663 0 2.214a1.38 1.38 0 0 0-.444 1.656 1.377 1.377 0 0 1-1.106 1.917 1.38 1.38 0 0 0-1.212 1.212 1.377 1.377 0 0 1-1.917 1.106 1.38 1.38 0 0 0-1.656.444 1.377 1.377 0 0 1-2.214 0 1.38 1.38 0 0 0-1.656-.444 1.377 1.377 0 0 1-1.916-1.106 1.38 1.38 0 0 0-1.213-1.212 1.377 1.377 0 0 1-1.106-1.917 1.38 1.38 0 0 0-.444-1.656 1.377 1.377 0 0 1 0-2.214c.515-.381.7-1.068.444-1.656a1.377 1.377 0 0 1 1.106-1.916 1.38 1.38 0 0 0 1.213-1.213 1.377 1.377 0 0 1 1.916-1.106 1.38 1.38 0 0 0 1.656-.444m5.193 5.91a.75.75 0 0 0-1.172-.936l-3.531 4.414-1.914-1.532a.75.75 0 1 0-.937 1.172l3.085 2.468z" clip-rule="evenodd"/></symbol>
|
|
3
3
|
<symbol id="tui-cred-badge-ribbon" viewBox="0 0 24 24"><path d="M11.032 3.488a1.205 1.205 0 0 1 1.936 0c.334.451.935.612 1.45.388a1.205 1.205 0 0 1 1.677.969c.063.557.503.997 1.06 1.06.805.092 1.291.935.969 1.678a1.204 1.204 0 0 0 .388 1.449c.65.481.65 1.455 0 1.936a1.205 1.205 0 0 0-.388 1.45 1.205 1.205 0 0 1-.969 1.677 1.204 1.204 0 0 0-1.06 1.06 1.205 1.205 0 0 1-1.678.969 1.205 1.205 0 0 0-1.449.388c-.481.65-1.455.65-1.936 0a1.204 1.204 0 0 0-1.45-.388 1.205 1.205 0 0 1-1.677-.969 1.205 1.205 0 0 0-1.06-1.06 1.205 1.205 0 0 1-.969-1.678 1.205 1.205 0 0 0-.388-1.449 1.205 1.205 0 0 1 0-1.936c.451-.334.612-.935.388-1.45a1.205 1.205 0 0 1 .969-1.677 1.205 1.205 0 0 0 1.06-1.06 1.205 1.205 0 0 1 1.678-.969 1.205 1.205 0 0 0 1.449-.388M8 17.482c.442.175.953.185 1.437-.025a.88.88 0 0 1 1.054.282 1.877 1.877 0 0 0 3.018 0 .88.88 0 0 1 1.054-.282c.484.21.995.2 1.437.025V21l-4-2.286L8 21z"/></symbol>
|
|
4
4
|
<symbol id="tui-cred-badge" viewBox="0 0 24 24"><path d="M13.107 4.558a1.377 1.377 0 0 0-2.214 0c-.381.515-1.068.7-1.656.444a1.377 1.377 0 0 0-1.916 1.106 1.38 1.38 0 0 1-1.213 1.213 1.377 1.377 0 0 0-1.106 1.916 1.38 1.38 0 0 1-.444 1.656 1.377 1.377 0 0 0 0 2.214c.515.381.7 1.068.444 1.656a1.377 1.377 0 0 0 1.106 1.917c.637.072 1.14.575 1.213 1.212a1.377 1.377 0 0 0 1.916 1.106 1.38 1.38 0 0 1 1.656.444c.55.744 1.663.744 2.214 0a1.38 1.38 0 0 1 1.656-.444 1.377 1.377 0 0 0 1.917-1.106 1.38 1.38 0 0 1 1.212-1.212 1.377 1.377 0 0 0 1.106-1.917 1.38 1.38 0 0 1 .444-1.656 1.377 1.377 0 0 0 0-2.214 1.38 1.38 0 0 1-.444-1.656 1.377 1.377 0 0 0-1.106-1.916 1.38 1.38 0 0 1-1.212-1.213 1.377 1.377 0 0 0-1.917-1.106 1.38 1.38 0 0 1-1.656-.444"/></symbol>
|
package/icons/sprite-version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SPRITE_VERSION = '0.2.
|
|
1
|
+
export const SPRITE_VERSION = '0.2.53';
|
package/icons/sprite.php
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
*/
|
|
22
22
|
|
|
23
23
|
// Replaced with the package version at build time.
|
|
24
|
-
$GLOBALS['tangible_ui_icon_sprite_copies'][__DIR__] = '0.2.
|
|
24
|
+
$GLOBALS['tangible_ui_icon_sprite_copies'][__DIR__] = '0.2.53';
|
|
25
25
|
|
|
26
26
|
if (!function_exists('tangible_ui_print_icon_sprite')) {
|
|
27
27
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tangible/ui",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.53",
|
|
4
4
|
"description": "React design system for Tangible's products: standalone React apps and WordPress plugins. Components, CSS custom property tokens, cascade layers.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./components/index.js",
|
|
@@ -58,6 +58,10 @@
|
|
|
58
58
|
"import": "./utils/color-scheme.js",
|
|
59
59
|
"types": "./utils/color-scheme.d.ts"
|
|
60
60
|
},
|
|
61
|
+
"./utils/pager": {
|
|
62
|
+
"import": "./utils/pager.js",
|
|
63
|
+
"types": "./utils/pager.d.ts"
|
|
64
|
+
},
|
|
61
65
|
"./icons": {
|
|
62
66
|
"import": "./icons/registry.js",
|
|
63
67
|
"types": "./icons/registry.d.ts"
|
|
@@ -79,6 +83,10 @@
|
|
|
79
83
|
"import": "./vanilla/modal.js",
|
|
80
84
|
"types": "./vanilla/modal.d.ts"
|
|
81
85
|
},
|
|
86
|
+
"./vanilla/accordion": {
|
|
87
|
+
"import": "./vanilla/accordion.js",
|
|
88
|
+
"types": "./vanilla/accordion.d.ts"
|
|
89
|
+
},
|
|
82
90
|
"./vanilla/*": "./vanilla/*",
|
|
83
91
|
"./components/Accordion": {
|
|
84
92
|
"import": "./components/Accordion/index.js",
|
|
@@ -135,6 +135,8 @@ components render their panels on mount, so they server-render (Astro, Next) and
|
|
|
135
135
|
|
|
136
136
|
If `<html>` itself is the `.tui-interface`, portal roots mount inside `<body>`, not on `<html>`.
|
|
137
137
|
|
|
138
|
+
Inside a `.tui-interface`, `[hidden]` is `display: none !important` (except `hidden="until-found"`), so `hidden` always hides, even on a TUI element or under a host display rule. To show and hide something with CSS, toggle a class, not the attribute. When `<html>` is the interface, that covers the whole page.
|
|
139
|
+
|
|
138
140
|
**3. Dark mode is `data-theme`, not a class.** TUI's palette is gated on `[data-theme="dark"]`
|
|
139
141
|
(`"auto"` follows `prefers-color-scheme`; absent means light and inherits the host's colour). With `data-theme="dark"`/`"auto"` on an ancestor such as `<html>` and an un-themed `.tui-interface` on `<body>`, TUI surfaces (panels, cards, filled controls) render correctly because they own their text colour, but in-flow text directly inside the interface still inherits the HOST's colour by design — so set the host's own body colour (e.g. `color: var(--tui-color-fg)` on `body`) if you want TUI's. A standalone app gets that, and more, from the app base sheet (§6). A host
|
|
140
142
|
that toggles a `.dark` class (Tailwind's strategy) drives nothing in TUI. Translate it: observe what
|
|
@@ -367,8 +369,25 @@ Three rules, all of them silent when broken:
|
|
|
367
369
|
has already rendered — a phantom `aria-labelledby` would resolve to the empty string and strip
|
|
368
370
|
*all* other name sources (AccName 1.2 step 2B), so TUI withholds it rather than risk that. A dev
|
|
369
371
|
warning fires on the wrong order; production is just unlabelled.
|
|
370
|
-
- **
|
|
371
|
-
`label` prop already have a name
|
|
372
|
+
- **A self-labelling control and `Field.Label` don't mix: pick one name.** Checkbox and Switch
|
|
373
|
+
with their own `label` prop already have a name. Adding `Field.Label` *replaces* it (the injected
|
|
374
|
+
`aria-labelledby` outranks the control's own `<label>`), so the text beside the control is no
|
|
375
|
+
longer announced (WCAG 2.5.3), and a dev warning says so. TUI deliberately doesn't join the two:
|
|
376
|
+
one is the name and the other explains it. For a settings row:
|
|
377
|
+
1. **The row heading is the name (the default).** `Field.Label` names the control, the Switch
|
|
378
|
+
takes no `label`, and the sentence goes in `Field.HelperText`. It reads "Site search, switch,
|
|
379
|
+
off. Replace the default WordPress search", the way WordPress and macOS settings read.
|
|
380
|
+
```tsx
|
|
381
|
+
<Field>
|
|
382
|
+
<Field.Label>Site search</Field.Label>
|
|
383
|
+
<Field.Control><Switch /></Field.Control>
|
|
384
|
+
<Field.HelperText>Replace the default WordPress search.</Field.HelperText>
|
|
385
|
+
</Field>
|
|
386
|
+
```
|
|
387
|
+
2. **The sentence beside the control is the name.** Keep the Switch's `label`, render the heading
|
|
388
|
+
as a plain element, and keep `Field.Control`: it still wires help text and errors, and only
|
|
389
|
+
injects `aria-labelledby` when a `Field.Label` exists. To have the heading heard too, give it an
|
|
390
|
+
`id` and pass that as the control's `aria-describedby`, which `Field.Control` merges.
|
|
372
391
|
- **Group controls need `Field.Label as="span"`.** RadioGroup and SegmentedControl render
|
|
373
392
|
`role="radiogroup"` on a `<div>`, which is not a labelable element, so the default
|
|
374
393
|
`<label for>` dangles. The span keeps the id, so the `aria-labelledby` wiring is untouched.
|
|
@@ -887,6 +906,33 @@ For templates and plugin PHP with no React build (Tangible Blocks, L&L): `@tangi
|
|
|
887
906
|
- **Two enqueues are fine.** If Blocks and L&L both load the script, only the first copy installs.
|
|
888
907
|
- **Limit: the top layer.** A native modal puts everything else inert and renders above it. A React Select, datepicker or any widget portaled to `<body>` renders under the dialog and can't be used inside it. Keep such controls in the dialog's own markup.
|
|
889
908
|
|
|
909
|
+
## Vanilla accordion (no React)
|
|
910
|
+
|
|
911
|
+
Same delivery as the vanilla modal: `vanilla/accordion.min.js` plus the shared `vanilla/styles.css` (`styles.unlayered.css` in WordPress). Behaviour hangs off attributes, so keep your own classes if you have a look already; wear `tui-accordion__*` for TUI's.
|
|
912
|
+
|
|
913
|
+
```html
|
|
914
|
+
<script src="https://unpkg.com/@tangible/ui/vanilla/accordion.min.js" defer></script>
|
|
915
|
+
|
|
916
|
+
<div class="tui-accordion" data-tui-accordion="multiple">
|
|
917
|
+
<div class="tui-accordion__item" data-tui-accordion-item data-state="open">
|
|
918
|
+
<h3 class="tui-accordion__heading">
|
|
919
|
+
<button type="button" class="tui-accordion__trigger" data-tui-accordion-trigger>
|
|
920
|
+
<span class="tui-accordion__trigger-content">Brand</span>
|
|
921
|
+
</button>
|
|
922
|
+
</h3>
|
|
923
|
+
<div class="tui-accordion__panel" data-tui-accordion-panel>
|
|
924
|
+
<div class="tui-accordion__panel-content">…</div>
|
|
925
|
+
</div>
|
|
926
|
+
</div>
|
|
927
|
+
</div>
|
|
928
|
+
```
|
|
929
|
+
|
|
930
|
+
- **The script owns the state.** `aria-expanded`, `aria-controls`, ids, `data-state` (item, trigger, panel) and `inert` + `aria-hidden` on closed panels. Don't hide a panel any other way: a grid-row or height collapse alone leaves its controls tabbable and readable.
|
|
931
|
+
- **Modes.** `single` (default) keeps one open; add `data-tui-accordion-collapsible` to let it close. Without it, the open header is `aria-disabled` (APG), still focusable and unpainted, as in the React Accordion. `multiple` toggles each. Start an item open with `data-state="open"` on it.
|
|
932
|
+
- **Triggers are `<button>`s** in a heading at your page's level; `disabled` or `aria-disabled="true"` stops toggling.
|
|
933
|
+
- **Markup added after load** works for clicks; call `TangibleUI.accordion.sync(el)` so it paints its closed panels inert. `open`, `close` and `toggle` take an item, trigger or panel (or an id); `tui-accordion-toggle` bubbles from the item with `{ open, trigger, panel }`.
|
|
934
|
+
- **React and vanilla can share a page.** The React Accordion stamps `data-tui-accordion-trigger` as a styling hook; without the root and item attributes around it, the script leaves it alone.
|
|
935
|
+
|
|
890
936
|
## Known issues
|
|
891
937
|
|
|
892
938
|
Each is tracked in the repo, so **follow the link for current state rather than trusting this
|