@jcsoftdev/ui 0.6.0 → 0.7.0
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/CHANGELOG.md +24 -0
- package/README.md +6 -2
- package/dist/atoms/avatar/avatar.d.ts +6 -1
- package/dist/atoms/avatar/avatar.js +3 -2
- package/dist/containers/kanban/kanban.js +2 -0
- package/dist/containers/list-detail/list-detail.js +2 -0
- package/dist/containers/responsive-list/responsive-list.d.ts +1 -1
- package/dist/containers/responsive-list/responsive-list.js +127 -116
- package/dist/forms/number-stepper/index.d.ts +1 -1
- package/dist/forms/number-stepper/number-stepper.d.ts +7 -0
- package/dist/forms/number-stepper/number-stepper.js +37 -6
- package/dist/i18n/strings.d.ts +8 -0
- package/dist/i18n/strings.js +4 -0
- package/dist/overlays/dialog/dialog.d.ts +1 -0
- package/dist/overlays/dialog/dialog.js +1 -1
- package/dist/overlays/toaster/toast-store.d.ts +2 -0
- package/dist/overlays/toaster/toast-store.js +6 -1
- package/dist/overlays/toaster/toaster.js +13 -0
- package/dist/states/skeleton/skeleton.d.ts +16 -1
- package/dist/states/skeleton/skeleton.js +12 -4
- package/dist/utils/focus-chain.d.ts +11 -0
- package/dist/utils/focus-chain.js +39 -0
- package/dist/utils/focus-rescue.d.ts +13 -0
- package/dist/utils/focus-rescue.js +48 -0
- package/package.json +2 -2
- package/src/atoms/avatar/avatar.tsx +8 -2
- package/src/containers/kanban/kanban.tsx +2 -0
- package/src/containers/list-detail/list-detail.tsx +2 -0
- package/src/containers/responsive-list/responsive-list.tsx +8 -2
- package/src/forms/number-stepper/index.ts +1 -0
- package/src/forms/number-stepper/number-stepper.tsx +51 -6
- package/src/i18n/strings.ts +8 -0
- package/src/overlays/dialog/dialog.tsx +2 -1
- package/src/overlays/toaster/toast-store.ts +8 -0
- package/src/overlays/toaster/toaster.tsx +14 -0
- package/src/states/skeleton/skeleton.tsx +32 -4
- package/src/utils/focus-chain.ts +53 -0
- package/src/utils/focus-rescue.ts +68 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.7.0 (2026-11-03)
|
|
4
|
+
|
|
5
|
+
### Demo gaps
|
|
6
|
+
|
|
7
|
+
#### Added
|
|
8
|
+
|
|
9
|
+
- **Focus restoration**: a toast's action, dismissal or timeout returns focus to the element that
|
|
10
|
+
was focused when the toast was published, or to its nearest surviving ancestor (a list). When the
|
|
11
|
+
focused item of a `ListDetail`, `ResponsiveList` or `Kanban` leaves the DOM (approved, started,
|
|
12
|
+
moved to another lane) focus moves to the item that took its place, the previous one when it was
|
|
13
|
+
the last, or the list when it empties. Focus that moved elsewhere on purpose is never touched.
|
|
14
|
+
- **`NumberStepper` `size`** (`sm` 30px, `md` default) and `incrementLabel` / `decrementLabel`.
|
|
15
|
+
New `increase` and `decrease` UI strings (en, es).
|
|
16
|
+
- **`SkeletonGroup`** and **`Skeleton` `announce`**: one status per loading region.
|
|
17
|
+
- **`Avatar` `decorative`**; `aria-hidden` passed to `Avatar` also drops its image role and label.
|
|
18
|
+
|
|
19
|
+
#### Changed
|
|
20
|
+
|
|
21
|
+
- `NumberStepper` plus and minus buttons are named by the verb and the field label (`Aumentar
|
|
22
|
+
billetes de S/ 100`) and follow the UI strings locale; they were a fixed Spanish "Aumentar" and
|
|
23
|
+
"Disminuir".
|
|
24
|
+
- `DialogHeader` stacks its children vertically (title above description) at every width; it was a
|
|
25
|
+
centred row. Pass `flex-row items-center` in `className` to keep the old layout.
|
|
26
|
+
|
|
3
27
|
## 0.6.0 (2026-10-30)
|
|
4
28
|
|
|
5
29
|
### App shells, layout containers and adaptive density
|
package/README.md
CHANGED
|
@@ -160,7 +160,7 @@ import { UiStringsProvider } from "@jcsoftdev/ui/i18n";
|
|
|
160
160
|
|
|
161
161
|
`uiStrings.en` and `uiStrings.es` export the presets; `useUiStrings()` reads the active set. A nested
|
|
162
162
|
provider inherits its parent and overrides only the keys it passes. Hard-coded Spanish labels that
|
|
163
|
-
older components already ship (
|
|
163
|
+
older components already ship (Carousel, AI set) are not routed through it yet.
|
|
164
164
|
|
|
165
165
|
## Status, forms and states (additive props)
|
|
166
166
|
|
|
@@ -207,7 +207,11 @@ Additive props on existing components:
|
|
|
207
207
|
| --- | --- |
|
|
208
208
|
| `DescriptionList` | `layout` (`auto`, `inline`, `stacked`), `columns` (1 to 3), `valueAlign` (`end`, `start`); `DescriptionListItem` with a dash placeholder for empty values. |
|
|
209
209
|
| `Chip` | `size="sm"` (compact; a tag is `<Chip size="sm" square>`). |
|
|
210
|
-
| `Skeleton` | `variant` `list`, `kpis`, `key-value`, `bar` and `count
|
|
210
|
+
| `Skeleton` | `variant` `list`, `kpis`, `key-value`, `bar` and `count`; `announce={false}` makes it silent (`aria-hidden`), and `SkeletonGroup` announces once for every skeleton inside it. |
|
|
211
|
+
| `NumberStepper` | `size` (`sm` 30px, `md`), `incrementLabel` / `decrementLabel`; the plus and minus buttons are named by the localized verb plus the field label (`aria-label`, `aria-labelledby` or the `<label>`). |
|
|
212
|
+
| `Avatar` | `decorative` (or `aria-hidden`) drops the image role and label, for an avatar beside a visible name. |
|
|
213
|
+
| `DialogHeader` | Stacks its title above the description at every width; pass `flex-row items-center` in `className` for the side-by-side layout. |
|
|
214
|
+
| `Toaster`, `ListDetail`, `ResponsiveList`, `Kanban` | Focus never falls to `<body>`: a toast action or dismissal returns it to the element focused when the toast was published (or its nearest surviving ancestor); an item removed while focused hands focus to the next one, the previous one, or the list. |
|
|
211
215
|
| `ErrorState` | `actions` node, rendered in the same row as the retry button (the retry button now sits inside a wrapper `div`). |
|
|
212
216
|
| `RadioGroup` | Each radio is named by its label and described by its description. |
|
|
213
217
|
| `Checkbox`, `Switch` | The 44px touch target is an invisible `::after`; under touch density the layout box stays 40px. |
|
|
@@ -17,9 +17,14 @@ export interface AvatarProps extends Omit<ComponentPropsWithRef<"span">, "childr
|
|
|
17
17
|
tone?: AvatarTone;
|
|
18
18
|
/** Small status dot at the bottom-right corner. */
|
|
19
19
|
status?: StatusDotTone;
|
|
20
|
+
/**
|
|
21
|
+
* Hides the avatar from assistive technology, for one beside a visible name that already says
|
|
22
|
+
* who it is. `aria-hidden` passed directly does the same.
|
|
23
|
+
*/
|
|
24
|
+
decorative?: boolean;
|
|
20
25
|
/** Accessible text for the status dot; defaults to the status name. */
|
|
21
26
|
statusLabel?: string;
|
|
22
27
|
/** Per-part classes merged with `cn`; consumer classes win. `className` still targets the root and is merged last. */
|
|
23
28
|
classNames?: ClassNames<AvatarPart>;
|
|
24
29
|
}
|
|
25
|
-
export declare function Avatar({ name, src, size, highlighted, tone, status: statusTone, statusLabel, className, classNames, style, ...props }: AvatarProps): import("react").JSX.Element;
|
|
30
|
+
export declare function Avatar({ name, src, size, highlighted, tone, status: statusTone, statusLabel, decorative, className, classNames, style, ...props }: AvatarProps): import("react").JSX.Element;
|
|
@@ -69,6 +69,7 @@ function Avatar({
|
|
|
69
69
|
tone = "neutral",
|
|
70
70
|
status: statusTone,
|
|
71
71
|
statusLabel,
|
|
72
|
+
decorative,
|
|
72
73
|
className,
|
|
73
74
|
classNames,
|
|
74
75
|
style,
|
|
@@ -80,8 +81,8 @@ function Avatar({
|
|
|
80
81
|
const avatar = /* @__PURE__ */ jsxs(
|
|
81
82
|
"span",
|
|
82
83
|
{
|
|
83
|
-
role: "img",
|
|
84
|
-
"aria-
|
|
84
|
+
...decorative || props["aria-hidden"] ? {} : { role: "img", "aria-label": name },
|
|
85
|
+
...decorative ? { "aria-hidden": true } : {},
|
|
85
86
|
...props,
|
|
86
87
|
style: customToneStyle(tone, builtinTones, style),
|
|
87
88
|
className: cn(
|
|
@@ -11,6 +11,7 @@ import { Avatar } from "../../atoms/avatar/avatar.js";
|
|
|
11
11
|
import { Chip } from "../../atoms/chip/chip.js";
|
|
12
12
|
import { GripVertical } from "../../icons/index.js";
|
|
13
13
|
import { cn } from "../../utils/cn.js";
|
|
14
|
+
import { useFocusRescue } from "../../utils/focus-rescue.js";
|
|
14
15
|
import {
|
|
15
16
|
dropIndex,
|
|
16
17
|
dropIndexGrid,
|
|
@@ -55,6 +56,7 @@ function Kanban({
|
|
|
55
56
|
const [drag, setDrag] = useState(null);
|
|
56
57
|
const [status, setStatus] = useState("");
|
|
57
58
|
const rootRef = useRef(null);
|
|
59
|
+
useFocusRescue(rootRef, { item: "[data-card-id]", group: "ul" });
|
|
58
60
|
const focusId = useRef(null);
|
|
59
61
|
const columnsRef = useRef(columns);
|
|
60
62
|
columnsRef.current = columns;
|
|
@@ -15,6 +15,7 @@ import { useUiStrings } from "../../i18n/index.js";
|
|
|
15
15
|
import { ChevronLeft } from "../../icons/index.js";
|
|
16
16
|
import { cn } from "../../utils/cn.js";
|
|
17
17
|
import { composeHandlers } from "../../utils/compose.js";
|
|
18
|
+
import { useFocusRescue } from "../../utils/focus-rescue.js";
|
|
18
19
|
import { useControllableState } from "../../utils/use-controllable-state.js";
|
|
19
20
|
const ListDetailContext = createContext(null);
|
|
20
21
|
function useListDetailContext(part) {
|
|
@@ -69,6 +70,7 @@ function ListDetail({
|
|
|
69
70
|
);
|
|
70
71
|
const rootRef = useRef(null);
|
|
71
72
|
const previous = useRef(value);
|
|
73
|
+
useFocusRescue(rootRef, { item: "[data-list-detail-item]", group: "ul" });
|
|
72
74
|
useEffect(() => {
|
|
73
75
|
const before = previous.current;
|
|
74
76
|
previous.current = value;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
2
|
import type { ClassNames } from "../../utils/class-names.js";
|
|
3
3
|
/** Container widths (px) from which `layout="auto"` shows the table. The set is closed so every query is a literal class. */
|
|
4
4
|
export type ResponsiveListBreakpoint = 480 | 640 | 672 | 768 | 960 | 1280;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useRef } from "react";
|
|
3
4
|
import { useUiStrings } from "../../i18n/index.js";
|
|
4
5
|
import { cn } from "../../utils/cn.js";
|
|
6
|
+
import { useFocusRescue } from "../../utils/focus-rescue.js";
|
|
5
7
|
import { focusRowByKey } from "../../utils/list-navigation.js";
|
|
6
8
|
import {
|
|
7
9
|
Table,
|
|
@@ -55,6 +57,8 @@ function ResponsiveList({
|
|
|
55
57
|
classNames
|
|
56
58
|
}) {
|
|
57
59
|
const strings = useUiStrings();
|
|
60
|
+
const rootRef = useRef(null);
|
|
61
|
+
useFocusRescue(rootRef, { item: "[data-row-key]", group: "tbody, ul" });
|
|
58
62
|
const primary = columns.find((column) => column.primary) ?? columns[0];
|
|
59
63
|
const details = columns.filter((column) => column !== primary);
|
|
60
64
|
const selectable = onSelect !== void 0;
|
|
@@ -98,129 +102,136 @@ function ResponsiveList({
|
|
|
98
102
|
}
|
|
99
103
|
};
|
|
100
104
|
};
|
|
101
|
-
return /* @__PURE__ */ jsxs(
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
),
|
|
110
|
-
children: /* @__PURE__ */ jsxs(
|
|
111
|
-
Table,
|
|
105
|
+
return /* @__PURE__ */ jsxs(
|
|
106
|
+
"div",
|
|
107
|
+
{
|
|
108
|
+
ref: rootRef,
|
|
109
|
+
className: cn("@container/responsive-list min-w-0", classNames?.root, className),
|
|
110
|
+
children: [
|
|
111
|
+
layout === "auto" ? /* @__PURE__ */ jsx(
|
|
112
|
+
"div",
|
|
112
113
|
{
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
"
|
|
124
|
-
className:
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
),
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
"
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
114
|
+
className: cn(
|
|
115
|
+
"rounded-card border-card shadow-card surface-card",
|
|
116
|
+
tableClasses[breakpoint].table,
|
|
117
|
+
classNames?.tableWrapper
|
|
118
|
+
),
|
|
119
|
+
children: /* @__PURE__ */ jsxs(
|
|
120
|
+
Table,
|
|
121
|
+
{
|
|
122
|
+
...selectable ? { role: "grid", "aria-label": caption, "data-row-scope": "" } : {},
|
|
123
|
+
children: [
|
|
124
|
+
/* @__PURE__ */ jsx("caption", { className: "sr-only", children: caption }),
|
|
125
|
+
/* @__PURE__ */ jsx(TableHead, { children: /* @__PURE__ */ jsxs(TableRow, { className: "hover:bg-transparent", children: [
|
|
126
|
+
columns.map((column) => /* @__PURE__ */ jsx(TableHeaderCell, { scope: "col", alignRight: column.align === "end", children: column.header }, column.key)),
|
|
127
|
+
renderActions ? /* @__PURE__ */ jsx(TableHeaderCell, { scope: "col", alignRight: true, children: actionsHeader ?? strings.actions }) : null
|
|
128
|
+
] }) }),
|
|
129
|
+
/* @__PURE__ */ jsx(TableBody, { children: items.map((item) => /* @__PURE__ */ jsxs(
|
|
130
|
+
TableRow,
|
|
131
|
+
{
|
|
132
|
+
"data-row-key": rowKey(item),
|
|
133
|
+
className: cn(
|
|
134
|
+
rowClassName?.(item),
|
|
135
|
+
selectable && "cursor-pointer focus-visible:focus-ring data-[selected=true]:bg-accent-soft"
|
|
136
|
+
),
|
|
137
|
+
...rowProps(item, "grid"),
|
|
138
|
+
children: [
|
|
139
|
+
columns.map((column) => /* @__PURE__ */ jsx(TableCell, { alignRight: column.align === "end", children: column.cell(item) }, column.key)),
|
|
140
|
+
renderActions ? /* @__PURE__ */ jsx(TableCell, { alignRight: true, children: /* @__PURE__ */ jsx(
|
|
141
|
+
"div",
|
|
142
|
+
{
|
|
143
|
+
"data-row-actions": "",
|
|
144
|
+
className: cn("flex flex-wrap justify-end gap-2", classNames?.actions),
|
|
145
|
+
children: renderActions(item)
|
|
146
|
+
}
|
|
147
|
+
) }) : null
|
|
148
|
+
]
|
|
149
|
+
},
|
|
150
|
+
rowKey(item)
|
|
151
|
+
)) })
|
|
152
|
+
]
|
|
153
|
+
}
|
|
154
|
+
)
|
|
144
155
|
}
|
|
145
|
-
)
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
/* @__PURE__ */ jsx(
|
|
149
|
-
"ul",
|
|
150
|
-
{
|
|
151
|
-
"aria-label": caption,
|
|
152
|
-
...listbox ? { role: "listbox" } : {},
|
|
153
|
-
...selectable ? { "data-row-scope": "" } : {},
|
|
154
|
-
className: cn(
|
|
155
|
-
"m-0 flex list-none flex-col gap-density p-0",
|
|
156
|
-
layout === "auto" && tableClasses[breakpoint].cards,
|
|
157
|
-
classNames?.cards
|
|
158
|
-
),
|
|
159
|
-
children: items.map((item) => /* @__PURE__ */ jsxs(
|
|
160
|
-
"li",
|
|
156
|
+
) : null,
|
|
157
|
+
/* @__PURE__ */ jsx(
|
|
158
|
+
"ul",
|
|
161
159
|
{
|
|
162
|
-
"
|
|
160
|
+
"aria-label": caption,
|
|
161
|
+
...listbox ? { role: "listbox" } : {},
|
|
162
|
+
...selectable ? { "data-row-scope": "" } : {},
|
|
163
163
|
className: cn(
|
|
164
|
-
"flex
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
classNames?.card
|
|
164
|
+
"m-0 flex list-none flex-col gap-density p-0",
|
|
165
|
+
layout === "auto" && tableClasses[breakpoint].cards,
|
|
166
|
+
classNames?.cards
|
|
168
167
|
),
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
"
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
168
|
+
children: items.map((item) => /* @__PURE__ */ jsxs(
|
|
169
|
+
"li",
|
|
170
|
+
{
|
|
171
|
+
"data-row-key": rowKey(item),
|
|
172
|
+
className: cn(
|
|
173
|
+
"flex min-w-0 flex-col gap-3 rounded-card border-card p-card shadow-card surface-card",
|
|
174
|
+
selectable && "cursor-pointer focus-visible:focus-ring data-[selected=true]:bg-accent-soft data-[selected=true]:shadow-selected",
|
|
175
|
+
rowClassName?.(item),
|
|
176
|
+
classNames?.card
|
|
177
|
+
),
|
|
178
|
+
...rowProps(item, "card"),
|
|
179
|
+
children: [
|
|
180
|
+
/* @__PURE__ */ jsx(
|
|
181
|
+
"div",
|
|
182
|
+
{
|
|
183
|
+
className: cn(
|
|
184
|
+
"min-w-0 font-semibold text-fs-150 text-ink [overflow-wrap:anywhere]",
|
|
185
|
+
classNames?.cardTitle
|
|
186
|
+
),
|
|
187
|
+
children: primary?.cell(item)
|
|
188
|
+
}
|
|
188
189
|
),
|
|
189
|
-
children:
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
190
|
+
details.length > 0 ? /* @__PURE__ */ jsx("dl", { className: cn("m-0 flex flex-col gap-2", classNames?.cardDetails), children: details.map((column) => /* @__PURE__ */ jsxs(
|
|
191
|
+
"div",
|
|
192
|
+
{
|
|
193
|
+
className: cn(
|
|
194
|
+
"flex items-baseline justify-between gap-4",
|
|
195
|
+
cardLabels === "hidden" && "justify-start",
|
|
196
|
+
classNames?.cardDetail
|
|
197
|
+
),
|
|
198
|
+
children: [
|
|
199
|
+
/* @__PURE__ */ jsx(
|
|
200
|
+
"dt",
|
|
201
|
+
{
|
|
202
|
+
className: cn(
|
|
203
|
+
"shrink-0 text-ink-3 text-meta",
|
|
204
|
+
cardLabels === "hidden" && "sr-only",
|
|
205
|
+
classNames?.cardLabel
|
|
206
|
+
),
|
|
207
|
+
children: column.header
|
|
208
|
+
}
|
|
197
209
|
),
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
)
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
] });
|
|
210
|
+
/* @__PURE__ */ jsx(
|
|
211
|
+
"dd",
|
|
212
|
+
{
|
|
213
|
+
className: cn(
|
|
214
|
+
"m-0 min-w-0 text-right text-body text-ink [overflow-wrap:anywhere]",
|
|
215
|
+
cardLabels === "hidden" && "text-left",
|
|
216
|
+
classNames?.cardValue
|
|
217
|
+
),
|
|
218
|
+
children: column.cell(item)
|
|
219
|
+
}
|
|
220
|
+
)
|
|
221
|
+
]
|
|
222
|
+
},
|
|
223
|
+
column.key
|
|
224
|
+
)) }) : null,
|
|
225
|
+
renderActions ? /* @__PURE__ */ jsx("div", { "data-row-actions": "", className: cn("flex flex-wrap gap-2", classNames?.actions), children: renderActions(item) }) : null
|
|
226
|
+
]
|
|
227
|
+
},
|
|
228
|
+
rowKey(item)
|
|
229
|
+
))
|
|
230
|
+
}
|
|
231
|
+
)
|
|
232
|
+
]
|
|
233
|
+
}
|
|
234
|
+
);
|
|
224
235
|
}
|
|
225
236
|
export {
|
|
226
237
|
ResponsiveList
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { NumberStepper, type NumberStepperPart, type NumberStepperProps, } from "./number-stepper.js";
|
|
1
|
+
export { NumberStepper, type NumberStepperPart, type NumberStepperProps, type NumberStepperSize, } from "./number-stepper.js";
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import { type ChangeEventHandler } from "react";
|
|
2
2
|
import type { ClassNames } from "../../utils/class-names.js";
|
|
3
3
|
export type NumberStepperPart = "root" | "decrement" | "increment" | "input" | "unit";
|
|
4
|
+
export type NumberStepperSize = "sm" | "md";
|
|
4
5
|
interface NumberStepperBaseProps {
|
|
6
|
+
/** `sm` (30px) matches a small `Button` or `Input` for dense rows; `md` (default) is the regular field height. */
|
|
7
|
+
size?: NumberStepperSize;
|
|
8
|
+
/** Accessible name of the plus button. Defaults to the localized verb followed by the field label. */
|
|
9
|
+
incrementLabel?: string;
|
|
10
|
+
/** Accessible name of the minus button. Defaults to the localized verb followed by the field label. */
|
|
11
|
+
decrementLabel?: string;
|
|
5
12
|
min?: number;
|
|
6
13
|
max?: number;
|
|
7
14
|
step?: number;
|
|
@@ -1,16 +1,25 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
3
|
import {
|
|
4
|
+
useEffect,
|
|
4
5
|
useId,
|
|
5
6
|
useRef,
|
|
6
7
|
useState
|
|
7
8
|
} from "react";
|
|
9
|
+
import { useUiStrings } from "../../i18n/index.js";
|
|
8
10
|
import { Minus, Plus } from "../../icons/index.js";
|
|
9
11
|
import { cn } from "../../utils/cn.js";
|
|
10
12
|
import { snapToStep } from "../slider/model.js";
|
|
11
13
|
import { canStep, parseNumber, stepText } from "./model.js";
|
|
14
|
+
const sizeClasses = {
|
|
15
|
+
sm: { root: "h-control-sm", button: "w-7" },
|
|
16
|
+
md: { root: "h-input", button: "w-9" }
|
|
17
|
+
};
|
|
12
18
|
function NumberStepper(props) {
|
|
13
19
|
const {
|
|
20
|
+
size = "md",
|
|
21
|
+
incrementLabel,
|
|
22
|
+
decrementLabel,
|
|
14
23
|
min = Number.NEGATIVE_INFINITY,
|
|
15
24
|
max = Number.POSITIVE_INFINITY,
|
|
16
25
|
step = 1,
|
|
@@ -28,9 +37,28 @@ function NumberStepper(props) {
|
|
|
28
37
|
"aria-describedby": ariaDescribedBy,
|
|
29
38
|
"aria-invalid": ariaInvalid
|
|
30
39
|
} = props;
|
|
40
|
+
const strings = useUiStrings();
|
|
31
41
|
const autoId = useId();
|
|
32
42
|
const id = idProp ?? autoId;
|
|
43
|
+
const decrementId = `${autoId}-decrement`;
|
|
44
|
+
const incrementId = `${autoId}-increment`;
|
|
45
|
+
const [fieldLabel, setFieldLabel] = useState("");
|
|
33
46
|
const inputRef = useRef(null);
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
if (ariaLabel || ariaLabelledBy) return;
|
|
49
|
+
const labels = Array.from(inputRef.current?.labels ?? []);
|
|
50
|
+
setFieldLabel(
|
|
51
|
+
labels.map((label) => label.textContent?.trim() ?? "").filter(Boolean).join(" ")
|
|
52
|
+
);
|
|
53
|
+
});
|
|
54
|
+
const stepButtonName = (verb, custom, buttonId) => {
|
|
55
|
+
if (custom) return { "aria-label": custom };
|
|
56
|
+
if (ariaLabelledBy) {
|
|
57
|
+
return { "aria-label": verb, "aria-labelledby": `${buttonId} ${ariaLabelledBy}` };
|
|
58
|
+
}
|
|
59
|
+
const subject = ariaLabel ?? fieldLabel;
|
|
60
|
+
return { "aria-label": subject ? `${verb} ${subject}` : verb };
|
|
61
|
+
};
|
|
34
62
|
const isString = props.mode === "string";
|
|
35
63
|
const [innerNumber, setInnerNumber] = useState(isString ? 0 : props.defaultValue ?? 0);
|
|
36
64
|
const [innerText, setInnerText] = useState(isString ? props.defaultValue ?? "" : "");
|
|
@@ -80,13 +108,14 @@ function NumberStepper(props) {
|
|
|
80
108
|
props.onChange?.(event);
|
|
81
109
|
props.onValueChange?.(event.target.value);
|
|
82
110
|
};
|
|
83
|
-
const button = "grid h-full
|
|
111
|
+
const button = "grid h-full shrink-0 place-items-center text-ink-2 outline-none hover:bg-surface-sunken hover:text-ink focus-visible:focus-ring disabled:cursor-not-allowed disabled:opacity-40";
|
|
84
112
|
const valid = !Number.isNaN(number);
|
|
85
113
|
return /* @__PURE__ */ jsxs(
|
|
86
114
|
"div",
|
|
87
115
|
{
|
|
88
116
|
className: cn(
|
|
89
|
-
"inline-flex
|
|
117
|
+
"inline-flex min-w-32 max-w-full items-stretch overflow-hidden rounded-input border-control bg-surface-control",
|
|
118
|
+
sizeClasses[size].root,
|
|
90
119
|
disabled && "opacity-60",
|
|
91
120
|
(invalid || ariaInvalid) && "border-danger",
|
|
92
121
|
classNames?.root,
|
|
@@ -98,11 +127,12 @@ function NumberStepper(props) {
|
|
|
98
127
|
{
|
|
99
128
|
type: "button",
|
|
100
129
|
tabIndex: -1,
|
|
101
|
-
|
|
130
|
+
id: decrementId,
|
|
131
|
+
...stepButtonName(strings.decrease, decrementLabel, decrementId),
|
|
102
132
|
"aria-controls": id,
|
|
103
133
|
disabled: disabled || !canStep(text, -1, { min, max }),
|
|
104
134
|
onClick: () => move(-1),
|
|
105
|
-
className: cn(button, "pressable", classNames?.decrement),
|
|
135
|
+
className: cn(button, sizeClasses[size].button, "pressable", classNames?.decrement),
|
|
106
136
|
children: /* @__PURE__ */ jsx(Minus, { "aria-hidden": "true", className: "size-3.5" })
|
|
107
137
|
}
|
|
108
138
|
),
|
|
@@ -149,11 +179,12 @@ function NumberStepper(props) {
|
|
|
149
179
|
{
|
|
150
180
|
type: "button",
|
|
151
181
|
tabIndex: -1,
|
|
152
|
-
|
|
182
|
+
id: incrementId,
|
|
183
|
+
...stepButtonName(strings.increase, incrementLabel, incrementId),
|
|
153
184
|
"aria-controls": id,
|
|
154
185
|
disabled: disabled || !canStep(text, 1, { min, max }),
|
|
155
186
|
onClick: () => move(1),
|
|
156
|
-
className: cn(button, "pressable", classNames?.increment),
|
|
187
|
+
className: cn(button, sizeClasses[size].button, "pressable", classNames?.increment),
|
|
157
188
|
children: /* @__PURE__ */ jsx(Plus, { "aria-hidden": "true", className: "size-3.5" })
|
|
158
189
|
}
|
|
159
190
|
)
|
package/dist/i18n/strings.d.ts
CHANGED
|
@@ -42,6 +42,10 @@ export interface UiStrings {
|
|
|
42
42
|
steps: string;
|
|
43
43
|
/** Default accessible name of an `Aside`. */
|
|
44
44
|
aside: string;
|
|
45
|
+
/** Verb of the `NumberStepper` plus button; the field label follows it. */
|
|
46
|
+
increase: string;
|
|
47
|
+
/** Verb of the `NumberStepper` minus button; the field label follows it. */
|
|
48
|
+
decrease: string;
|
|
45
49
|
/** Back action of a single-pane `ListDetail`. */
|
|
46
50
|
backToList: string;
|
|
47
51
|
/** Screen-reader state of a `DueChip` past its date. */
|
|
@@ -172,6 +176,8 @@ export declare const uiStrings: {
|
|
|
172
176
|
readonly stepOf: "Step {current} of {total}: {label}";
|
|
173
177
|
readonly steps: "Steps";
|
|
174
178
|
readonly aside: "Related information";
|
|
179
|
+
readonly increase: "Increase";
|
|
180
|
+
readonly decrease: "Decrease";
|
|
175
181
|
readonly backToList: "Back to list";
|
|
176
182
|
readonly overdue: "Overdue";
|
|
177
183
|
readonly dueSoon: "Due soon";
|
|
@@ -259,6 +265,8 @@ export declare const uiStrings: {
|
|
|
259
265
|
readonly stepOf: "Paso {current} de {total}: {label}";
|
|
260
266
|
readonly steps: "Pasos";
|
|
261
267
|
readonly aside: "Información relacionada";
|
|
268
|
+
readonly increase: "Aumentar";
|
|
269
|
+
readonly decrease: "Disminuir";
|
|
262
270
|
readonly backToList: "Volver a la lista";
|
|
263
271
|
readonly overdue: "Vencido";
|
|
264
272
|
readonly dueSoon: "Vence pronto";
|
package/dist/i18n/strings.js
CHANGED
|
@@ -40,6 +40,8 @@ const uiStrings = {
|
|
|
40
40
|
stepOf: "Step {current} of {total}: {label}",
|
|
41
41
|
steps: "Steps",
|
|
42
42
|
aside: "Related information",
|
|
43
|
+
increase: "Increase",
|
|
44
|
+
decrease: "Decrease",
|
|
43
45
|
backToList: "Back to list",
|
|
44
46
|
overdue: "Overdue",
|
|
45
47
|
dueSoon: "Due soon",
|
|
@@ -127,6 +129,8 @@ const uiStrings = {
|
|
|
127
129
|
stepOf: "Paso {current} de {total}: {label}",
|
|
128
130
|
steps: "Pasos",
|
|
129
131
|
aside: "Informaci\xF3n relacionada",
|
|
132
|
+
increase: "Aumentar",
|
|
133
|
+
decrease: "Disminuir",
|
|
130
134
|
backToList: "Volver a la lista",
|
|
131
135
|
overdue: "Vencido",
|
|
132
136
|
dueSoon: "Vence pronto",
|
|
@@ -33,6 +33,7 @@ export interface DialogContentProps extends DialogPrimitive.DialogContentProps {
|
|
|
33
33
|
container?: HTMLElement | null;
|
|
34
34
|
}
|
|
35
35
|
export declare function DialogContent({ className, classNames, width, material, blocking, closeLabel, container, children, onEscapeKeyDown, onPointerDownOutside, onInteractOutside, onCloseAutoFocus, ...props }: DialogContentProps): import("react").JSX.Element;
|
|
36
|
+
/** Title above description at every width; pass `flex-row items-center` in `className` for a side-by-side layout. */
|
|
36
37
|
export declare function DialogHeader({ className, ...props }: HTMLAttributes<HTMLDivElement>): import("react").JSX.Element;
|
|
37
38
|
export declare function DialogTitle({ className, ...props }: ComponentPropsWithoutRef<typeof DialogPrimitive.Title>): import("react").JSX.Element;
|
|
38
39
|
export declare function DialogDescription({ className, ...props }: ComponentPropsWithoutRef<typeof DialogPrimitive.Description>): import("react").JSX.Element;
|
|
@@ -97,7 +97,7 @@ function DialogHeader({ className, ...props }) {
|
|
|
97
97
|
return /* @__PURE__ */ jsx(
|
|
98
98
|
"div",
|
|
99
99
|
{
|
|
100
|
-
className: cn("flex
|
|
100
|
+
className: cn("flex flex-col gap-1 border-b-divider py-3.5 pr-10 pl-4.5", className),
|
|
101
101
|
...props
|
|
102
102
|
}
|
|
103
103
|
);
|
|
@@ -24,6 +24,8 @@ export interface ToastRecord extends Omit<ToastOptions, "id"> {
|
|
|
24
24
|
state: "open" | "closed";
|
|
25
25
|
/** Bumped on every update so timers restart. */
|
|
26
26
|
revision: number;
|
|
27
|
+
/** Where focus was, nearest first, when the toast was published; focus returns there once the toast leaves. */
|
|
28
|
+
origin: readonly HTMLElement[];
|
|
27
29
|
}
|
|
28
30
|
export declare function subscribe(listener: () => void): () => void;
|
|
29
31
|
export declare function getSnapshot(): readonly ToastRecord[];
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { focusChain } from "../../utils/focus-chain.js";
|
|
1
2
|
const EMPTY = [];
|
|
2
3
|
let toasts = EMPTY;
|
|
3
4
|
let counter = 0;
|
|
@@ -18,6 +19,9 @@ function getSnapshot() {
|
|
|
18
19
|
function getServerSnapshot() {
|
|
19
20
|
return EMPTY;
|
|
20
21
|
}
|
|
22
|
+
function currentFocusChain() {
|
|
23
|
+
return typeof document === "undefined" ? [] : focusChain(document.activeElement);
|
|
24
|
+
}
|
|
21
25
|
function publish(message, tone, options = {}) {
|
|
22
26
|
const id = options.id ?? `toast-${++counter}`;
|
|
23
27
|
const existing = toasts.find((t) => t.id === id);
|
|
@@ -27,7 +31,8 @@ function publish(message, tone, options = {}) {
|
|
|
27
31
|
message,
|
|
28
32
|
tone,
|
|
29
33
|
state: "open",
|
|
30
|
-
revision: (existing?.revision ?? 0) + 1
|
|
34
|
+
revision: (existing?.revision ?? 0) + 1,
|
|
35
|
+
origin: existing?.origin ?? currentFocusChain()
|
|
31
36
|
};
|
|
32
37
|
commit(existing ? toasts.map((t) => t.id === id ? record : t) : [...toasts, record]);
|
|
33
38
|
return id;
|