@jcsoftdev/ui 0.6.0 → 0.7.1

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.
Files changed (41) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/README.md +12 -2
  3. package/dist/atoms/avatar/avatar.d.ts +6 -1
  4. package/dist/atoms/avatar/avatar.js +3 -2
  5. package/dist/containers/kanban/kanban.js +2 -0
  6. package/dist/containers/list-detail/list-detail.js +2 -0
  7. package/dist/containers/responsive-list/responsive-list.d.ts +1 -1
  8. package/dist/containers/responsive-list/responsive-list.js +127 -116
  9. package/dist/forms/number-stepper/index.d.ts +1 -1
  10. package/dist/forms/number-stepper/number-stepper.d.ts +7 -0
  11. package/dist/forms/number-stepper/number-stepper.js +37 -6
  12. package/dist/i18n/strings.d.ts +12 -0
  13. package/dist/i18n/strings.js +6 -0
  14. package/dist/overlays/dialog/dialog.d.ts +1 -0
  15. package/dist/overlays/dialog/dialog.js +1 -1
  16. package/dist/overlays/toaster/toast-store.d.ts +2 -0
  17. package/dist/overlays/toaster/toast-store.js +6 -1
  18. package/dist/overlays/toaster/toaster.js +13 -0
  19. package/dist/shell/bottom-nav/bottom-nav.d.ts +5 -1
  20. package/dist/shell/bottom-nav/bottom-nav.js +52 -9
  21. package/dist/states/skeleton/skeleton.d.ts +16 -1
  22. package/dist/states/skeleton/skeleton.js +12 -4
  23. package/dist/utils/focus-chain.d.ts +11 -0
  24. package/dist/utils/focus-chain.js +39 -0
  25. package/dist/utils/focus-rescue.d.ts +13 -0
  26. package/dist/utils/focus-rescue.js +48 -0
  27. package/package.json +2 -2
  28. package/src/atoms/avatar/avatar.tsx +8 -2
  29. package/src/containers/kanban/kanban.tsx +2 -0
  30. package/src/containers/list-detail/list-detail.tsx +2 -0
  31. package/src/containers/responsive-list/responsive-list.tsx +8 -2
  32. package/src/forms/number-stepper/index.ts +1 -0
  33. package/src/forms/number-stepper/number-stepper.tsx +51 -6
  34. package/src/i18n/strings.ts +12 -0
  35. package/src/overlays/dialog/dialog.tsx +2 -1
  36. package/src/overlays/toaster/toast-store.ts +8 -0
  37. package/src/overlays/toaster/toaster.tsx +14 -0
  38. package/src/shell/bottom-nav/bottom-nav.tsx +78 -8
  39. package/src/states/skeleton/skeleton.tsx +32 -4
  40. package/src/utils/focus-chain.ts +53 -0
  41. package/src/utils/focus-rescue.ts +68 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,48 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.7.1 (2026-11-03)
4
+
5
+ ### Phone bottom bar counts
6
+
7
+ #### Changed
8
+
9
+ - **`BottomNav` shows numeric badges as a count chip** on the icon corner (capped at `99+`,
10
+ `bg-danger` for `badgeTone="danger"`, `bg-warning` otherwise); it rendered a dot for every badge.
11
+ Non-numeric badges (nodes, `true`) keep the dot. Behavior change from 0.7.0: pass
12
+ `badgeStyle="dot"` to keep dots everywhere.
13
+
14
+ #### Added
15
+
16
+ - **`BottomNav` `badgeStyle`** (`"count"` default, `"dot"`).
17
+ - **"More" total**: the button sums the numeric badges of the items it hides and shows the count
18
+ chip (danger when any hidden item is danger, a dot when only non-numeric badges exist, nothing
19
+ without badges). Its screen-reader text comes from the new `morePending` UI string (`{count}
20
+ pending` / `{count} pendientes`) or the new `moreBadgeLabel` prop.
21
+
22
+ ## 0.7.0 (2026-11-03)
23
+
24
+ ### Demo gaps
25
+
26
+ #### Added
27
+
28
+ - **Focus restoration**: a toast's action, dismissal or timeout returns focus to the element that
29
+ was focused when the toast was published, or to its nearest surviving ancestor (a list). When the
30
+ focused item of a `ListDetail`, `ResponsiveList` or `Kanban` leaves the DOM (approved, started,
31
+ moved to another lane) focus moves to the item that took its place, the previous one when it was
32
+ the last, or the list when it empties. Focus that moved elsewhere on purpose is never touched.
33
+ - **`NumberStepper` `size`** (`sm` 30px, `md` default) and `incrementLabel` / `decrementLabel`.
34
+ New `increase` and `decrease` UI strings (en, es).
35
+ - **`SkeletonGroup`** and **`Skeleton` `announce`**: one status per loading region.
36
+ - **`Avatar` `decorative`**; `aria-hidden` passed to `Avatar` also drops its image role and label.
37
+
38
+ #### Changed
39
+
40
+ - `NumberStepper` plus and minus buttons are named by the verb and the field label (`Aumentar
41
+ billetes de S/ 100`) and follow the UI strings locale; they were a fixed Spanish "Aumentar" and
42
+ "Disminuir".
43
+ - `DialogHeader` stacks its children vertically (title above description) at every width; it was a
44
+ centred row. Pass `flex-row items-center` in `className` to keep the old layout.
45
+
3
46
  ## 0.6.0 (2026-10-30)
4
47
 
5
48
  ### App shells, layout containers and adaptive density
package/README.md CHANGED
@@ -160,7 +160,13 @@ 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 (NumberStepper, Carousel, AI set) are not routed through it yet.
163
+ older components already ship (Carousel, AI set) are not routed through it yet.
164
+
165
+ ## Phone bottom bar badges
166
+
167
+ `BottomNav` renders numeric `SidebarItem.badge` values as count chips (`99+` cap) and sums the badges
168
+ of the items behind "More" onto that button; `badgeStyle="dot"` restores plain dots, and
169
+ `moreBadgeLabel={(count) => ...}` replaces the localized `morePending` text read by screen readers.
164
170
 
165
171
  ## Status, forms and states (additive props)
166
172
 
@@ -207,7 +213,11 @@ Additive props on existing components:
207
213
  | --- | --- |
208
214
  | `DescriptionList` | `layout` (`auto`, `inline`, `stacked`), `columns` (1 to 3), `valueAlign` (`end`, `start`); `DescriptionListItem` with a dash placeholder for empty values. |
209
215
  | `Chip` | `size="sm"` (compact; a tag is `<Chip size="sm" square>`). |
210
- | `Skeleton` | `variant` `list`, `kpis`, `key-value`, `bar` and `count`. |
216
+ | `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. |
217
+ | `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>`). |
218
+ | `Avatar` | `decorative` (or `aria-hidden`) drops the image role and label, for an avatar beside a visible name. |
219
+ | `DialogHeader` | Stacks its title above the description at every width; pass `flex-row items-center` in `className` for the side-by-side layout. |
220
+ | `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
221
  | `ErrorState` | `actions` node, rendered in the same row as the retry button (the retry button now sits inside a wrapper `div`). |
212
222
  | `RadioGroup` | Each radio is named by its label and described by its description. |
213
223
  | `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-label": name,
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 { ReactNode } from "react";
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("div", { className: cn("@container/responsive-list min-w-0", classNames?.root, className), children: [
102
- layout === "auto" ? /* @__PURE__ */ jsx(
103
- "div",
104
- {
105
- className: cn(
106
- "rounded-card border-card shadow-card surface-card",
107
- tableClasses[breakpoint].table,
108
- classNames?.tableWrapper
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
- ...selectable ? { role: "grid", "aria-label": caption, "data-row-scope": "" } : {},
114
- children: [
115
- /* @__PURE__ */ jsx("caption", { className: "sr-only", children: caption }),
116
- /* @__PURE__ */ jsx(TableHead, { children: /* @__PURE__ */ jsxs(TableRow, { className: "hover:bg-transparent", children: [
117
- columns.map((column) => /* @__PURE__ */ jsx(TableHeaderCell, { scope: "col", alignRight: column.align === "end", children: column.header }, column.key)),
118
- renderActions ? /* @__PURE__ */ jsx(TableHeaderCell, { scope: "col", alignRight: true, children: actionsHeader ?? strings.actions }) : null
119
- ] }) }),
120
- /* @__PURE__ */ jsx(TableBody, { children: items.map((item) => /* @__PURE__ */ jsxs(
121
- TableRow,
122
- {
123
- "data-row-key": rowKey(item),
124
- className: cn(
125
- rowClassName?.(item),
126
- selectable && "cursor-pointer focus-visible:focus-ring data-[selected=true]:bg-accent-soft"
127
- ),
128
- ...rowProps(item, "grid"),
129
- children: [
130
- columns.map((column) => /* @__PURE__ */ jsx(TableCell, { alignRight: column.align === "end", children: column.cell(item) }, column.key)),
131
- renderActions ? /* @__PURE__ */ jsx(TableCell, { alignRight: true, children: /* @__PURE__ */ jsx(
132
- "div",
133
- {
134
- "data-row-actions": "",
135
- className: cn("flex flex-wrap justify-end gap-2", classNames?.actions),
136
- children: renderActions(item)
137
- }
138
- ) }) : null
139
- ]
140
- },
141
- rowKey(item)
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
- ) : null,
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
- "data-row-key": rowKey(item),
160
+ "aria-label": caption,
161
+ ...listbox ? { role: "listbox" } : {},
162
+ ...selectable ? { "data-row-scope": "" } : {},
163
163
  className: cn(
164
- "flex min-w-0 flex-col gap-3 rounded-card border-card p-card shadow-card surface-card",
165
- selectable && "cursor-pointer focus-visible:focus-ring data-[selected=true]:bg-accent-soft data-[selected=true]:shadow-selected",
166
- rowClassName?.(item),
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
- ...rowProps(item, "card"),
170
- children: [
171
- /* @__PURE__ */ jsx(
172
- "div",
173
- {
174
- className: cn(
175
- "min-w-0 font-semibold text-fs-150 text-ink [overflow-wrap:anywhere]",
176
- classNames?.cardTitle
177
- ),
178
- children: primary?.cell(item)
179
- }
180
- ),
181
- details.length > 0 ? /* @__PURE__ */ jsx("dl", { className: cn("m-0 flex flex-col gap-2", classNames?.cardDetails), children: details.map((column) => /* @__PURE__ */ jsxs(
182
- "div",
183
- {
184
- className: cn(
185
- "flex items-baseline justify-between gap-4",
186
- cardLabels === "hidden" && "justify-start",
187
- classNames?.cardDetail
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
- /* @__PURE__ */ jsx(
191
- "dt",
192
- {
193
- className: cn(
194
- "shrink-0 text-ink-3 text-meta",
195
- cardLabels === "hidden" && "sr-only",
196
- classNames?.cardLabel
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
- children: column.header
199
- }
200
- ),
201
- /* @__PURE__ */ jsx(
202
- "dd",
203
- {
204
- className: cn(
205
- "m-0 min-w-0 text-right text-body text-ink [overflow-wrap:anywhere]",
206
- cardLabels === "hidden" && "text-left",
207
- classNames?.cardValue
208
- ),
209
- children: column.cell(item)
210
- }
211
- )
212
- ]
213
- },
214
- column.key
215
- )) }) : null,
216
- renderActions ? /* @__PURE__ */ jsx("div", { "data-row-actions": "", className: cn("flex flex-wrap gap-2", classNames?.actions), children: renderActions(item) }) : null
217
- ]
218
- },
219
- rowKey(item)
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 w-9 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";
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 h-input min-w-32 max-w-full items-stretch overflow-hidden rounded-input border-control bg-surface-control",
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
- "aria-label": "Disminuir",
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
- "aria-label": "Aumentar",
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
  )
@@ -20,6 +20,8 @@ export interface UiStrings {
20
20
  copy: string;
21
21
  copied: string;
22
22
  more: string;
23
+ /** Accessible total on the bottom bar "More" button; `{count}` is replaced. */
24
+ morePending: string;
23
25
  remove: string;
24
26
  noResults: string;
25
27
  clear: string;
@@ -42,6 +44,10 @@ export interface UiStrings {
42
44
  steps: string;
43
45
  /** Default accessible name of an `Aside`. */
44
46
  aside: string;
47
+ /** Verb of the `NumberStepper` plus button; the field label follows it. */
48
+ increase: string;
49
+ /** Verb of the `NumberStepper` minus button; the field label follows it. */
50
+ decrease: string;
45
51
  /** Back action of a single-pane `ListDetail`. */
46
52
  backToList: string;
47
53
  /** Screen-reader state of a `DueChip` past its date. */
@@ -153,6 +159,7 @@ export declare const uiStrings: {
153
159
  readonly copy: "Copy";
154
160
  readonly copied: "Copied";
155
161
  readonly more: "More";
162
+ readonly morePending: "{count} pending";
156
163
  readonly remove: "Remove";
157
164
  readonly noResults: "No results";
158
165
  readonly clear: "Clear";
@@ -172,6 +179,8 @@ export declare const uiStrings: {
172
179
  readonly stepOf: "Step {current} of {total}: {label}";
173
180
  readonly steps: "Steps";
174
181
  readonly aside: "Related information";
182
+ readonly increase: "Increase";
183
+ readonly decrease: "Decrease";
175
184
  readonly backToList: "Back to list";
176
185
  readonly overdue: "Overdue";
177
186
  readonly dueSoon: "Due soon";
@@ -240,6 +249,7 @@ export declare const uiStrings: {
240
249
  readonly copy: "Copiar";
241
250
  readonly copied: "Copiado";
242
251
  readonly more: "Más";
252
+ readonly morePending: "{count} pendientes";
243
253
  readonly remove: "Quitar";
244
254
  readonly noResults: "Sin resultados";
245
255
  readonly clear: "Limpiar";
@@ -259,6 +269,8 @@ export declare const uiStrings: {
259
269
  readonly stepOf: "Paso {current} de {total}: {label}";
260
270
  readonly steps: "Pasos";
261
271
  readonly aside: "Información relacionada";
272
+ readonly increase: "Aumentar";
273
+ readonly decrease: "Disminuir";
262
274
  readonly backToList: "Volver a la lista";
263
275
  readonly overdue: "Vencido";
264
276
  readonly dueSoon: "Vence pronto";
@@ -21,6 +21,7 @@ const uiStrings = {
21
21
  copy: "Copy",
22
22
  copied: "Copied",
23
23
  more: "More",
24
+ morePending: "{count} pending",
24
25
  remove: "Remove",
25
26
  noResults: "No results",
26
27
  clear: "Clear",
@@ -40,6 +41,8 @@ const uiStrings = {
40
41
  stepOf: "Step {current} of {total}: {label}",
41
42
  steps: "Steps",
42
43
  aside: "Related information",
44
+ increase: "Increase",
45
+ decrease: "Decrease",
43
46
  backToList: "Back to list",
44
47
  overdue: "Overdue",
45
48
  dueSoon: "Due soon",
@@ -108,6 +111,7 @@ const uiStrings = {
108
111
  copy: "Copiar",
109
112
  copied: "Copiado",
110
113
  more: "M\xE1s",
114
+ morePending: "{count} pendientes",
111
115
  remove: "Quitar",
112
116
  noResults: "Sin resultados",
113
117
  clear: "Limpiar",
@@ -127,6 +131,8 @@ const uiStrings = {
127
131
  stepOf: "Paso {current} de {total}: {label}",
128
132
  steps: "Pasos",
129
133
  aside: "Informaci\xF3n relacionada",
134
+ increase: "Aumentar",
135
+ decrease: "Disminuir",
130
136
  backToList: "Volver a la lista",
131
137
  overdue: "Vencido",
132
138
  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;