@tangible/ui 0.2.41 → 0.2.43
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/CommandPalette/CommandPalette.d.ts +30 -0
- package/components/CommandPalette/CommandPalette.js +409 -0
- package/components/CommandPalette/CommandPaletteContext.d.ts +31 -0
- package/components/CommandPalette/CommandPaletteContext.js +8 -0
- package/components/CommandPalette/index.d.ts +3 -0
- package/components/CommandPalette/index.js +2 -0
- package/components/CommandPalette/shortcut.d.ts +15 -0
- package/components/CommandPalette/shortcut.js +83 -0
- package/components/CommandPalette/types.d.ts +152 -0
- package/components/CommandPalette/types.js +16 -0
- package/components/IconButton/IconButton.js +5 -2
- package/components/IconButton/IconButtonCore.js +16 -4
- package/components/IconButton/badge.d.ts +20 -0
- package/components/IconButton/badge.js +22 -0
- package/components/IconButton/types.d.ts +54 -2
- package/components/IconButton/types.js +2 -0
- package/components/IconTile/IconTile.d.ts +16 -0
- package/components/IconTile/IconTile.js +17 -0
- package/components/IconTile/index.d.ts +2 -0
- package/components/IconTile/index.js +1 -0
- package/components/IconTile/types.d.ts +29 -0
- package/components/IconTile/types.js +1 -0
- package/components/SegmentedControl/SegmentedControl.js +2 -2
- package/components/SegmentedControl/types.d.ts +10 -0
- package/components/Table/DataTable.js +1 -1
- package/components/Table/types.d.ts +6 -0
- package/components/Table/types.js +3 -0
- package/components/index.d.ts +4 -0
- package/components/index.js +2 -0
- package/figma-tokens.json +101 -3
- package/icons/icons.svg +1 -1
- package/icons/sprite-version.js +1 -1
- package/icons/sprite.php +1 -1
- package/package.json +13 -1
- package/skills/building-with-tui/SKILL.md +33 -1
- package/styles/all.css +1 -1
- package/styles/all.expanded.css +563 -67
- package/styles/all.expanded.unlayered.css +563 -67
- package/styles/all.unlayered.css +1 -1
- package/styles/components/_bundle.scss +8 -0
- package/styles/components/avatar.scss +6 -23
- package/styles/components/button.scss +15 -15
- package/styles/components/chip.scss +35 -11
- package/styles/components/command-palette.scss +314 -0
- package/styles/components/content-indicator.scss +6 -1
- package/styles/components/date-picker.scss +1 -1
- package/styles/components/icon-button.scss +82 -11
- package/styles/components/icon-tile.scss +89 -0
- package/styles/components/input/index.scss +4 -0
- package/styles/components/multi-select.scss +1 -1
- package/styles/components/progress.scss +23 -0
- package/styles/components/segmented-control.scss +11 -1
- package/styles/components/step-indicator.scss +1 -1
- package/styles/components/tabs.scss +1 -1
- package/styles/core.css +1 -1
- package/styles/core.unlayered.css +1 -1
- package/styles/system/_constants.scss +5 -0
- package/styles/system/_palettes.scss +1 -0
- package/styles/system/_tokens.scss +40 -1
- package/tui-manifest.json +189 -5
- package/utils/color/theme.d.ts +66 -0
- package/utils/color/theme.js +232 -0
- package/vanilla/styles.css +1 -1
- package/vanilla/styles.unlayered.css +1 -1
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import type { ButtonHTMLAttributes, HTMLAttributes, ReactNode, RefObject } from 'react';
|
|
2
|
+
import type { IconSource } from '../Icon';
|
|
3
|
+
import type { SizeStandard } from '../../types';
|
|
4
|
+
import type { ListboxGroupProps, ListboxLabelProps } from '../../utils/listbox';
|
|
5
|
+
import type { OptionValue } from '../../utils/value-key';
|
|
6
|
+
/** Where the palette is in fetching results. */
|
|
7
|
+
export type CommandPaletteStatus = 'ready' | 'loading' | 'error';
|
|
8
|
+
export type CommandPaletteLabels = {
|
|
9
|
+
/** The dialog's name, rendered as a visually hidden heading. */
|
|
10
|
+
title: string;
|
|
11
|
+
/** The search field's accessible name. */
|
|
12
|
+
search: string;
|
|
13
|
+
/** The results list's accessible name. Distinct from `title`, so AT doesn't hear "Search" three times. */
|
|
14
|
+
list: string;
|
|
15
|
+
/** Placeholder text in the search field. */
|
|
16
|
+
placeholder: string;
|
|
17
|
+
/**
|
|
18
|
+
* The narrow-screen close button (wide screens show an Esc hint instead).
|
|
19
|
+
* "Cancel" rather than `hintClose`'s "Close": it's the touch-sheet
|
|
20
|
+
* convention, and the two never show at once.
|
|
21
|
+
*/
|
|
22
|
+
close: string;
|
|
23
|
+
/** Read with the field when results have an `href`, so the new-tab keys are discoverable. */
|
|
24
|
+
newTabHint: string;
|
|
25
|
+
/** Visible and announced when nothing matches. */
|
|
26
|
+
noResults: (query: string) => string;
|
|
27
|
+
/** Announced as the result count changes. */
|
|
28
|
+
results: (count: number) => string;
|
|
29
|
+
/** Visible and announced while `status` is `loading`. */
|
|
30
|
+
loading: string;
|
|
31
|
+
/** Visible and announced while `status` is `error`. */
|
|
32
|
+
error: string;
|
|
33
|
+
/** The retry button, shown with `onRetry` while `status` is `error`. */
|
|
34
|
+
retry: string;
|
|
35
|
+
/** Footer hint for the arrow keys. */
|
|
36
|
+
hintNavigate: string;
|
|
37
|
+
/** Footer hint for Enter. */
|
|
38
|
+
hintOpen: string;
|
|
39
|
+
/** Footer hint for Escape. */
|
|
40
|
+
hintClose: string;
|
|
41
|
+
};
|
|
42
|
+
export declare const defaultCommandPaletteLabels: CommandPaletteLabels;
|
|
43
|
+
/** Extra detail handed to `onSelect`. */
|
|
44
|
+
export type CommandPaletteSelectDetail = {
|
|
45
|
+
/** The item's `href`, when it has one. */
|
|
46
|
+
href?: string;
|
|
47
|
+
};
|
|
48
|
+
/** Custom match for built-in filtering. `keywords` are the item's own, unjoined. */
|
|
49
|
+
export type CommandPaletteFilter = (text: string, query: string, keywords: readonly string[]) => boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Remaining props (`id`, `data-testid`, `aria-describedby`…) land on the
|
|
52
|
+
* dialog element.
|
|
53
|
+
*/
|
|
54
|
+
export type CommandPaletteProps = Omit<HTMLAttributes<HTMLDivElement>, 'role' | 'aria-modal' | 'tabIndex' | 'children' | 'onSelect' | 'aria-labelledby' | 'defaultValue'> & {
|
|
55
|
+
/** Whether the palette is showing (controlled). Pair with `onOpenChange`. */
|
|
56
|
+
open?: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Initial state when `open` is uncontrolled: enough for a palette opened
|
|
59
|
+
* only by its `shortcut`. A separate `Trigger` needs controlled `open`.
|
|
60
|
+
* @default false
|
|
61
|
+
*/
|
|
62
|
+
defaultOpen?: boolean;
|
|
63
|
+
/** Called to open or close: Escape, the backdrop, a selection, the shortcut. */
|
|
64
|
+
onOpenChange?: (open: boolean) => void;
|
|
65
|
+
/**
|
|
66
|
+
* The search text (controlled). Controlling it hands filtering to you: every
|
|
67
|
+
* item you render is shown, so filter (or fetch) before rendering. Leave it
|
|
68
|
+
* uncontrolled and the palette filters items by their text and `keywords`.
|
|
69
|
+
*/
|
|
70
|
+
inputValue?: string;
|
|
71
|
+
/** Called with the search text on every change. */
|
|
72
|
+
onInputChange?: (value: string) => void;
|
|
73
|
+
/**
|
|
74
|
+
* Custom match for built-in filtering, or `false` to show every item.
|
|
75
|
+
* Ignored when `inputValue` is controlled.
|
|
76
|
+
* @default case-insensitive substring match on the item's text or any keyword
|
|
77
|
+
*/
|
|
78
|
+
filter?: CommandPaletteFilter | false;
|
|
79
|
+
/**
|
|
80
|
+
* Called when an item is chosen with Enter or a click. When it's omitted, an
|
|
81
|
+
* item with an `href` navigates there (http, https and relative URLs only).
|
|
82
|
+
* Opening an `href` in a new tab (Cmd/Ctrl+Enter, Cmd/Ctrl+click,
|
|
83
|
+
* middle-click) never calls it: items are options, not links, so these are
|
|
84
|
+
* the only new-tab routes.
|
|
85
|
+
*/
|
|
86
|
+
onSelect?: (value: OptionValue, detail: CommandPaletteSelectDetail) => void;
|
|
87
|
+
/**
|
|
88
|
+
* `loading` and `error` show a message under the results, which is also
|
|
89
|
+
* announced. Items you still render stay visible and navigable.
|
|
90
|
+
* @default 'ready'
|
|
91
|
+
*/
|
|
92
|
+
status?: CommandPaletteStatus;
|
|
93
|
+
/** Shows a retry button in the `error` state. */
|
|
94
|
+
onRetry?: () => void;
|
|
95
|
+
/**
|
|
96
|
+
* A global shortcut that toggles the palette, e.g. `"mod+k"` (`mod` is Cmd
|
|
97
|
+
* on Apple platforms, Ctrl elsewhere). Omit for none. A shortcut without
|
|
98
|
+
* `mod` or `alt` (such as `"/"`) is ignored while the user is typing in a
|
|
99
|
+
* field. Avoid `alt+<letter>` on macOS, where Option changes the character.
|
|
100
|
+
* The shortcut stands down while another modal dialog is open.
|
|
101
|
+
*/
|
|
102
|
+
shortcut?: string;
|
|
103
|
+
/**
|
|
104
|
+
* Show the keyboard hints footer. It is hidden on narrow screens regardless.
|
|
105
|
+
* @default true
|
|
106
|
+
*/
|
|
107
|
+
showHints?: boolean;
|
|
108
|
+
/** Where focus returns on close. Defaults to whatever had focus on open. */
|
|
109
|
+
restoreFocusTo?: RefObject<HTMLElement | null> | (() => HTMLElement | null);
|
|
110
|
+
labels?: Partial<CommandPaletteLabels>;
|
|
111
|
+
className?: string;
|
|
112
|
+
/** `CommandPalette.Group`s and `CommandPalette.Item`s. */
|
|
113
|
+
children?: ReactNode;
|
|
114
|
+
};
|
|
115
|
+
export type CommandPaletteItemProps = {
|
|
116
|
+
/** Handed to `onSelect`. Unique within the palette. */
|
|
117
|
+
value: OptionValue;
|
|
118
|
+
/** Searchable text, when `children` isn't a plain string. */
|
|
119
|
+
textValue?: string;
|
|
120
|
+
/** Extra words that match in built-in filtering but aren't shown. */
|
|
121
|
+
keywords?: string[];
|
|
122
|
+
/** A leading icon. */
|
|
123
|
+
icon?: IconSource;
|
|
124
|
+
/** A second, muted line. */
|
|
125
|
+
description?: ReactNode;
|
|
126
|
+
/** A destination. Cmd/Ctrl+Enter opens it in a new tab. */
|
|
127
|
+
href?: string;
|
|
128
|
+
/** Keep the palette open after this item is chosen. */
|
|
129
|
+
keepOpen?: boolean;
|
|
130
|
+
disabled?: boolean;
|
|
131
|
+
className?: string;
|
|
132
|
+
children?: ReactNode;
|
|
133
|
+
};
|
|
134
|
+
export type CommandPaletteGroupProps = ListboxGroupProps;
|
|
135
|
+
export type CommandPaletteLabelProps = ListboxLabelProps;
|
|
136
|
+
export type CommandPaletteTriggerProps = Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'children' | 'type'> & {
|
|
137
|
+
/**
|
|
138
|
+
* Visible text, which is also the button's accessible name.
|
|
139
|
+
* @default defaultCommandPaletteLabels.placeholder ("Search…")
|
|
140
|
+
*/
|
|
141
|
+
children?: ReactNode;
|
|
142
|
+
/**
|
|
143
|
+
* Shown as a key hint and in `aria-keyshortcuts`, e.g. `"mod+k"`. Display
|
|
144
|
+
* only: it registers nothing, so match the palette's own `shortcut`.
|
|
145
|
+
*/
|
|
146
|
+
shortcut?: string;
|
|
147
|
+
/**
|
|
148
|
+
* Control height tier, as for the form controls. App headers usually want `sm`.
|
|
149
|
+
* @default 'md'
|
|
150
|
+
*/
|
|
151
|
+
size?: SizeStandard;
|
|
152
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export const defaultCommandPaletteLabels = {
|
|
2
|
+
title: 'Search',
|
|
3
|
+
search: 'Search',
|
|
4
|
+
list: 'Search results',
|
|
5
|
+
placeholder: 'Search…',
|
|
6
|
+
close: 'Cancel',
|
|
7
|
+
newTabHint: 'Press Control or Command with Enter to open a page in a new tab.',
|
|
8
|
+
noResults: (query) => (query ? `No results for “${query}”` : 'No results'),
|
|
9
|
+
results: (count) => (count === 1 ? '1 result' : `${count} results`),
|
|
10
|
+
loading: 'Searching…',
|
|
11
|
+
error: 'Something went wrong while searching.',
|
|
12
|
+
retry: 'Try again',
|
|
13
|
+
hintNavigate: 'Navigate',
|
|
14
|
+
hintOpen: 'Open',
|
|
15
|
+
hintClose: 'Close',
|
|
16
|
+
};
|
|
@@ -2,6 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { forwardRef } from 'react';
|
|
3
3
|
import { Tooltip } from '../Tooltip/index.js';
|
|
4
4
|
import { IconButtonCore } from './IconButtonCore.js';
|
|
5
|
+
import { resolveBadge } from './badge.js';
|
|
5
6
|
// =============================================================================
|
|
6
7
|
// IconButton Component
|
|
7
8
|
// =============================================================================
|
|
@@ -24,7 +25,9 @@ export const IconButton = forwardRef((props, ref) => {
|
|
|
24
25
|
if (!showTooltip)
|
|
25
26
|
return element;
|
|
26
27
|
return (
|
|
27
|
-
// The tooltip shows the
|
|
28
|
-
|
|
28
|
+
// The tooltip shows the button's name, badge count included ("Notifications,
|
|
29
|
+
// 5 new"), so its words match what AT hears. Not the busy name: loading
|
|
30
|
+
// is shown by the spinner.
|
|
31
|
+
_jsxs(Tooltip, { type: "label", children: [_jsx(Tooltip.Trigger, { asChild: true, children: element }), _jsx(Tooltip.Content, { side: tooltipSide, children: resolveBadge(props).name })] }));
|
|
29
32
|
});
|
|
30
33
|
IconButton.displayName = 'IconButton';
|
|
@@ -7,6 +7,7 @@ import { isDev } from '../../utils/is-dev.js';
|
|
|
7
7
|
import { composeRefs } from '../../utils/compose-refs.js';
|
|
8
8
|
import { useLoadingAnnouncer } from '../../utils/use-loading-announcer.js';
|
|
9
9
|
import { defaultIconButtonLabels } from './types.js';
|
|
10
|
+
import { resolveBadge } from './badge.js';
|
|
10
11
|
// =============================================================================
|
|
11
12
|
// IconButtonCore (@internal)
|
|
12
13
|
// =============================================================================
|
|
@@ -30,10 +31,19 @@ import { defaultIconButtonLabels } from './types.js';
|
|
|
30
31
|
//
|
|
31
32
|
// =============================================================================
|
|
32
33
|
export const IconButtonCore = forwardRef((props, ref) => {
|
|
33
|
-
const { icon, label, size = 'sm', theme = 'secondary', variant = 'ghost', disabled = false, loading = false, loadingLabel: loadingLabelProp, labels: labelsProp, pressed, shape = 'square', className, ...restWithStray } = props;
|
|
34
|
+
const { icon, label, size = 'sm', theme = 'secondary', variant = 'ghost', disabled = false, loading = false, loadingLabel: loadingLabelProp, labels: labelsProp, pressed, shape = 'square', badge, badgeDot, badgeMax, className, ...restWithStray } = props;
|
|
34
35
|
const stray = restWithStray;
|
|
35
36
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
36
37
|
const { showTooltip: strayShowTooltip, tooltipSide: _tooltipSide, ...rest } = stray;
|
|
38
|
+
// `aria-label` is omitted from the props type, but JSX lets hyphenated
|
|
39
|
+
// attributes through anyway (see CLAUDE.md), so read it untyped.
|
|
40
|
+
const restAria = rest;
|
|
41
|
+
const overridesName = restAria['aria-label'] !== undefined || restAria['aria-labelledby'] !== undefined;
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
if (isDev() && overridesName && (badge || badgeDot)) {
|
|
44
|
+
console.warn(`IconButton ("${label}"): \`aria-label\` or \`aria-labelledby\` replaces the name the badge is spoken in, so screen readers won't hear the count. Use \`label\` and \`labels.badgeCount\` instead.`);
|
|
45
|
+
}
|
|
46
|
+
}, [overridesName, badge, badgeDot, label]);
|
|
37
47
|
useEffect(() => {
|
|
38
48
|
if (isDev() && strayShowTooltip) {
|
|
39
49
|
console.warn(`IconButtonCore ("${label}"): \`showTooltip\` does nothing here. A component that offers the tooltip must render IconButton.`);
|
|
@@ -44,14 +54,16 @@ export const IconButtonCore = forwardRef((props, ref) => {
|
|
|
44
54
|
// Loading keeps focus (see Button): aria-disabled plus a click guard, never
|
|
45
55
|
// native `disabled` or a dropped href. Only explicit `disabled` goes native.
|
|
46
56
|
const loadingOnly = loading && !disabled;
|
|
47
|
-
const resolvedLabel = loading ? (loadingLabelProp ?? `${label}, loading`) : label;
|
|
48
57
|
const labels = { ...defaultIconButtonLabels, ...labelsProp };
|
|
58
|
+
const badgeState = resolveBadge({ label, badge, badgeDot, badgeMax, labels: labelsProp });
|
|
59
|
+
const namedLabel = badgeState.name;
|
|
60
|
+
const resolvedLabel = loading ? (loadingLabelProp ?? `${namedLabel}, loading`) : namedLabel;
|
|
49
61
|
// Opt-in loading announcements (#131): portaled, so no DOM sibling.
|
|
50
62
|
const elementRef = useRef(null);
|
|
51
63
|
const announcer = useLoadingAnnouncer(elementRef, loading, labels.loadingStart, labels.loadingEnd);
|
|
52
64
|
const mergedRef = useMemo(() => composeRefs(ref, elementRef), [ref]);
|
|
53
|
-
const classes = cx('tui-icon-button', `is-size-${size}`, `is-theme-${theme}`, `is-style-${variant}`, isDisabled && 'is-disabled', shape === 'circle' && 'is-shape-circle', className);
|
|
54
|
-
const iconContent = (_jsxs(_Fragment, { children: [_jsx(Icon, { name: icon }), loading && _jsx("span", { className: "tui-icon-button__spinner", "aria-hidden": "true" })] }));
|
|
65
|
+
const classes = cx('tui-icon-button', `is-size-${size}`, `is-theme-${theme}`, `is-style-${variant}`, isDisabled && 'is-disabled', shape === 'circle' && 'is-shape-circle', badgeState.shown && 'has-badge', className);
|
|
66
|
+
const iconContent = (_jsxs(_Fragment, { children: [_jsx(Icon, { name: icon }), loading && _jsx("span", { className: "tui-icon-button__spinner", "aria-hidden": "true" }), badgeState.shown && (_jsx("span", { className: cx('tui-icon-button__badge', badgeState.dot && 'is-dot'), "aria-hidden": "true", "data-count": badgeState.count || undefined, children: badgeState.text }))] }));
|
|
55
67
|
// Render the base element (button or anchor)
|
|
56
68
|
let element;
|
|
57
69
|
if (isLink) {
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { IconButtonLabels } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* The badge's count, visible text and the button name it produces. One
|
|
4
|
+
* function, so the button's name and its label tooltip can't drift apart.
|
|
5
|
+
* Not a component file, so IconButton.tsx stays component-only.
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export declare function resolveBadge(options: {
|
|
9
|
+
label: string;
|
|
10
|
+
badge?: number;
|
|
11
|
+
badgeDot?: boolean;
|
|
12
|
+
badgeMax?: number;
|
|
13
|
+
labels?: IconButtonLabels;
|
|
14
|
+
}): {
|
|
15
|
+
shown: boolean;
|
|
16
|
+
dot: boolean;
|
|
17
|
+
count: number;
|
|
18
|
+
text: string;
|
|
19
|
+
name: string;
|
|
20
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { defaultIconButtonLabels } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* The badge's count, visible text and the button name it produces. One
|
|
4
|
+
* function, so the button's name and its label tooltip can't drift apart.
|
|
5
|
+
* Not a component file, so IconButton.tsx stays component-only.
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export function resolveBadge(options) {
|
|
9
|
+
const { label, badge, badgeDot = false, labels: labelsProp } = options;
|
|
10
|
+
const labels = { ...defaultIconButtonLabels, ...labelsProp };
|
|
11
|
+
// A count is a positive whole number; anything else (0, NaN, negative) is
|
|
12
|
+
// no count, so `badge={items.length}` needs no guard at the call site.
|
|
13
|
+
const count = typeof badge === 'number' && Number.isFinite(badge) && badge >= 1 ? Math.floor(badge) : 0;
|
|
14
|
+
const rawMax = options.badgeMax ?? 99;
|
|
15
|
+
const max = Number.isFinite(rawMax) ? Math.max(1, Math.floor(rawMax)) : 99;
|
|
16
|
+
const shown = count > 0 || badgeDot;
|
|
17
|
+
const text = badgeDot || count === 0 ? '' : count > max ? `${max}+` : String(count);
|
|
18
|
+
// The badge is aria-hidden; its meaning goes into the name instead. A
|
|
19
|
+
// count beats the dot for the name, so a dot that stands for 5 says 5.
|
|
20
|
+
const name = count > 0 ? labels.badgeCount(count, label) : badgeDot ? labels.badgeDot(label) : label;
|
|
21
|
+
return { shown, dot: badgeDot, count, text, name };
|
|
22
|
+
}
|
|
@@ -16,6 +16,20 @@ export type IconButtonLabels = {
|
|
|
16
16
|
* @default '' (not announced)
|
|
17
17
|
*/
|
|
18
18
|
loadingEnd?: string;
|
|
19
|
+
/**
|
|
20
|
+
* The button's whole name when it has a count: "Notifications, 5 new". It
|
|
21
|
+
* gets the count and `label`, so a translation can put them in any order.
|
|
22
|
+
* Say what the count counts when "new" doesn't fit, and mind plurals:
|
|
23
|
+
* `(n, label) => \`${label}, ${n === 1 ? '1 item' : \`${n} items\`}\``
|
|
24
|
+
* for a cart (or `Intl.PluralRules`).
|
|
25
|
+
* @default (count, label) => `${label}, ${count} new`
|
|
26
|
+
*/
|
|
27
|
+
badgeCount?: (count: number, label: string) => string;
|
|
28
|
+
/**
|
|
29
|
+
* The button's whole name when `badgeDot` is set and there's no count.
|
|
30
|
+
* @default (label) => `${label}, new`
|
|
31
|
+
*/
|
|
32
|
+
badgeDot?: (label: string) => string;
|
|
19
33
|
};
|
|
20
34
|
export declare const defaultIconButtonLabels: Required<IconButtonLabels>;
|
|
21
35
|
type IconButtonBaseProps = {
|
|
@@ -89,8 +103,9 @@ type IconButtonBaseProps = {
|
|
|
89
103
|
*/
|
|
90
104
|
loading?: boolean;
|
|
91
105
|
/**
|
|
92
|
-
* Accessible label override during loading state. For i18n support.
|
|
93
|
-
*
|
|
106
|
+
* Accessible label override during loading state. For i18n support. It
|
|
107
|
+
* is the whole busy name: include the badge count yourself if it matters.
|
|
108
|
+
* @default `${name}, loading` (English), where `name` includes any badge
|
|
94
109
|
*/
|
|
95
110
|
loadingLabel?: string;
|
|
96
111
|
/**
|
|
@@ -120,6 +135,43 @@ type IconButtonBaseProps = {
|
|
|
120
135
|
* @default 'top'
|
|
121
136
|
*/
|
|
122
137
|
tooltipSide?: 'top' | 'right' | 'bottom' | 'left';
|
|
138
|
+
/**
|
|
139
|
+
* A count on the button's corner: unread notifications, items in a cart.
|
|
140
|
+
* Above `badgeMax` it shows "99+". `0`, a negative or a non-number shows
|
|
141
|
+
* nothing, so `badge={items.length}` needs no guard.
|
|
142
|
+
*
|
|
143
|
+
* The count is part of the button's name, not only its look: "Notifications,
|
|
144
|
+
* 5 new" (`labels.badgeCount`). The full count is spoken even when the badge
|
|
145
|
+
* is capped. Anything that replaces the name replaces the count with it: an
|
|
146
|
+
* `aria-label` or `aria-labelledby` (a dev warning fires), and
|
|
147
|
+
* `loadingLabel`, which is the whole busy name.
|
|
148
|
+
*
|
|
149
|
+
* A change of count is NOT announced: the name changes silently on a button
|
|
150
|
+
* the user isn't on. If people need to know about an arrival right away,
|
|
151
|
+
* tell them with your own status message (a Toast).
|
|
152
|
+
*
|
|
153
|
+
* The badge overhangs the button's end edge (a "99+" by about 10px at `sm`)
|
|
154
|
+
* and paints above later siblings, so leave a gap after a badged button.
|
|
155
|
+
* Its colour doesn't follow `theme`: it is `--tui-icon-button-badge-bg`
|
|
156
|
+
* (primary by default) on every button. Set `--tui-icon-button-badge-ring`
|
|
157
|
+
* to the surface the button sits on (a header) so its cut-out blends in.
|
|
158
|
+
* @example badge={unreadCount}
|
|
159
|
+
*/
|
|
160
|
+
badge?: number;
|
|
161
|
+
/**
|
|
162
|
+
* Show the badge as a dot instead of a number: "there's something new"
|
|
163
|
+
* without a count, or a quieter look for one. With a `badge` count as well,
|
|
164
|
+
* the dot still speaks the count in the name.
|
|
165
|
+
* @default false
|
|
166
|
+
*/
|
|
167
|
+
badgeDot?: boolean;
|
|
168
|
+
/**
|
|
169
|
+
* The largest count the badge shows; above it, the badge reads "99+". At
|
|
170
|
+
* `xs`, consider 9: a wide count overhangs a small button a long way.
|
|
171
|
+
* Whole numbers of 1 or more.
|
|
172
|
+
* @default 99
|
|
173
|
+
*/
|
|
174
|
+
badgeMax?: number;
|
|
123
175
|
/**
|
|
124
176
|
* Button shape. Use `'circle'` for avatar-adjacent actions, FABs,
|
|
125
177
|
* or anywhere a round affordance is expected.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An icon in a tinted tile: a stat's category, an empty state, a step in a
|
|
3
|
+
* list. Avatar's sibling. Avatar is a person, drawn from their name; IconTile
|
|
4
|
+
* is a thing, coloured by meaning (a theme). They share one size ladder so
|
|
5
|
+
* they line up in the same list.
|
|
6
|
+
*
|
|
7
|
+
* Decorative by default: the text beside it says what it means. Give it a
|
|
8
|
+
* `label` when it stands alone. Not interactive: wrap it in a Button to act.
|
|
9
|
+
*/
|
|
10
|
+
export declare const IconTile: import("react").ForwardRefExoticComponent<Omit<import("react").HTMLAttributes<HTMLSpanElement>, "role" | "aria-hidden" | "children" | "aria-label" | "tabIndex" | "aria-labelledby"> & {
|
|
11
|
+
icon: import("..").IconSource;
|
|
12
|
+
size?: import("./types").IconTileSize;
|
|
13
|
+
shape?: import("./types").IconTileShape;
|
|
14
|
+
theme?: import("./types").IconTileTheme;
|
|
15
|
+
label?: string;
|
|
16
|
+
} & import("react").RefAttributes<HTMLSpanElement>>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef } from "react";
|
|
3
|
+
import { cx } from "../../utils/cx.js";
|
|
4
|
+
import { Icon } from "../Icon/index.js";
|
|
5
|
+
/**
|
|
6
|
+
* An icon in a tinted tile: a stat's category, an empty state, a step in a
|
|
7
|
+
* list. Avatar's sibling. Avatar is a person, drawn from their name; IconTile
|
|
8
|
+
* is a thing, coloured by meaning (a theme). They share one size ladder so
|
|
9
|
+
* they line up in the same list.
|
|
10
|
+
*
|
|
11
|
+
* Decorative by default: the text beside it says what it means. Give it a
|
|
12
|
+
* `label` when it stands alone. Not interactive: wrap it in a Button to act.
|
|
13
|
+
*/
|
|
14
|
+
export const IconTile = forwardRef(function IconTile({ icon, size = "md", shape = "square", theme = "primary", label, className, ...rest }, ref) {
|
|
15
|
+
const name = label?.trim();
|
|
16
|
+
return (_jsx("span", { ...rest, ref: ref, className: cx("tui-icon-tile", `is-size-${size}`, `is-shape-${shape}`, `is-theme-${theme}`, className), role: name ? "img" : undefined, "aria-label": name || undefined, "aria-hidden": name ? undefined : true, "aria-labelledby": undefined, tabIndex: undefined, children: _jsx(Icon, { name: icon }) }));
|
|
17
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { IconTile } from "./IconTile.js";
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { HTMLAttributes } from "react";
|
|
2
|
+
import type { SizeExtended, ThemeIntent, ThemeStatus } from "../../types";
|
|
3
|
+
import type { IconSource } from "../Icon";
|
|
4
|
+
/** Avatar's box ladder: xs 24, sm 32, md 40, lg 48, xl 64, xxl 80 */
|
|
5
|
+
export type IconTileSize = SizeExtended;
|
|
6
|
+
export type IconTileShape = "square" | "circle";
|
|
7
|
+
export type IconTileTheme = ThemeIntent | ThemeStatus;
|
|
8
|
+
/**
|
|
9
|
+
* Not interactive, so no tabIndex; and named only through `label`, so no
|
|
10
|
+
* aria-labelledby (it would outrank `label`, and a dangling id blanks the
|
|
11
|
+
* name). To make a tile act, wrap it in a Button.
|
|
12
|
+
*/
|
|
13
|
+
export type IconTileProps = Omit<HTMLAttributes<HTMLSpanElement>, "children" | "role" | "aria-label" | "aria-labelledby" | "aria-hidden" | "tabIndex"> & {
|
|
14
|
+
/** The icon, by registry name (`"system/folder"`) or as an imported icon component */
|
|
15
|
+
icon: IconSource;
|
|
16
|
+
/** Default `md` (40px). The same ladder as Avatar, so the two line up in a list. */
|
|
17
|
+
size?: IconTileSize;
|
|
18
|
+
/** Default `square` (radius-md) */
|
|
19
|
+
shape?: IconTileShape;
|
|
20
|
+
/** Default `primary`. Meaning, not identity: the tint and icon colour follow the theme. */
|
|
21
|
+
theme?: IconTileTheme;
|
|
22
|
+
/**
|
|
23
|
+
* Names the tile as an image. Leave it out when the text beside the tile
|
|
24
|
+
* already says what it means (the usual case): the tile is then decorative
|
|
25
|
+
* and hidden from assistive tech. Don't repeat text that's already beside it,
|
|
26
|
+
* or it's read twice. Blank or whitespace-only counts as no label.
|
|
27
|
+
*/
|
|
28
|
+
label?: string;
|
|
29
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -8,7 +8,7 @@ import { SegmentedControlContext, useSegmentedControlContext } from './Segmented
|
|
|
8
8
|
// =============================================================================
|
|
9
9
|
// SegmentedControl Root
|
|
10
10
|
// =============================================================================
|
|
11
|
-
function SegmentedControlRoot({ value: controlledValue, defaultValue, onValueChange, variant = 'pill', size = 'md', orientation = 'horizontal', loop = true, wrap = false, disabled = false, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, className, children, }) {
|
|
11
|
+
function SegmentedControlRoot({ value: controlledValue, defaultValue, onValueChange, variant = 'pill', size = 'md', orientation = 'horizontal', loop = true, wrap = false, disabled = false, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, 'aria-describedby': ariaDescribedBy, 'aria-invalid': ariaInvalid, 'aria-required': ariaRequired, className, children, }) {
|
|
12
12
|
const [internalValue, setInternalValue] = useState(defaultValue);
|
|
13
13
|
// Lock controlled/uncontrolled decision at mount to prevent mode switching
|
|
14
14
|
const isControlled = useRef(controlledValue !== undefined).current;
|
|
@@ -61,7 +61,7 @@ function SegmentedControlRoot({ value: controlledValue, defaultValue, onValueCha
|
|
|
61
61
|
unregisterItem,
|
|
62
62
|
onSelect,
|
|
63
63
|
]);
|
|
64
|
-
return (_jsx(SegmentedControlContext.Provider, { value: contextValue, children: _jsx("div", { role: "radiogroup", className: cx('tui-segmented', `is-variant-${variant}`, `is-size-${size}`, orientation === 'vertical' && 'is-vertical', wrap && 'is-wrap', className), "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-disabled": disabled || undefined, "aria-orientation": orientation, onKeyDown: handleKeyDown, children: children }) }));
|
|
64
|
+
return (_jsx(SegmentedControlContext.Provider, { value: contextValue, children: _jsx("div", { role: "radiogroup", className: cx('tui-segmented', `is-variant-${variant}`, `is-size-${size}`, orientation === 'vertical' && 'is-vertical', wrap && 'is-wrap', className), "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, "aria-invalid": ariaInvalid, "aria-required": ariaRequired, "aria-disabled": disabled || undefined, "aria-orientation": orientation, onKeyDown: handleKeyDown, children: children }) }));
|
|
65
65
|
}
|
|
66
66
|
// =============================================================================
|
|
67
67
|
// SegmentedControl.Item
|
|
@@ -34,6 +34,16 @@ export type SegmentedControlProps = {
|
|
|
34
34
|
* At least one of `aria-label` or `aria-labelledby` is required.
|
|
35
35
|
*/
|
|
36
36
|
'aria-labelledby'?: string;
|
|
37
|
+
/**
|
|
38
|
+
* Help or error text, by id. Declared (not left to a rest spread) so
|
|
39
|
+
* Field.Control's injection reaches the radiogroup: help and errors are
|
|
40
|
+
* announced, as on RadioGroup.
|
|
41
|
+
*/
|
|
42
|
+
'aria-describedby'?: string;
|
|
43
|
+
/** Marks the group invalid; Field.Control injects it from `error` */
|
|
44
|
+
'aria-invalid'?: boolean | 'true' | 'false';
|
|
45
|
+
/** Marks the group required; Field.Control injects it from `required` */
|
|
46
|
+
'aria-required'?: boolean | 'true' | 'false';
|
|
37
47
|
/** Additional classes */
|
|
38
48
|
className?: string;
|
|
39
49
|
children: ReactNode;
|
|
@@ -237,7 +237,7 @@ enableRowSelection = false, getRowId, getRowLabelForSelection, onSelectionChange
|
|
|
237
237
|
selectedRowIds,
|
|
238
238
|
clearSelection: () => table.resetRowSelection(),
|
|
239
239
|
selectedCount
|
|
240
|
-
})) : (_jsx(BulkActionsBar, { count: selectedCount, onClear: () => table.resetRowSelection(), "aria-controls": tableId }))), _jsxs("table", { ...rest, id: tableId, className: "tui-table", "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-busy": loading || undefined, children: [_jsx("thead", { className: "tui-table__head", children: table.getHeaderGroups().map((headerGroup) => (_jsx("tr", { className: "tui-table__row tui-table__row--head", children: headerGroup.headers.map((header) => {
|
|
240
|
+
})) : (_jsx(BulkActionsBar, { count: selectedCount, onClear: () => table.resetRowSelection(), "aria-controls": tableId, labels: { selected: labels.bulkSelected, actions: labels.bulkActions }, clearLabel: labels.bulkClear }))), _jsxs("table", { ...rest, id: tableId, className: "tui-table", "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-busy": loading || undefined, children: [_jsx("thead", { className: "tui-table__head", children: table.getHeaderGroups().map((headerGroup) => (_jsx("tr", { className: "tui-table__row tui-table__row--head", children: headerGroup.headers.map((header) => {
|
|
241
241
|
const canSort = header.column.getCanSort();
|
|
242
242
|
const sortDirection = header.column.getIsSorted();
|
|
243
243
|
const headerDef = header.column.columnDef.header;
|
|
@@ -16,5 +16,11 @@ export type DataTableLabels = {
|
|
|
16
16
|
sortBy?: (column: string) => string;
|
|
17
17
|
/** Live-region announcement after sorting. Default: `` `Sorted by ${column}, ${direction}` `` */
|
|
18
18
|
sorted?: (column: string, direction: 'ascending' | 'descending') => string;
|
|
19
|
+
/** Built-in bulk bar's visible count. Default: BulkActionsBar's `selected`, `` `${count} selected` `` */
|
|
20
|
+
bulkSelected?: (count: number) => string;
|
|
21
|
+
/** Built-in bulk bar's group `aria-label`. Default: BulkActionsBar's `actions` */
|
|
22
|
+
bulkActions?: (count: number) => string;
|
|
23
|
+
/** Built-in bulk bar's clear-selection button. Default: `"Clear"` */
|
|
24
|
+
bulkClear?: string;
|
|
19
25
|
};
|
|
20
26
|
export declare const defaultDataTableLabels: Required<DataTableLabels>;
|
|
@@ -8,4 +8,7 @@ export const defaultDataTableLabels = {
|
|
|
8
8
|
pageStatus: (current, total) => `Page ${current} of ${total}`,
|
|
9
9
|
sortBy: (column) => `Sort by ${column}`,
|
|
10
10
|
sorted: (column, direction) => `Sorted by ${column}, ${direction}`,
|
|
11
|
+
bulkSelected: defaultBulkActionsBarLabels.selected,
|
|
12
|
+
bulkActions: defaultBulkActionsBarLabels.actions,
|
|
13
|
+
bulkClear: 'Clear',
|
|
11
14
|
};
|
package/components/index.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export { MultiSelect, MultiSelectTrigger, MultiSelectContent, MultiSelectOption,
|
|
|
21
21
|
export { Select, SelectTrigger, SelectContent, SelectOption, SelectGroup, SelectLabel, useSelect } from './Select';
|
|
22
22
|
export { Icon } from './Icon';
|
|
23
23
|
export { IconButton, defaultIconButtonLabels } from './IconButton';
|
|
24
|
+
export { IconTile } from './IconTile';
|
|
24
25
|
export { Modal } from './Modal';
|
|
25
26
|
export { MoveHandle } from './MoveHandle';
|
|
26
27
|
export { Notice } from './Notice';
|
|
@@ -37,6 +38,7 @@ export { NavMenu, defaultNavMenuLabels } from './NavMenu';
|
|
|
37
38
|
export { StepIndicator, defaultStepIndicatorLabels } from './StepIndicator';
|
|
38
39
|
export { StepList, defaultStepListLabels } from './StepList';
|
|
39
40
|
export { DataTable, BulkActionsBar, defaultDataTableLabels, defaultBulkActionsBarLabels } from './Table';
|
|
41
|
+
export { CommandPalette, CommandPaletteItem, CommandPaletteGroup, CommandPaletteLabel, CommandPaletteTrigger, defaultCommandPaletteLabels, } from './CommandPalette';
|
|
40
42
|
export { SearchInput } from './SearchInput';
|
|
41
43
|
export { SecretInput, defaultSecretInputLabels } from './SecretInput';
|
|
42
44
|
export { SearchSelect, SearchSelectTrigger, SearchSelectContent, SearchSelectOption, SearchSelectGroup, SearchSelectLabel, useSearchSelect, } from './SearchSelect';
|
|
@@ -69,6 +71,7 @@ export type { MultiSelectProps, MultiSelectTriggerProps, MultiSelectContentProps
|
|
|
69
71
|
export type { SelectProps, SelectTriggerProps, SelectContentProps, SelectOptionProps, SelectGroupProps, SelectLabelProps, OptionValue as SelectOptionValue, } from './Select';
|
|
70
72
|
export type { IconProps, IconSource, IconComponent } from './Icon';
|
|
71
73
|
export type { IconButtonProps, IconButtonLabels, Shape as IconButtonShape, Theme as IconButtonTheme, Variant as IconButtonVariant, } from './IconButton';
|
|
74
|
+
export type { IconTileProps, IconTileSize, IconTileShape, IconTileTheme } from './IconTile';
|
|
72
75
|
export type { ModalProps, ModalRole, ModalFootProps, ModalFootJustify } from './Modal';
|
|
73
76
|
export type { MoveHandleLabels, MoveHandleMode, MoveHandleProps, MoveHandleSize } from './MoveHandle';
|
|
74
77
|
export type { NoticeProps, NoticeHandle, NoticeExitAnimation } from './Notice';
|
|
@@ -85,6 +88,7 @@ export type { StepIndicatorProps, StepStatus, StepIndicatorLabels } from './Step
|
|
|
85
88
|
export type { StepListProps, StepListItemProps, StepListLabels } from './StepList';
|
|
86
89
|
export type { DataTableProps, DataTableLabels, BulkActionsBarLabels } from './Table';
|
|
87
90
|
export type { TabsProps, TabsListProps, TabProps, TabPanelProps, TabsVariant, TabsActivationMode, TabsOrientation, } from './Tabs';
|
|
91
|
+
export type { CommandPaletteProps, CommandPaletteItemProps, CommandPaletteGroupProps, CommandPaletteLabelProps, CommandPaletteTriggerProps, CommandPaletteLabels, CommandPaletteStatus, CommandPaletteSelectDetail, CommandPaletteFilter, } from './CommandPalette';
|
|
88
92
|
export type { SearchInputProps } from './SearchInput';
|
|
89
93
|
export type { SliderProps } from './Slider';
|
|
90
94
|
export type { SecretInputProps, SecretInputLabels } from './SecretInput';
|
package/components/index.js
CHANGED
|
@@ -19,6 +19,7 @@ export { MultiSelect, MultiSelectTrigger, MultiSelectContent, MultiSelectOption,
|
|
|
19
19
|
export { Select, SelectTrigger, SelectContent, SelectOption, SelectGroup, SelectLabel, useSelect } from './Select/index.js';
|
|
20
20
|
export { Icon } from './Icon/index.js';
|
|
21
21
|
export { IconButton, defaultIconButtonLabels } from './IconButton/index.js';
|
|
22
|
+
export { IconTile } from './IconTile/index.js';
|
|
22
23
|
export { Modal } from './Modal/index.js';
|
|
23
24
|
export { MoveHandle } from './MoveHandle/index.js';
|
|
24
25
|
export { Notice } from './Notice/index.js';
|
|
@@ -35,6 +36,7 @@ export { NavMenu, defaultNavMenuLabels } from './NavMenu/index.js';
|
|
|
35
36
|
export { StepIndicator, defaultStepIndicatorLabels } from './StepIndicator/index.js';
|
|
36
37
|
export { StepList, defaultStepListLabels } from './StepList/index.js';
|
|
37
38
|
export { DataTable, BulkActionsBar, defaultDataTableLabels, defaultBulkActionsBarLabels } from './Table/index.js';
|
|
39
|
+
export { CommandPalette, CommandPaletteItem, CommandPaletteGroup, CommandPaletteLabel, CommandPaletteTrigger, defaultCommandPaletteLabels, } from './CommandPalette/index.js';
|
|
38
40
|
export { SearchInput } from './SearchInput/index.js';
|
|
39
41
|
export { SecretInput, defaultSecretInputLabels } from './SecretInput/index.js';
|
|
40
42
|
export { SearchSelect, SearchSelectTrigger, SearchSelectContent, SearchSelectOption, SearchSelectGroup, SearchSelectLabel, useSearchSelect, } from './SearchSelect/index.js';
|