@plexui/ui 0.59.5 → 0.60.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/NavigationRow/NavigationRow.js +5 -4
- package/dist/es/components/NavigationRow/NavigationRow.js.map +1 -1
- package/dist/es/components/Progress/Progress.js +3 -3
- package/dist/es/components/Progress/Progress.js.map +1 -1
- package/dist/es/components/Progress/index.js.map +1 -1
- package/dist/es/components/StatsCard/StatsCard.js +6 -2
- package/dist/es/components/StatsCard/StatsCard.js.map +1 -1
- package/dist/es/lib/fitValueScale.js +54 -0
- package/dist/es/lib/fitValueScale.js.map +1 -0
- package/dist/types/components/NavigationRow/NavigationRow.d.ts +12 -1
- package/dist/types/components/Progress/Progress.d.ts +13 -1
- package/dist/types/components/Progress/index.d.ts +1 -1
- package/dist/types/lib/fitValueScale.d.ts +7 -0
- package/package.json +2 -2
|
@@ -27,11 +27,12 @@ const valueFitsBeside = (row) => {
|
|
|
27
27
|
* the row opens (`aria-haspopup`, `aria-expanded`) itself.
|
|
28
28
|
*/
|
|
29
29
|
export function NavigationRow(props) {
|
|
30
|
-
const { label, value, description, href, external, as, disabled, valuePlacement = "end", className, ref, target, rel, download, hrefLang, ping, referrerPolicy, ...rest } = props;
|
|
30
|
+
const { label, value, description, leading, disclosure = true, href, external, as, disabled, valuePlacement = "end", className, ref, target, rel, download, hrefLang, ping, referrerPolicy, ...rest } = props;
|
|
31
31
|
// Only the link attributes given: an undefined `target` would override the new tab of an external link
|
|
32
32
|
const linkAttributes = Object.fromEntries(Object.entries({ target, rel, download, hrefLang, ping, referrerPolicy }).filter(([, attribute]) => attribute !== undefined));
|
|
33
33
|
const hasValue = shown(value);
|
|
34
34
|
const hasDescription = shown(description);
|
|
35
|
+
const hasLeading = shown(leading);
|
|
35
36
|
const rowRef = useRef(null);
|
|
36
37
|
// FieldGroup columns give the label a column of its own: a change of them measures again
|
|
37
38
|
const columns = useFieldColumns();
|
|
@@ -71,9 +72,9 @@ export function NavigationRow(props) {
|
|
|
71
72
|
stop();
|
|
72
73
|
observer.disconnect();
|
|
73
74
|
};
|
|
74
|
-
}, [auto, label, value, description, columns]);
|
|
75
|
+
}, [auto, label, value, description, leading, disclosure, columns]);
|
|
75
76
|
const below = hasValue && (valuePlacement === "below" || (auto && !fits));
|
|
76
|
-
const content = (_jsxs("span", { className: s.Content, "data-navigation-row-content": "", children: [_jsxs("span", { className: s.Text, children: [_jsx("span", { className: s.Label, "data-navigation-row-part": "", children: label }), hasDescription && _jsx("span", { className: s.Description, children: description })] }), hasValue && _jsx("span", { className: s.Value, "data-navigation-row-part": "", children: value }), _jsx(Disclosure, { className: s.Disclosure, "aria-hidden": "true", "data-no-autosize": "" })] }));
|
|
77
|
+
const content = (_jsxs("span", { className: s.Content, "data-navigation-row-content": "", children: [hasLeading && _jsx("span", { className: s.Leading, children: leading }), _jsxs("span", { className: s.Text, children: [_jsx("span", { className: s.Label, "data-navigation-row-part": "", children: label }), hasDescription && _jsx("span", { className: s.Description, children: description })] }), hasValue && _jsx("span", { className: s.Value, "data-navigation-row-part": "", children: value }), disclosure && _jsx(Disclosure, { className: s.Disclosure, "aria-hidden": "true", "data-no-autosize": "" })] }));
|
|
77
78
|
const shared = {
|
|
78
79
|
className: clsx(s.Pressable, className),
|
|
79
80
|
block: true,
|
|
@@ -81,6 +82,6 @@ export function NavigationRow(props) {
|
|
|
81
82
|
variant: "ghost",
|
|
82
83
|
"data-navigation-row": "",
|
|
83
84
|
};
|
|
84
|
-
return (_jsx("div", { ref: rowRef, className: s.NavigationRow, "data-row": "", "data-value-below": below ? "" : undefined, "data-value": hasValue ? "" : undefined, "data-description": hasDescription ? "" : undefined, children: href !== undefined && !disabled ? (_jsx(ButtonLink, { ...rest, ...shared, ref: ref, href: href, external: external, as: as, ...linkAttributes, children: content })) : (_jsx(Button, { ...rest, ...shared, ref: ref, disabled: disabled, children: content })) }));
|
|
85
|
+
return (_jsx("div", { ref: rowRef, className: s.NavigationRow, "data-row": "", "data-value-below": below ? "" : undefined, "data-value": hasValue ? "" : undefined, "data-description": hasDescription ? "" : undefined, "data-leading": hasLeading ? "" : undefined, "data-disclosure": disclosure ? undefined : "none", children: href !== undefined && !disabled ? (_jsx(ButtonLink, { ...rest, ...shared, ref: ref, href: href, external: external, as: as, ...linkAttributes, children: content })) : (_jsx(Button, { ...rest, ...shared, ref: ref, disabled: disabled, children: content })) }));
|
|
85
86
|
}
|
|
86
87
|
//# sourceMappingURL=NavigationRow.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NavigationRow.js","sourceRoot":"","sources":["../../../../src/components/NavigationRow/NavigationRow.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAsG,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAC7J,OAAO,CAAC,MAAM,kEAAkE,CAAA;AAChF,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAkCpD,MAAM,KAAK,GAAG,CAAC,KAAgB,EAAE,EAAE,CAAC,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,KAAK,IAAI,KAAK,KAAK,EAAE,CAAA;AAE5G,wHAAwH;AACxH,MAAM,eAAe,GAAG,CAAC,GAAgB,EAAE,EAAE;IAC3C,MAAM,OAAO,GAAG,GAAG,CAAC,aAAa,CAAc,+BAA+B,CAAC,CAAA;IAC/E,IAAI,CAAC,OAAO;QAAE,OAAO,IAAI,CAAA;IACzB,MAAM,KAAK,GAAG,GAAG,CAAC,YAAY,CAAC,kBAAkB,CAAC,CAAA;IAClD,GAAG,CAAC,eAAe,CAAC,kBAAkB,CAAC,CAAA;IACvC,GA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C5B,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,sBACnB,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,YAEhD,IAAI,KAAK,SAAS,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CACjC,KAAC,UAAU,OACJ,IAAgC,KACjC,MAAM,EACV,GAAG,EAAE,GAA6B,EAClC,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,QAAQ,EAClB,EAAE,EAAE,EAA0B,KAC1B,cAAc,YAEjB,OAAO,GACG,CACd,CAAC,CAAC,CAAC,CACF,KAAC,MAAM,OAAM,IAAgD,KAAM,MAAM,EAAE,GAAG,EAAE,GAA6B,EAAE,QAAQ,EAAE,QAAQ,YAC9H,OAAO,GACD,CACV,GACG,CACP,CAAA;AACH,CAAC","sourcesContent":["\"use client\"\n\nimport clsx from \"clsx\"\nimport { type AnchorHTMLAttributes, type ButtonHTMLAttributes, type ComponentType, type ReactNode, type Ref, useLayoutEffect, useRef, useState } from \"react\"\nimport s from \"@plexui/styles/components/NavigationRow/NavigationRow.module.css\"\nimport { Button, ButtonLink } from \"../Button\"\nimport { Disclosure } from \"../Icon\"\nimport { useFieldColumns } from \"../../lib/fieldRow\"\n\ntype LinkAttributes = Pick<\n AnchorHTMLAttributes<HTMLAnchorElement>,\n \"target\" | \"rel\" | \"download\" | \"hrefLang\" | \"ping\" | \"referrerPolicy\"\n>\n\n// Events come from a button or, with `href`, a link (a disabled link is a button again), so handlers see either\nexport type NavigationRowProps = Omit<ButtonHTMLAttributes<HTMLButtonElement | HTMLAnchorElement>, \"children\" | \"value\" | \"type\"> &\n LinkAttributes & {\n /** The row's name, where a row's label starts */\n label: ReactNode\n /** The current value, at the end of the row in the secondary label. `0` shows; `null`, `undefined` and `\"\"` do not. */\n value?: ReactNode\n /** A line under the label; the row grows from 52 to hold it */\n description?: ReactNode\n /** Where the row goes. With it the row is a link (through `PlexUIProvider`'s `linkComponent`, or `as`). */\n href?: string\n /** Force external-link behavior for `href` */\n external?: boolean\n /** Link component for `href`, e.g. a router's link. @default PlexUIProvider linkComponent */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n as?: ComponentType<any> | \"a\"\n /** The row can't be pressed. A disabled link renders as a disabled button, so it never navigates. */\n disabled?: boolean\n /**\n * Where the value stands: at the `end` of the row, `below` the label at the full width, or `auto`: at the end while\n * it fits beside the label on one line, otherwise below (as Calendar sets a long value). @default \"end\"\n */\n valuePlacement?: \"end\" | \"below\" | \"auto\"\n /** Ref for the row's pressable (a `button`, or the link's element) */\n ref?: Ref<HTMLButtonElement | HTMLAnchorElement | null>\n}\n\nconst shown = (value: ReactNode) => value !== null && value !== undefined && value !== false && value !== \"\"\n\n/** Whether the label and the value of a row fit beside each other on one line: measured in the end layout, unwrapped */\nconst valueFitsBeside = (row: HTMLElement) => {\n const content = row.querySelector<HTMLElement>(\"[data-navigation-row-content]\")\n if (!content) return true\n const below = row.hasAttribute(\"data-value-below\")\n row.removeAttribute(\"data-value-below\")\n row.setAttribute(\"data-measuring\", \"\")\n const fits = [content, ...content.querySelectorAll<HTMLElement>(\"[data-navigation-row-part]\")].every(\n (element) => element.scrollWidth <= element.clientWidth + 0.5,\n )\n row.removeAttribute(\"data-measuring\")\n if (below) row.setAttribute(\"data-value-below\", \"\")\n return fits\n}\n\n/**\n * A FieldGroup row that opens what it holds, as an iOS Settings drill-in: label, current value, chevron, one press.\n * Every other prop (id, events, ARIA, data attributes, className) goes to the pressable, so a caller states what\n * the row opens (`aria-haspopup`, `aria-expanded`) itself.\n */\nexport function NavigationRow(props: NavigationRowProps) {\n const { label, value, description, href, external, as, disabled, valuePlacement = \"end\", className, ref, target, rel, download, hrefLang, ping, referrerPolicy, ...rest } = props\n // Only the link attributes given: an undefined `target` would override the new tab of an external link\n const linkAttributes = Object.fromEntries(\n Object.entries({ target, rel, download, hrefLang, ping, referrerPolicy }).filter(([, attribute]) => attribute !== undefined),\n )\n const hasValue = shown(value)\n const hasDescription = shown(description)\n const rowRef = useRef<HTMLDivElement>(null)\n // FieldGroup columns give the label a column of its own: a change of them measures again\n const columns = useFieldColumns()\n const [fits, setFits] = useState(true)\n const auto = valuePlacement === \"auto\" && hasValue\n\n // \"auto\": measure on mount, when the label or value changes, and when the row's width changes\n useLayoutEffect(() => {\n const row = rowRef.current\n if (!auto || !row) return\n let live = true\n const check = () => {\n if (live) setFits(valueFitsBeside(row))\n }\n check()\n // A web font that arrives late (font-display: swap) changes the words' widths, not the row's\n const fonts = typeof document !== \"undefined\" ? document.fonts : undefined\n fonts?.ready.then(check)\n fonts?.addEventListener?.(\"loadingdone\", check)\n const stop = () => {\n live = false\n fonts?.removeEventListener?.(\"loadingdone\", check)\n }\n if (typeof ResizeObserver === \"undefined\") return stop\n let width = row.getBoundingClientRect().width\n const observer = new ResizeObserver(() => {\n const next = row.getBoundingClientRect().width\n if (next === width) return\n width = next\n check()\n })\n observer.observe(row)\n return () => {\n stop()\n observer.disconnect()\n }\n }, [auto, label, value, description, columns])\n\n const below = hasValue && (valuePlacement === \"below\" || (auto && !fits))\n\n const content = (\n <span className={s.Content} data-navigation-row-content=\"\">\n <span className={s.Text}>\n <span className={s.Label} data-navigation-row-part=\"\">{label}</span>\n {hasDescription && <span className={s.Description}>{description}</span>}\n </span>\n {hasValue && <span className={s.Value} data-navigation-row-part=\"\">{value}</span>}\n <Disclosure className={s.Disclosure} aria-hidden=\"true\" data-no-autosize=\"\" />\n </span>\n )\n\n const shared = {\n className: clsx(s.Pressable, className),\n block: true,\n color: \"secondary\",\n variant: \"ghost\",\n \"data-navigation-row\": \"\",\n } as const\n\n return (\n <div\n ref={rowRef}\n className={s.NavigationRow}\n data-row=\"\"\n data-value-below={below ? \"\" : undefined}\n data-value={hasValue ? \"\" : undefined}\n data-description={hasDescription ? \"\" : undefined}\n >\n {href !== undefined && !disabled ? (\n <ButtonLink\n {...(rest as Record<string, unknown>)}\n {...shared}\n ref={ref as Ref<HTMLAnchorElement>}\n href={href}\n external={external}\n as={as as PlexUI.LinkComponent}\n {...linkAttributes}\n >\n {content}\n </ButtonLink>\n ) : (\n <Button {...(rest as ButtonHTMLAttributes<HTMLButtonElement>)} {...shared} ref={ref as Ref<HTMLButtonElement>} disabled={disabled}>\n {content}\n </Button>\n )}\n </div>\n )\n}\n"]}
|
|
1
|
+
{"version":3,"file":"NavigationRow.js","sourceRoot":"","sources":["../../../../src/components/NavigationRow/NavigationRow.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAsG,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAC7J,OAAO,CAAC,MAAM,kEAAkE,CAAA;AAChF,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AA6CpD,MAAM,KAAK,GAAG,CAAC,KAAgB,EAAE,EAAE,CAAC,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,KAAK,IAAI,KAAK,KAAK,EAAE,CAAA;AAE5G,wHAAwH;AACxH,MAAM,eAAe,GAAG,CAAC,GAAgB,EAAE,EAAE;IAC3C,MAAM,OAAO,GAAG,GAAG,CAAC,aAAa,CAAc,+BAA+B,CAAC,CAAA;IAC/E,IAAI,CAAC,OAAO;QAAE,OAAO,IAAI,CAAA;IACzB,MAAM,KAAK,GAAG,GAAG,CAAC,YAAY,CAAC,kBAAkB,CAAC,CAAA;IAClD,GAAG,CAAC,eAAe,CAAC,kBAAkB,CAAC,CAAA;IACvC,GAAG,CAAC,YAAY,CAAC,gBAAgB,EAAE,EAAE,CAAC,CAAA;IACtC,MAAM,IAAI,GAAG,CAAC,OAAO,EAAE,GAAG,OAAO,CAAC,gBAAgB,CAAc,4BAA4B,CA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BACO,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,gBAC5B,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,sBACnB,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,kBACnC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,qBACxB,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,YAE/C,IAAI,KAAK,SAAS,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CACjC,KAAC,UAAU,OACJ,IAAgC,KACjC,MAAM,EACV,GAAG,EAAE,GAA6B,EAClC,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,QAAQ,EAClB,EAAE,EAAE,EAA0B,KAC1B,cAAc,YAEjB,OAAO,GACG,CACd,CAAC,CAAC,CAAC,CACF,KAAC,MAAM,OAAM,IAAgD,KAAM,MAAM,EAAE,GAAG,EAAE,GAA6B,EAAE,QAAQ,EAAE,QAAQ,YAC9H,OAAO,GACD,CACV,GACG,CACP,CAAA;AACH,CAAC","sourcesContent":["\"use client\"\n\nimport clsx from \"clsx\"\nimport { type AnchorHTMLAttributes, type ButtonHTMLAttributes, type ComponentType, type ReactNode, type Ref, useLayoutEffect, useRef, useState } from \"react\"\nimport s from \"@plexui/styles/components/NavigationRow/NavigationRow.module.css\"\nimport { Button, ButtonLink } from \"../Button\"\nimport { Disclosure } from \"../Icon\"\nimport { useFieldColumns } from \"../../lib/fieldRow\"\n\ntype LinkAttributes = Pick<\n AnchorHTMLAttributes<HTMLAnchorElement>,\n \"target\" | \"rel\" | \"download\" | \"hrefLang\" | \"ping\" | \"referrerPolicy\"\n>\n\n// Events come from a button or, with `href`, a link (a disabled link is a button again), so handlers see either\nexport type NavigationRowProps = Omit<ButtonHTMLAttributes<HTMLButtonElement | HTMLAnchorElement>, \"children\" | \"value\" | \"type\"> &\n LinkAttributes & {\n /** The row's name, where a row's label starts */\n label: ReactNode\n /** The current value, at the end of the row in the secondary label. `0` shows; `null`, `undefined` and `\"\"` do not. */\n value?: ReactNode\n /** A line under the label; the row grows from 52 to hold it. A `<br />` starts a second line. */\n description?: ReactNode\n /**\n * What leads the row, such as an `Avatar` or a symbol, in a column before the label (`--navigation-row-leading-size`,\n * its own size), on the label's first line: a shorter text is centred beside it, a longer one starts level with it.\n * The line above the row starts after it, where the text starts (iOS Find My's People list).\n */\n leading?: ReactNode\n /**\n * The chevron at the end. `false` drops it, for a row that opens a record rather than a page of choices (as the\n * Contacts list of iOS); the row is still one press. @default true\n */\n disclosure?: boolean\n /** Where the row goes. With it the row is a link (through `PlexUIProvider`'s `linkComponent`, or `as`). */\n href?: string\n /** Force external-link behavior for `href` */\n external?: boolean\n /** Link component for `href`, e.g. a router's link. @default PlexUIProvider linkComponent */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n as?: ComponentType<any> | \"a\"\n /** The row can't be pressed. A disabled link renders as a disabled button, so it never navigates. */\n disabled?: boolean\n /**\n * Where the value stands: at the `end` of the row, `below` the label at the full width, or `auto`: at the end while\n * it fits beside the label on one line, otherwise below (as Calendar sets a long value). @default \"end\"\n */\n valuePlacement?: \"end\" | \"below\" | \"auto\"\n /** Ref for the row's pressable (a `button`, or the link's element) */\n ref?: Ref<HTMLButtonElement | HTMLAnchorElement | null>\n}\n\nconst shown = (value: ReactNode) => value !== null && value !== undefined && value !== false && value !== \"\"\n\n/** Whether the label and the value of a row fit beside each other on one line: measured in the end layout, unwrapped */\nconst valueFitsBeside = (row: HTMLElement) => {\n const content = row.querySelector<HTMLElement>(\"[data-navigation-row-content]\")\n if (!content) return true\n const below = row.hasAttribute(\"data-value-below\")\n row.removeAttribute(\"data-value-below\")\n row.setAttribute(\"data-measuring\", \"\")\n const fits = [content, ...content.querySelectorAll<HTMLElement>(\"[data-navigation-row-part]\")].every(\n (element) => element.scrollWidth <= element.clientWidth + 0.5,\n )\n row.removeAttribute(\"data-measuring\")\n if (below) row.setAttribute(\"data-value-below\", \"\")\n return fits\n}\n\n/**\n * A FieldGroup row that opens what it holds, as an iOS Settings drill-in: label, current value, chevron, one press.\n * Every other prop (id, events, ARIA, data attributes, className) goes to the pressable, so a caller states what\n * the row opens (`aria-haspopup`, `aria-expanded`) itself.\n */\nexport function NavigationRow(props: NavigationRowProps) {\n const { label, value, description, leading, disclosure = true, href, external, as, disabled, valuePlacement = \"end\", className, ref, target, rel, download, hrefLang, ping, referrerPolicy, ...rest } = props\n // Only the link attributes given: an undefined `target` would override the new tab of an external link\n const linkAttributes = Object.fromEntries(\n Object.entries({ target, rel, download, hrefLang, ping, referrerPolicy }).filter(([, attribute]) => attribute !== undefined),\n )\n const hasValue = shown(value)\n const hasDescription = shown(description)\n const hasLeading = shown(leading)\n const rowRef = useRef<HTMLDivElement>(null)\n // FieldGroup columns give the label a column of its own: a change of them measures again\n const columns = useFieldColumns()\n const [fits, setFits] = useState(true)\n const auto = valuePlacement === \"auto\" && hasValue\n\n // \"auto\": measure on mount, when the label or value changes, and when the row's width changes\n useLayoutEffect(() => {\n const row = rowRef.current\n if (!auto || !row) return\n let live = true\n const check = () => {\n if (live) setFits(valueFitsBeside(row))\n }\n check()\n // A web font that arrives late (font-display: swap) changes the words' widths, not the row's\n const fonts = typeof document !== \"undefined\" ? document.fonts : undefined\n fonts?.ready.then(check)\n fonts?.addEventListener?.(\"loadingdone\", check)\n const stop = () => {\n live = false\n fonts?.removeEventListener?.(\"loadingdone\", check)\n }\n if (typeof ResizeObserver === \"undefined\") return stop\n let width = row.getBoundingClientRect().width\n const observer = new ResizeObserver(() => {\n const next = row.getBoundingClientRect().width\n if (next === width) return\n width = next\n check()\n })\n observer.observe(row)\n return () => {\n stop()\n observer.disconnect()\n }\n }, [auto, label, value, description, leading, disclosure, columns])\n\n const below = hasValue && (valuePlacement === \"below\" || (auto && !fits))\n\n const content = (\n <span className={s.Content} data-navigation-row-content=\"\">\n {hasLeading && <span className={s.Leading}>{leading}</span>}\n <span className={s.Text}>\n <span className={s.Label} data-navigation-row-part=\"\">{label}</span>\n {hasDescription && <span className={s.Description}>{description}</span>}\n </span>\n {hasValue && <span className={s.Value} data-navigation-row-part=\"\">{value}</span>}\n {disclosure && <Disclosure className={s.Disclosure} aria-hidden=\"true\" data-no-autosize=\"\" />}\n </span>\n )\n\n const shared = {\n className: clsx(s.Pressable, className),\n block: true,\n color: \"secondary\",\n variant: \"ghost\",\n \"data-navigation-row\": \"\",\n } as const\n\n return (\n <div\n ref={rowRef}\n className={s.NavigationRow}\n data-row=\"\"\n data-value-below={below ? \"\" : undefined}\n data-value={hasValue ? \"\" : undefined}\n data-description={hasDescription ? \"\" : undefined}\n data-leading={hasLeading ? \"\" : undefined}\n data-disclosure={disclosure ? undefined : \"none\"}\n >\n {href !== undefined && !disabled ? (\n <ButtonLink\n {...(rest as Record<string, unknown>)}\n {...shared}\n ref={ref as Ref<HTMLAnchorElement>}\n href={href}\n external={external}\n as={as as PlexUI.LinkComponent}\n {...linkAttributes}\n >\n {content}\n </ButtonLink>\n ) : (\n <Button {...(rest as ButtonHTMLAttributes<HTMLButtonElement>)} {...shared} ref={ref as Ref<HTMLButtonElement>} disabled={disabled}>\n {content}\n </Button>\n )}\n </div>\n )\n}\n"]}
|
|
@@ -15,16 +15,16 @@ export const progressSegments = (segments, max) => {
|
|
|
15
15
|
return { parts, total };
|
|
16
16
|
};
|
|
17
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 }) => {
|
|
18
|
+
export const Progress = ({ value = null, max = 100, segments, size = "sm", color = "primary", className, ...restProps }) => {
|
|
19
19
|
if (segments) {
|
|
20
20
|
// Radix falls back to 100 for a max that is not a positive number; the parts are measured against the same
|
|
21
21
|
const rootMax = typeof max === "number" && max > 0 && !Number.isNaN(max) ? max : 100;
|
|
22
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) }));
|
|
23
|
+
return (_jsx(RadixProgress.Root, { value: total, max: rootMax, getValueLabel: () => segmentsLabel(parts, rootMax), className: clsx(s.Root, className), "data-segmented": "", "data-size": size, ...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
24
|
}
|
|
25
25
|
const resolved = value == null ? null : Math.max(0, Math.min(max, value));
|
|
26
26
|
const percentage = resolved == null ? null : (resolved / max) * 100;
|
|
27
|
-
return (_jsx(RadixProgress.Root, { value: resolved, max: max, className: clsx(s.Root, className), ...restProps, children: _jsx(RadixProgress.Indicator, { className: s.Indicator, style: {
|
|
27
|
+
return (_jsx(RadixProgress.Root, { value: resolved, max: max, className: clsx(s.Root, className), "data-size": size, "data-color": color, ...restProps, children: _jsx(RadixProgress.Indicator, { className: s.Indicator, style: {
|
|
28
28
|
transform: percentage == null ? undefined : `translateX(-${100 - percentage}%)`,
|
|
29
29
|
}, "data-indeterminate": percentage == null ? "" : undefined }) }));
|
|
30
30
|
};
|
|
@@ -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
|
+
{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AC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAA;IACzE,MAAM,UAAU,GAAG,QAAQ,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,GAAG,GAAG,CAAC,GAAG,GAAG,CAAA;IAEnE,OAAO,CACL,KAAC,aAAa,CAAC,IAAI,IACjB,KAAK,EAAE,QAAQ,EACf,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,SAAS,CAAC,eACvB,IAAI,gBACH,KAAK,KACb,SAAS,YAEb,KAAC,aAAa,CAAC,SAAS,IACtB,SAAS,EAAE,CAAC,CAAC,SAAS,EACtB,KAAK,EAAE;gBACL,SAAS,EACP,UAAU,IAAI,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,eAAe,GAAG,GAAG,UAAU,IAAI;aACvE,wBACmB,UAAU,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,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 ProgressSize = \"sm\" | \"md\" | \"lg\"\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 /**\n * The bar's thickness: `sm` 4px (iOS's progress view), `md` 6px, `lg` 8px (a bar in a stats card, as Apple Fitness).\n * @default \"sm\"\n */\n size?: ProgressSize\n /**\n * The color of the filled part, such as `secondary` (grey) for a second series beside a `primary` one. A segmented\n * bar's parts take their own colors.\n * @default \"primary\"\n */\n color?: ProgressColor\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 size = \"sm\",\n color = \"primary\",\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 data-size={size}\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 data-size={size}\n data-color={color}\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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/Progress/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,gBAAgB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/Progress/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAmF,MAAM,YAAY,CAAA","sourcesContent":["export { Progress, progressSegments, type ProgressColor, type ProgressProps, type ProgressSegment, type ProgressSize } from \"./Progress\"\n"]}
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import clsx from "clsx";
|
|
4
|
-
import {} from "react";
|
|
4
|
+
import { useLayoutEffect, useRef } from "react";
|
|
5
5
|
import { Badge } from "../Badge/index.js";
|
|
6
6
|
import { InfoCircle, Trending } from "../Icon/index.js";
|
|
7
7
|
import { Tooltip } from "../Tooltip/index.js";
|
|
8
|
+
import { fitValueScale } from "../../lib/fitValueScale.js";
|
|
8
9
|
import s from "@plexui/styles/components/StatsCard/StatsCard.module.css";
|
|
9
10
|
export const StatsCard = ({ label, value, description, trend, invertTrend, icon, sparkline, progress, progressLabel, tooltip, trendPosition = "value", trendVariant = "text", size = "default", variant = "default", accentColor = "primary", className, ref, ...restProps }) => {
|
|
11
|
+
// A value wider than the card (two cards a row on a phone) scales down to fit, as iOS's minimumScaleFactor
|
|
12
|
+
const valueRef = useRef(null);
|
|
13
|
+
useLayoutEffect(() => (valueRef.current ? fitValueScale(valueRef.current, "--stats-card-value-scale") : undefined), []);
|
|
10
14
|
const trendValue = trend?.value ?? 0;
|
|
11
15
|
const trendClassName = trendValue === 0
|
|
12
16
|
? s.TrendNeutral
|
|
@@ -36,7 +40,7 @@ export const StatsCard = ({ label, value, description, trend, invertTrend, icon,
|
|
|
36
40
|
const iconEl = icon ? _jsx("div", { className: s.IconWrapper, children: icon }) : null;
|
|
37
41
|
const headerTrendEl = trendPosition === "header" ? trendEl : null;
|
|
38
42
|
const headerEl = (_jsxs("div", { className: s.Header, children: [_jsxs("div", { className: s.LabelRow, children: [_jsx("div", { className: s.Label, children: label }), tooltip && (_jsx(Tooltip, { content: tooltip, children: _jsx("span", { className: s.InfoIcon, tabIndex: 0, role: "img", "aria-label": "More information", children: _jsx(InfoCircle, {}) }) }))] }), (headerTrendEl || iconEl) && (_jsxs("div", { className: s.HeaderEnd, children: [headerTrendEl, iconEl] }))] }));
|
|
39
|
-
const valueRowEl = (_jsx("div", { className: s.ValueRow, children: _jsx("div", { className: s.Value, children: value }) }));
|
|
43
|
+
const valueRowEl = (_jsx("div", { className: s.ValueRow, children: _jsx("div", { ref: valueRef, className: s.Value, children: value }) }));
|
|
40
44
|
// Under the value, a trend and what it compares with, on one line (shadcn's metric card with a trend); a trend in
|
|
41
45
|
// the header leaves its label there
|
|
42
46
|
const trendRowEl = trend != null && (trendPosition === "value" || trend.label) ? (_jsxs("div", { className: s.TrendRow, children: [trendPosition === "value" && trendEl, trend.label && _jsx("span", { className: s.TrendLabel, children: trend.label })] })) : null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StatsCard.js","sourceRoot":"","sources":["../../../../src/components/StatsCard/StatsCard.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAA4B,MAAM,OAAO,CAAA;AAChD,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAChC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM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AC,IAAI,CAAA;IAER,MAAM,WAAW,GAAG,SAAS,CAAC,CAAC,CAAC,cAAK,SAAS,EAAE,CAAC,CAAC,SAAS,YAAG,SAAS,GAAO,CAAC,CAAC,CAAC,IAAI,CAAA;IAErF,OAAO,CACL,eACE,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC,SAAS,EAAE,SAAS,CAAC,kBACzB,OAAO,eACV,IAAI,uBACI,WAAW,KAC1B,SAAS,aAEZ,QAAQ,EACR,UAAU,EACV,UAAU,EACV,aAAa,EACb,UAAU,EACV,WAAW,IACR,CACP,CAAA;AACH,CAAC,CAAA","sourcesContent":["\"use client\"\n\nimport clsx from \"clsx\"\nimport { type ReactNode, type Ref } from \"react\"\nimport { Badge } from \"../Badge\"\nimport { InfoCircle, Trending } from \"../Icon\"\nimport { Tooltip } from \"../Tooltip\"\nimport s from \"@plexui/styles/components/StatsCard/StatsCard.module.css\"\n\nexport type StatsCardProps = {\n /** Label describing the metric */\n label: string\n /** The primary metric value (e.g. \"1,234\" or \"$50K\") */\n value: ReactNode\n /** Optional description or subtitle below the value */\n description?: string\n /** Trend indicator with percentage change */\n trend?: {\n /** The percentage change value (e.g. 12.5 for +12.5%) */\n value: number\n /** Optional label for the trend (e.g. \"vs last month\") */\n label?: string\n }\n /** When true, a positive trend is bad (red) and negative is good (green). Use for metrics like \"Error Rate\" or \"Avg Completion Time\". */\n invertTrend?: boolean\n /** Icon in a small tile with a soft background, at the end of the header */\n icon?: ReactNode\n /** Optional ReactNode for a sparkline/chart rendered at the bottom */\n sparkline?: ReactNode\n /** Progress value from 0 to 100. Shows a progress bar at the bottom. */\n progress?: number\n /** Label displayed after the progress bar */\n progressLabel?: string\n /** Tooltip text — renders an (i) icon next to the label with a tooltip on hover */\n tooltip?: string\n /**\n * Where the trend indicator is positioned\n * - `\"value\"` — under the value, with its label (default)\n * - `\"header\"` — right-aligned in the header row, its label under the value\n * @default \"value\"\n */\n trendPosition?: \"value\" | \"header\"\n /**\n * Visual style of the trend indicator\n * - `\"text\"` — plain colored text (default)\n * - `\"badge\"` — wrapped in a Badge component\n * @default \"text\"\n */\n trendVariant?: \"text\" | \"badge\"\n /**\n * Size of the card\n * - `\"default\"` — standard dashboard card\n * - `\"sm\"` — compact card for dense layouts\n * @default \"default\"\n */\n size?: \"default\" | \"sm\"\n /**\n * Visual variant of the card\n * @default \"default\"\n */\n variant?: \"default\" | \"accent\"\n /**\n * Color of the accent variant's bar\n * @default \"primary\"\n */\n accentColor?: \"primary\" | \"secondary\" | \"info\" | \"success\" | \"warning\" | \"danger\" | \"discovery\" | \"caution\"\n /** Class applied to the card container */\n className?: string\n /** Ref applied to the card container */\n ref?: Ref<HTMLDivElement>\n}\n\nexport const StatsCard = ({\n label,\n value,\n description,\n trend,\n invertTrend,\n icon,\n sparkline,\n progress,\n progressLabel,\n tooltip,\n trendPosition = \"value\",\n trendVariant = \"text\",\n size = \"default\",\n variant = \"default\",\n accentColor = \"primary\",\n className,\n ref,\n ...restProps\n}: StatsCardProps) => {\n const trendValue = trend?.value ?? 0\n const trendClassName =\n trendValue === 0\n ? s.TrendNeutral\n : trendValue > 0\n ? invertTrend\n ? s.TrendNegative\n : s.TrendPositive\n : invertTrend\n ? s.TrendPositive\n : s.TrendNegative\n\n const trendText = `${trendValue > 0 ? \"+\" : \"\"}${trendValue}%`\n const progressValue =\n progress === undefined ? undefined : Math.min(100, Math.max(0, progress))\n\n const trendBadgeColor =\n trendValue === 0\n ? \"secondary\"\n : trendValue > 0\n ? invertTrend\n ? \"danger\"\n : \"success\"\n : invertTrend\n ? \"success\"\n : \"danger\"\n\n // A trend line points the way the value moved, whichever colour that is (shadcn's metric cards draw lucide's\n // trending-up and trending-down); a fall is the rise mirrored\n const trendContent = (\n <>\n {trendValue !== 0 && <Trending className={trendValue < 0 ? s.TrendDown : undefined} />}\n {trendText}\n </>\n )\n\n const trendEl = trend != null && (\n trendVariant === \"badge\" ? (\n <Badge size=\"sm\" color={trendBadgeColor as \"secondary\" | \"success\" | \"danger\"}>\n {trendContent}\n </Badge>\n ) : (\n <div className={clsx(s.Trend, trendClassName)}>\n {trendContent}\n </div>\n )\n )\n\n // The icon's tile stands at the end of the header, as the trend may (shadcn's metric card with an icon)\n const iconEl = icon ? <div className={s.IconWrapper}>{icon}</div> : null\n const headerTrendEl = trendPosition === \"header\" ? trendEl : null\n\n const headerEl = (\n <div className={s.Header}>\n <div className={s.LabelRow}>\n <div className={s.Label}>{label}</div>\n {tooltip && (\n <Tooltip content={tooltip}>\n {/* Focusable and named so keyboard and screen-reader users reach the tooltip */}\n <span className={s.InfoIcon} tabIndex={0} role=\"img\" aria-label=\"More information\">\n <InfoCircle />\n </span>\n </Tooltip>\n )}\n </div>\n {(headerTrendEl || iconEl) && (\n <div className={s.HeaderEnd}>\n {headerTrendEl}\n {iconEl}\n </div>\n )}\n </div>\n )\n\n const valueRowEl = (\n <div className={s.ValueRow}>\n <div className={s.Value}>{value}</div>\n </div>\n )\n\n // Under the value, a trend and what it compares with, on one line (shadcn's metric card with a trend); a trend in\n // the header leaves its label there\n const trendRowEl = trend != null && (trendPosition === \"value\" || trend.label) ? (\n <div className={s.TrendRow}>\n {trendPosition === \"value\" && trendEl}\n {trend.label && <span className={s.TrendLabel}>{trend.label}</span>}\n </div>\n ) : null\n\n const descriptionEl = description ? <div className={s.Description}>{description}</div> : null\n\n const progressEl = (progressValue !== undefined || progressLabel) ? (\n <div className={s.Progress}>\n <div className={s.ProgressTrack}>\n <div\n className={s.ProgressBar}\n style={{ width: `${progressValue ?? 0}%` }}\n aria-hidden\n />\n </div>\n {progressLabel && <div className={s.ProgressLabel}>{progressLabel}</div>}\n </div>\n ) : null\n\n const sparklineEl = sparkline ? <div className={s.Sparkline}>{sparkline}</div> : null\n\n return (\n <div\n ref={ref}\n className={clsx(s.StatsCard, className)}\n data-variant={variant}\n data-size={size}\n data-accent-color={accentColor}\n {...restProps}\n >\n {headerEl}\n {valueRowEl}\n {trendRowEl}\n {descriptionEl}\n {progressEl}\n {sparklineEl}\n </div>\n )\n}\n"]}
|
|
1
|
+
{"version":3,"file":"StatsCard.js","sourceRoot":"","sources":["../../../../src/components/StatsCard/StatsCard.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAA4B,eAAe,EAAE,MAAM,EAAE,MAAM,OAAO,CAAA;AACzE,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAChC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AACvD,OAAO,CAAC,MAAM,0DAA0D,CAAA;AAiExE,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,EACxB,KAAK,EACL,KAAK,EACL,WAAW,EACX,KAAK,EACL,WAAW,EACX,IAAI,EACJ,SAAS,EACT,QAAQ,EACR,aAAa,EACb,OAAO,EACP,aAAa,GAAG,OAAO,EACvB,YAAY,GAAG,MAAM,EACrB,IAAI,GAAG,SAAS,EAChB,OAAO,GAAG,SAAS,EACnB,WAAW,GAAG,SAAS,EACvB,SAAS,EACT,GAAG,EACH,GAAG,SAAS,EACG,EAAE,EAAE;IACnB,2GAA2G;IAC3G,MAAM,QAAQ,GAAG,MAAM,CAAiB,IAAI,CAAC,CAAA;IAC7C,eAAe,CAAC,GAAG,EAAE,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,aAAa,CAAC,QAAQ,CAAC,OAAO,EAAE,0BAA0B,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,EAAE,EAAE,CAAC,CAAA;IACvH,MAAM,UAAU,GAAG,KAAK,EAAE,KAAK,IAAI,CAAC,CAAA;IACpC,MAAM,cAAc,GAClB,UAAU,KAAK,CAAC;QACd,CAAC,CAAC,CAAC,CAAC,YAA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,KAAK,OAAO,IAAI,OAAO,EACpC,KAAK,CAAC,KAAK,IAAI,eAAM,SAAS,EAAE,CAAC,CAAC,UAAU,YAAG,KAAK,CAAC,KAAK,GAAQ,IAC/D,CACP,CAAC,CAAC,CAAC,IAAI,CAAA;IAER,MAAM,aAAa,GAAG,WAAW,CAAC,CAAC,CAAC,cAAK,SAAS,EAAE,CAAC,CAAC,WAAW,YAAG,WAAW,GAAO,CAAC,CAAC,CAAC,IAAI,CAAA;IAE7F,MAAM,UAAU,GAAG,CAAC,aAAa,KAAK,SAAS,IAAI,aAAa,CAAC,CAAC,CAAC,CAAC,CAClE,eAAK,SAAS,EAAE,CAAC,CAAC,QAAQ,aACxB,cAAK,SAAS,EAAE,CAAC,CAAC,aAAa,YAC7B,cACE,SAAS,EAAE,CAAC,CAAC,WAAW,EACxB,KAAK,EAAE,EAAE,KAAK,EAAE,GAAG,aAAa,IAAI,CAAC,GAAG,EAAE,wBAE1C,GACE,EACL,aAAa,IAAI,cAAK,SAAS,EAAE,CAAC,CAAC,aAAa,YAAG,aAAa,GAAO,IACpE,CACP,CAAC,CAAC,CAAC,IAAI,CAAA;IAER,MAAM,WAAW,GAAG,SAAS,CAAC,CAAC,CAAC,cAAK,SAAS,EAAE,CAAC,CAAC,SAAS,YAAG,SAAS,GAAO,CAAC,CAAC,CAAC,IAAI,CAAA;IAErF,OAAO,CACL,eACE,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC,SAAS,EAAE,SAAS,CAAC,kBACzB,OAAO,eACV,IAAI,uBACI,WAAW,KAC1B,SAAS,aAEZ,QAAQ,EACR,UAAU,EACV,UAAU,EACV,aAAa,EACb,UAAU,EACV,WAAW,IACR,CACP,CAAA;AACH,CAAC,CAAA","sourcesContent":["\"use client\"\n\nimport clsx from \"clsx\"\nimport { type ReactNode, type Ref, useLayoutEffect, useRef } from \"react\"\nimport { Badge } from \"../Badge\"\nimport { InfoCircle, Trending } from \"../Icon\"\nimport { Tooltip } from \"../Tooltip\"\nimport { fitValueScale } from \"../../lib/fitValueScale\"\nimport s from \"@plexui/styles/components/StatsCard/StatsCard.module.css\"\n\nexport type StatsCardProps = {\n /** Label describing the metric */\n label: string\n /** The primary metric value (e.g. \"1,234\" or \"$50K\") */\n value: ReactNode\n /** Optional description or subtitle below the value */\n description?: string\n /** Trend indicator with percentage change */\n trend?: {\n /** The percentage change value (e.g. 12.5 for +12.5%) */\n value: number\n /** Optional label for the trend (e.g. \"vs last month\") */\n label?: string\n }\n /** When true, a positive trend is bad (red) and negative is good (green). Use for metrics like \"Error Rate\" or \"Avg Completion Time\". */\n invertTrend?: boolean\n /** Icon in a small tile with a soft background, at the end of the header */\n icon?: ReactNode\n /** Optional ReactNode for a sparkline/chart rendered at the bottom */\n sparkline?: ReactNode\n /** Progress value from 0 to 100. Shows a progress bar at the bottom. */\n progress?: number\n /** Label displayed after the progress bar */\n progressLabel?: string\n /** Tooltip text — renders an (i) icon next to the label with a tooltip on hover */\n tooltip?: string\n /**\n * Where the trend indicator is positioned\n * - `\"value\"` — under the value, with its label (default)\n * - `\"header\"` — right-aligned in the header row, its label under the value\n * @default \"value\"\n */\n trendPosition?: \"value\" | \"header\"\n /**\n * Visual style of the trend indicator\n * - `\"text\"` — plain colored text (default)\n * - `\"badge\"` — wrapped in a Badge component\n * @default \"text\"\n */\n trendVariant?: \"text\" | \"badge\"\n /**\n * Size of the card\n * - `\"default\"` — standard dashboard card\n * - `\"sm\"` — compact card for dense layouts\n * @default \"default\"\n */\n size?: \"default\" | \"sm\"\n /**\n * Visual variant of the card\n * @default \"default\"\n */\n variant?: \"default\" | \"accent\"\n /**\n * Color of the accent variant's bar\n * @default \"primary\"\n */\n accentColor?: \"primary\" | \"secondary\" | \"info\" | \"success\" | \"warning\" | \"danger\" | \"discovery\" | \"caution\"\n /** Class applied to the card container */\n className?: string\n /** Ref applied to the card container */\n ref?: Ref<HTMLDivElement>\n}\n\nexport const StatsCard = ({\n label,\n value,\n description,\n trend,\n invertTrend,\n icon,\n sparkline,\n progress,\n progressLabel,\n tooltip,\n trendPosition = \"value\",\n trendVariant = \"text\",\n size = \"default\",\n variant = \"default\",\n accentColor = \"primary\",\n className,\n ref,\n ...restProps\n}: StatsCardProps) => {\n // A value wider than the card (two cards a row on a phone) scales down to fit, as iOS's minimumScaleFactor\n const valueRef = useRef<HTMLDivElement>(null)\n useLayoutEffect(() => (valueRef.current ? fitValueScale(valueRef.current, \"--stats-card-value-scale\") : undefined), [])\n const trendValue = trend?.value ?? 0\n const trendClassName =\n trendValue === 0\n ? s.TrendNeutral\n : trendValue > 0\n ? invertTrend\n ? s.TrendNegative\n : s.TrendPositive\n : invertTrend\n ? s.TrendPositive\n : s.TrendNegative\n\n const trendText = `${trendValue > 0 ? \"+\" : \"\"}${trendValue}%`\n const progressValue =\n progress === undefined ? undefined : Math.min(100, Math.max(0, progress))\n\n const trendBadgeColor =\n trendValue === 0\n ? \"secondary\"\n : trendValue > 0\n ? invertTrend\n ? \"danger\"\n : \"success\"\n : invertTrend\n ? \"success\"\n : \"danger\"\n\n // A trend line points the way the value moved, whichever colour that is (shadcn's metric cards draw lucide's\n // trending-up and trending-down); a fall is the rise mirrored\n const trendContent = (\n <>\n {trendValue !== 0 && <Trending className={trendValue < 0 ? s.TrendDown : undefined} />}\n {trendText}\n </>\n )\n\n const trendEl = trend != null && (\n trendVariant === \"badge\" ? (\n <Badge size=\"sm\" color={trendBadgeColor as \"secondary\" | \"success\" | \"danger\"}>\n {trendContent}\n </Badge>\n ) : (\n <div className={clsx(s.Trend, trendClassName)}>\n {trendContent}\n </div>\n )\n )\n\n // The icon's tile stands at the end of the header, as the trend may (shadcn's metric card with an icon)\n const iconEl = icon ? <div className={s.IconWrapper}>{icon}</div> : null\n const headerTrendEl = trendPosition === \"header\" ? trendEl : null\n\n const headerEl = (\n <div className={s.Header}>\n <div className={s.LabelRow}>\n <div className={s.Label}>{label}</div>\n {tooltip && (\n <Tooltip content={tooltip}>\n {/* Focusable and named so keyboard and screen-reader users reach the tooltip */}\n <span className={s.InfoIcon} tabIndex={0} role=\"img\" aria-label=\"More information\">\n <InfoCircle />\n </span>\n </Tooltip>\n )}\n </div>\n {(headerTrendEl || iconEl) && (\n <div className={s.HeaderEnd}>\n {headerTrendEl}\n {iconEl}\n </div>\n )}\n </div>\n )\n\n const valueRowEl = (\n <div className={s.ValueRow}>\n <div ref={valueRef} className={s.Value}>{value}</div>\n </div>\n )\n\n // Under the value, a trend and what it compares with, on one line (shadcn's metric card with a trend); a trend in\n // the header leaves its label there\n const trendRowEl = trend != null && (trendPosition === \"value\" || trend.label) ? (\n <div className={s.TrendRow}>\n {trendPosition === \"value\" && trendEl}\n {trend.label && <span className={s.TrendLabel}>{trend.label}</span>}\n </div>\n ) : null\n\n const descriptionEl = description ? <div className={s.Description}>{description}</div> : null\n\n const progressEl = (progressValue !== undefined || progressLabel) ? (\n <div className={s.Progress}>\n <div className={s.ProgressTrack}>\n <div\n className={s.ProgressBar}\n style={{ width: `${progressValue ?? 0}%` }}\n aria-hidden\n />\n </div>\n {progressLabel && <div className={s.ProgressLabel}>{progressLabel}</div>}\n </div>\n ) : null\n\n const sparklineEl = sparkline ? <div className={s.Sparkline}>{sparkline}</div> : null\n\n return (\n <div\n ref={ref}\n className={clsx(s.StatsCard, className)}\n data-variant={variant}\n data-size={size}\n data-accent-color={accentColor}\n {...restProps}\n >\n {headerEl}\n {valueRowEl}\n {trendRowEl}\n {descriptionEl}\n {progressEl}\n {sparklineEl}\n </div>\n )\n}\n"]}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scales a one-line value down until it fits the width of its parent, as iOS's `minimumScaleFactor` does: writes
|
|
3
|
+
* `property` on the value as a factor from `min` to 1 (removed at 1), for its CSS to multiply its font size by. It is
|
|
4
|
+
* measured again when the parent or the value resizes, the value's text changes, or the fonts load. Under `min` the
|
|
5
|
+
* value's own CSS cuts it (an ellipsis). Returns the cleanup.
|
|
6
|
+
*/
|
|
7
|
+
export function fitValueScale(value, property, min = 0.5) {
|
|
8
|
+
let frame = 0;
|
|
9
|
+
const measure = () => {
|
|
10
|
+
frame = 0;
|
|
11
|
+
const row = value.parentElement;
|
|
12
|
+
if (!row)
|
|
13
|
+
return;
|
|
14
|
+
const current = value.style.getPropertyValue(property);
|
|
15
|
+
// The width the text takes at full size, measured at full size: a width read at a scaled size comes in whole
|
|
16
|
+
// pixels, and a factor from it can step back and forth with each resize it causes
|
|
17
|
+
value.style.removeProperty(property);
|
|
18
|
+
const natural = value.scrollWidth;
|
|
19
|
+
const available = row.clientWidth;
|
|
20
|
+
if (!natural || !available) {
|
|
21
|
+
if (current)
|
|
22
|
+
value.style.setProperty(property, current);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
// Two decimals, rounded down (1e-9 keeps a float like 98.99999 on its step)
|
|
26
|
+
const next = Math.max(min, Math.min(1, Math.floor((available / natural) * 100 + 1e-9) / 100));
|
|
27
|
+
if (next < 1)
|
|
28
|
+
value.style.setProperty(property, String(next));
|
|
29
|
+
};
|
|
30
|
+
const schedule = () => {
|
|
31
|
+
if (!frame)
|
|
32
|
+
frame = requestAnimationFrame(measure);
|
|
33
|
+
};
|
|
34
|
+
measure();
|
|
35
|
+
const resize = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(schedule);
|
|
36
|
+
if (value.parentElement)
|
|
37
|
+
resize?.observe(value.parentElement);
|
|
38
|
+
resize?.observe(value);
|
|
39
|
+
const mutation = typeof MutationObserver === "undefined" ? null : new MutationObserver(schedule);
|
|
40
|
+
mutation?.observe(value, { childList: true, characterData: true, subtree: true });
|
|
41
|
+
let live = true;
|
|
42
|
+
document.fonts?.ready.then(() => {
|
|
43
|
+
if (live)
|
|
44
|
+
schedule();
|
|
45
|
+
});
|
|
46
|
+
return () => {
|
|
47
|
+
live = false;
|
|
48
|
+
if (frame)
|
|
49
|
+
cancelAnimationFrame(frame);
|
|
50
|
+
resize?.disconnect();
|
|
51
|
+
mutation?.disconnect();
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=fitValueScale.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fitValueScale.js","sourceRoot":"","sources":["../../../src/lib/fitValueScale.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,KAAkB,EAAE,QAAgB,EAAE,GAAG,GAAG,GAAG;IAC3E,IAAI,KAAK,GAAG,CAAC,CAAA;IACb,MAAM,OAAO,GAAG,GAAG,EAAE;QACnB,KAAK,GAAG,CAAC,CAAA;QACT,MAAM,GAAG,GAAG,KAAK,CAAC,aAAa,CAAA;QAC/B,IAAI,CAAC,GAAG;YAAE,OAAM;QAChB,MAAM,OAAO,GAAG,KAAK,CAAC,KAAK,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAA;QACtD,6GAA6G;QAC7G,kFAAkF;QAClF,KAAK,CAAC,KAAK,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAA;QACpC,MAAM,OAAO,GAAG,KAAK,CAAC,WAAW,CAAA;QACjC,MAAM,SAAS,GAAG,GAAG,CAAC,WAAW,CAAA;QACjC,IAAI,CAAC,OAAO,IAAI,CAAC,SAAS,EAAE,CAAC;YAC3B,IAAI,OAAO;gBAAE,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;YACvD,OAAM;QACR,CAAC;QACD,4EAA4E;QAC5E,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,SAAS,GAAG,OAAO,CAAC,GAAG,GAAG,GAAG,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,CAAA;QAC7F,IAAI,IAAI,GAAG,CAAC;YAAE,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,QAAQ,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAA;IAC/D,CAAC,CAAA;IACD,MAAM,QAAQ,GAAG,GAAG,EAAE;QACpB,IAAI,CAAC,KAAK;YAAE,KAAK,GAAG,qBAAqB,CAAC,OAAO,CAAC,CAAA;IACpD,CAAC,CAAA;IACD,OAAO,EAAE,CAAA;IACT,MAAM,MAAM,GAAG,OAAO,cAAc,KAAK,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,cAAc,CAAC,QAAQ,CAAC,CAAA;IAC1F,IAAI,KAAK,CAAC,aAAa;QAAE,MAAM,EAAE,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,CAAA;IAC7D,MAAM,EAAE,OAAO,CAAC,KAAK,CAAC,CAAA;IACtB,MAAM,QAAQ,GAAG,OAAO,gBAAgB,KAAK,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,gBAAgB,CAAC,QAAQ,CAAC,CAAA;IAChG,QAAQ,EAAE,OAAO,CAAC,KAAK,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAA;IACjF,IAAI,IAAI,GAAG,IAAI,CAAA;IACf,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE;QAC9B,IAAI,IAAI;YAAE,QAAQ,EAAE,CAAA;IACtB,CAAC,CAAC,CAAA;IACF,OAAO,GAAG,EAAE;QACV,IAAI,GAAG,KAAK,CAAA;QACZ,IAAI,KAAK;YAAE,oBAAoB,CAAC,KAAK,CAAC,CAAA;QACtC,MAAM,EAAE,UAAU,EAAE,CAAA;QACpB,QAAQ,EAAE,UAAU,EAAE,CAAA;IACxB,CAAC,CAAA;AACH,CAAC","sourcesContent":["/**\n * Scales a one-line value down until it fits the width of its parent, as iOS's `minimumScaleFactor` does: writes\n * `property` on the value as a factor from `min` to 1 (removed at 1), for its CSS to multiply its font size by. It is\n * measured again when the parent or the value resizes, the value's text changes, or the fonts load. Under `min` the\n * value's own CSS cuts it (an ellipsis). Returns the cleanup.\n */\nexport function fitValueScale(value: HTMLElement, property: string, min = 0.5): () => void {\n let frame = 0\n const measure = () => {\n frame = 0\n const row = value.parentElement\n if (!row) return\n const current = value.style.getPropertyValue(property)\n // The width the text takes at full size, measured at full size: a width read at a scaled size comes in whole\n // pixels, and a factor from it can step back and forth with each resize it causes\n value.style.removeProperty(property)\n const natural = value.scrollWidth\n const available = row.clientWidth\n if (!natural || !available) {\n if (current) value.style.setProperty(property, current)\n return\n }\n // Two decimals, rounded down (1e-9 keeps a float like 98.99999 on its step)\n const next = Math.max(min, Math.min(1, Math.floor((available / natural) * 100 + 1e-9) / 100))\n if (next < 1) value.style.setProperty(property, String(next))\n }\n const schedule = () => {\n if (!frame) frame = requestAnimationFrame(measure)\n }\n measure()\n const resize = typeof ResizeObserver === \"undefined\" ? null : new ResizeObserver(schedule)\n if (value.parentElement) resize?.observe(value.parentElement)\n resize?.observe(value)\n const mutation = typeof MutationObserver === \"undefined\" ? null : new MutationObserver(schedule)\n mutation?.observe(value, { childList: true, characterData: true, subtree: true })\n let live = true\n document.fonts?.ready.then(() => {\n if (live) schedule()\n })\n return () => {\n live = false\n if (frame) cancelAnimationFrame(frame)\n resize?.disconnect()\n mutation?.disconnect()\n }\n}\n"]}
|
|
@@ -5,8 +5,19 @@ export type NavigationRowProps = Omit<ButtonHTMLAttributes<HTMLButtonElement | H
|
|
|
5
5
|
label: ReactNode;
|
|
6
6
|
/** The current value, at the end of the row in the secondary label. `0` shows; `null`, `undefined` and `""` do not. */
|
|
7
7
|
value?: ReactNode;
|
|
8
|
-
/** A line under the label; the row grows from 52 to hold it */
|
|
8
|
+
/** A line under the label; the row grows from 52 to hold it. A `<br />` starts a second line. */
|
|
9
9
|
description?: ReactNode;
|
|
10
|
+
/**
|
|
11
|
+
* What leads the row, such as an `Avatar` or a symbol, in a column before the label (`--navigation-row-leading-size`,
|
|
12
|
+
* its own size), on the label's first line: a shorter text is centred beside it, a longer one starts level with it.
|
|
13
|
+
* The line above the row starts after it, where the text starts (iOS Find My's People list).
|
|
14
|
+
*/
|
|
15
|
+
leading?: ReactNode;
|
|
16
|
+
/**
|
|
17
|
+
* The chevron at the end. `false` drops it, for a row that opens a record rather than a page of choices (as the
|
|
18
|
+
* Contacts list of iOS); the row is still one press. @default true
|
|
19
|
+
*/
|
|
20
|
+
disclosure?: boolean;
|
|
10
21
|
/** Where the row goes. With it the row is a link (through `PlexUIProvider`'s `linkComponent`, or `as`). */
|
|
11
22
|
href?: string;
|
|
12
23
|
/** Force external-link behavior for `href` */
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type ComponentProps } from "react";
|
|
2
2
|
import { Progress as RadixProgress } from "radix-ui";
|
|
3
|
+
export type ProgressSize = "sm" | "md" | "lg";
|
|
3
4
|
export type ProgressColor = "primary" | "secondary" | "success" | "warning" | "caution" | "danger" | "info" | "discovery";
|
|
4
5
|
/** A part of a segmented bar: its share of `max`, its color, and the name it is read with. */
|
|
5
6
|
export type ProgressSegment = {
|
|
@@ -25,6 +26,17 @@ export type ProgressProps = Omit<ComponentProps<typeof RadixProgress.Root>, "chi
|
|
|
25
26
|
* take `value`'s place. A part's share is clamped so the bar never passes `max`.
|
|
26
27
|
*/
|
|
27
28
|
segments?: ProgressSegment[];
|
|
29
|
+
/**
|
|
30
|
+
* The bar's thickness: `sm` 4px (iOS's progress view), `md` 6px, `lg` 8px (a bar in a stats card, as Apple Fitness).
|
|
31
|
+
* @default "sm"
|
|
32
|
+
*/
|
|
33
|
+
size?: ProgressSize;
|
|
34
|
+
/**
|
|
35
|
+
* The color of the filled part, such as `secondary` (grey) for a second series beside a `primary` one. A segmented
|
|
36
|
+
* bar's parts take their own colors.
|
|
37
|
+
* @default "primary"
|
|
38
|
+
*/
|
|
39
|
+
color?: ProgressColor;
|
|
28
40
|
className?: string;
|
|
29
41
|
};
|
|
30
42
|
/** The parts of a segmented bar, each clamped so their sum stays within `max`, and their sum. */
|
|
@@ -38,4 +50,4 @@ export declare const progressSegments: (segments: ProgressSegment[], max: number
|
|
|
38
50
|
}[];
|
|
39
51
|
total: number;
|
|
40
52
|
};
|
|
41
|
-
export declare const Progress: ({ value, max, segments, className, ...restProps }: ProgressProps) => import("react/jsx-runtime").JSX.Element;
|
|
53
|
+
export declare const Progress: ({ value, max, segments, size, color, className, ...restProps }: ProgressProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { Progress, progressSegments, type ProgressColor, type ProgressProps, type ProgressSegment } from "./Progress.js";
|
|
1
|
+
export { Progress, progressSegments, type ProgressColor, type ProgressProps, type ProgressSegment, type ProgressSize } from "./Progress.js";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scales a one-line value down until it fits the width of its parent, as iOS's `minimumScaleFactor` does: writes
|
|
3
|
+
* `property` on the value as a factor from `min` to 1 (removed at 1), for its CSS to multiply its font size by. It is
|
|
4
|
+
* measured again when the parent or the value resizes, the value's text changes, or the fonts load. Under `min` the
|
|
5
|
+
* value's own CSS cuts it (an ellipsis). Returns the cleanup.
|
|
6
|
+
*/
|
|
7
|
+
export declare function fitValueScale(value: HTMLElement, property: string, min?: number): () => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plexui/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.60.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.16.
|
|
102
|
+
"@plexui/styles": "^0.16.4",
|
|
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",
|