@tangible/ui 0.2.15 → 0.2.17

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.
@@ -1,6 +1,14 @@
1
- import type { RadioProps } from './types';
2
1
  /**
3
2
  * Ref targets the inner `<button role="radio">`, not the outer wrapper `<div>`.
4
3
  * This is intentional — roving tabindex and focus management operate on the button.
5
4
  */
6
- export declare const Radio: import("react").ForwardRefExoticComponent<RadioProps & import("react").RefAttributes<HTMLButtonElement>>;
5
+ export declare const Radio: import("react").ForwardRefExoticComponent<{
6
+ value: import("..").MultiSelectOptionValue;
7
+ label?: import("react").ReactNode;
8
+ description?: string;
9
+ disabled?: boolean;
10
+ 'aria-label'?: string;
11
+ 'aria-labelledby'?: string;
12
+ className?: string;
13
+ children?: import("react").ReactNode;
14
+ } & Omit<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "hidden" | "className" | "role" | "aria-hidden" | "children" | "aria-label" | "tabIndex" | "aria-labelledby" | "inert"> & import("react").RefAttributes<HTMLButtonElement>>;
@@ -18,7 +18,7 @@ import { useRadioGroupContext } from './RadioGroupContext.js';
18
18
  * Ref targets the inner `<button role="radio">`, not the outer wrapper `<div>`.
19
19
  * This is intentional — roving tabindex and focus management operate on the button.
20
20
  */
21
- export const Radio = forwardRef(function Radio({ value, label, description, disabled = false, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, className, children, }, externalRef) {
21
+ export const Radio = forwardRef(function Radio({ value, label, description, disabled = false, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, className, children, ...rest }, externalRef) {
22
22
  const { selectedValue, focusableValue, rootDisabled, registerItem, unregisterItem, onSelect, } = useRadioGroupContext();
23
23
  const id = useId();
24
24
  const descriptionId = `${id}-desc`;
@@ -52,7 +52,7 @@ export const Radio = forwardRef(function Radio({ value, label, description, disa
52
52
  onSelect(value);
53
53
  };
54
54
  const hasExpandedContent = !!(description || children);
55
- return (_jsxs("div", { className: cx('tui-radio', hasExpandedContent && 'has-content', className), children: [_jsxs("button", { ref: composeRefs(callbackRef, externalRef), type: "button", role: "radio", className: "tui-radio__control", "aria-checked": isSelected, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-describedby": description ? descriptionId : undefined,
55
+ return (_jsxs("div", { ...rest, "aria-hidden": undefined, className: cx('tui-radio', hasExpandedContent && 'has-content', className), "data-value": value, "data-state": isSelected ? 'active' : 'inactive', "data-disabled": isDisabled || undefined, children: [_jsxs("button", { ref: composeRefs(callbackRef, externalRef), type: "button", role: "radio", className: "tui-radio__control", "aria-checked": isSelected, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-describedby": description ? descriptionId : undefined,
56
56
  // Item-level disabled: native disabled (removes from focus cycle).
57
57
  // Group-level disabled: aria-disabled (preserves AT group context).
58
58
  disabled: disabled || undefined, "aria-disabled": rootDisabled || undefined, tabIndex: isFocusable ? 0 : -1, onClick: handleClick, children: [_jsx("span", { className: "tui-radio__indicator", "aria-hidden": "true" }), label && _jsx("span", { className: "tui-radio__label", children: label })] }), hasExpandedContent && (_jsxs("div", { className: "tui-radio__body", children: [description && (_jsx("p", { id: descriptionId, className: "tui-radio__description", children: description })), children] }))] }));
@@ -1,4 +1,4 @@
1
- import type { ReactNode } from 'react';
1
+ import type { ComponentPropsWithoutRef, ReactNode } from 'react';
2
2
  import type { OptionValue } from '../../utils/value-key';
3
3
  import type { RovingItemRecord } from '../../utils/use-roving-group';
4
4
  export type RadioGroupProps = {
@@ -28,7 +28,7 @@ export type RadioProps = {
28
28
  'aria-labelledby'?: string;
29
29
  className?: string;
30
30
  children?: ReactNode;
31
- };
31
+ } & Omit<ComponentPropsWithoutRef<'div'>, 'className' | 'children' | 'aria-label' | 'aria-labelledby' | 'role' | 'tabIndex' | 'aria-hidden' | 'inert' | 'hidden'>;
32
32
  export type RadioItemRecord = RovingItemRecord;
33
33
  export type RadioGroupContextValue = {
34
34
  selectedValue: OptionValue | undefined;
@@ -5,6 +5,6 @@ type SegmentedControlCompound = {
5
5
  displayName?: string;
6
6
  Item: typeof Item;
7
7
  };
8
- declare function Item({ value, disabled, icon, 'aria-label': ariaLabel, className, children, }: SegmentedControlItemProps): import("react/jsx-runtime").JSX.Element;
8
+ declare function Item({ value, disabled, icon, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, className, children, ...rest }: SegmentedControlItemProps): import("react/jsx-runtime").JSX.Element;
9
9
  export declare const SegmentedControl: SegmentedControlCompound;
10
10
  export {};
@@ -66,7 +66,7 @@ function SegmentedControlRoot({ value: controlledValue, defaultValue, onValueCha
66
66
  // =============================================================================
67
67
  // SegmentedControl.Item
68
68
  // =============================================================================
69
- function Item({ value, disabled = false, icon, 'aria-label': ariaLabel, className, children, }) {
69
+ function Item({ value, disabled = false, icon, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, className, children, ...rest }) {
70
70
  const { selectedValue, focusableValue, rootDisabled, registerItem, unregisterItem, onSelect, } = useSegmentedControlContext();
71
71
  const isSelected = selectedValue !== undefined && toKey(selectedValue) === toKey(value);
72
72
  const isDisabled = rootDisabled || disabled;
@@ -90,7 +90,7 @@ function Item({ value, disabled = false, icon, 'aria-label': ariaLabel, classNam
90
90
  };
91
91
  const hasIcon = icon !== undefined && icon !== null;
92
92
  const hasChildren = children !== undefined && children !== null;
93
- return (_jsxs("button", { ref: callbackRef, type: "button", role: "radio", className: cx('tui-segmented__item', className), "aria-checked": isSelected, "aria-disabled": isDisabled || undefined, "aria-label": ariaLabel, tabIndex: isDisabled ? -1 : isFocusable ? 0 : -1, onClick: handleClick, children: [hasIcon && _jsx("span", { className: "tui-segmented__item-icon", children: icon }), hasChildren && _jsx("span", { className: "tui-segmented__item-label", children: children })] }));
93
+ return (_jsxs("button", { ...rest, "aria-hidden": undefined, ref: callbackRef, type: "button", role: "radio", className: cx('tui-segmented__item', className), "data-value": value, "data-state": isSelected ? 'active' : 'inactive', "data-disabled": isDisabled || undefined, "aria-checked": isSelected, "aria-disabled": isDisabled || undefined, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, tabIndex: isDisabled ? -1 : isFocusable ? 0 : -1, onClick: handleClick, children: [hasIcon && _jsx("span", { className: "tui-segmented__item-icon", children: icon }), hasChildren && _jsx("span", { className: "tui-segmented__item-label", children: children })] }));
94
94
  }
95
95
  // =============================================================================
96
96
  // Compound Component Export
@@ -1,4 +1,4 @@
1
- import type { ReactNode } from 'react';
1
+ import type { ComponentPropsWithoutRef, ReactNode } from 'react';
2
2
  import type { RovingItemRecord } from '../../utils/use-roving-group';
3
3
  import type { Size } from '../../types/sizes';
4
4
  export type SegmentedControlValue = string | number;
@@ -50,11 +50,21 @@ export type SegmentedControlItemProps = {
50
50
  icon?: ReactNode;
51
51
  /** Accessible label — required for icon-only items */
52
52
  'aria-label'?: string;
53
+ /**
54
+ * Accessible name by reference. Modelled explicitly, like `aria-label`
55
+ * above and like the group root already does — otherwise it rides
56
+ * `...rest` and its ordering relative to the group's own attributes is
57
+ * incidental. Forwarding is deliberate: it is a legitimate way to name an
58
+ * item from visible text elsewhere. It does OUTRANK the item's own label
59
+ * (AccName 2A), and an id that resolves to nothing empties the name
60
+ * entirely (step 2B) — so point it at an element that exists.
61
+ */
62
+ 'aria-labelledby'?: string;
53
63
  /** Additional classes */
54
64
  className?: string;
55
65
  /** Label content */
56
66
  children?: ReactNode;
57
- };
67
+ } & Omit<ComponentPropsWithoutRef<'button'>, 'value' | 'type' | 'role' | 'aria-checked' | 'aria-disabled' | 'tabIndex' | 'onClick' | 'disabled' | 'aria-label' | 'aria-labelledby' | 'className' | 'children' | 'aria-hidden' | 'inert' | 'hidden'>;
58
68
  export type ItemRecord = RovingItemRecord;
59
69
  export type SegmentedControlContextValue = {
60
70
  variant: SegmentedControlVariant;
@@ -11,7 +11,7 @@ declare function TabsList({ 'aria-label': ariaLabel, 'aria-labelledby': ariaLabe
11
11
  declare namespace TabsList {
12
12
  var displayName: string;
13
13
  }
14
- declare function Tab({ value, icon, 'aria-label': ariaLabel, disabled, className, children }: TabProps): import("react/jsx-runtime").JSX.Element;
14
+ declare function Tab({ value, icon, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, disabled, className, children, ...rest }: TabProps): import("react/jsx-runtime").JSX.Element;
15
15
  declare namespace Tab {
16
16
  var displayName: string;
17
17
  }
@@ -259,7 +259,7 @@ function TabsList({ 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy,
259
259
  // =============================================================================
260
260
  // Tabs.Tab
261
261
  // =============================================================================
262
- function Tab({ value, icon, 'aria-label': ariaLabel, disabled = false, className, children }) {
262
+ function Tab({ value, icon, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, disabled = false, className, children, ...rest }) {
263
263
  const { activationMode, activeValue, focusedValue, registerTab, unregisterTab, onSelect, getTabId, getPanelId, } = useTabsContext();
264
264
  const tabId = getTabId(value);
265
265
  const panelId = getPanelId(value);
@@ -299,7 +299,7 @@ function Tab({ value, icon, 'aria-label': ariaLabel, disabled = false, className
299
299
  onSelect(value);
300
300
  }
301
301
  };
302
- return (_jsxs("button", { ref: callbackRef, type: "button", role: "tab", id: tabId, className: cx('tui-tabs__tab', className), "data-tui-tab-value": value, "data-state": isActive ? 'active' : 'inactive', "aria-selected": isActive, "aria-controls": panelId, "aria-label": ariaLabel, "aria-disabled": disabled || undefined, tabIndex: disabled ? -1 : isFocusable ? 0 : -1, "data-disabled": disabled || undefined, onClick: handleClick, children: [icon && _jsx(Icon, { name: icon, "aria-hidden": "true" }), children && _jsx("span", { className: "tui-tabs__tab-label", children: children })] }));
302
+ return (_jsxs("button", { ...rest, "aria-hidden": undefined, ref: callbackRef, type: "button", role: "tab", id: tabId, className: cx('tui-tabs__tab', className), "data-tui-tab-value": value, "data-value": value, "data-state": isActive ? 'active' : 'inactive', "aria-selected": isActive, "aria-controls": panelId, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-disabled": disabled || undefined, tabIndex: disabled ? -1 : isFocusable ? 0 : -1, "data-disabled": disabled || undefined, onClick: handleClick, children: [icon && _jsx(Icon, { name: icon, "aria-hidden": "true" }), children && _jsx("span", { className: "tui-tabs__tab-label", children: children })] }));
303
303
  }
304
304
  // =============================================================================
305
305
  // Tabs.Panel
@@ -1,4 +1,4 @@
1
- import type { ReactNode } from 'react';
1
+ import type { ComponentPropsWithoutRef, ReactNode } from 'react';
2
2
  import type { IconName } from '../../icons/registry';
3
3
  export type TabsVariant = 'pill' | 'underline' | 'outline';
4
4
  export type TabsActivationMode = 'auto' | 'manual';
@@ -48,12 +48,22 @@ export type TabProps = {
48
48
  * without an accessible name, making it invisible to screen readers.
49
49
  */
50
50
  'aria-label'?: string;
51
+ /**
52
+ * Accessible name by reference. Modelled explicitly, like `aria-label`
53
+ * above and like the group root already does — otherwise it rides
54
+ * `...rest` and its ordering relative to the group's own attributes is
55
+ * incidental. Forwarding is deliberate: it is a legitimate way to name an
56
+ * item from visible text elsewhere. It does OUTRANK the item's own label
57
+ * (AccName 2A), and an id that resolves to nothing empties the name
58
+ * entirely (step 2B) — so point it at an element that exists.
59
+ */
60
+ 'aria-labelledby'?: string;
51
61
  /** Disable tab (skipped in keyboard nav) */
52
62
  disabled?: boolean;
53
63
  /** Additional classes */
54
64
  className?: string;
55
65
  children?: ReactNode;
56
- };
66
+ } & Omit<ComponentPropsWithoutRef<'button'>, 'value' | 'type' | 'role' | 'id' | 'aria-selected' | 'aria-controls' | 'aria-disabled' | 'tabIndex' | 'onClick' | 'disabled' | 'aria-label' | 'aria-labelledby' | 'className' | 'children' | 'aria-hidden' | 'inert' | 'hidden'>;
57
67
  export type TabPanelProps = {
58
68
  /** Must match a Tab value */
59
69
  value: string;
package/figma-tokens.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.2.15",
2
+ "version": "0.2.17",
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.",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangible/ui",
3
- "version": "0.2.15",
3
+ "version": "0.2.17",
4
4
  "description": "Tangible Design System",
5
5
  "type": "module",
6
6
  "main": "./components/index.js",
@@ -228,6 +228,66 @@ Useful primitives:
228
228
  `className` is for layout integration (margin, grid placement), not appearance. Beyond the token
229
229
  API the sanctioned escape hatch is to **swizzle** — copy the component source and own the fork.
230
230
 
231
+ ### Styling one member of a group
232
+
233
+ Selection components expose their state as attributes, so you can style a *particular* option
234
+ without threading a `className` through every item. `SegmentedControl.Item`, `Tabs.Tab` and `Radio`
235
+ carry `data-value` (the item's own value) and `data-state` (`active` / `inactive`), plus
236
+ `data-disabled` when disabled; `data-state` is the same vocabulary Accordion, Modal, Sidebar and
237
+ DataTable already use.
238
+
239
+ ```css
240
+ /* Grading control: failing red, passing green — only when chosen. */
241
+ .tui-segmented__item[data-value='fail'] {
242
+ --tui-segmented-item-bg-active: var(--tui-theme-danger-subtlest);
243
+ --tui-segmented-item-fg-active: var(--tui-theme-danger-stronger);
244
+ }
245
+ .tui-segmented__item[data-value='pass'] {
246
+ --tui-segmented-item-bg-active: var(--tui-theme-success-subtlest);
247
+ --tui-segmented-item-fg-active: var(--tui-theme-success-stronger);
248
+ }
249
+ ```
250
+
251
+ On `SegmentedControl`'s **outline** variant the selected *border* is the whole selection
252
+ indicator, and it has its own token — `--tui-segmented-item-border-active` (added 0.2.17). Before
253
+ that it read the theme token directly, so the fill and text were overridable per value and the
254
+ border was not. If you recolour a segment in the outline variant, move the border with the fill or
255
+ the option will read as the wrong colour outlined in the theme's:
256
+
257
+ ```css
258
+ .tui-segmented__item[data-value='fail'] {
259
+ --tui-segmented-item-bg-active: var(--tui-theme-danger-subtlest);
260
+ --tui-segmented-item-fg-active: var(--tui-theme-danger-stronger);
261
+ --tui-segmented-item-border-active: var(--tui-theme-danger-base);
262
+ }
263
+ ```
264
+
265
+ Check the border you pick against the **page**, not against the fill — it is a non-text indicator,
266
+ so WCAG SC 1.4.11 asks for 3:1 there, and a tone that looks right on the fill can fall under that
267
+ against a dark page. TUI's own defaults are 3.60:1 (dark) and 7.52:1 (light).
268
+
269
+ Reach for the component's own tokens inside the rule, as above, rather than setting `background`
270
+ directly — that keeps the hover and focus treatments the component already derives. Note that
271
+ `--tui-segmented-item-bg-active` only applies when the item *is* active, so the selector above does
272
+ not need `[data-state='active']` as well; add it when the property you are setting is not already
273
+ state-scoped. Token names come from `tui-manifest.json` → `cssTokens`.
274
+
275
+ **Recolour the foreground with the background.** The pairing above is `-subtlest` fill with
276
+ `-stronger` text — the two-sided pairing Chip already uses, and both halves move with the theme.
277
+ Setting only the fill to a `-base` tone leaves the default white-on-accent foreground behind, which
278
+ clears 4.5:1 in light mode and then fails it in dark, because the dark ladder lightens: danger drops
279
+ to 3.7:1 and success to 3.4:1. The ladder cannot rescue this on its own — "stronger" means more
280
+ contrast against the *page*, so in dark mode it moves the fill towards the text, not away from it.
281
+
282
+ All three items accept `aria-label` and `aria-labelledby` as declared props, so naming one from
283
+ visible text elsewhere is supported — but `aria-labelledby` **replaces** the item's own label
284
+ rather than adding to it, and an id that matches nothing empties the name completely. Point it at
285
+ an element that exists, and check the name you actually get.
286
+
287
+ `Radio` puts these on the wrapper `<div class="tui-radio">`, so a rule can reach the label and
288
+ description too. `Tabs.Tab` also carries `data-tui-tab-value`; that one is internal (Tabs reads it
289
+ back for focus lookup) — style against `data-value`.
290
+
231
291
  ### Replacing a trigger with `asChild`
232
292
 
233
293
  `Select.Trigger`, `Dropdown.Trigger`, `Popover.Trigger`, `Tooltip.Trigger`, `Accordion.Trigger`,
@@ -327,10 +387,17 @@ There are no device icons (monitor / tablet / phone) in any set.
327
387
  `data-testid` pass-through is uneven, and the split is not the one you would guess. These spread
328
388
  rest props onto their primary element: **Button, Card, Checkbox, Chip, ColorPicker, ColorField,
329
389
  `Field`'s slots, GradientPicker, IconButton, Modal, Notice, SearchInput, SearchSelect, Switch,
330
- Textarea, TextInput**, and **DataTable** (onto the `<table>`). Everything else drops them silently,
390
+ Textarea, TextInput**, **DataTable** (onto the `<table>`), and — since 0.2.16 — the group members
391
+ **SegmentedControl.Item, Tabs.Tab and Radio**. Everything else drops them silently,
331
392
  including several that look like they would take them — Dropdown, Popover, Tooltip, Select,
332
- MultiSelect, Combobox, MultiCombobox, Tabs, Sidebar, Toolbar, Pager, Radio, Rating, Progress,
333
- Avatar, Icon, Slider, MoveHandle, StepList, SegmentedControl, DatePicker.
393
+ MultiSelect, Combobox, MultiCombobox, Sidebar, Toolbar, Pager, Rating, Progress,
394
+ Avatar, Icon, Slider, MoveHandle, StepList, DatePicker.
395
+
396
+ Two notes on those three. **Radio spreads onto the wrapper `<div class="tui-radio">`, not the
397
+ control its ref targets** — the wrapper is where `className` already goes, and it is the element
398
+ holding the label and description. And on all three the spread is applied *before* the component's
399
+ own attributes, so a forwarded `role` or `aria-checked` cannot desynchronise the group from what it
400
+ announces; the props types omit those, so TypeScript rejects them rather than dropping them.
334
401
 
335
402
  Typecheck will not save you here: TypeScript exempts **hyphenated** JSX attributes from excess
336
403
  property checking, so `<Select data-testid="x" />` compiles clean against a prop type that has no