@jcsoftdev/ui 0.7.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.
- package/CHANGELOG.md +19 -0
- package/README.md +6 -0
- package/dist/i18n/strings.d.ts +4 -0
- package/dist/i18n/strings.js +2 -0
- package/dist/shell/bottom-nav/bottom-nav.d.ts +5 -1
- package/dist/shell/bottom-nav/bottom-nav.js +52 -9
- package/package.json +2 -2
- package/src/i18n/strings.ts +4 -0
- package/src/shell/bottom-nav/bottom-nav.tsx +78 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
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
|
+
|
|
3
22
|
## 0.7.0 (2026-11-03)
|
|
4
23
|
|
|
5
24
|
### Demo gaps
|
package/README.md
CHANGED
|
@@ -162,6 +162,12 @@ import { UiStringsProvider } from "@jcsoftdev/ui/i18n";
|
|
|
162
162
|
provider inherits its parent and overrides only the keys it passes. Hard-coded Spanish labels that
|
|
163
163
|
older components already ship (Carousel, AI set) are not routed through it yet.
|
|
164
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.
|
|
170
|
+
|
|
165
171
|
## Status, forms and states (additive props)
|
|
166
172
|
|
|
167
173
|
| Component | Added |
|
package/dist/i18n/strings.d.ts
CHANGED
|
@@ -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;
|
|
@@ -157,6 +159,7 @@ export declare const uiStrings: {
|
|
|
157
159
|
readonly copy: "Copy";
|
|
158
160
|
readonly copied: "Copied";
|
|
159
161
|
readonly more: "More";
|
|
162
|
+
readonly morePending: "{count} pending";
|
|
160
163
|
readonly remove: "Remove";
|
|
161
164
|
readonly noResults: "No results";
|
|
162
165
|
readonly clear: "Clear";
|
|
@@ -246,6 +249,7 @@ export declare const uiStrings: {
|
|
|
246
249
|
readonly copy: "Copiar";
|
|
247
250
|
readonly copied: "Copiado";
|
|
248
251
|
readonly more: "Más";
|
|
252
|
+
readonly morePending: "{count} pendientes";
|
|
249
253
|
readonly remove: "Quitar";
|
|
250
254
|
readonly noResults: "Sin resultados";
|
|
251
255
|
readonly clear: "Limpiar";
|
package/dist/i18n/strings.js
CHANGED
|
@@ -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",
|
|
@@ -110,6 +111,7 @@ const uiStrings = {
|
|
|
110
111
|
copy: "Copiar",
|
|
111
112
|
copied: "Copiado",
|
|
112
113
|
more: "M\xE1s",
|
|
114
|
+
morePending: "{count} pendientes",
|
|
113
115
|
remove: "Quitar",
|
|
114
116
|
noResults: "Sin resultados",
|
|
115
117
|
clear: "Limpiar",
|
|
@@ -17,6 +17,10 @@ export interface BottomNavProps {
|
|
|
17
17
|
maxSlots?: number;
|
|
18
18
|
/** Text of the "More" button and the drawer title. Defaults to the localized "More". */
|
|
19
19
|
moreLabel?: string;
|
|
20
|
+
/** Accessible text of the total on "More"; defaults to the localized "{count} pending". */
|
|
21
|
+
moreBadgeLabel?: (count: number) => string;
|
|
22
|
+
/** `count` (default) shows numeric badges as a count chip on the phone bar; `dot` keeps the small dot. */
|
|
23
|
+
badgeStyle?: "count" | "dot";
|
|
20
24
|
/** Pinned at the bottom of the "More" drawer, e.g. the account or a sign-out button. */
|
|
21
25
|
moreFooter?: ReactNode;
|
|
22
26
|
/** Link renderer; defaults to a plain anchor. */
|
|
@@ -31,4 +35,4 @@ export interface BottomNavProps {
|
|
|
31
35
|
* inside `AppShell`: it sticks to the bottom of the viewport and hides itself once the shell is
|
|
32
36
|
* 900 px or wider, where the sidebar takes over. Without an `AppShell` it is always visible.
|
|
33
37
|
*/
|
|
34
|
-
export declare function BottomNav({ items, ariaLabel, maxSlots, moreLabel, moreFooter, renderLink, className, classNames, }: BottomNavProps): import("react").JSX.Element;
|
|
38
|
+
export declare function BottomNav({ items, ariaLabel, maxSlots, moreLabel, moreBadgeLabel, badgeStyle, moreFooter, renderLink, className, classNames, }: BottomNavProps): import("react").JSX.Element;
|
|
@@ -6,6 +6,29 @@ import { Menu } from "../../icons/index.js";
|
|
|
6
6
|
import { Drawer, DrawerContent, DrawerTitle } from "../../overlays/drawer/index.js";
|
|
7
7
|
import { cn } from "../../utils/cn.js";
|
|
8
8
|
import { BOTTOM_NAV_MAX_SLOTS, splitBottomNavItems } from "./split.js";
|
|
9
|
+
const BADGE_CAP = 99;
|
|
10
|
+
function numericBadge(badge) {
|
|
11
|
+
if (typeof badge === "number") return Number.isFinite(badge) ? badge : void 0;
|
|
12
|
+
if (typeof badge === "string" && /^\s*\d+\s*$/.test(badge)) return Number(badge);
|
|
13
|
+
return void 0;
|
|
14
|
+
}
|
|
15
|
+
function formatCount(count) {
|
|
16
|
+
return count > BADGE_CAP ? `${BADGE_CAP}+` : String(count);
|
|
17
|
+
}
|
|
18
|
+
const dotClasses = "absolute -top-0.5 -right-1 size-2 rounded-pill";
|
|
19
|
+
const chipClasses = "absolute -top-1.5 -right-2.5 inline-flex h-4 min-w-4 items-center justify-center rounded-pill px-1 font-bold text-count text-surface leading-none";
|
|
20
|
+
function BadgeMark({
|
|
21
|
+
count,
|
|
22
|
+
danger,
|
|
23
|
+
asDot,
|
|
24
|
+
className
|
|
25
|
+
}) {
|
|
26
|
+
const tone = danger ? "bg-danger" : "bg-warning";
|
|
27
|
+
if (count === void 0 || asDot) {
|
|
28
|
+
return /* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: cn(dotClasses, tone, className) });
|
|
29
|
+
}
|
|
30
|
+
return /* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: cn(chipClasses, tone, className), children: formatCount(count) });
|
|
31
|
+
}
|
|
9
32
|
const defaultRenderLink = ({ children, ...props }) => /* @__PURE__ */ jsx("a", { ...props, children });
|
|
10
33
|
const slotClasses = "relative flex min-h-14 w-full flex-col items-center justify-center gap-0.5 px-1 text-ink-2 text-meta focus-visible:focus-ring aria-[current=page]:font-bold aria-[current=page]:text-accent-ink data-[active=true]:font-bold data-[active=true]:text-accent-ink [&_svg]:size-5 [&_svg]:shrink-0";
|
|
11
34
|
function BottomNav({
|
|
@@ -13,6 +36,8 @@ function BottomNav({
|
|
|
13
36
|
ariaLabel,
|
|
14
37
|
maxSlots = BOTTOM_NAV_MAX_SLOTS,
|
|
15
38
|
moreLabel,
|
|
39
|
+
moreBadgeLabel,
|
|
40
|
+
badgeStyle = "count",
|
|
16
41
|
moreFooter,
|
|
17
42
|
renderLink = defaultRenderLink,
|
|
18
43
|
className,
|
|
@@ -23,6 +48,14 @@ function BottomNav({
|
|
|
23
48
|
const { visible, overflow } = splitBottomNavItems(items, maxSlots);
|
|
24
49
|
const more = moreLabel ?? strings.more;
|
|
25
50
|
const moreActive = overflow.some((item) => item.active);
|
|
51
|
+
const badged = overflow.filter((item) => item.badge !== void 0);
|
|
52
|
+
const overflowCounts = badged.map((item) => numericBadge(item.badge));
|
|
53
|
+
const overflowTotal = overflowCounts.reduce(
|
|
54
|
+
(sum, count) => count === void 0 ? sum : (sum ?? 0) + count,
|
|
55
|
+
void 0
|
|
56
|
+
);
|
|
57
|
+
const overflowDanger = badged.some((item) => item.badgeTone === "danger");
|
|
58
|
+
const overflowBadgeText = overflowTotal === void 0 ? void 0 : (moreBadgeLabel ?? ((count) => strings.morePending.replace("{count}", String(count))))(overflowTotal);
|
|
26
59
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
27
60
|
/* @__PURE__ */ jsx(
|
|
28
61
|
"nav",
|
|
@@ -50,14 +83,12 @@ function BottomNav({
|
|
|
50
83
|
item.icon,
|
|
51
84
|
item.badge !== void 0 ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
52
85
|
/* @__PURE__ */ jsx(
|
|
53
|
-
|
|
86
|
+
BadgeMark,
|
|
54
87
|
{
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
classNames?.badge
|
|
60
|
-
)
|
|
88
|
+
count: numericBadge(item.badge),
|
|
89
|
+
danger: item.badgeTone === "danger",
|
|
90
|
+
asDot: badgeStyle === "dot",
|
|
91
|
+
className: classNames?.badge
|
|
61
92
|
}
|
|
62
93
|
),
|
|
63
94
|
/* @__PURE__ */ jsx("span", { className: "sr-only", children: item.badgeLabel ?? item.badge })
|
|
@@ -76,8 +107,20 @@ function BottomNav({
|
|
|
76
107
|
onClick: () => setMoreOpen(true),
|
|
77
108
|
className: cn(slotClasses, classNames?.moreButton),
|
|
78
109
|
children: [
|
|
79
|
-
/* @__PURE__ */
|
|
80
|
-
|
|
110
|
+
/* @__PURE__ */ jsxs("span", { className: "relative", children: [
|
|
111
|
+
/* @__PURE__ */ jsx(Menu, { "aria-hidden": "true" }),
|
|
112
|
+
badged.length > 0 ? /* @__PURE__ */ jsx(
|
|
113
|
+
BadgeMark,
|
|
114
|
+
{
|
|
115
|
+
count: overflowTotal,
|
|
116
|
+
danger: overflowDanger,
|
|
117
|
+
asDot: badgeStyle === "dot",
|
|
118
|
+
className: classNames?.badge
|
|
119
|
+
}
|
|
120
|
+
) : null
|
|
121
|
+
] }),
|
|
122
|
+
/* @__PURE__ */ jsx("span", { children: more }),
|
|
123
|
+
badged.length > 0 && overflowBadgeText ? /* @__PURE__ */ jsx("span", { className: "sr-only", children: overflowBadgeText }) : null
|
|
81
124
|
]
|
|
82
125
|
}
|
|
83
126
|
) }) : null
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jcsoftdev/ui",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "Token-driven React component library: React 19, Tailwind v4.",
|
|
5
5
|
"author": "jcsoftdev",
|
|
6
6
|
"license": "MIT",
|
|
@@ -102,7 +102,7 @@
|
|
|
102
102
|
"typescript": "^5.5.4",
|
|
103
103
|
"vite": "7.3.6",
|
|
104
104
|
"vitest": "4.1.11",
|
|
105
|
-
"@jcsoftdev/ui-tokens": "^0.7.
|
|
105
|
+
"@jcsoftdev/ui-tokens": "^0.7.1"
|
|
106
106
|
},
|
|
107
107
|
"publishConfig": {
|
|
108
108
|
"access": "public"
|
package/src/i18n/strings.ts
CHANGED
|
@@ -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;
|
|
@@ -159,6 +161,7 @@ export const uiStrings = {
|
|
|
159
161
|
copy: "Copy",
|
|
160
162
|
copied: "Copied",
|
|
161
163
|
more: "More",
|
|
164
|
+
morePending: "{count} pending",
|
|
162
165
|
remove: "Remove",
|
|
163
166
|
noResults: "No results",
|
|
164
167
|
clear: "Clear",
|
|
@@ -248,6 +251,7 @@ export const uiStrings = {
|
|
|
248
251
|
copy: "Copiar",
|
|
249
252
|
copied: "Copiado",
|
|
250
253
|
more: "Más",
|
|
254
|
+
morePending: "{count} pendientes",
|
|
251
255
|
remove: "Quitar",
|
|
252
256
|
noResults: "Sin resultados",
|
|
253
257
|
clear: "Limpiar",
|
|
@@ -36,6 +36,10 @@ export interface BottomNavProps {
|
|
|
36
36
|
maxSlots?: number;
|
|
37
37
|
/** Text of the "More" button and the drawer title. Defaults to the localized "More". */
|
|
38
38
|
moreLabel?: string;
|
|
39
|
+
/** Accessible text of the total on "More"; defaults to the localized "{count} pending". */
|
|
40
|
+
moreBadgeLabel?: (count: number) => string;
|
|
41
|
+
/** `count` (default) shows numeric badges as a count chip on the phone bar; `dot` keeps the small dot. */
|
|
42
|
+
badgeStyle?: "count" | "dot";
|
|
39
43
|
/** Pinned at the bottom of the "More" drawer, e.g. the account or a sign-out button. */
|
|
40
44
|
moreFooter?: ReactNode;
|
|
41
45
|
/** Link renderer; defaults to a plain anchor. */
|
|
@@ -45,6 +49,45 @@ export interface BottomNavProps {
|
|
|
45
49
|
classNames?: ClassNames<BottomNavPart>;
|
|
46
50
|
}
|
|
47
51
|
|
|
52
|
+
const BADGE_CAP = 99;
|
|
53
|
+
|
|
54
|
+
function numericBadge(badge: ReactNode): number | undefined {
|
|
55
|
+
if (typeof badge === "number") return Number.isFinite(badge) ? badge : undefined;
|
|
56
|
+
if (typeof badge === "string" && /^\s*\d+\s*$/.test(badge)) return Number(badge);
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function formatCount(count: number): string {
|
|
61
|
+
return count > BADGE_CAP ? `${BADGE_CAP}+` : String(count);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const dotClasses = "absolute -top-0.5 -right-1 size-2 rounded-pill";
|
|
65
|
+
|
|
66
|
+
const chipClasses =
|
|
67
|
+
"absolute -top-1.5 -right-2.5 inline-flex h-4 min-w-4 items-center justify-center rounded-pill px-1 font-bold text-count text-surface leading-none";
|
|
68
|
+
|
|
69
|
+
function BadgeMark({
|
|
70
|
+
count,
|
|
71
|
+
danger,
|
|
72
|
+
asDot,
|
|
73
|
+
className,
|
|
74
|
+
}: {
|
|
75
|
+
count: number | undefined;
|
|
76
|
+
danger: boolean;
|
|
77
|
+
asDot: boolean;
|
|
78
|
+
className?: string;
|
|
79
|
+
}) {
|
|
80
|
+
const tone = danger ? "bg-danger" : "bg-warning";
|
|
81
|
+
if (count === undefined || asDot) {
|
|
82
|
+
return <span aria-hidden="true" className={cn(dotClasses, tone, className)} />;
|
|
83
|
+
}
|
|
84
|
+
return (
|
|
85
|
+
<span aria-hidden="true" className={cn(chipClasses, tone, className)}>
|
|
86
|
+
{formatCount(count)}
|
|
87
|
+
</span>
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
48
91
|
const defaultRenderLink: BottomNavRenderLink = ({ children, ...props }) => (
|
|
49
92
|
<a {...props}>{children}</a>
|
|
50
93
|
);
|
|
@@ -63,6 +106,8 @@ export function BottomNav({
|
|
|
63
106
|
ariaLabel,
|
|
64
107
|
maxSlots = BOTTOM_NAV_MAX_SLOTS,
|
|
65
108
|
moreLabel,
|
|
109
|
+
moreBadgeLabel,
|
|
110
|
+
badgeStyle = "count",
|
|
66
111
|
moreFooter,
|
|
67
112
|
renderLink = defaultRenderLink,
|
|
68
113
|
className,
|
|
@@ -73,6 +118,20 @@ export function BottomNav({
|
|
|
73
118
|
const { visible, overflow } = splitBottomNavItems(items, maxSlots);
|
|
74
119
|
const more = moreLabel ?? strings.more;
|
|
75
120
|
const moreActive = overflow.some((item) => item.active);
|
|
121
|
+
const badged = overflow.filter((item) => item.badge !== undefined);
|
|
122
|
+
const overflowCounts = badged.map((item) => numericBadge(item.badge));
|
|
123
|
+
const overflowTotal = overflowCounts.reduce<number | undefined>(
|
|
124
|
+
(sum, count) => (count === undefined ? sum : (sum ?? 0) + count),
|
|
125
|
+
undefined,
|
|
126
|
+
);
|
|
127
|
+
const overflowDanger = badged.some((item) => item.badgeTone === "danger");
|
|
128
|
+
const overflowBadgeText =
|
|
129
|
+
overflowTotal === undefined
|
|
130
|
+
? undefined
|
|
131
|
+
: (
|
|
132
|
+
moreBadgeLabel ??
|
|
133
|
+
((count: number) => strings.morePending.replace("{count}", String(count)))
|
|
134
|
+
)(overflowTotal);
|
|
76
135
|
|
|
77
136
|
return (
|
|
78
137
|
<>
|
|
@@ -102,13 +161,11 @@ export function BottomNav({
|
|
|
102
161
|
{item.icon}
|
|
103
162
|
{item.badge !== undefined ? (
|
|
104
163
|
<>
|
|
105
|
-
<
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
classNames?.badge,
|
|
111
|
-
)}
|
|
164
|
+
<BadgeMark
|
|
165
|
+
count={numericBadge(item.badge)}
|
|
166
|
+
danger={item.badgeTone === "danger"}
|
|
167
|
+
asDot={badgeStyle === "dot"}
|
|
168
|
+
className={classNames?.badge}
|
|
112
169
|
/>
|
|
113
170
|
<span className="sr-only">{item.badgeLabel ?? item.badge}</span>
|
|
114
171
|
</>
|
|
@@ -130,8 +187,21 @@ export function BottomNav({
|
|
|
130
187
|
onClick={() => setMoreOpen(true)}
|
|
131
188
|
className={cn(slotClasses, classNames?.moreButton)}
|
|
132
189
|
>
|
|
133
|
-
<
|
|
190
|
+
<span className="relative">
|
|
191
|
+
<Menu aria-hidden="true" />
|
|
192
|
+
{badged.length > 0 ? (
|
|
193
|
+
<BadgeMark
|
|
194
|
+
count={overflowTotal}
|
|
195
|
+
danger={overflowDanger}
|
|
196
|
+
asDot={badgeStyle === "dot"}
|
|
197
|
+
className={classNames?.badge}
|
|
198
|
+
/>
|
|
199
|
+
) : null}
|
|
200
|
+
</span>
|
|
134
201
|
<span>{more}</span>
|
|
202
|
+
{badged.length > 0 && overflowBadgeText ? (
|
|
203
|
+
<span className="sr-only">{overflowBadgeText}</span>
|
|
204
|
+
) : null}
|
|
135
205
|
</button>
|
|
136
206
|
</li>
|
|
137
207
|
) : null}
|