@plexui/ui 0.56.0 → 0.58.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/dist/es/components/Kbd/Kbd.js +3 -0
- package/dist/es/components/Kbd/Kbd.js.map +1 -1
- package/dist/es/components/Kbd/KbdModifier.js +27 -0
- package/dist/es/components/Kbd/KbdModifier.js.map +1 -0
- package/dist/es/components/Kbd/index.js +1 -0
- package/dist/es/components/Kbd/index.js.map +1 -1
- package/dist/es/components/Progress/Progress.js +18 -1
- package/dist/es/components/Progress/Progress.js.map +1 -1
- package/dist/es/components/Progress/index.js +1 -1
- package/dist/es/components/Progress/index.js.map +1 -1
- package/dist/es/components/RollingNumber/RollingNumber.js +41 -0
- package/dist/es/components/RollingNumber/RollingNumber.js.map +1 -0
- package/dist/es/components/RollingNumber/index.js +2 -0
- package/dist/es/components/RollingNumber/index.js.map +1 -0
- package/dist/es/components/Stepper/Stepper.js +4 -4
- package/dist/es/components/Stepper/Stepper.js.map +1 -1
- package/dist/types/components/Kbd/Kbd.d.ts +2 -0
- package/dist/types/components/Kbd/KbdModifier.d.ts +18 -0
- package/dist/types/components/Kbd/index.d.ts +1 -0
- package/dist/types/components/Progress/Progress.d.ts +26 -1
- package/dist/types/components/Progress/index.d.ts +1 -1
- package/dist/types/components/RollingNumber/RollingNumber.d.ts +25 -0
- package/dist/types/components/RollingNumber/index.d.ts +1 -0
- package/dist/types/components/Stepper/Stepper.d.ts +8 -3
- package/package.json +2 -2
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import clsx from "clsx";
|
|
3
3
|
import s from "@plexui/styles/components/Kbd/Kbd.module.css";
|
|
4
|
+
import { KbdModifier } from "./KbdModifier.js";
|
|
4
5
|
/** A key or a shortcut, such as ⌘K, in a tooltip, a menu item or a sentence. */
|
|
5
6
|
export const Kbd = ({ size = "sm", variant = "soft", className, ...restProps }) => {
|
|
6
7
|
return _jsx("kbd", { className: clsx(s.Kbd, className), "data-size": size, "data-variant": variant, ...restProps });
|
|
@@ -10,4 +11,6 @@ const Group = ({ className, ...restProps }) => {
|
|
|
10
11
|
return _jsx("span", { className: clsx(s.Group, className), ...restProps });
|
|
11
12
|
};
|
|
12
13
|
Kbd.Group = Group;
|
|
14
|
+
/** A modifier key as the reader's keyboard prints it: ⌘ on a Mac, Ctrl elsewhere (`name` picks ⌘, ⌃, ⌥ or ⇧). */
|
|
15
|
+
Kbd.Modifier = KbdModifier;
|
|
13
16
|
//# sourceMappingURL=Kbd.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Kbd.js","sourceRoot":"","sources":["../../../../src/components/Kbd/Kbd.tsx"],"names":[],"mappings":";AAAA,OAAO,IAAI,MAAM,MAAM,CAAA;AAEvB,OAAO,CAAC,MAAM,8CAA8C,CAAA;
|
|
1
|
+
{"version":3,"file":"Kbd.js","sourceRoot":"","sources":["../../../../src/components/Kbd/Kbd.tsx"],"names":[],"mappings":";AAAA,OAAO,IAAI,MAAM,MAAM,CAAA;AAEvB,OAAO,CAAC,MAAM,8CAA8C,CAAA;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAgB3C,gFAAgF;AAChF,MAAM,CAAC,MAAM,GAAG,GAAG,CAAC,EAAE,IAAI,GAAG,IAAI,EAAE,OAAO,GAAG,MAAM,EAAE,SAAS,EAAE,GAAG,SAAS,EAAY,EAAE,EAAE;IAC1F,OAAO,cAAK,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC,GAAG,EAAE,SAAS,CAAC,eAAa,IAAI,kBAAgB,OAAO,KAAM,SAAS,GAAI,CAAA;AAC1G,CAAC,CAAA;AAID,6CAA6C;AAC7C,MAAM,KAAK,GAAG,CAAC,EAAE,SAAS,EAAE,GAAG,SAAS,EAAiB,EAAE,EAAE;IAC3D,OAAO,eAAM,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC,KAAK,EAAE,SAAS,CAAC,KAAM,SAAS,GAAI,CAAA;AACrE,CAAC,CAAA;AAED,GAAG,CAAC,KAAK,GAAG,KAAK,CAAA;AACjB,iHAAiH;AACjH,GAAG,CAAC,QAAQ,GAAG,WAAW,CAAA","sourcesContent":["import clsx from \"clsx\"\nimport type { ComponentProps } from \"react\"\nimport s from \"@plexui/styles/components/Kbd/Kbd.module.css\"\nimport { KbdModifier } from \"./KbdModifier\"\n\nexport type KbdProps = ComponentProps<\"kbd\"> & {\n /**\n * Height and text size: `xs` 16px, `sm` 20px, `md` 24px\n * @default sm\n */\n size?: \"xs\" | \"sm\" | \"md\"\n /**\n * `soft` fills the key, `outline` draws its edge. Both mix the text color,\n * so the key reads on any surface.\n * @default soft\n */\n variant?: \"soft\" | \"outline\"\n}\n\n/** A key or a shortcut, such as ⌘K, in a tooltip, a menu item or a sentence. */\nexport const Kbd = ({ size = \"sm\", variant = \"soft\", className, ...restProps }: KbdProps) => {\n return <kbd className={clsx(s.Kbd, className)} data-size={size} data-variant={variant} {...restProps} />\n}\n\nexport type KbdGroupProps = ComponentProps<\"span\">\n\n/** Keys pressed together: a row of `Kbd`. */\nconst Group = ({ className, ...restProps }: KbdGroupProps) => {\n return <span className={clsx(s.Group, className)} {...restProps} />\n}\n\nKbd.Group = Group\n/** A modifier key as the reader's keyboard prints it: ⌘ on a Mac, Ctrl elsewhere (`name` picks ⌘, ⌃, ⌥ or ⇧). */\nKbd.Modifier = KbdModifier\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import clsx from "clsx";
|
|
4
|
+
import { useSyncExternalStore } from "react";
|
|
5
|
+
import s from "@plexui/styles/components/Kbd/Kbd.module.css";
|
|
6
|
+
/** Each modifier on an Apple keyboard (a symbol and its name) and on another one. `mod` is ⌘ there and Ctrl here. */
|
|
7
|
+
export const KBD_MODIFIERS = {
|
|
8
|
+
mod: { apple: { symbol: "⌘", name: "Command" }, other: { symbol: "Ctrl", name: "Ctrl" } },
|
|
9
|
+
ctrl: { apple: { symbol: "⌃", name: "Control" }, other: { symbol: "Ctrl", name: "Ctrl" } },
|
|
10
|
+
alt: { apple: { symbol: "⌥", name: "Option" }, other: { symbol: "Alt", name: "Alt" } },
|
|
11
|
+
shift: { apple: { symbol: "⇧", name: "Shift" }, other: { symbol: "Shift", name: "Shift" } },
|
|
12
|
+
};
|
|
13
|
+
/** Whether the browser runs on a Mac, an iPhone or an iPad, whose keyboards print ⌘ and ⌥. */
|
|
14
|
+
export const isApplePlatform = () => {
|
|
15
|
+
if (typeof navigator === "undefined")
|
|
16
|
+
return true;
|
|
17
|
+
const platform = navigator.userAgentData?.platform || navigator.platform || navigator.userAgent;
|
|
18
|
+
return /mac|iphone|ipad|ipod/i.test(platform);
|
|
19
|
+
};
|
|
20
|
+
const subscribe = () => () => { };
|
|
21
|
+
/** A modifier key printed as the reader's keyboard prints it: ⌘ on a Mac, Ctrl elsewhere; its name is read out. */
|
|
22
|
+
export const KbdModifier = ({ name = "mod", platform, size = "sm", variant = "soft", className, ...restProps }) => {
|
|
23
|
+
const apple = useSyncExternalStore(subscribe, isApplePlatform, () => true);
|
|
24
|
+
const key = KBD_MODIFIERS[name][platform ?? (apple ? "apple" : "other")];
|
|
25
|
+
return (_jsx("kbd", { className: clsx(s.Kbd, className), "data-size": size, "data-variant": variant, "data-modifier": name, ...restProps, children: key.symbol === key.name ? (key.symbol) : (_jsxs(_Fragment, { children: [_jsx("span", { "aria-hidden": "true", children: key.symbol }), _jsx("span", { className: s.Name, children: key.name })] })) }));
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=KbdModifier.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KbdModifier.js","sourceRoot":"","sources":["../../../../src/components/Kbd/KbdModifier.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,I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AC,CAAA;AAShC,mHAAmH;AACnH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,EAAE,IAAI,GAAG,KAAK,EAAE,QAAQ,EAAE,IAAI,GAAG,IAAI,EAAE,OAAO,GAAG,MAAM,EAAE,SAAS,EAAE,GAAG,SAAS,EAAoB,EAAE,EAAE;IAClI,MAAM,KAAK,GAAG,oBAAoB,CAAC,SAAS,EAAE,eAAe,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,CAAA;IAC1E,MAAM,GAAG,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC,QAAQ,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAA;IACxE,OAAO,CACL,cAAK,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC,GAAG,EAAE,SAAS,CAAC,eAAa,IAAI,kBAAgB,OAAO,mBAAiB,IAAI,KAAM,SAAS,YAC/G,GAAG,CAAC,MAAM,KAAK,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CACzB,GAAG,CAAC,MAAM,CACX,CAAC,CAAC,CAAC,CACF,8BACE,8BAAkB,MAAM,YAAE,GAAG,CAAC,MAAM,GAAQ,EAC5C,eAAM,SAAS,EAAE,CAAC,CAAC,IAAI,YAAG,GAAG,CAAC,IAAI,GAAQ,IACzC,CACJ,GACG,CACP,CAAA;AACH,CAAC,CAAA","sourcesContent":["\"use client\"\n\nimport clsx from \"clsx\"\nimport { useSyncExternalStore } from \"react\"\nimport s from \"@plexui/styles/components/Kbd/Kbd.module.css\"\nimport type { KbdProps } from \"./Kbd\"\n\nexport type KbdModifierName = \"mod\" | \"ctrl\" | \"alt\" | \"shift\"\nexport type KbdPlatform = \"apple\" | \"other\"\n\n/** Each modifier on an Apple keyboard (a symbol and its name) and on another one. `mod` is ⌘ there and Ctrl here. */\nexport const KBD_MODIFIERS: Record<KbdModifierName, Record<KbdPlatform, { symbol: string; name: string }>> = {\n mod: { apple: { symbol: \"⌘\", name: \"Command\" }, other: { symbol: \"Ctrl\", name: \"Ctrl\" } },\n ctrl: { apple: { symbol: \"⌃\", name: \"Control\" }, other: { symbol: \"Ctrl\", name: \"Ctrl\" } },\n alt: { apple: { symbol: \"⌥\", name: \"Option\" }, other: { symbol: \"Alt\", name: \"Alt\" } },\n shift: { apple: { symbol: \"⇧\", name: \"Shift\" }, other: { symbol: \"Shift\", name: \"Shift\" } },\n}\n\n/** Whether the browser runs on a Mac, an iPhone or an iPad, whose keyboards print ⌘ and ⌥. */\nexport const isApplePlatform = () => {\n if (typeof navigator === \"undefined\") return true\n const platform = (navigator as Navigator & { userAgentData?: { platform?: string } }).userAgentData?.platform || navigator.platform || navigator.userAgent\n return /mac|iphone|ipad|ipod/i.test(platform)\n}\n\nconst subscribe = () => () => {}\n\nexport type KbdModifierProps = Omit<KbdProps, \"children\"> & {\n /** The modifier: `mod` is ⌘ on an Apple keyboard and Ctrl on another, as an app's shortcuts are. @default \"mod\" */\n name?: KbdModifierName\n /** The keyboard to print for; by default the one the browser runs on (Apple on the server). */\n platform?: KbdPlatform\n}\n\n/** A modifier key printed as the reader's keyboard prints it: ⌘ on a Mac, Ctrl elsewhere; its name is read out. */\nexport const KbdModifier = ({ name = \"mod\", platform, size = \"sm\", variant = \"soft\", className, ...restProps }: KbdModifierProps) => {\n const apple = useSyncExternalStore(subscribe, isApplePlatform, () => true)\n const key = KBD_MODIFIERS[name][platform ?? (apple ? \"apple\" : \"other\")]\n return (\n <kbd className={clsx(s.Kbd, className)} data-size={size} data-variant={variant} data-modifier={name} {...restProps}>\n {key.symbol === key.name ? (\n key.symbol\n ) : (\n <>\n <span aria-hidden=\"true\">{key.symbol}</span>\n <span className={s.Name}>{key.name}</span>\n </>\n )}\n </kbd>\n )\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/Kbd/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAqC,MAAM,OAAO,CAAA","sourcesContent":["export { Kbd, type KbdGroupProps, type KbdProps } from \"./Kbd\"\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/Kbd/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAqC,MAAM,OAAO,CAAA;AAC9D,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,eAAe,EAAiE,MAAM,eAAe,CAAA","sourcesContent":["export { Kbd, type KbdGroupProps, type KbdProps } from \"./Kbd\"\nexport { KBD_MODIFIERS, KbdModifier, isApplePlatform, type KbdModifierName, type KbdModifierProps, type KbdPlatform } from \"./KbdModifier\"\n"]}
|
|
@@ -4,7 +4,24 @@ import clsx from "clsx";
|
|
|
4
4
|
import {} from "react";
|
|
5
5
|
import { Progress as RadixProgress } from "radix-ui";
|
|
6
6
|
import s from "@plexui/styles/components/Progress/Progress.module.css";
|
|
7
|
-
|
|
7
|
+
/** The parts of a segmented bar, each clamped so their sum stays within `max`, and their sum. */
|
|
8
|
+
export const progressSegments = (segments, max) => {
|
|
9
|
+
let total = 0;
|
|
10
|
+
const parts = segments.map((segment) => {
|
|
11
|
+
const value = Math.max(0, Math.min(max - total, segment.value || 0));
|
|
12
|
+
total += value;
|
|
13
|
+
return { ...segment, value };
|
|
14
|
+
});
|
|
15
|
+
return { parts, total };
|
|
16
|
+
};
|
|
17
|
+
const segmentsLabel = (parts, max) => parts.map((part) => `${part.label ? `${part.label} ` : ""}${Math.round((part.value / max) * 100)}%`).join(", ");
|
|
18
|
+
export const Progress = ({ value = null, max = 100, segments, className, ...restProps }) => {
|
|
19
|
+
if (segments) {
|
|
20
|
+
// Radix falls back to 100 for a max that is not a positive number; the parts are measured against the same
|
|
21
|
+
const rootMax = typeof max === "number" && max > 0 && !Number.isNaN(max) ? max : 100;
|
|
22
|
+
const { parts, total } = progressSegments(segments, rootMax);
|
|
23
|
+
return (_jsx(RadixProgress.Root, { value: total, max: rootMax, getValueLabel: () => segmentsLabel(parts, rootMax), className: clsx(s.Root, className), "data-segmented": "", ...restProps, children: parts.map((part, index) => part.value > 0 ? (_jsx("div", { className: s.Segment, "data-color": part.color ?? "primary", style: { width: `${(part.value / rootMax) * 100}%` } }, index)) : null) }));
|
|
24
|
+
}
|
|
8
25
|
const resolved = value == null ? null : Math.max(0, Math.min(max, value));
|
|
9
26
|
const percentage = resolved == null ? null : (resolved / max) * 100;
|
|
10
27
|
return (_jsx(RadixProgress.Root, { value: resolved, max: max, className: clsx(s.Root, className), ...restProps, children: _jsx(RadixProgress.Indicator, { className: s.Indicator, style: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Progress.js","sourceRoot":"","sources":["../../../../src/components/Progress/Progress.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAuB,MAAM,OAAO,CAAA;AAC3C,OAAO,EAAE,QAAQ,IAAI,aAAa,EAAE,MAAM,UAAU,CAAA;AACpD,OAAO,CAAC,MAAM,wDAAwD,CAAA;
|
|
1
|
+
{"version":3,"file":"Progress.js","sourceRoot":"","sources":["../../../../src/components/Progress/Progress.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAuB,MAAM,OAAO,CAAA;AAC3C,OAAO,EAAE,QAAQ,IAAI,aAAa,EAAE,MAAM,UAAU,CAAA;AACpD,OAAO,CAAC,MAAM,wDAAwD,CAAA;AAmCtE,iGAAiG;AACjG,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,QAA2B,EAAE,GAAW,EAAE,EAAE;IAC3E,IAAI,KAAK,GAAG,CAAC,CAAA;IACb,MAAM,KAAK,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE;QACrC,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,C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,CAAC,CAAC,SAAS,GACvD,GACiB,CACtB,CAAA;AACH,CAAC,CAAA","sourcesContent":["\"use client\"\n\nimport clsx from \"clsx\"\nimport { type ComponentProps } from \"react\"\nimport { Progress as RadixProgress } from \"radix-ui\"\nimport s from \"@plexui/styles/components/Progress/Progress.module.css\"\n\nexport type ProgressColor = \"primary\" | \"secondary\" | \"success\" | \"warning\" | \"caution\" | \"danger\" | \"info\" | \"discovery\"\n\n/** A part of a segmented bar: its share of `max`, its color, and the name it is read with. */\nexport type ProgressSegment = {\n value: number\n /** @default \"primary\" */\n color?: ProgressColor\n /** Read out with its share, such as \"Paid 60%\" */\n label?: string\n}\n\nexport type ProgressProps = Omit<\n ComponentProps<typeof RadixProgress.Root>,\n \"children\"\n> & {\n /**\n * Current progress value, between `0` and `max`.\n * Omit (or pass `null`) for an indeterminate state.\n */\n value?: number | null\n /**\n * Maximum value.\n * @default 100\n */\n max?: number\n /**\n * Parts of one bar, side by side in their colors, such as paid, pending and due. The value is their sum; they\n * take `value`'s place. A part's share is clamped so the bar never passes `max`.\n */\n segments?: ProgressSegment[]\n className?: string\n}\n\n/** The parts of a segmented bar, each clamped so their sum stays within `max`, and their sum. */\nexport const progressSegments = (segments: ProgressSegment[], max: number) => {\n let total = 0\n const parts = segments.map((segment) => {\n const value = Math.max(0, Math.min(max - total, segment.value || 0))\n total += value\n return { ...segment, value }\n })\n return { parts, total }\n}\n\nconst segmentsLabel = (parts: ProgressSegment[], max: number) =>\n parts.map((part) => `${part.label ? `${part.label} ` : \"\"}${Math.round((part.value / max) * 100)}%`).join(\", \")\n\nexport const Progress = ({\n value = null,\n max = 100,\n segments,\n className,\n ...restProps\n}: ProgressProps) => {\n if (segments) {\n // Radix falls back to 100 for a max that is not a positive number; the parts are measured against the same\n const rootMax = typeof max === \"number\" && max > 0 && !Number.isNaN(max) ? max : 100\n const { parts, total } = progressSegments(segments, rootMax)\n return (\n <RadixProgress.Root\n value={total}\n max={rootMax}\n getValueLabel={() => segmentsLabel(parts, rootMax)}\n className={clsx(s.Root, className)}\n data-segmented=\"\"\n {...restProps}\n >\n {parts.map((part, index) =>\n part.value > 0 ? (\n <div key={index} className={s.Segment} data-color={part.color ?? \"primary\"} style={{ width: `${(part.value / rootMax) * 100}%` }} />\n ) : null,\n )}\n </RadixProgress.Root>\n )\n }\n\n const resolved = value == null ? null : Math.max(0, Math.min(max, value))\n const percentage = resolved == null ? null : (resolved / max) * 100\n\n return (\n <RadixProgress.Root\n value={resolved}\n max={max}\n className={clsx(s.Root, className)}\n {...restProps}\n >\n <RadixProgress.Indicator\n className={s.Indicator}\n style={{\n transform:\n percentage == null ? undefined : `translateX(-${100 - percentage}%)`,\n }}\n data-indeterminate={percentage == null ? \"\" : undefined}\n />\n </RadixProgress.Root>\n )\n}\n"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { Progress } from "./Progress.js";
|
|
1
|
+
export { Progress, progressSegments } from "./Progress.js";
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/Progress/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/Progress/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAgE,MAAM,YAAY,CAAA","sourcesContent":["export { Progress, progressSegments, type ProgressColor, type ProgressProps, type ProgressSegment } from \"./Progress\"\n"]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import clsx from "clsx";
|
|
3
|
+
import s from "@plexui/styles/components/RollingNumber/RollingNumber.module.css";
|
|
4
|
+
/** A written number's characters, each keyed by its place around the decimal separator, so a digit keeps its reel
|
|
5
|
+
* when the number grows or its fraction gets longer; digits are the locale's own (Arabic-Indic, Bengali…). */
|
|
6
|
+
export const rollingNumberParts = (value, locales = "en-US", format) => {
|
|
7
|
+
const formatter = new Intl.NumberFormat(locales, format);
|
|
8
|
+
const { locale, numberingSystem } = formatter.resolvedOptions();
|
|
9
|
+
const digitFormatter = new Intl.NumberFormat(locale, { numberingSystem, useGrouping: false });
|
|
10
|
+
const glyphs = Array.from({ length: 10 }, (_, digit) => digitFormatter.format(digit));
|
|
11
|
+
const parts = formatter.formatToParts(value);
|
|
12
|
+
let integers = parts.reduce((count, part) => count + (part.type === "integer" ? Array.from(part.value).length : 0), 0);
|
|
13
|
+
let fractions = 0;
|
|
14
|
+
const seen = {};
|
|
15
|
+
const characters = parts.flatMap((part) => Array.from(part.value).map((character) => {
|
|
16
|
+
const glyph = glyphs.indexOf(character);
|
|
17
|
+
const digit = (part.type === "integer" || part.type === "fraction") && glyph >= 0 ? glyph : null;
|
|
18
|
+
let key;
|
|
19
|
+
if (part.type === "integer")
|
|
20
|
+
key = `i${integers--}`;
|
|
21
|
+
else if (part.type === "fraction")
|
|
22
|
+
key = `f${++fractions}`;
|
|
23
|
+
else if (part.type === "group")
|
|
24
|
+
key = `g${integers}`;
|
|
25
|
+
else {
|
|
26
|
+
seen[part.type] = (seen[part.type] ?? 0) + 1;
|
|
27
|
+
key = `${part.type}${seen[part.type]}-${character}`;
|
|
28
|
+
}
|
|
29
|
+
return { character, digit, key };
|
|
30
|
+
}));
|
|
31
|
+
return { text: parts.map((part) => part.value).join(""), glyphs, characters };
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* A number whose digits roll to a new value, as an odometer: for a total, a balance, a count or a KPI that changes
|
|
35
|
+
* while it is watched. It reads as the written number; its reels are hidden from a screen reader.
|
|
36
|
+
*/
|
|
37
|
+
export const RollingNumber = ({ value, locales, format, className, ...restProps }) => {
|
|
38
|
+
const { text, glyphs, characters } = rollingNumberParts(value, locales, format);
|
|
39
|
+
return (_jsxs("span", { className: clsx(s.RollingNumber, className), ...restProps, children: [_jsx("span", { className: s.Text, children: text }), _jsx("span", { className: s.Visual, "aria-hidden": "true", children: characters.map(({ character, digit, key }) => digit === null ? (_jsx("span", { children: character }, key)) : (_jsxs("span", { className: s.Digit, "data-digit": digit, children: [_jsx("span", { className: s.Ghost, children: character }), _jsx("span", { className: s.Reel, style: { "--rolling-number-digit": digit }, children: glyphs.map((reelDigit) => (_jsx("span", { children: reelDigit }, reelDigit))) })] }, key))) })] }));
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=RollingNumber.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RollingNumber.js","sourceRoot":"","sources":["../../../../src/components/RollingNumber/RollingNumber.tsx"],"names":[],"mappings":";AAAA,OAAO,IAAI,MAAM,MAAM,CAAA;AAEvB,OAAO,CAAC,MAAM,kEAAkE,CAAA;AAWhF;8GAC8G;AAC9G,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,KAAa,EAAE,UAAgC,OAAO,EAAE,MAAiC,EAAE,EAAE;IAC9H,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;IACxD,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,GAAG,SAAS,CAAC,eAAe,EAAE,CAAA;IAC/D,MAAM,cAAc,GAAG,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,EAAE,eAAe,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC,CAAA;IAC7F,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,cAAc,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;IACrF,MAAM,KAAK,GAAG,SAAS,CAAC,aAAa,CAAC,KAAK,CAAC,CAAA;IAC5C,IAAI,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,IAAI,E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B,yBAAuB,SAAS,IAArB,SAAS,CAAoB,CACzC,CAAC,GACG,KANE,GAAG,CAOP,CACR,CACF,GACI,IACF,CACR,CAAA;AACH,CAAC,CAAA","sourcesContent":["import clsx from \"clsx\"\nimport type { ComponentProps, CSSProperties } from \"react\"\nimport s from \"@plexui/styles/components/RollingNumber/RollingNumber.module.css\"\n\nexport type RollingNumberProps = Omit<ComponentProps<\"span\">, \"children\"> & {\n /** The number shown. A new value rolls each changed digit to it. */\n value: number\n /** The locale the number is written in, as `Intl.NumberFormat` takes it; fixed, so the server writes it as the browser does. @default \"en-US\" */\n locales?: Intl.LocalesArgument\n /** How the number is written: currency, percent, fraction digits, grouping, as `Intl.NumberFormat` takes it. */\n format?: Intl.NumberFormatOptions\n}\n\n/** A written number's characters, each keyed by its place around the decimal separator, so a digit keeps its reel\n * when the number grows or its fraction gets longer; digits are the locale's own (Arabic-Indic, Bengali…). */\nexport const rollingNumberParts = (value: number, locales: Intl.LocalesArgument = \"en-US\", format?: Intl.NumberFormatOptions) => {\n const formatter = new Intl.NumberFormat(locales, format)\n const { locale, numberingSystem } = formatter.resolvedOptions()\n const digitFormatter = new Intl.NumberFormat(locale, { numberingSystem, useGrouping: false })\n const glyphs = Array.from({ length: 10 }, (_, digit) => digitFormatter.format(digit))\n const parts = formatter.formatToParts(value)\n let integers = parts.reduce((count, part) => count + (part.type === \"integer\" ? Array.from(part.value).length : 0), 0)\n let fractions = 0\n const seen: Record<string, number> = {}\n const characters = parts.flatMap((part) =>\n Array.from(part.value).map((character) => {\n const glyph = glyphs.indexOf(character)\n const digit = (part.type === \"integer\" || part.type === \"fraction\") && glyph >= 0 ? glyph : null\n let key: string\n if (part.type === \"integer\") key = `i${integers--}`\n else if (part.type === \"fraction\") key = `f${++fractions}`\n else if (part.type === \"group\") key = `g${integers}`\n else {\n seen[part.type] = (seen[part.type] ?? 0) + 1\n key = `${part.type}${seen[part.type]}-${character}`\n }\n return { character, digit, key }\n }),\n )\n return { text: parts.map((part) => part.value).join(\"\"), glyphs, characters }\n}\n\n/**\n * A number whose digits roll to a new value, as an odometer: for a total, a balance, a count or a KPI that changes\n * while it is watched. It reads as the written number; its reels are hidden from a screen reader.\n */\nexport const RollingNumber = ({ value, locales, format, className, ...restProps }: RollingNumberProps) => {\n const { text, glyphs, characters } = rollingNumberParts(value, locales, format)\n return (\n <span className={clsx(s.RollingNumber, className)} {...restProps}>\n <span className={s.Text}>{text}</span>\n <span className={s.Visual} aria-hidden=\"true\">\n {characters.map(({ character, digit, key }) =>\n digit === null ? (\n <span key={key}>{character}</span>\n ) : (\n <span key={key} className={s.Digit} data-digit={digit}>\n <span className={s.Ghost}>{character}</span>\n <span className={s.Reel} style={{ \"--rolling-number-digit\": digit } as CSSProperties}>\n {glyphs.map((reelDigit) => (\n <span key={reelDigit}>{reelDigit}</span>\n ))}\n </span>\n </span>\n ),\n )}\n </span>\n </span>\n )\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/RollingNumber/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAA2B,MAAM,iBAAiB,CAAA","sourcesContent":["export { RollingNumber, rollingNumberParts, type RollingNumberProps } from \"./RollingNumber\"\n"]}
|
|
@@ -23,11 +23,11 @@ export const stepValue = (current, direction, { min, max, step, wrap }) => {
|
|
|
23
23
|
return next;
|
|
24
24
|
};
|
|
25
25
|
/**
|
|
26
|
-
* Two segments that decrease and increase a number, as the iOS 26 stepper does. It shows no value of its own
|
|
27
|
-
* name it with `aria-label` or `aria-labelledby
|
|
26
|
+
* Two segments that decrease and increase a number, as the iOS 26 stepper does. It shows no value of its own
|
|
27
|
+
* (`showValue` puts it between the segments): name it with `aria-label` or `aria-labelledby`. Keyboard focus lands on the
|
|
28
28
|
* stepper, a spin button: Up and Down step, Page Up and Page Down step ten times, Home and End go to the range ends.
|
|
29
29
|
*/
|
|
30
|
-
export function Stepper({ id, value: valueProp, defaultValue, onChange, min = 0, max = 100, step = 1, wrap = false, autoRepeat = true, disabled = false, pill = true, decrementLabel = "Decrease", incrementLabel = "Increase", onRemove, removeLabel = "Remove", name, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, onFocus, onBlur, className, }) {
|
|
30
|
+
export function Stepper({ id, value: valueProp, defaultValue, onChange, min = 0, max = 100, step = 1, wrap = false, autoRepeat = true, disabled = false, pill = true, showValue = false, decrementLabel = "Decrease", incrementLabel = "Increase", onRemove, removeLabel = "Remove", name, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, onFocus, onBlur, className, }) {
|
|
31
31
|
const [internalValue, setInternalValue] = useState(() => defaultValue ?? min);
|
|
32
32
|
const value = valueProp ?? internalValue;
|
|
33
33
|
// Timers and key handlers read the value through this ref; an uncontrolled step advances it at once.
|
|
@@ -123,6 +123,6 @@ export function Stepper({ id, value: valueProp, defaultValue, onChange, min = 0,
|
|
|
123
123
|
// Keeps the focus where it is, as a native stepper takes none.
|
|
124
124
|
onMouseDown: (event) => event.preventDefault(), onPointerDown: (event) => startPress(kind, event), onPointerUp: stopRepeat, onPointerCancel: stopRepeat, onLostPointerCapture: stopRepeat, onClick: (event) => handleClick(kind, event), children: _jsx(Icon, { className: s.Icon }) }));
|
|
125
125
|
};
|
|
126
|
-
return (_jsxs("div", { id: id, role: "spinbutton", tabIndex: disabled ? -1 : 0, "aria-valuenow": value, "aria-valuemin": min, "aria-valuemax": max, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, "aria-keyshortcuts": removes ? "Delete" : undefined, "aria-disabled": disabled || undefined, className: clsx(s.Stepper, className), "data-disabled": disabled ? "" : undefined, "data-pill": pill ? "" : undefined, onKeyDown: handleKeyDown, onFocus: onFocus, onBlur: onBlur, children: [segment("decrement"), _jsx("span", { className: s.Separator, "aria-hidden": "true" }), segment("increment"), name !== undefined && _jsx("input", { type: "hidden", name: name, value: value, disabled: disabled })] }));
|
|
126
|
+
return (_jsxs("div", { id: id, role: "spinbutton", tabIndex: disabled ? -1 : 0, "aria-valuenow": value, "aria-valuemin": min, "aria-valuemax": max, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, "aria-keyshortcuts": removes ? "Delete" : undefined, "aria-disabled": disabled || undefined, className: clsx(s.Stepper, className), "data-disabled": disabled ? "" : undefined, "data-pill": pill ? "" : undefined, "data-show-value": showValue ? "" : undefined, onKeyDown: handleKeyDown, onFocus: onFocus, onBlur: onBlur, children: [segment("decrement"), showValue ? (_jsx("span", { className: s.Value, "aria-hidden": "true", children: value })) : (_jsx("span", { className: s.Separator, "aria-hidden": "true" })), segment("increment"), name !== undefined && _jsx("input", { type: "hidden", name: name, value: value, disabled: disabled })] }));
|
|
127
127
|
}
|
|
128
128
|
//# sourceMappingURL=Stepper.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Stepper.js","sourceRoot":"","sources":["../../../../src/components/Stepper/Stepper.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAKL,WAAW,EACX,SAAS,EACT,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAA;AACd,OAAO,CAAC,MAAM,sDAAsD,CAAA;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAC3D,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAoDlD,yFAAyF;AACzF,MAAM,YAAY,GAAG,GAAG,CAAA;AACxB,MAAM,eAAe,GAAG,GAAG,CAAA;AAE3B,MAAM,QAAQ,GAAG,CAAC,CAAS,EAAE,EAAE;IAC7B,MAAM,CAAC,EAAE,QAAQ,GAAG,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CA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IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,EAChC,SAAS,EAAE,aAAa,EACxB,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,aAEb,OAAO,CAAC,WAAW,CAAC,EACrB,eAAM,SAAS,EAAE,CAAC,CAAC,SAAS,iBAAc,MAAM,GAAG,EAClD,OAAO,CAAC,WAAW,CAAC,EACpB,IAAI,KAAK,SAAS,IAAI,gBAAO,IAAI,EAAC,QAAQ,EAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,GAAI,IACxF,CACP,CAAA;AACH,CAAC","sourcesContent":["\"use client\"\n\nimport clsx from \"clsx\"\nimport {\n type FocusEventHandler,\n type KeyboardEvent,\n type MouseEvent,\n type PointerEvent,\n useCallback,\n useEffect,\n useRef,\n useState,\n} from \"react\"\nimport s from \"@plexui/styles/components/Stepper/Stepper.module.css\"\nimport { useLatestValue } from \"../../hooks/useLatestValue\"\nimport { Minus, Plus, RemoveTrash } from \"../Icon\"\n\nexport type StepperProps = {\n /** The `id` of the stepper. */\n id?: string\n /** The controlled value. Use with `onChange`. */\n value?: number\n /** The value when it is initially rendered. Use when you do not need to control the value. @default min */\n defaultValue?: number\n /** Called with the next value after a step. */\n onChange?: (value: number) => void\n /** The lowest value. @default 0 */\n min?: number\n /** The highest value. @default 100 */\n max?: number\n /** The amount each step adds or removes. @default 1 */\n step?: number\n /** A step past `max` continues from `min`, and one below `min` from `max`. @default false */\n wrap?: boolean\n /** Holding a segment keeps stepping, as a native stepper does. @default true */\n autoRepeat?: boolean\n /** When `true`, prevents the user from interacting with the stepper. */\n disabled?: boolean\n /** Fully rounded ends. @default true */\n pill?: boolean\n /** Accessible name of the decrement segment. @default \"Decrease\" */\n decrementLabel?: string\n /** Accessible name of the increment segment. @default \"Increase\" */\n incrementLabel?: string\n /**\n * Called when the decrement segment is pressed at `min`. With it, the segment shows a trash can there and removes\n * the item, as a cart's stepper does at a quantity of one (without `wrap`).\n */\n onRemove?: () => void\n /** Accessible name of the decrement segment when it removes. @default \"Remove\" */\n removeLabel?: string\n /** The name of the stepper. Submits its value with the owning form. */\n name?: string\n /** Accessible name of the value the stepper changes, when no visible label names it. */\n \"aria-label\"?: string\n /** The `id` of the visible label of the value the stepper changes. */\n \"aria-labelledby\"?: string\n /** The `id` of an element that describes the stepper, such as the text that shows its value. */\n \"aria-describedby\"?: string\n /** Event handler called when the stepper gains focus. */\n onFocus?: FocusEventHandler<HTMLDivElement>\n /** Event handler called when the stepper loses focus. */\n onBlur?: FocusEventHandler<HTMLDivElement>\n /** CSS classes applied to the stepper */\n className?: string\n}\n\n/** Delay before a held segment starts repeating, and the time between repeats, in ms. */\nconst REPEAT_DELAY = 400\nconst REPEAT_INTERVAL = 100\n\nconst decimals = (n: number) => {\n const [, fraction = \"\"] = String(n).split(\".\")\n return fraction.length\n}\n\n/** The value one step away, clamped to the range or wrapped, without floating point drift. */\nexport const stepValue = (current: number, direction: 1 | -1, { min, max, step, wrap }: { min: number; max: number; step: number; wrap: boolean }) => {\n const precision = Math.max(decimals(step), decimals(min), decimals(current))\n const next = Number((current + direction * step).toFixed(precision))\n if (next > max) return wrap ? min : max\n if (next < min) return wrap ? max : min\n return next\n}\n\n/**\n * Two segments that decrease and increase a number, as the iOS 26 stepper does. It shows no value of its own:\n * name it with `aria-label` or `aria-labelledby` and show the value beside it. Keyboard focus lands on the\n * stepper, a spin button: Up and Down step, Page Up and Page Down step ten times, Home and End go to the range ends.\n */\nexport function Stepper({\n id,\n value: valueProp,\n defaultValue,\n onChange,\n min = 0,\n max = 100,\n step = 1,\n wrap = false,\n autoRepeat = true,\n disabled = false,\n pill = true,\n decrementLabel = \"Decrease\",\n incrementLabel = \"Increase\",\n onRemove,\n removeLabel = \"Remove\",\n name,\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledBy,\n \"aria-describedby\": ariaDescribedBy,\n onFocus,\n onBlur,\n className,\n}: StepperProps) {\n const [internalValue, setInternalValue] = useState(() => defaultValue ?? min)\n const value = valueProp ?? internalValue\n // Timers and key handlers read the value through this ref; an uncontrolled step advances it at once.\n const valueRef = useLatestValue(value)\n const onChangeRef = useLatestValue(onChange)\n const optionsRef = useLatestValue({ min, max, step, wrap, disabled, controlled: valueProp !== undefined })\n const timer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined)\n const [pressed, setPressed] = useState<\"decrement\" | \"increment\" | null>(null)\n\n const commit = useCallback((next: number) => {\n if (next === valueRef.current) return false\n // A controlled value changes only when the owner passes it back, as in Vue.\n if (!optionsRef.current.controlled) {\n valueRef.current = next\n setInternalValue(next)\n }\n onChangeRef.current?.(next)\n return true\n }, [valueRef, optionsRef, onChangeRef])\n\n const stepBy = useCallback((direction: 1 | -1, times = 1) => {\n let next = valueRef.current\n for (let i = 0; i < times; i++) next = stepValue(next, direction, optionsRef.current)\n return commit(next)\n }, [commit, valueRef, optionsRef])\n\n const stopRepeat = useCallback(() => {\n clearTimeout(timer.current)\n timer.current = undefined\n setPressed(null)\n }, [])\n\n useEffect(() => stopRepeat, [stopRepeat])\n\n const atMin = !wrap && value <= min\n const atMax = !wrap && value >= max\n // At the minimum the decrement segment removes the item, when the owner can remove it\n const removes = atMin && onRemove !== undefined\n const onRemoveRef = useLatestValue(onRemove)\n\n const startPress = (segment: \"decrement\" | \"increment\", event: PointerEvent<HTMLButtonElement>) => {\n if (event.button !== 0 || disabled) return\n if (segment === \"decrement\" && removes) {\n event.currentTarget.setPointerCapture?.(event.pointerId)\n setPressed(segment)\n onRemoveRef.current?.()\n return\n }\n if (segment === \"decrement\" ? atMin : atMax) return\n event.currentTarget.setPointerCapture?.(event.pointerId)\n setPressed(segment)\n const direction = segment === \"decrement\" ? -1 : 1\n stepBy(direction)\n if (!autoRepeat) return\n const repeat = () => {\n if (optionsRef.current.disabled || !stepBy(direction)) return stopRepeat()\n timer.current = setTimeout(repeat, REPEAT_INTERVAL)\n }\n timer.current = setTimeout(repeat, REPEAT_DELAY)\n }\n\n // A pointer steps on press, so only a click without one (assistive technology, `element.click()`) steps here.\n const handleClick = (segment: \"decrement\" | \"increment\", event: MouseEvent<HTMLButtonElement>) => {\n if (event.detail !== 0 || disabled) return\n if (segment === \"decrement\" && removes) return onRemoveRef.current?.()\n stepBy(segment === \"decrement\" ? -1 : 1)\n }\n\n const handleKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {\n if (disabled || event.altKey || event.ctrlKey || event.metaKey) return\n const keys: Record<string, () => void> = {\n ArrowUp: () => stepBy(1),\n ArrowDown: () => stepBy(-1),\n PageUp: () => stepBy(1, 10),\n PageDown: () => stepBy(-1, 10),\n Home: () => commit(min),\n End: () => commit(max),\n // At the minimum Delete or Backspace removes, as the trash can does; the arrows never do\n ...(removes && { Delete: () => onRemoveRef.current?.(), Backspace: () => onRemoveRef.current?.() }),\n }\n const action = keys[event.key]\n if (!action) return\n event.preventDefault()\n action()\n }\n\n const segment = (kind: \"decrement\" | \"increment\") => {\n const remove = kind === \"decrement\" && removes\n const atEnd = !remove && (kind === \"decrement\" ? atMin : atMax)\n const Icon = remove ? RemoveTrash : kind === \"decrement\" ? Minus : Plus\n return (\n <button\n type=\"button\"\n tabIndex={-1}\n aria-label={remove ? removeLabel : kind === \"decrement\" ? decrementLabel : incrementLabel}\n aria-disabled={atEnd || undefined}\n disabled={disabled}\n className={s.Segment}\n data-segment={kind}\n data-remove={remove ? \"\" : undefined}\n data-disabled={atEnd || disabled ? \"\" : undefined}\n data-pressed={pressed === kind && !disabled ? \"\" : undefined}\n // Keeps the focus where it is, as a native stepper takes none.\n onMouseDown={(event) => event.preventDefault()}\n onPointerDown={(event) => startPress(kind, event)}\n onPointerUp={stopRepeat}\n onPointerCancel={stopRepeat}\n onLostPointerCapture={stopRepeat}\n onClick={(event) => handleClick(kind, event)}\n >\n <Icon className={s.Icon} />\n </button>\n )\n }\n\n return (\n <div\n id={id}\n role=\"spinbutton\"\n tabIndex={disabled ? -1 : 0}\n aria-valuenow={value}\n aria-valuemin={min}\n aria-valuemax={max}\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n aria-describedby={ariaDescribedBy}\n aria-keyshortcuts={removes ? \"Delete\" : undefined}\n aria-disabled={disabled || undefined}\n className={clsx(s.Stepper, className)}\n data-disabled={disabled ? \"\" : undefined}\n data-pill={pill ? \"\" : undefined}\n onKeyDown={handleKeyDown}\n onFocus={onFocus}\n onBlur={onBlur}\n >\n {segment(\"decrement\")}\n <span className={s.Separator} aria-hidden=\"true\" />\n {segment(\"increment\")}\n {name !== undefined && <input type=\"hidden\" name={name} value={value} disabled={disabled} />}\n </div>\n )\n}\n"]}
|
|
1
|
+
{"version":3,"file":"Stepper.js","sourceRoot":"","sources":["../../../../src/components/Stepper/Stepper.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAKL,WAAW,EACX,SAAS,EACT,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAA;AACd,OAAO,CAAC,MAAM,sDAAsD,CAAA;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAC3D,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAyDlD,yFAAyF;AACzF,MAAM,YAAY,GAAG,GAAG,CAAA;AACxB,MAAM,eAAe,GAAG,GAAG,CAAA;AAE3B,MAAM,QAAQ,GAAG,CAAC,CAAS,EAAE,EAAE;IAC7B,MAAM,CAAC,EAAE,QAAQ,GAAG,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAC9C,OAAO,QAAQ,CAAC,MAAM,CAAA;AACxB,CAAC,CAAA;AAED,8FAA8F;AAC9F,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,OAAe,EAAE,SAAiB,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,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AM,EAAE,MAAM,aAEb,OAAO,CAAC,WAAW,CAAC,EAEpB,SAAS,CAAC,CAAC,CAAC,CACX,eAAM,SAAS,EAAE,CAAC,CAAC,KAAK,iBAAc,MAAM,YACzC,KAAK,GACD,CACR,CAAC,CAAC,CAAC,CACF,eAAM,SAAS,EAAE,CAAC,CAAC,SAAS,iBAAc,MAAM,GAAG,CACpD,EACA,OAAO,CAAC,WAAW,CAAC,EACpB,IAAI,KAAK,SAAS,IAAI,gBAAO,IAAI,EAAC,QAAQ,EAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,GAAI,IACxF,CACP,CAAA;AACH,CAAC","sourcesContent":["\"use client\"\n\nimport clsx from \"clsx\"\nimport {\n type FocusEventHandler,\n type KeyboardEvent,\n type MouseEvent,\n type PointerEvent,\n useCallback,\n useEffect,\n useRef,\n useState,\n} from \"react\"\nimport s from \"@plexui/styles/components/Stepper/Stepper.module.css\"\nimport { useLatestValue } from \"../../hooks/useLatestValue\"\nimport { Minus, Plus, RemoveTrash } from \"../Icon\"\n\nexport type StepperProps = {\n /** The `id` of the stepper. */\n id?: string\n /** The controlled value. Use with `onChange`. */\n value?: number\n /** The value when it is initially rendered. Use when you do not need to control the value. @default min */\n defaultValue?: number\n /** Called with the next value after a step. */\n onChange?: (value: number) => void\n /** The lowest value. @default 0 */\n min?: number\n /** The highest value. @default 100 */\n max?: number\n /** The amount each step adds or removes. @default 1 */\n step?: number\n /** A step past `max` continues from `min`, and one below `min` from `max`. @default false */\n wrap?: boolean\n /** Holding a segment keeps stepping, as a native stepper does. @default true */\n autoRepeat?: boolean\n /** When `true`, prevents the user from interacting with the stepper. */\n disabled?: boolean\n /** Fully rounded ends. @default true */\n pill?: boolean\n /**\n * Shows the value between the minus and the plus on one fill, as a cart's quantity: round segments and no\n * separator. Without it the stepper shows no value, as the native one. @default false\n */\n showValue?: boolean\n /** Accessible name of the decrement segment. @default \"Decrease\" */\n decrementLabel?: string\n /** Accessible name of the increment segment. @default \"Increase\" */\n incrementLabel?: string\n /**\n * Called when the decrement segment is pressed at `min`. With it, the segment shows a trash can there and removes\n * the item, as a cart's stepper does at a quantity of one (without `wrap`).\n */\n onRemove?: () => void\n /** Accessible name of the decrement segment when it removes. @default \"Remove\" */\n removeLabel?: string\n /** The name of the stepper. Submits its value with the owning form. */\n name?: string\n /** Accessible name of the value the stepper changes, when no visible label names it. */\n \"aria-label\"?: string\n /** The `id` of the visible label of the value the stepper changes. */\n \"aria-labelledby\"?: string\n /** The `id` of an element that describes the stepper, such as the text that shows its value. */\n \"aria-describedby\"?: string\n /** Event handler called when the stepper gains focus. */\n onFocus?: FocusEventHandler<HTMLDivElement>\n /** Event handler called when the stepper loses focus. */\n onBlur?: FocusEventHandler<HTMLDivElement>\n /** CSS classes applied to the stepper */\n className?: string\n}\n\n/** Delay before a held segment starts repeating, and the time between repeats, in ms. */\nconst REPEAT_DELAY = 400\nconst REPEAT_INTERVAL = 100\n\nconst decimals = (n: number) => {\n const [, fraction = \"\"] = String(n).split(\".\")\n return fraction.length\n}\n\n/** The value one step away, clamped to the range or wrapped, without floating point drift. */\nexport const stepValue = (current: number, direction: 1 | -1, { min, max, step, wrap }: { min: number; max: number; step: number; wrap: boolean }) => {\n const precision = Math.max(decimals(step), decimals(min), decimals(current))\n const next = Number((current + direction * step).toFixed(precision))\n if (next > max) return wrap ? min : max\n if (next < min) return wrap ? max : min\n return next\n}\n\n/**\n * Two segments that decrease and increase a number, as the iOS 26 stepper does. It shows no value of its own\n * (`showValue` puts it between the segments): name it with `aria-label` or `aria-labelledby`. Keyboard focus lands on the\n * stepper, a spin button: Up and Down step, Page Up and Page Down step ten times, Home and End go to the range ends.\n */\nexport function Stepper({\n id,\n value: valueProp,\n defaultValue,\n onChange,\n min = 0,\n max = 100,\n step = 1,\n wrap = false,\n autoRepeat = true,\n disabled = false,\n pill = true,\n showValue = false,\n decrementLabel = \"Decrease\",\n incrementLabel = \"Increase\",\n onRemove,\n removeLabel = \"Remove\",\n name,\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledBy,\n \"aria-describedby\": ariaDescribedBy,\n onFocus,\n onBlur,\n className,\n}: StepperProps) {\n const [internalValue, setInternalValue] = useState(() => defaultValue ?? min)\n const value = valueProp ?? internalValue\n // Timers and key handlers read the value through this ref; an uncontrolled step advances it at once.\n const valueRef = useLatestValue(value)\n const onChangeRef = useLatestValue(onChange)\n const optionsRef = useLatestValue({ min, max, step, wrap, disabled, controlled: valueProp !== undefined })\n const timer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined)\n const [pressed, setPressed] = useState<\"decrement\" | \"increment\" | null>(null)\n\n const commit = useCallback((next: number) => {\n if (next === valueRef.current) return false\n // A controlled value changes only when the owner passes it back, as in Vue.\n if (!optionsRef.current.controlled) {\n valueRef.current = next\n setInternalValue(next)\n }\n onChangeRef.current?.(next)\n return true\n }, [valueRef, optionsRef, onChangeRef])\n\n const stepBy = useCallback((direction: 1 | -1, times = 1) => {\n let next = valueRef.current\n for (let i = 0; i < times; i++) next = stepValue(next, direction, optionsRef.current)\n return commit(next)\n }, [commit, valueRef, optionsRef])\n\n const stopRepeat = useCallback(() => {\n clearTimeout(timer.current)\n timer.current = undefined\n setPressed(null)\n }, [])\n\n useEffect(() => stopRepeat, [stopRepeat])\n\n const atMin = !wrap && value <= min\n const atMax = !wrap && value >= max\n // At the minimum the decrement segment removes the item, when the owner can remove it\n const removes = atMin && onRemove !== undefined\n const onRemoveRef = useLatestValue(onRemove)\n\n const startPress = (segment: \"decrement\" | \"increment\", event: PointerEvent<HTMLButtonElement>) => {\n if (event.button !== 0 || disabled) return\n if (segment === \"decrement\" && removes) {\n event.currentTarget.setPointerCapture?.(event.pointerId)\n setPressed(segment)\n onRemoveRef.current?.()\n return\n }\n if (segment === \"decrement\" ? atMin : atMax) return\n event.currentTarget.setPointerCapture?.(event.pointerId)\n setPressed(segment)\n const direction = segment === \"decrement\" ? -1 : 1\n stepBy(direction)\n if (!autoRepeat) return\n const repeat = () => {\n if (optionsRef.current.disabled || !stepBy(direction)) return stopRepeat()\n timer.current = setTimeout(repeat, REPEAT_INTERVAL)\n }\n timer.current = setTimeout(repeat, REPEAT_DELAY)\n }\n\n // A pointer steps on press, so only a click without one (assistive technology, `element.click()`) steps here.\n const handleClick = (segment: \"decrement\" | \"increment\", event: MouseEvent<HTMLButtonElement>) => {\n if (event.detail !== 0 || disabled) return\n if (segment === \"decrement\" && removes) return onRemoveRef.current?.()\n stepBy(segment === \"decrement\" ? -1 : 1)\n }\n\n const handleKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {\n if (disabled || event.altKey || event.ctrlKey || event.metaKey) return\n const keys: Record<string, () => void> = {\n ArrowUp: () => stepBy(1),\n ArrowDown: () => stepBy(-1),\n PageUp: () => stepBy(1, 10),\n PageDown: () => stepBy(-1, 10),\n Home: () => commit(min),\n End: () => commit(max),\n // At the minimum Delete or Backspace removes, as the trash can does; the arrows never do\n ...(removes && { Delete: () => onRemoveRef.current?.(), Backspace: () => onRemoveRef.current?.() }),\n }\n const action = keys[event.key]\n if (!action) return\n event.preventDefault()\n action()\n }\n\n const segment = (kind: \"decrement\" | \"increment\") => {\n const remove = kind === \"decrement\" && removes\n const atEnd = !remove && (kind === \"decrement\" ? atMin : atMax)\n const Icon = remove ? RemoveTrash : kind === \"decrement\" ? Minus : Plus\n return (\n <button\n type=\"button\"\n tabIndex={-1}\n aria-label={remove ? removeLabel : kind === \"decrement\" ? decrementLabel : incrementLabel}\n aria-disabled={atEnd || undefined}\n disabled={disabled}\n className={s.Segment}\n data-segment={kind}\n data-remove={remove ? \"\" : undefined}\n data-disabled={atEnd || disabled ? \"\" : undefined}\n data-pressed={pressed === kind && !disabled ? \"\" : undefined}\n // Keeps the focus where it is, as a native stepper takes none.\n onMouseDown={(event) => event.preventDefault()}\n onPointerDown={(event) => startPress(kind, event)}\n onPointerUp={stopRepeat}\n onPointerCancel={stopRepeat}\n onLostPointerCapture={stopRepeat}\n onClick={(event) => handleClick(kind, event)}\n >\n <Icon className={s.Icon} />\n </button>\n )\n }\n\n return (\n <div\n id={id}\n role=\"spinbutton\"\n tabIndex={disabled ? -1 : 0}\n aria-valuenow={value}\n aria-valuemin={min}\n aria-valuemax={max}\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n aria-describedby={ariaDescribedBy}\n aria-keyshortcuts={removes ? \"Delete\" : undefined}\n aria-disabled={disabled || undefined}\n className={clsx(s.Stepper, className)}\n data-disabled={disabled ? \"\" : undefined}\n data-pill={pill ? \"\" : undefined}\n data-show-value={showValue ? \"\" : undefined}\n onKeyDown={handleKeyDown}\n onFocus={onFocus}\n onBlur={onBlur}\n >\n {segment(\"decrement\")}\n {/* The spin button already reads its value, so the shown one is not read again */}\n {showValue ? (\n <span className={s.Value} aria-hidden=\"true\">\n {value}\n </span>\n ) : (\n <span className={s.Separator} aria-hidden=\"true\" />\n )}\n {segment(\"increment\")}\n {name !== undefined && <input type=\"hidden\" name={name} value={value} disabled={disabled} />}\n </div>\n )\n}\n"]}
|
|
@@ -16,5 +16,7 @@ export type KbdProps = ComponentProps<"kbd"> & {
|
|
|
16
16
|
export declare const Kbd: {
|
|
17
17
|
({ size, variant, className, ...restProps }: KbdProps): import("react/jsx-runtime").JSX.Element;
|
|
18
18
|
Group: ({ className, ...restProps }: KbdGroupProps) => import("react/jsx-runtime").JSX.Element;
|
|
19
|
+
/** A modifier key as the reader's keyboard prints it: ⌘ on a Mac, Ctrl elsewhere (`name` picks ⌘, ⌃, ⌥ or ⇧). */
|
|
20
|
+
Modifier: ({ name, platform, size, variant, className, ...restProps }: import("./KbdModifier.js").KbdModifierProps) => import("react/jsx-runtime").JSX.Element;
|
|
19
21
|
};
|
|
20
22
|
export type KbdGroupProps = ComponentProps<"span">;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { KbdProps } from "./Kbd.js";
|
|
2
|
+
export type KbdModifierName = "mod" | "ctrl" | "alt" | "shift";
|
|
3
|
+
export type KbdPlatform = "apple" | "other";
|
|
4
|
+
/** Each modifier on an Apple keyboard (a symbol and its name) and on another one. `mod` is ⌘ there and Ctrl here. */
|
|
5
|
+
export declare const KBD_MODIFIERS: Record<KbdModifierName, Record<KbdPlatform, {
|
|
6
|
+
symbol: string;
|
|
7
|
+
name: string;
|
|
8
|
+
}>>;
|
|
9
|
+
/** Whether the browser runs on a Mac, an iPhone or an iPad, whose keyboards print ⌘ and ⌥. */
|
|
10
|
+
export declare const isApplePlatform: () => boolean;
|
|
11
|
+
export type KbdModifierProps = Omit<KbdProps, "children"> & {
|
|
12
|
+
/** The modifier: `mod` is ⌘ on an Apple keyboard and Ctrl on another, as an app's shortcuts are. @default "mod" */
|
|
13
|
+
name?: KbdModifierName;
|
|
14
|
+
/** The keyboard to print for; by default the one the browser runs on (Apple on the server). */
|
|
15
|
+
platform?: KbdPlatform;
|
|
16
|
+
};
|
|
17
|
+
/** A modifier key printed as the reader's keyboard prints it: ⌘ on a Mac, Ctrl elsewhere; its name is read out. */
|
|
18
|
+
export declare const KbdModifier: ({ name, platform, size, variant, className, ...restProps }: KbdModifierProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import { type ComponentProps } from "react";
|
|
2
2
|
import { Progress as RadixProgress } from "radix-ui";
|
|
3
|
+
export type ProgressColor = "primary" | "secondary" | "success" | "warning" | "caution" | "danger" | "info" | "discovery";
|
|
4
|
+
/** A part of a segmented bar: its share of `max`, its color, and the name it is read with. */
|
|
5
|
+
export type ProgressSegment = {
|
|
6
|
+
value: number;
|
|
7
|
+
/** @default "primary" */
|
|
8
|
+
color?: ProgressColor;
|
|
9
|
+
/** Read out with its share, such as "Paid 60%" */
|
|
10
|
+
label?: string;
|
|
11
|
+
};
|
|
3
12
|
export type ProgressProps = Omit<ComponentProps<typeof RadixProgress.Root>, "children"> & {
|
|
4
13
|
/**
|
|
5
14
|
* Current progress value, between `0` and `max`.
|
|
@@ -11,6 +20,22 @@ export type ProgressProps = Omit<ComponentProps<typeof RadixProgress.Root>, "chi
|
|
|
11
20
|
* @default 100
|
|
12
21
|
*/
|
|
13
22
|
max?: number;
|
|
23
|
+
/**
|
|
24
|
+
* Parts of one bar, side by side in their colors, such as paid, pending and due. The value is their sum; they
|
|
25
|
+
* take `value`'s place. A part's share is clamped so the bar never passes `max`.
|
|
26
|
+
*/
|
|
27
|
+
segments?: ProgressSegment[];
|
|
14
28
|
className?: string;
|
|
15
29
|
};
|
|
16
|
-
|
|
30
|
+
/** The parts of a segmented bar, each clamped so their sum stays within `max`, and their sum. */
|
|
31
|
+
export declare const progressSegments: (segments: ProgressSegment[], max: number) => {
|
|
32
|
+
parts: {
|
|
33
|
+
value: number;
|
|
34
|
+
/** @default "primary" */
|
|
35
|
+
color?: ProgressColor;
|
|
36
|
+
/** Read out with its share, such as "Paid 60%" */
|
|
37
|
+
label?: string;
|
|
38
|
+
}[];
|
|
39
|
+
total: number;
|
|
40
|
+
};
|
|
41
|
+
export declare const Progress: ({ value, max, segments, className, ...restProps }: ProgressProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { Progress, type ProgressProps } from "./Progress.js";
|
|
1
|
+
export { Progress, progressSegments, type ProgressColor, type ProgressProps, type ProgressSegment } from "./Progress.js";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ComponentProps } from "react";
|
|
2
|
+
export type RollingNumberProps = Omit<ComponentProps<"span">, "children"> & {
|
|
3
|
+
/** The number shown. A new value rolls each changed digit to it. */
|
|
4
|
+
value: number;
|
|
5
|
+
/** The locale the number is written in, as `Intl.NumberFormat` takes it; fixed, so the server writes it as the browser does. @default "en-US" */
|
|
6
|
+
locales?: Intl.LocalesArgument;
|
|
7
|
+
/** How the number is written: currency, percent, fraction digits, grouping, as `Intl.NumberFormat` takes it. */
|
|
8
|
+
format?: Intl.NumberFormatOptions;
|
|
9
|
+
};
|
|
10
|
+
/** A written number's characters, each keyed by its place around the decimal separator, so a digit keeps its reel
|
|
11
|
+
* when the number grows or its fraction gets longer; digits are the locale's own (Arabic-Indic, Bengali…). */
|
|
12
|
+
export declare const rollingNumberParts: (value: number, locales?: Intl.LocalesArgument, format?: Intl.NumberFormatOptions) => {
|
|
13
|
+
text: string;
|
|
14
|
+
glyphs: string[];
|
|
15
|
+
characters: {
|
|
16
|
+
character: string;
|
|
17
|
+
digit: number | null;
|
|
18
|
+
key: string;
|
|
19
|
+
}[];
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* A number whose digits roll to a new value, as an odometer: for a total, a balance, a count or a KPI that changes
|
|
23
|
+
* while it is watched. It reads as the written number; its reels are hidden from a screen reader.
|
|
24
|
+
*/
|
|
25
|
+
export declare const RollingNumber: ({ value, locales, format, className, ...restProps }: RollingNumberProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { RollingNumber, rollingNumberParts, type RollingNumberProps } from "./RollingNumber.js";
|
|
@@ -22,6 +22,11 @@ export type StepperProps = {
|
|
|
22
22
|
disabled?: boolean;
|
|
23
23
|
/** Fully rounded ends. @default true */
|
|
24
24
|
pill?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Shows the value between the minus and the plus on one fill, as a cart's quantity: round segments and no
|
|
27
|
+
* separator. Without it the stepper shows no value, as the native one. @default false
|
|
28
|
+
*/
|
|
29
|
+
showValue?: boolean;
|
|
25
30
|
/** Accessible name of the decrement segment. @default "Decrease" */
|
|
26
31
|
decrementLabel?: string;
|
|
27
32
|
/** Accessible name of the increment segment. @default "Increase" */
|
|
@@ -56,8 +61,8 @@ export declare const stepValue: (current: number, direction: 1 | -1, { min, max,
|
|
|
56
61
|
wrap: boolean;
|
|
57
62
|
}) => number;
|
|
58
63
|
/**
|
|
59
|
-
* Two segments that decrease and increase a number, as the iOS 26 stepper does. It shows no value of its own
|
|
60
|
-
* name it with `aria-label` or `aria-labelledby
|
|
64
|
+
* Two segments that decrease and increase a number, as the iOS 26 stepper does. It shows no value of its own
|
|
65
|
+
* (`showValue` puts it between the segments): name it with `aria-label` or `aria-labelledby`. Keyboard focus lands on the
|
|
61
66
|
* stepper, a spin button: Up and Down step, Page Up and Page Down step ten times, Home and End go to the range ends.
|
|
62
67
|
*/
|
|
63
|
-
export declare function Stepper({ id, value: valueProp, defaultValue, onChange, min, max, step, wrap, autoRepeat, disabled, pill, decrementLabel, incrementLabel, onRemove, removeLabel, name, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, onFocus, onBlur, className, }: StepperProps): import("react/jsx-runtime").JSX.Element;
|
|
68
|
+
export declare function Stepper({ id, value: valueProp, defaultValue, onChange, min, max, step, wrap, autoRepeat, disabled, pill, showValue, decrementLabel, incrementLabel, onRemove, removeLabel, name, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, onFocus, onBlur, className, }: StepperProps): import("react/jsx-runtime").JSX.Element;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plexui/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.58.0",
|
|
4
4
|
"description": "Modern design system for building high-quality applications",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -99,7 +99,7 @@
|
|
|
99
99
|
"@maskito/core": "^5.2.2",
|
|
100
100
|
"@maskito/kit": "^5.2.2",
|
|
101
101
|
"@maskito/react": "^5.2.2",
|
|
102
|
-
"@plexui/styles": "^0.
|
|
102
|
+
"@plexui/styles": "^0.16.0",
|
|
103
103
|
"@radix-ui/react-dismissable-layer": "1.2.1",
|
|
104
104
|
"@radix-ui/react-focus-guards": "1.2.0",
|
|
105
105
|
"@radix-ui/react-focus-scope": "1.3.1",
|