@plexui/vue 0.39.5 → 0.40.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 +16 -3
- package/dist/es/components/NavigationRow/NavigationRow.js.map +1 -1
- package/dist/es/components/Progress/Progress.js +19 -5
- 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 +11 -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 +21 -3
- package/dist/types/components/Progress/Progress.d.ts +37 -0
- package/dist/types/components/Progress/index.d.ts +1 -1
- package/dist/types/components/Sidebar/Sidebar.d.ts +1 -1
- package/dist/types/lib/fitValueScale.d.ts +7 -0
- package/package.json +2 -2
|
@@ -2,6 +2,7 @@ import { defineComponent, h, nextTick, onBeforeUnmount, onMounted, onUpdated, re
|
|
|
2
2
|
import { Button, ButtonLink } from "../Button/index.js";
|
|
3
3
|
import { Disclosure } from "../Icon/index.js";
|
|
4
4
|
import { useFieldColumns } from "../../lib/fieldRow.js";
|
|
5
|
+
import { hasContent } from "../../lib/slotContent.js";
|
|
5
6
|
import s from "@plexui/styles/components/NavigationRow/NavigationRow.module.css";
|
|
6
7
|
const shown = (value) => value !== null && value !== undefined && value !== false && value !== "";
|
|
7
8
|
/** Whether the label and the value of a row fit beside each other on one line: measured in the end layout, unwrapped */
|
|
@@ -21,7 +22,8 @@ const valueFitsBeside = (row) => {
|
|
|
21
22
|
/**
|
|
22
23
|
* Vue port of `NavigationRow` from packages/ui/src/components/NavigationRow/NavigationRow.tsx: a FieldGroup row
|
|
23
24
|
* that opens what it holds, as an iOS Settings drill-in. Attributes (id, class, ARIA, data, listeners) fall through
|
|
24
|
-
* to the pressable. The `label`, `value` and `description` slots take the place of their props
|
|
25
|
+
* to the pressable. The `label`, `value` and `description` slots take the place of their props; the `leading` slot
|
|
26
|
+
* (an `Avatar` or a picture) leads the row, as React's `leading`.
|
|
25
27
|
*/
|
|
26
28
|
const NavigationRowComponent = defineComponent({
|
|
27
29
|
name: "NavigationRow",
|
|
@@ -31,7 +33,7 @@ const NavigationRowComponent = defineComponent({
|
|
|
31
33
|
label: [String, Number],
|
|
32
34
|
/** The current value, at the end of the row in the secondary label. `0` shows; `null`, `undefined` and `""` do not. */
|
|
33
35
|
value: [String, Number],
|
|
34
|
-
/** A line under the label; the row grows from 52 to hold it */
|
|
36
|
+
/** A line under the label; the row grows from 52 to hold it. A `<br />` in the slot starts a second line. */
|
|
35
37
|
description: [String, Number],
|
|
36
38
|
/** Where the row goes. With it the row is a link (through `PlexUIProvider`'s `linkComponent`, or `as`). */
|
|
37
39
|
href: String,
|
|
@@ -48,6 +50,11 @@ const NavigationRowComponent = defineComponent({
|
|
|
48
50
|
* it fits beside the label on one line, otherwise below (as Calendar sets a long value).
|
|
49
51
|
*/
|
|
50
52
|
valuePlacement: { type: String, default: "end" },
|
|
53
|
+
/**
|
|
54
|
+
* The chevron at the end. `false` drops it, for a row that opens a record rather than a page of choices (as the
|
|
55
|
+
* Contacts list of iOS); the row is still one press.
|
|
56
|
+
*/
|
|
57
|
+
disclosure: { type: Boolean, default: true },
|
|
51
58
|
},
|
|
52
59
|
setup(props, { attrs, slots, expose }) {
|
|
53
60
|
const pressable = ref(null);
|
|
@@ -112,14 +119,18 @@ const NavigationRowComponent = defineComponent({
|
|
|
112
119
|
const description = slots.description ? slots.description() : props.description;
|
|
113
120
|
const hasValue = slots.value ? true : shown(props.value);
|
|
114
121
|
const hasDescription = slots.description ? true : shown(props.description);
|
|
122
|
+
// A slot that renders nothing (a v-if that is off) leaves no column, as React's empty `leading` does
|
|
123
|
+
const leading = slots.leading?.();
|
|
124
|
+
const hasLeading = hasContent(leading);
|
|
115
125
|
const below = hasValue && (props.valuePlacement === "below" || (props.valuePlacement === "auto" && !fits.value));
|
|
116
126
|
const content = () => h("span", { "class": s.Content, "data-navigation-row-content": "" }, [
|
|
127
|
+
hasLeading ? h("span", { class: s.Leading }, [leading]) : null,
|
|
117
128
|
h("span", { class: s.Text }, [
|
|
118
129
|
h("span", { "class": s.Label, "data-navigation-row-part": "" }, [label]),
|
|
119
130
|
hasDescription ? h("span", { class: s.Description }, [description]) : null,
|
|
120
131
|
]),
|
|
121
132
|
hasValue ? h("span", { "class": s.Value, "data-navigation-row-part": "" }, [value]) : null,
|
|
122
|
-
h(Disclosure, { "class": s.Disclosure, "aria-hidden": "true", "data-no-autosize": "" }),
|
|
133
|
+
props.disclosure ? h(Disclosure, { "class": s.Disclosure, "aria-hidden": "true", "data-no-autosize": "" }) : null,
|
|
123
134
|
]);
|
|
124
135
|
const { class: className, ...rest } = attrs;
|
|
125
136
|
const shared = {
|
|
@@ -137,6 +148,8 @@ const NavigationRowComponent = defineComponent({
|
|
|
137
148
|
"data-value-below": below ? "" : undefined,
|
|
138
149
|
"data-value": hasValue ? "" : undefined,
|
|
139
150
|
"data-description": hasDescription ? "" : undefined,
|
|
151
|
+
"data-leading": hasLeading ? "" : undefined,
|
|
152
|
+
"data-disclosure": props.disclosure ? undefined : "none",
|
|
140
153
|
}, [
|
|
141
154
|
link
|
|
142
155
|
? h(ButtonLink, { ...rest, ...shared, ref: pressable, href: props.href, to: props.to, external: props.external, as: props.as }, { default: content })
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NavigationRow.js","sourceRoot":"","sources":["../../../../src/components/NavigationRow/NavigationRow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsF,eAAe,EAAE,CAAC,EAAE,QAAQ,EAAE,eAAe,EAAE,SAAS,EAAE,SAAS,EAAiB,GAAG,EAAmB,KAAK,EAAE,MAAM,KAAK,CAAA;AACzN,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AACvD,OAAO,EAA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E,KAAK,CAAC,QAAQ,EAAE,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;aACtG,CACF,CAAA;QACH,CAAC,CAAA;IACH,CAAC;CACF,CAAC,CAAA;AAYF,MAAM,CAAC,MAAM,aAAa,GAAG,sBAE5B,CAAA","sourcesContent":["import { type AnchorHTMLAttributes, type ButtonHTMLAttributes, type ComponentPublicInstance, defineComponent, h, nextTick, onBeforeUnmount, onMounted, onUpdated, type PropType, ref, type VNodeChild, watch } from \"vue\"\nimport { Button, ButtonLink } from \"../Button/index.js\"\nimport { Disclosure } from \"../Icon/index.js\"\nimport { useFieldColumns } from \"../../lib/fieldRow.js\"\nimport type { LinkComponent } from \"../PlexUIProvider/index.js\"\nimport s from \"@plexui/styles/components/NavigationRow/NavigationRow.module.css\"\n\ntype RouteTarget = string | Record<string, unknown>\n\nconst shown = (value: unknown) => 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 * Vue port of `NavigationRow` from packages/ui/src/components/NavigationRow/NavigationRow.tsx: a FieldGroup row\n * that opens what it holds, as an iOS Settings drill-in. Attributes (id, class, ARIA, data, listeners) fall through\n * to the pressable. The `label`, `value` and `description` slots take the place of their props.\n */\nconst NavigationRowComponent = defineComponent({\n name: \"NavigationRow\",\n inheritAttrs: false,\n props: {\n /** The row's name, where a row's label starts */\n label: [String, Number] as PropType<string | number>,\n /** The current value, at the end of the row in the secondary label. `0` shows; `null`, `undefined` and `\"\"` do not. */\n value: [String, Number] as PropType<string | number | null>,\n /** A line under the label; the row grows from 52 to hold it */\n description: [String, Number] as PropType<string | number>,\n /** Where the row goes. With it the row is a link (through `PlexUIProvider`'s `linkComponent`, or `as`). */\n href: String,\n /** A router target; with it the row is a link through the provider's link component */\n to: [String, Object] as PropType<RouteTarget>,\n /** Force external-link behavior */\n external: { type: Boolean, default: undefined },\n /** Link component override (e.g. a router link). */\n as: [String, Object, Function] as PropType<LinkComponent>,\n /** The row can't be pressed. A disabled link renders as a disabled button, so it never navigates. */\n disabled: { type: Boolean, default: undefined },\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).\n */\n valuePlacement: { type: String as PropType<\"end\" | \"below\" | \"auto\">, default: \"end\" },\n },\n setup(props, { attrs, slots, expose }) {\n const pressable = ref<ComponentPublicInstance | null>(null)\n const element = () => (pressable.value?.$el ?? null) as HTMLElement | null\n // A ref reaches the pressable, as in React: its element and focus()\n expose({ focus: (options?: FocusOptions) => element()?.focus(options), get element() { return element() } })\n\n // \"auto\": measure after each render and when the row's width changes\n const row = ref<HTMLElement | null>(null)\n const fits = ref(true)\n const hasValueNow = () => !!slots.value || shown(props.value)\n const check = () => {\n if (props.valuePlacement !== \"auto\" || !hasValueNow() || !row.value) return\n const next = valueFitsBeside(row.value)\n if (next !== fits.value) fits.value = next\n }\n let observer: ResizeObserver | undefined\n let width = -1\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 let live = true\n const onFonts = () => {\n if (live) check()\n }\n onMounted(() => {\n fonts?.addEventListener?.(\"loadingdone\", onFonts)\n if (typeof ResizeObserver === \"undefined\" || !row.value) {\n check()\n fonts?.ready.then(onFonts)\n return\n }\n // The first measure waits for the observer's first report, after the frame's layout and before its paint: a\n // measure on mount forced a layout for every row while a sheet of rows was being built. Fonts that finish\n // loading after that report measure again; before it, the report itself measures with them.\n fonts?.ready.then(() => {\n if (width !== -1) onFonts()\n })\n observer = new ResizeObserver((entries?: ResizeObserverEntry[]) => {\n const next = entries?.[entries.length - 1]?.contentRect.width ?? row.value?.getBoundingClientRect().width ?? width\n if (next === width) return\n width = next\n check()\n })\n observer.observe(row.value)\n })\n onUpdated(check)\n // FieldGroup columns give the label a column of its own: a change of them measures again, after the group renders\n const columns = useFieldColumns()\n watch(columns, () => nextTick(check), { flush: \"post\" })\n onBeforeUnmount(() => {\n live = false\n fonts?.removeEventListener?.(\"loadingdone\", onFonts)\n observer?.disconnect()\n })\n\n return () => {\n const label: VNodeChild = slots.label ? slots.label() : props.label\n const value: VNodeChild = slots.value ? slots.value() : shown(props.value) ? props.value : undefined\n const description: VNodeChild = slots.description ? slots.description() : props.description\n const hasValue = slots.value ? true : shown(props.value)\n const hasDescription = slots.description ? true : shown(props.description)\n const below = hasValue && (props.valuePlacement === \"below\" || (props.valuePlacement === \"auto\" && !fits.value))\n\n const content = () =>\n h(\"span\", { \"class\": s.Content, \"data-navigation-row-content\": \"\" }, [\n h(\"span\", { class: s.Text }, [\n h(\"span\", { \"class\": s.Label, \"data-navigation-row-part\": \"\" }, [label as never]),\n hasDescription ? h(\"span\", { class: s.Description }, [description as never]) : null,\n ]),\n hasValue ? h(\"span\", { \"class\": s.Value, \"data-navigation-row-part\": \"\" }, [value as never]) : null,\n h(Disclosure, { \"class\": s.Disclosure, \"aria-hidden\": \"true\", \"data-no-autosize\": \"\" }),\n ])\n\n const { class: className, ...rest } = attrs\n const shared = {\n \"class\": [s.Pressable, className],\n \"block\": true,\n \"color\": \"secondary\",\n \"variant\": \"ghost\",\n \"data-navigation-row\": \"\",\n } as const\n const link = (props.href !== undefined || props.to !== undefined) && !props.disabled\n\n return h(\n \"div\",\n {\n \"ref\": row,\n \"class\": s.NavigationRow,\n \"data-row\": \"\",\n \"data-value-below\": below ? \"\" : undefined,\n \"data-value\": hasValue ? \"\" : undefined,\n \"data-description\": hasDescription ? \"\" : undefined,\n },\n [\n link\n ? h(\n ButtonLink,\n { ...rest, ...shared, ref: pressable, href: props.href, to: props.to, external: props.external, as: props.as },\n { default: content },\n )\n : h(Button, { ...rest, ...shared, ref: pressable, disabled: props.disabled }, { default: content }),\n ],\n )\n }\n },\n})\n\ntype NavigationRowOwnProps = InstanceType<typeof NavigationRowComponent>[\"$props\"]\n\n/** NavigationRow props plus the native button and link attributes and the click listener that fall through to the\n * pressable, as in React. */\nexport type NavigationRowProps = NavigationRowOwnProps &\n Omit<ButtonHTMLAttributes, keyof NavigationRowOwnProps | \"value\" | \"type\"> &\n Pick<AnchorHTMLAttributes, \"target\" | \"rel\" | \"download\" | \"hreflang\" | \"ping\" | \"referrerpolicy\"> & {\n onClick?: (event: MouseEvent) => void\n }\n\nexport const NavigationRow = NavigationRowComponent as typeof NavigationRowComponent & {\n new (): { $props: NavigationRowProps; focus: (options?: FocusOptions) => void; element: HTMLElement | null }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"NavigationRow.js","sourceRoot":"","sources":["../../../../src/components/NavigationRow/NavigationRow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsF,eAAe,EAAE,CAAC,EAAE,QAAQ,EAAE,eAAe,EAAE,SAAS,EAAE,SAAS,EAAiB,GAAG,EAAmB,KAAK,EAAE,MAAM,KAAK,CAAA;AACzN,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAEvD,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AACrD,OAAO,CAAC,MAAM,kEAAkE,CAAA;AAIhF,MAAM,KAAK,GAAG,CAAC,KAAc,EAAE,EAAE,CAAC,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,KAAK,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AAM,EAAE,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,EAAE,EAAE,KAAK,CAAC,EAAE,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,EAAE,EAAE,KAAK,CAAC,EAAE,EAAE,EAC9G,EAAE,OAAO,EAAE,OAAO,EAAE,CACrB;oBACH,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;aACtG,CACF,CAAA;QACH,CAAC,CAAA;IACH,CAAC;CACF,CAAC,CAAA;AAYF,MAAM,CAAC,MAAM,aAAa,GAAG,sBAE5B,CAAA","sourcesContent":["import { type AnchorHTMLAttributes, type ButtonHTMLAttributes, type ComponentPublicInstance, defineComponent, h, nextTick, onBeforeUnmount, onMounted, onUpdated, type PropType, ref, type VNodeChild, watch } from \"vue\"\nimport { Button, ButtonLink } from \"../Button/index.js\"\nimport { Disclosure } from \"../Icon/index.js\"\nimport { useFieldColumns } from \"../../lib/fieldRow.js\"\nimport type { LinkComponent } from \"../PlexUIProvider/index.js\"\nimport { hasContent } from \"../../lib/slotContent.js\"\nimport s from \"@plexui/styles/components/NavigationRow/NavigationRow.module.css\"\n\ntype RouteTarget = string | Record<string, unknown>\n\nconst shown = (value: unknown) => 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 * Vue port of `NavigationRow` from packages/ui/src/components/NavigationRow/NavigationRow.tsx: a FieldGroup row\n * that opens what it holds, as an iOS Settings drill-in. Attributes (id, class, ARIA, data, listeners) fall through\n * to the pressable. The `label`, `value` and `description` slots take the place of their props; the `leading` slot\n * (an `Avatar` or a picture) leads the row, as React's `leading`.\n */\nconst NavigationRowComponent = defineComponent({\n name: \"NavigationRow\",\n inheritAttrs: false,\n props: {\n /** The row's name, where a row's label starts */\n label: [String, Number] as PropType<string | number>,\n /** The current value, at the end of the row in the secondary label. `0` shows; `null`, `undefined` and `\"\"` do not. */\n value: [String, Number] as PropType<string | number | null>,\n /** A line under the label; the row grows from 52 to hold it. A `<br />` in the slot starts a second line. */\n description: [String, Number] as PropType<string | number>,\n /** Where the row goes. With it the row is a link (through `PlexUIProvider`'s `linkComponent`, or `as`). */\n href: String,\n /** A router target; with it the row is a link through the provider's link component */\n to: [String, Object] as PropType<RouteTarget>,\n /** Force external-link behavior */\n external: { type: Boolean, default: undefined },\n /** Link component override (e.g. a router link). */\n as: [String, Object, Function] as PropType<LinkComponent>,\n /** The row can't be pressed. A disabled link renders as a disabled button, so it never navigates. */\n disabled: { type: Boolean, default: undefined },\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).\n */\n valuePlacement: { type: String as PropType<\"end\" | \"below\" | \"auto\">, default: \"end\" },\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.\n */\n disclosure: { type: Boolean, default: true },\n },\n setup(props, { attrs, slots, expose }) {\n const pressable = ref<ComponentPublicInstance | null>(null)\n const element = () => (pressable.value?.$el ?? null) as HTMLElement | null\n // A ref reaches the pressable, as in React: its element and focus()\n expose({ focus: (options?: FocusOptions) => element()?.focus(options), get element() { return element() } })\n\n // \"auto\": measure after each render and when the row's width changes\n const row = ref<HTMLElement | null>(null)\n const fits = ref(true)\n const hasValueNow = () => !!slots.value || shown(props.value)\n const check = () => {\n if (props.valuePlacement !== \"auto\" || !hasValueNow() || !row.value) return\n const next = valueFitsBeside(row.value)\n if (next !== fits.value) fits.value = next\n }\n let observer: ResizeObserver | undefined\n let width = -1\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 let live = true\n const onFonts = () => {\n if (live) check()\n }\n onMounted(() => {\n fonts?.addEventListener?.(\"loadingdone\", onFonts)\n if (typeof ResizeObserver === \"undefined\" || !row.value) {\n check()\n fonts?.ready.then(onFonts)\n return\n }\n // The first measure waits for the observer's first report, after the frame's layout and before its paint: a\n // measure on mount forced a layout for every row while a sheet of rows was being built. Fonts that finish\n // loading after that report measure again; before it, the report itself measures with them.\n fonts?.ready.then(() => {\n if (width !== -1) onFonts()\n })\n observer = new ResizeObserver((entries?: ResizeObserverEntry[]) => {\n const next = entries?.[entries.length - 1]?.contentRect.width ?? row.value?.getBoundingClientRect().width ?? width\n if (next === width) return\n width = next\n check()\n })\n observer.observe(row.value)\n })\n onUpdated(check)\n // FieldGroup columns give the label a column of its own: a change of them measures again, after the group renders\n const columns = useFieldColumns()\n watch(columns, () => nextTick(check), { flush: \"post\" })\n onBeforeUnmount(() => {\n live = false\n fonts?.removeEventListener?.(\"loadingdone\", onFonts)\n observer?.disconnect()\n })\n\n return () => {\n const label: VNodeChild = slots.label ? slots.label() : props.label\n const value: VNodeChild = slots.value ? slots.value() : shown(props.value) ? props.value : undefined\n const description: VNodeChild = slots.description ? slots.description() : props.description\n const hasValue = slots.value ? true : shown(props.value)\n const hasDescription = slots.description ? true : shown(props.description)\n // A slot that renders nothing (a v-if that is off) leaves no column, as React's empty `leading` does\n const leading = slots.leading?.()\n const hasLeading = hasContent(leading)\n const below = hasValue && (props.valuePlacement === \"below\" || (props.valuePlacement === \"auto\" && !fits.value))\n\n const content = () =>\n h(\"span\", { \"class\": s.Content, \"data-navigation-row-content\": \"\" }, [\n hasLeading ? h(\"span\", { class: s.Leading }, [leading as never]) : null,\n h(\"span\", { class: s.Text }, [\n h(\"span\", { \"class\": s.Label, \"data-navigation-row-part\": \"\" }, [label as never]),\n hasDescription ? h(\"span\", { class: s.Description }, [description as never]) : null,\n ]),\n hasValue ? h(\"span\", { \"class\": s.Value, \"data-navigation-row-part\": \"\" }, [value as never]) : null,\n props.disclosure ? h(Disclosure, { \"class\": s.Disclosure, \"aria-hidden\": \"true\", \"data-no-autosize\": \"\" }) : null,\n ])\n\n const { class: className, ...rest } = attrs\n const shared = {\n \"class\": [s.Pressable, className],\n \"block\": true,\n \"color\": \"secondary\",\n \"variant\": \"ghost\",\n \"data-navigation-row\": \"\",\n } as const\n const link = (props.href !== undefined || props.to !== undefined) && !props.disabled\n\n return h(\n \"div\",\n {\n \"ref\": row,\n \"class\": 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\": props.disclosure ? undefined : \"none\",\n },\n [\n link\n ? h(\n ButtonLink,\n { ...rest, ...shared, ref: pressable, href: props.href, to: props.to, external: props.external, as: props.as },\n { default: content },\n )\n : h(Button, { ...rest, ...shared, ref: pressable, disabled: props.disabled }, { default: content }),\n ],\n )\n }\n },\n})\n\ntype NavigationRowOwnProps = InstanceType<typeof NavigationRowComponent>[\"$props\"]\n\n/** NavigationRow props plus the native button and link attributes and the click listener that fall through to the\n * pressable, as in React. */\nexport type NavigationRowProps = NavigationRowOwnProps &\n Omit<ButtonHTMLAttributes, keyof NavigationRowOwnProps | \"value\" | \"type\"> &\n Pick<AnchorHTMLAttributes, \"target\" | \"rel\" | \"download\" | \"hreflang\" | \"ping\" | \"referrerpolicy\"> & {\n onClick?: (event: MouseEvent) => void\n }\n\nexport const NavigationRow = NavigationRowComponent as typeof NavigationRowComponent & {\n new (): { $props: NavigationRowProps; focus: (options?: FocusOptions) => void; element: HTMLElement | null }\n}\n"]}
|
|
@@ -43,6 +43,17 @@ const ProgressComponent = defineComponent({
|
|
|
43
43
|
* take `value`'s place. A part's share is clamped so the bar never passes `max`.
|
|
44
44
|
*/
|
|
45
45
|
segments: { type: Array, default: undefined },
|
|
46
|
+
/**
|
|
47
|
+
* The bar's thickness: `sm` 4px (iOS's progress view), `md` 6px, `lg` 8px (a bar in a stats card, as Apple Fitness).
|
|
48
|
+
* @default "sm"
|
|
49
|
+
*/
|
|
50
|
+
size: { type: String, default: "sm" },
|
|
51
|
+
/**
|
|
52
|
+
* The color of the filled part, such as `secondary` (grey) for a second series beside a `primary` one. A segmented
|
|
53
|
+
* bar's parts take their own colors.
|
|
54
|
+
* @default "primary"
|
|
55
|
+
*/
|
|
56
|
+
color: { type: String, default: "primary" },
|
|
46
57
|
},
|
|
47
58
|
setup(props) {
|
|
48
59
|
const getValueText = (value, max) => isNumber(value) ? (props.getValueLabel ?? defaultGetValueLabel)(value, max) : undefined;
|
|
@@ -57,6 +68,7 @@ const ProgressComponent = defineComponent({
|
|
|
57
68
|
"getValueText": (current, currentMax) => props.getValueLabel && isNumber(current) ? props.getValueLabel(current, currentMax) : segmentsLabel(parts, rootMax),
|
|
58
69
|
"class": s.Root,
|
|
59
70
|
"data-segmented": "",
|
|
71
|
+
"data-size": props.size,
|
|
60
72
|
}, {
|
|
61
73
|
default: () => parts.map((part, index) => part.value > 0
|
|
62
74
|
? h("div", { "key": index, "class": s.Segment, "data-color": part.color ?? "primary", "style": { width: `${(part.value / rootMax) * 100}%` } })
|
|
@@ -70,11 +82,13 @@ const ProgressComponent = defineComponent({
|
|
|
70
82
|
const rootMax = isValidMax(max) ? max : DEFAULT_MAX;
|
|
71
83
|
const rootValue = isValidValue(resolved, rootMax) ? resolved : null;
|
|
72
84
|
return h(ProgressRoot, {
|
|
73
|
-
modelValue: rootValue,
|
|
74
|
-
max: rootMax,
|
|
75
|
-
getValueLabel: () => undefined,
|
|
76
|
-
getValueText,
|
|
77
|
-
class: s.Root,
|
|
85
|
+
"modelValue": rootValue,
|
|
86
|
+
"max": rootMax,
|
|
87
|
+
"getValueLabel": () => undefined,
|
|
88
|
+
"getValueText": getValueText,
|
|
89
|
+
"class": s.Root,
|
|
90
|
+
"data-size": props.size,
|
|
91
|
+
"data-color": props.color,
|
|
78
92
|
}, {
|
|
79
93
|
default: () => h(ProgressIndicator, {
|
|
80
94
|
"class": s.Indicator,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Progress.js","sourceRoot":"","sources":["../../../../src/components/Progress/Progress.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,CAAC,EAAsC,MAAM,KAAK,CAAA;AAC5E,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AACzD,OAAO,CAAC,MAAM,wDAAwD,CAAA;AAEtE,4EAA4E;AAC5E,6EAA6E;AAC7E,qBAAqB;AACrB,8EAA8E;AAC9E,6EAA6E;AAC7E,iEAAiE;AACjE,2EAA2E;AAC3E,2EAA2E;AAC3E,gFAAgF;AAEhF,MAAM,WAAW,GAAG,GAAG,CAAA;AAEvB,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAmB,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAA;AAC/E,MAAM,UAAU,GAAG,CAAC,GAAY,EAAiB,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,GAAG,GAAG,CAAC,CAAA;AAClG,MAAM,YAAY,GAAG,CAAC,KAAc,EAAE,GAAW,EAAmB,EAAE,CACpE,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,G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AC,IAAI;aACd,EACD;gBACE,OAAO,EAAE,GAAG,EAAE,CACZ,CAAC,CAAC,iBAAiB,EAAE;oBACnB,OAAO,EAAE,CAAC,CAAC,SAAS;oBACpB,OAAO,EAAE,UAAU,IAAI,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,eAAe,GAAG,GAAG,UAAU,IAAI,EAAE;oBAC5F,oBAAoB,EAAE,UAAU,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS;iBAC1D,CAAC;aACL,CACF,CAAA;QACH,CAAC,CAAA;IACH,CAAC;CACF,CAAC,CAAA;AAOF,MAAM,CAAC,MAAM,QAAQ,GAAG,iBAAqF,CAAA","sourcesContent":["import { defineComponent, h, type HTMLAttributes, type PropType } from \"vue\"\nimport { ProgressIndicator, ProgressRoot } from \"reka-ui\"\nimport s from \"@plexui/styles/components/Progress/Progress.module.css\"\n\n// Vue port of packages/ui/src/components/Progress/Progress.tsx on Reka UI's\n// Progress. Radix and Reka differ in three places, smoothed over here so the\n// DOM matches React:\n// - Radix announces the percentage as `aria-valuetext` (via `getValueLabel`),\n// Reka as `aria-label`. Reka's label is turned off and its value text set.\n// - Radix falls back to `max = 100` for an invalid max and to an\n// indeterminate value for an invalid value. Reka keeps them and asks the\n// parent to correct them, so the same fallbacks are applied before Reka.\n// - Caller attributes still win over Reka's, as `{...restProps}` does in React.\n\nconst DEFAULT_MAX = 100\n\nconst isNumber = (value: unknown): value is number => typeof value === \"number\"\nconst isValidMax = (max: unknown): max is number => isNumber(max) && !Number.isNaN(max) && max > 0\nconst isValidValue = (value: unknown, max: number): value is number =>\n isNumber(value) && !Number.isNaN(value) && value <= max && value >= 0\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\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\nconst defaultGetValueLabel = (value: number, max: number) => `${Math.round((value / max) * 100)}%`\n\nconst ProgressComponent = defineComponent({\n name: \"Progress\",\n props: {\n /**\n * Current progress value, between `0` and `max`.\n * Omit (or pass `null`) for an indeterminate state.\n */\n value: { type: Number as PropType<number | null>, default: null },\n /** Maximum value. @default 100 */\n max: { type: Number, default: DEFAULT_MAX },\n /** Accessible value text for the current value. @default \"<percentage>%\" */\n getValueLabel: Function as PropType<(value: number, max: number) => string>,\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: { type: Array as PropType<ProgressSegment[]>, default: undefined },\n },\n setup(props) {\n const getValueText = (value: number | null | undefined, max: number) =>\n isNumber(value) ? (props.getValueLabel ?? defaultGetValueLabel)(value, max) : undefined\n\n return () => {\n if (props.segments) {\n const rootMax = isValidMax(props.max) ? props.max : DEFAULT_MAX\n const { parts, total } = progressSegments(props.segments, rootMax)\n return h(\n ProgressRoot,\n {\n \"modelValue\": total,\n \"max\": rootMax,\n \"getValueLabel\": () => undefined,\n \"getValueText\": (current: number | null | undefined, currentMax: number) =>\n props.getValueLabel && isNumber(current) ? props.getValueLabel(current, currentMax) : segmentsLabel(parts, rootMax),\n \"class\": s.Root,\n \"data-segmented\": \"\",\n },\n {\n default: () => parts.map((part, index) =>\n part.value > 0\n ? h(\"div\", { \"key\": index, \"class\": s.Segment, \"data-color\": part.color ?? \"primary\", \"style\": { width: `${(part.value / rootMax) * 100}%` } })\n : null),\n },\n )\n }\n const { value, max } = props\n const resolved = value == null ? null : Math.max(0, Math.min(max, value))\n const percentage = resolved == null ? null : (resolved / max) * 100\n\n // What Radix renders for the props React hands it\n const rootMax = isValidMax(max) ? max : DEFAULT_MAX\n const rootValue = isValidValue(resolved, rootMax) ? resolved : null\n\n return h(\n ProgressRoot,\n {\n modelValue: rootValue,\n max: rootMax,\n getValueLabel: () => undefined,\n getValueText,\n class: s.Root,\n },\n {\n default: () =>\n h(ProgressIndicator, {\n \"class\": s.Indicator,\n \"style\": percentage == null ? undefined : { transform: `translateX(-${100 - percentage}%)` },\n \"data-indeterminate\": percentage == null ? \"\" : undefined,\n }),\n },\n )\n }\n },\n})\n\ntype ProgressOwnProps = InstanceType<typeof ProgressComponent>[\"$props\"]\n\n/** Progress props plus the native <div> attributes that fall through to the root, as in React. */\nexport type ProgressProps = ProgressOwnProps & Omit<HTMLAttributes, keyof ProgressOwnProps>\n\nexport const Progress = ProgressComponent as typeof ProgressComponent & { new (): { $props: ProgressProps } }\n"]}
|
|
1
|
+
{"version":3,"file":"Progress.js","sourceRoot":"","sources":["../../../../src/components/Progress/Progress.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,CAAC,EAAsC,MAAM,KAAK,CAAA;AAC5E,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AACzD,OAAO,CAAC,MAAM,wDAAwD,CAAA;AAEtE,4EAA4E;AAC5E,6EAA6E;AAC7E,qBAAqB;AACrB,8EAA8E;AAC9E,6EAA6E;AAC7E,iEAAiE;AACjE,2EAA2E;AAC3E,2EAA2E;AAC3E,gFAAgF;AAEhF,MAAM,WAAW,GAAG,GAAG,CAAA;AAEvB,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAmB,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAA;AAC/E,MA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,GAAG,QAAQ,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,GAAG,GAAG,CAAC,GAAG,GAAG,CAAA;YAEnE,kDAAkD;YAClD,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,WAAW,CAAA;YACnD,MAAM,SAAS,GAAG,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAA;YAEnE,OAAO,CAAC,CACN,YAAY,EACZ;gBACE,YAAY,EAAE,SAAS;gBACvB,KAAK,EAAE,OAAO;gBACd,eAAe,EAAE,GAAG,EAAE,CAAC,SAAS;gBAChC,cAAc,EAAE,YAAY;gBAC5B,OAAO,EAAE,CAAC,CAAC,IAAI;gBACf,WAAW,EAAE,KAAK,CAAC,IAAI;gBACvB,YAAY,EAAE,KAAK,CAAC,KAAK;aAC1B,EACD;gBACE,OAAO,EAAE,GAAG,EAAE,CACZ,CAAC,CAAC,iBAAiB,EAAE;oBACnB,OAAO,EAAE,CAAC,CAAC,SAAS;oBACpB,OAAO,EAAE,UAAU,IAAI,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,eAAe,GAAG,GAAG,UAAU,IAAI,EAAE;oBAC5F,oBAAoB,EAAE,UAAU,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS;iBAC1D,CAAC;aACL,CACF,CAAA;QACH,CAAC,CAAA;IACH,CAAC;CACF,CAAC,CAAA;AAOF,MAAM,CAAC,MAAM,QAAQ,GAAG,iBAAqF,CAAA","sourcesContent":["import { defineComponent, h, type HTMLAttributes, type PropType } from \"vue\"\nimport { ProgressIndicator, ProgressRoot } from \"reka-ui\"\nimport s from \"@plexui/styles/components/Progress/Progress.module.css\"\n\n// Vue port of packages/ui/src/components/Progress/Progress.tsx on Reka UI's\n// Progress. Radix and Reka differ in three places, smoothed over here so the\n// DOM matches React:\n// - Radix announces the percentage as `aria-valuetext` (via `getValueLabel`),\n// Reka as `aria-label`. Reka's label is turned off and its value text set.\n// - Radix falls back to `max = 100` for an invalid max and to an\n// indeterminate value for an invalid value. Reka keeps them and asks the\n// parent to correct them, so the same fallbacks are applied before Reka.\n// - Caller attributes still win over Reka's, as `{...restProps}` does in React.\n\nconst DEFAULT_MAX = 100\n\nconst isNumber = (value: unknown): value is number => typeof value === \"number\"\nconst isValidMax = (max: unknown): max is number => isNumber(max) && !Number.isNaN(max) && max > 0\nconst isValidValue = (value: unknown, max: number): value is number =>\n isNumber(value) && !Number.isNaN(value) && value <= max && value >= 0\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\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\nconst defaultGetValueLabel = (value: number, max: number) => `${Math.round((value / max) * 100)}%`\n\nconst ProgressComponent = defineComponent({\n name: \"Progress\",\n props: {\n /**\n * Current progress value, between `0` and `max`.\n * Omit (or pass `null`) for an indeterminate state.\n */\n value: { type: Number as PropType<number | null>, default: null },\n /** Maximum value. @default 100 */\n max: { type: Number, default: DEFAULT_MAX },\n /** Accessible value text for the current value. @default \"<percentage>%\" */\n getValueLabel: Function as PropType<(value: number, max: number) => string>,\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: { type: Array as PropType<ProgressSegment[]>, default: undefined },\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: { type: String as PropType<ProgressSize>, default: \"sm\" },\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: { type: String as PropType<ProgressColor>, default: \"primary\" },\n },\n setup(props) {\n const getValueText = (value: number | null | undefined, max: number) =>\n isNumber(value) ? (props.getValueLabel ?? defaultGetValueLabel)(value, max) : undefined\n\n return () => {\n if (props.segments) {\n const rootMax = isValidMax(props.max) ? props.max : DEFAULT_MAX\n const { parts, total } = progressSegments(props.segments, rootMax)\n return h(\n ProgressRoot,\n {\n \"modelValue\": total,\n \"max\": rootMax,\n \"getValueLabel\": () => undefined,\n \"getValueText\": (current: number | null | undefined, currentMax: number) =>\n props.getValueLabel && isNumber(current) ? props.getValueLabel(current, currentMax) : segmentsLabel(parts, rootMax),\n \"class\": s.Root,\n \"data-segmented\": \"\",\n \"data-size\": props.size,\n },\n {\n default: () => parts.map((part, index) =>\n part.value > 0\n ? h(\"div\", { \"key\": index, \"class\": s.Segment, \"data-color\": part.color ?? \"primary\", \"style\": { width: `${(part.value / rootMax) * 100}%` } })\n : null),\n },\n )\n }\n const { value, max } = props\n const resolved = value == null ? null : Math.max(0, Math.min(max, value))\n const percentage = resolved == null ? null : (resolved / max) * 100\n\n // What Radix renders for the props React hands it\n const rootMax = isValidMax(max) ? max : DEFAULT_MAX\n const rootValue = isValidValue(resolved, rootMax) ? resolved : null\n\n return h(\n ProgressRoot,\n {\n \"modelValue\": rootValue,\n \"max\": rootMax,\n \"getValueLabel\": () => undefined,\n \"getValueText\": getValueText,\n \"class\": s.Root,\n \"data-size\": props.size,\n \"data-color\": props.color,\n },\n {\n default: () =>\n h(ProgressIndicator, {\n \"class\": s.Indicator,\n \"style\": percentage == null ? undefined : { transform: `translateX(-${100 - percentage}%)` },\n \"data-indeterminate\": percentage == null ? \"\" : undefined,\n }),\n },\n )\n }\n },\n})\n\ntype ProgressOwnProps = InstanceType<typeof ProgressComponent>[\"$props\"]\n\n/** Progress props plus the native <div> attributes that fall through to the root, as in React. */\nexport type ProgressProps = ProgressOwnProps & Omit<HTMLAttributes, keyof ProgressOwnProps>\n\nexport const Progress = ProgressComponent as typeof ProgressComponent & { new (): { $props: ProgressProps } }\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/Progress/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,gBAAgB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/Progress/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAmF,MAAM,eAAe,CAAA","sourcesContent":["export { Progress, progressSegments, type ProgressColor, type ProgressProps, type ProgressSegment, type ProgressSize } from \"./Progress.js\"\n"]}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { defineComponent, h } from "vue";
|
|
1
|
+
import { defineComponent, h, onBeforeUnmount, onMounted, ref } from "vue";
|
|
2
2
|
import { Badge } from "../Badge/index.js";
|
|
3
3
|
import { InfoCircle, Trending } from "../Icon/index.js";
|
|
4
4
|
import { Tooltip } from "../Tooltip/index.js";
|
|
5
5
|
import { hasContent } from "../../lib/slotContent.js";
|
|
6
|
+
import { fitValueScale } from "../../lib/fitValueScale.js";
|
|
6
7
|
import s from "@plexui/styles/components/StatsCard/StatsCard.module.css";
|
|
7
8
|
const StatsCardComponent = defineComponent({
|
|
8
9
|
name: "StatsCard",
|
|
@@ -35,6 +36,14 @@ const StatsCardComponent = defineComponent({
|
|
|
35
36
|
accentColor: { type: String, default: "primary" },
|
|
36
37
|
},
|
|
37
38
|
setup(props, { slots }) {
|
|
39
|
+
// A value wider than the card (two cards a row on a phone) scales down to fit, as iOS's minimumScaleFactor
|
|
40
|
+
const valueRef = ref(null);
|
|
41
|
+
let stopFit;
|
|
42
|
+
onMounted(() => {
|
|
43
|
+
if (valueRef.value)
|
|
44
|
+
stopFit = fitValueScale(valueRef.value, "--stats-card-value-scale");
|
|
45
|
+
});
|
|
46
|
+
onBeforeUnmount(() => stopFit?.());
|
|
38
47
|
return () => {
|
|
39
48
|
const { label, description, trend, invertTrend, progress, progressLabel, tooltip, trendPosition, trendVariant } = props;
|
|
40
49
|
const trendValue = trend?.value ?? 0;
|
|
@@ -89,7 +98,7 @@ const StatsCardComponent = defineComponent({
|
|
|
89
98
|
]);
|
|
90
99
|
const valueSlot = slots.value?.();
|
|
91
100
|
const valueRowEl = h("div", { class: s.ValueRow }, [
|
|
92
|
-
h("div", { class: s.Value }, hasContent(valueSlot) ? valueSlot : props.value),
|
|
101
|
+
h("div", { ref: valueRef, class: s.Value }, hasContent(valueSlot) ? valueSlot : props.value),
|
|
93
102
|
]);
|
|
94
103
|
// Under the value, a trend and what it compares with, on one line (shadcn's metric card with a trend); a trend
|
|
95
104
|
// in the header leaves its label there
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StatsCard.js","sourceRoot":"","sources":["../../../../src/components/StatsCard/StatsCard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,CAAC,EAAsC,MAAM,KAAK,CAAA;AAC5E,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AACzC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,0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vC,EACD,CAAC,QAAQ,EAAE,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,UAAU,EAAE,WAAW,CAAC,CAC3E,CAAA;QACH,CAAC,CAAA;IACH,CAAC;CACF,CAAC,CAAA;AAOF,MAAM,CAAC,MAAM,SAAS,GAAG,kBAAwF,CAAA","sourcesContent":["import { defineComponent, h, type HTMLAttributes, type PropType } from \"vue\"\nimport { Badge } from \"../Badge/index.js\"\nimport { InfoCircle, Trending } from \"../Icon/index.js\"\nimport { Tooltip } from \"../Tooltip/index.js\"\nimport { hasContent } from \"../../lib/slotContent.js\"\nimport s from \"@plexui/styles/components/StatsCard/StatsCard.module.css\"\n\n// Vue port of packages/ui/src/components/StatsCard/StatsCard.tsx. Props,\n// defaults and rendered DOM match React (checked by the parity tests).\n// ReactNode props are slots: `value` (also a prop, for plain values),\n// `icon` and `sparkline`. React spreads the remaining props after its own\n// attributes, so caller attributes win; Vue's fallthrough does the same.\n\nexport type StatsCardTrend = {\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\nexport type StatsCardAccentColor =\n | \"primary\"\n | \"secondary\"\n | \"info\"\n | \"success\"\n | \"warning\"\n | \"danger\"\n | \"discovery\"\n | \"caution\"\n\nconst StatsCardComponent = defineComponent({\n name: \"StatsCard\",\n props: {\n /** Label describing the metric */\n label: { type: String, required: true },\n /** The primary metric value (e.g. \"1,234\" or \"$50K\"); the `value` slot takes rich content */\n value: { type: [String, Number] as PropType<string | number>, default: undefined },\n /** Optional description or subtitle below the value */\n description: String,\n /** Trend indicator with percentage change */\n trend: Object as PropType<StatsCardTrend>,\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: { type: Boolean, default: undefined },\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 /** Where the trend indicator is positioned: under the value with its label, or right-aligned in the header row (its label under the value). @default \"value\" */\n trendPosition: { type: String as PropType<\"value\" | \"header\">, default: \"value\" },\n /** Visual style of the trend indicator: plain colored text, or a Badge. @default \"text\" */\n trendVariant: { type: String as PropType<\"text\" | \"badge\">, default: \"text\" },\n /** Size of the card: standard dashboard card, or compact for dense layouts. @default \"default\" */\n size: { type: String as PropType<\"default\" | \"sm\">, default: \"default\" },\n /** Visual variant of the card. @default \"default\" */\n variant: { type: String as PropType<\"default\" | \"accent\">, default: \"default\" },\n /** Color of the accent variant's bar. @default \"primary\" */\n accentColor: { type: String as PropType<StatsCardAccentColor>, default: \"primary\" },\n },\n setup(props, { slots }) {\n return () => {\n const { label, description, trend, invertTrend, progress, progressLabel, tooltip, trendPosition, trendVariant } =\n props\n\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 = 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 trendValue !== 0 ? h(Trending, { class: trendValue < 0 ? s.TrendDown : undefined }) : null,\n trendText,\n ]\n\n const trendEl =\n trend != null\n ? trendVariant === \"badge\"\n ? h(Badge, { size: \"sm\", color: trendBadgeColor }, { default: trendContent })\n : h(\"div\", { class: [s.Trend, trendClassName] }, trendContent())\n : null\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 iconSlot = slots.icon?.()\n const iconEl = hasContent(iconSlot) ? h(\"div\", { class: s.IconWrapper }, iconSlot) : null\n const headerTrendEl = trendPosition === \"header\" ? trendEl : null\n\n const headerEl = h(\"div\", { class: s.Header }, [\n h(\"div\", { class: s.LabelRow }, [\n h(\"div\", { class: s.Label }, label),\n tooltip\n ? h(\n Tooltip,\n { content: tooltip },\n {\n // Focusable and named so keyboard and screen-reader users reach the tooltip\n default: () =>\n h(\"span\", { \"class\": s.InfoIcon, \"tabindex\": 0, \"role\": \"img\", \"aria-label\": \"More information\" }, [\n h(InfoCircle),\n ]),\n },\n )\n : null,\n ]),\n headerTrendEl || iconEl ? h(\"div\", { class: s.HeaderEnd }, [headerTrendEl, iconEl]) : null,\n ])\n\n const valueSlot = slots.value?.()\n const valueRowEl = h(\"div\", { class: s.ValueRow }, [\n h(\"div\", { class: s.Value }, hasContent(valueSlot) ? valueSlot : props.value),\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\n // in the header leaves its label there\n const trendRowEl =\n trend != null && (trendPosition === \"value\" || trend.label)\n ? h(\"div\", { class: s.TrendRow }, [\n trendPosition === \"value\" ? trendEl : null,\n trend.label ? h(\"span\", { class: s.TrendLabel }, trend.label) : null,\n ])\n : null\n\n const descriptionEl = description ? h(\"div\", { class: s.Description }, description) : null\n\n const progressEl =\n progressValue !== undefined || progressLabel\n ? h(\"div\", { class: s.Progress }, [\n h(\"div\", { class: s.ProgressTrack }, [\n h(\"div\", {\n \"class\": s.ProgressBar,\n \"style\": { width: `${progressValue ?? 0}%` },\n \"aria-hidden\": \"true\",\n }),\n ]),\n progressLabel ? h(\"div\", { class: s.ProgressLabel }, progressLabel) : null,\n ])\n : null\n\n const sparklineSlot = slots.sparkline?.()\n const sparklineEl = hasContent(sparklineSlot) ? h(\"div\", { class: s.Sparkline }, sparklineSlot) : null\n\n return h(\n \"div\",\n {\n \"class\": s.StatsCard,\n \"data-variant\": props.variant,\n \"data-size\": props.size,\n \"data-accent-color\": props.accentColor,\n },\n [headerEl, valueRowEl, trendRowEl, descriptionEl, progressEl, sparklineEl],\n )\n }\n },\n})\n\ntype StatsCardOwnProps = InstanceType<typeof StatsCardComponent>[\"$props\"]\n\n/** StatsCard props plus the native <div> attributes that fall through to it, as in React. */\nexport type StatsCardProps = StatsCardOwnProps & Omit<HTMLAttributes, keyof StatsCardOwnProps>\n\nexport const StatsCard = StatsCardComponent as typeof StatsCardComponent & { new (): { $props: StatsCardProps } }\n"]}
|
|
1
|
+
{"version":3,"file":"StatsCard.js","sourceRoot":"","sources":["../../../../src/components/StatsCard/StatsCard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,CAAC,EAAE,eAAe,EAAE,SAAS,EAAE,GAAG,EAAsC,MAAM,KAAK,CAAA;AAC7G,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AACzC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC1D,OAAO,CAAC,MAAM,0DAA0D,CAAA;AAyBxE,MAAM,kBAAkB,GAAG,eAAe,CAAC;IACzC,IAAI,EAAE,WAAW;IACjB,KAAK,EAAE;QACL,kCAAkC;QAClC,KAAK,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE;QACvC,6FAA6F;QAC7F,KAAK,EAAE,EAAE,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,CAA8B,EAAE,OAAO,EAAE,SAAS,EAAE;QAClF,uDAAuD;QACvD,WAAW,EAAE,MAAM;QACnB,6CAA6C;QAC7C,KAAK,EAAE,MAAkC;QACzC,yIAAyI;QACzI,WAAW,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,E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CAAC,CAAA;AAOF,MAAM,CAAC,MAAM,SAAS,GAAG,kBAAwF,CAAA","sourcesContent":["import { defineComponent, h, onBeforeUnmount, onMounted, ref, type HTMLAttributes, type PropType } from \"vue\"\nimport { Badge } from \"../Badge/index.js\"\nimport { InfoCircle, Trending } from \"../Icon/index.js\"\nimport { Tooltip } from \"../Tooltip/index.js\"\nimport { hasContent } from \"../../lib/slotContent.js\"\nimport { fitValueScale } from \"../../lib/fitValueScale.js\"\nimport s from \"@plexui/styles/components/StatsCard/StatsCard.module.css\"\n\n// Vue port of packages/ui/src/components/StatsCard/StatsCard.tsx. Props,\n// defaults and rendered DOM match React (checked by the parity tests).\n// ReactNode props are slots: `value` (also a prop, for plain values),\n// `icon` and `sparkline`. React spreads the remaining props after its own\n// attributes, so caller attributes win; Vue's fallthrough does the same.\n\nexport type StatsCardTrend = {\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\nexport type StatsCardAccentColor =\n | \"primary\"\n | \"secondary\"\n | \"info\"\n | \"success\"\n | \"warning\"\n | \"danger\"\n | \"discovery\"\n | \"caution\"\n\nconst StatsCardComponent = defineComponent({\n name: \"StatsCard\",\n props: {\n /** Label describing the metric */\n label: { type: String, required: true },\n /** The primary metric value (e.g. \"1,234\" or \"$50K\"); the `value` slot takes rich content */\n value: { type: [String, Number] as PropType<string | number>, default: undefined },\n /** Optional description or subtitle below the value */\n description: String,\n /** Trend indicator with percentage change */\n trend: Object as PropType<StatsCardTrend>,\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: { type: Boolean, default: undefined },\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 /** Where the trend indicator is positioned: under the value with its label, or right-aligned in the header row (its label under the value). @default \"value\" */\n trendPosition: { type: String as PropType<\"value\" | \"header\">, default: \"value\" },\n /** Visual style of the trend indicator: plain colored text, or a Badge. @default \"text\" */\n trendVariant: { type: String as PropType<\"text\" | \"badge\">, default: \"text\" },\n /** Size of the card: standard dashboard card, or compact for dense layouts. @default \"default\" */\n size: { type: String as PropType<\"default\" | \"sm\">, default: \"default\" },\n /** Visual variant of the card. @default \"default\" */\n variant: { type: String as PropType<\"default\" | \"accent\">, default: \"default\" },\n /** Color of the accent variant's bar. @default \"primary\" */\n accentColor: { type: String as PropType<StatsCardAccentColor>, default: \"primary\" },\n },\n setup(props, { slots }) {\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 = ref<HTMLElement | null>(null)\n let stopFit: (() => void) | undefined\n onMounted(() => {\n if (valueRef.value) stopFit = fitValueScale(valueRef.value, \"--stats-card-value-scale\")\n })\n onBeforeUnmount(() => stopFit?.())\n\n return () => {\n const { label, description, trend, invertTrend, progress, progressLabel, tooltip, trendPosition, trendVariant } =\n props\n\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 = 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 trendValue !== 0 ? h(Trending, { class: trendValue < 0 ? s.TrendDown : undefined }) : null,\n trendText,\n ]\n\n const trendEl =\n trend != null\n ? trendVariant === \"badge\"\n ? h(Badge, { size: \"sm\", color: trendBadgeColor }, { default: trendContent })\n : h(\"div\", { class: [s.Trend, trendClassName] }, trendContent())\n : null\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 iconSlot = slots.icon?.()\n const iconEl = hasContent(iconSlot) ? h(\"div\", { class: s.IconWrapper }, iconSlot) : null\n const headerTrendEl = trendPosition === \"header\" ? trendEl : null\n\n const headerEl = h(\"div\", { class: s.Header }, [\n h(\"div\", { class: s.LabelRow }, [\n h(\"div\", { class: s.Label }, label),\n tooltip\n ? h(\n Tooltip,\n { content: tooltip },\n {\n // Focusable and named so keyboard and screen-reader users reach the tooltip\n default: () =>\n h(\"span\", { \"class\": s.InfoIcon, \"tabindex\": 0, \"role\": \"img\", \"aria-label\": \"More information\" }, [\n h(InfoCircle),\n ]),\n },\n )\n : null,\n ]),\n headerTrendEl || iconEl ? h(\"div\", { class: s.HeaderEnd }, [headerTrendEl, iconEl]) : null,\n ])\n\n const valueSlot = slots.value?.()\n const valueRowEl = h(\"div\", { class: s.ValueRow }, [\n h(\"div\", { ref: valueRef, class: s.Value }, hasContent(valueSlot) ? valueSlot : props.value),\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\n // in the header leaves its label there\n const trendRowEl =\n trend != null && (trendPosition === \"value\" || trend.label)\n ? h(\"div\", { class: s.TrendRow }, [\n trendPosition === \"value\" ? trendEl : null,\n trend.label ? h(\"span\", { class: s.TrendLabel }, trend.label) : null,\n ])\n : null\n\n const descriptionEl = description ? h(\"div\", { class: s.Description }, description) : null\n\n const progressEl =\n progressValue !== undefined || progressLabel\n ? h(\"div\", { class: s.Progress }, [\n h(\"div\", { class: s.ProgressTrack }, [\n h(\"div\", {\n \"class\": s.ProgressBar,\n \"style\": { width: `${progressValue ?? 0}%` },\n \"aria-hidden\": \"true\",\n }),\n ]),\n progressLabel ? h(\"div\", { class: s.ProgressLabel }, progressLabel) : null,\n ])\n : null\n\n const sparklineSlot = slots.sparkline?.()\n const sparklineEl = hasContent(sparklineSlot) ? h(\"div\", { class: s.Sparkline }, sparklineSlot) : null\n\n return h(\n \"div\",\n {\n \"class\": s.StatsCard,\n \"data-variant\": props.variant,\n \"data-size\": props.size,\n \"data-accent-color\": props.accentColor,\n },\n [headerEl, valueRowEl, trendRowEl, descriptionEl, progressEl, sparklineEl],\n )\n }\n },\n})\n\ntype StatsCardOwnProps = InstanceType<typeof StatsCardComponent>[\"$props\"]\n\n/** StatsCard props plus the native <div> attributes that fall through to it, as in React. */\nexport type StatsCardProps = StatsCardOwnProps & Omit<HTMLAttributes, keyof StatsCardOwnProps>\n\nexport const StatsCard = StatsCardComponent as typeof StatsCardComponent & { new (): { $props: StatsCardProps } }\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,g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C,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"]}
|
|
@@ -4,14 +4,15 @@ type RouteTarget = string | Record<string, unknown>;
|
|
|
4
4
|
/**
|
|
5
5
|
* Vue port of `NavigationRow` from packages/ui/src/components/NavigationRow/NavigationRow.tsx: a FieldGroup row
|
|
6
6
|
* that opens what it holds, as an iOS Settings drill-in. Attributes (id, class, ARIA, data, listeners) fall through
|
|
7
|
-
* to the pressable. The `label`, `value` and `description` slots take the place of their props
|
|
7
|
+
* to the pressable. The `label`, `value` and `description` slots take the place of their props; the `leading` slot
|
|
8
|
+
* (an `Avatar` or a picture) leads the row, as React's `leading`.
|
|
8
9
|
*/
|
|
9
10
|
declare const NavigationRowComponent: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
10
11
|
/** The row's name, where a row's label starts */
|
|
11
12
|
label: PropType<string | number>;
|
|
12
13
|
/** The current value, at the end of the row in the secondary label. `0` shows; `null`, `undefined` and `""` do not. */
|
|
13
14
|
value: PropType<string | number | null>;
|
|
14
|
-
/** A line under the label; the row grows from 52 to hold it */
|
|
15
|
+
/** A line under the label; the row grows from 52 to hold it. A `<br />` in the slot starts a second line. */
|
|
15
16
|
description: PropType<string | number>;
|
|
16
17
|
/** Where the row goes. With it the row is a link (through `PlexUIProvider`'s `linkComponent`, or `as`). */
|
|
17
18
|
href: StringConstructor;
|
|
@@ -37,6 +38,14 @@ declare const NavigationRowComponent: import("vue").DefineComponent<import("vue"
|
|
|
37
38
|
type: PropType<"end" | "below" | "auto">;
|
|
38
39
|
default: string;
|
|
39
40
|
};
|
|
41
|
+
/**
|
|
42
|
+
* The chevron at the end. `false` drops it, for a row that opens a record rather than a page of choices (as the
|
|
43
|
+
* Contacts list of iOS); the row is still one press.
|
|
44
|
+
*/
|
|
45
|
+
disclosure: {
|
|
46
|
+
type: BooleanConstructor;
|
|
47
|
+
default: boolean;
|
|
48
|
+
};
|
|
40
49
|
}>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
41
50
|
[key: string]: any;
|
|
42
51
|
}>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
@@ -44,7 +53,7 @@ declare const NavigationRowComponent: import("vue").DefineComponent<import("vue"
|
|
|
44
53
|
label: PropType<string | number>;
|
|
45
54
|
/** The current value, at the end of the row in the secondary label. `0` shows; `null`, `undefined` and `""` do not. */
|
|
46
55
|
value: PropType<string | number | null>;
|
|
47
|
-
/** A line under the label; the row grows from 52 to hold it */
|
|
56
|
+
/** A line under the label; the row grows from 52 to hold it. A `<br />` in the slot starts a second line. */
|
|
48
57
|
description: PropType<string | number>;
|
|
49
58
|
/** Where the row goes. With it the row is a link (through `PlexUIProvider`'s `linkComponent`, or `as`). */
|
|
50
59
|
href: StringConstructor;
|
|
@@ -70,10 +79,19 @@ declare const NavigationRowComponent: import("vue").DefineComponent<import("vue"
|
|
|
70
79
|
type: PropType<"end" | "below" | "auto">;
|
|
71
80
|
default: string;
|
|
72
81
|
};
|
|
82
|
+
/**
|
|
83
|
+
* The chevron at the end. `false` drops it, for a row that opens a record rather than a page of choices (as the
|
|
84
|
+
* Contacts list of iOS); the row is still one press.
|
|
85
|
+
*/
|
|
86
|
+
disclosure: {
|
|
87
|
+
type: BooleanConstructor;
|
|
88
|
+
default: boolean;
|
|
89
|
+
};
|
|
73
90
|
}>> & Readonly<{}>, {
|
|
74
91
|
disabled: boolean;
|
|
75
92
|
external: boolean;
|
|
76
93
|
valuePlacement: "auto" | "end" | "below";
|
|
94
|
+
disclosure: boolean;
|
|
77
95
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
78
96
|
type NavigationRowOwnProps = InstanceType<typeof NavigationRowComponent>["$props"];
|
|
79
97
|
/** NavigationRow props plus the native button and link attributes and the click listener that fall through to the
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type HTMLAttributes, type PropType } from "vue";
|
|
2
|
+
export type ProgressSize = "sm" | "md" | "lg";
|
|
2
3
|
export type ProgressColor = "primary" | "secondary" | "success" | "warning" | "caution" | "danger" | "info" | "discovery";
|
|
3
4
|
/** A part of a segmented bar: its share of `max`, its color, and the name it is read with. */
|
|
4
5
|
export type ProgressSegment = {
|
|
@@ -43,6 +44,23 @@ declare const ProgressComponent: import("vue").DefineComponent<import("vue").Ext
|
|
|
43
44
|
type: PropType<ProgressSegment[]>;
|
|
44
45
|
default: undefined;
|
|
45
46
|
};
|
|
47
|
+
/**
|
|
48
|
+
* The bar's thickness: `sm` 4px (iOS's progress view), `md` 6px, `lg` 8px (a bar in a stats card, as Apple Fitness).
|
|
49
|
+
* @default "sm"
|
|
50
|
+
*/
|
|
51
|
+
size: {
|
|
52
|
+
type: PropType<ProgressSize>;
|
|
53
|
+
default: string;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* The color of the filled part, such as `secondary` (grey) for a second series beside a `primary` one. A segmented
|
|
57
|
+
* bar's parts take their own colors.
|
|
58
|
+
* @default "primary"
|
|
59
|
+
*/
|
|
60
|
+
color: {
|
|
61
|
+
type: PropType<ProgressColor>;
|
|
62
|
+
default: string;
|
|
63
|
+
};
|
|
46
64
|
}>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
47
65
|
[key: string]: any;
|
|
48
66
|
}>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
@@ -69,8 +87,27 @@ declare const ProgressComponent: import("vue").DefineComponent<import("vue").Ext
|
|
|
69
87
|
type: PropType<ProgressSegment[]>;
|
|
70
88
|
default: undefined;
|
|
71
89
|
};
|
|
90
|
+
/**
|
|
91
|
+
* The bar's thickness: `sm` 4px (iOS's progress view), `md` 6px, `lg` 8px (a bar in a stats card, as Apple Fitness).
|
|
92
|
+
* @default "sm"
|
|
93
|
+
*/
|
|
94
|
+
size: {
|
|
95
|
+
type: PropType<ProgressSize>;
|
|
96
|
+
default: string;
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* The color of the filled part, such as `secondary` (grey) for a second series beside a `primary` one. A segmented
|
|
100
|
+
* bar's parts take their own colors.
|
|
101
|
+
* @default "primary"
|
|
102
|
+
*/
|
|
103
|
+
color: {
|
|
104
|
+
type: PropType<ProgressColor>;
|
|
105
|
+
default: string;
|
|
106
|
+
};
|
|
72
107
|
}>> & Readonly<{}>, {
|
|
73
108
|
value: number | null;
|
|
109
|
+
size: ProgressSize;
|
|
110
|
+
color: ProgressColor;
|
|
74
111
|
max: number;
|
|
75
112
|
segments: ProgressSegment[];
|
|
76
113
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
@@ -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";
|
|
@@ -463,8 +463,8 @@ declare const SidebarMobileComponent: DefineComponent<import("vue").ExtractPropT
|
|
|
463
463
|
default: boolean;
|
|
464
464
|
};
|
|
465
465
|
}>> & Readonly<{}>, {
|
|
466
|
-
contained: boolean;
|
|
467
466
|
disclosure: boolean;
|
|
467
|
+
contained: boolean;
|
|
468
468
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
469
469
|
export type SidebarMobileProps = InstanceType<typeof SidebarMobileComponent>["$props"] & HTMLAttributes;
|
|
470
470
|
export declare const SidebarMobile: typeof SidebarMobileComponent & {
|
|
@@ -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/vue",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.40.0",
|
|
4
4
|
"description": "Plex UI components for Vue 3, built on Reka UI and the shared @plexui/styles CSS",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
"@maskito/core": "5.2.2",
|
|
78
78
|
"@maskito/kit": "5.2.2",
|
|
79
79
|
"@maskito/vue": "5.2.2",
|
|
80
|
-
"@plexui/styles": "^0.16.
|
|
80
|
+
"@plexui/styles": "^0.16.4",
|
|
81
81
|
"@tanstack/table-core": "8.21.3",
|
|
82
82
|
"@tanstack/vue-table": "8.21.3",
|
|
83
83
|
"@tiptap/core": "3.21.0",
|