@plexui/vue 0.21.0 → 0.22.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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { h } from "vue";
|
|
1
|
+
import { defineComponent, h, onMounted, ref } from "vue";
|
|
2
2
|
import { Badge } from "../Badge/index.js";
|
|
3
3
|
import { CopyTooltip, Tooltip } from "../Tooltip/index.js";
|
|
4
4
|
/** Monospace ID that copies itself on click, with a copy tooltip. */
|
|
@@ -18,19 +18,101 @@ export function idCell(accessor) {
|
|
|
18
18
|
IdCell.displayName = "IdCell";
|
|
19
19
|
return IdCell;
|
|
20
20
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
// ISO 8601: a date, a time, and a zone (Z or an offset) when the value names an instant.
|
|
22
|
+
const ISO_DATE = /^([+-]\d{6}|\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2})(?:\.(\d+))?)?(Z|[+-]\d{2}(?::?\d{2})?)?)?$/;
|
|
23
|
+
/**
|
|
24
|
+
* An ISO date read field by field, the same in every runtime (engines read the edges of the format each their own
|
|
25
|
+
* way), null when it is no date (the 30th of February, an hour of 25; 24:00 is the next midnight). A date, or a
|
|
26
|
+
* date and time, written without a zone ("2023-01-15", "2023-01-15T09:00") names no instant, and a runtime would
|
|
27
|
+
* read it in its own zone, the server's in one and the reader's in another: it is `written`, shown as written in
|
|
28
|
+
* every zone.
|
|
29
|
+
*/
|
|
30
|
+
function readIsoDate(value) {
|
|
31
|
+
const match = ISO_DATE.exec(value);
|
|
32
|
+
if (!match)
|
|
33
|
+
return undefined;
|
|
34
|
+
const [, yearText, monthText, dayText, hourText = "0", minuteText = "0", secondText = "0", fraction = "0", zone] = match;
|
|
35
|
+
const [year, month, day, hour, minute, second] = [yearText, monthText, dayText, hourText, minuteText, secondText].map(Number);
|
|
36
|
+
const leap = (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
|
|
37
|
+
const monthDays = [31, leap ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month - 1];
|
|
38
|
+
const endOfDay = hour === 24 && minute + second + Number(fraction) === 0;
|
|
39
|
+
const offsetHours = zone && zone !== "Z" ? Number(zone.slice(1, 3)) : 0;
|
|
40
|
+
const offsetMinutes = zone && zone.length > 3 ? Number(zone.slice(-2)) : 0;
|
|
41
|
+
const inRange = monthDays !== undefined && day >= 1 && day <= monthDays && (hour <= 23 || endOfDay) && minute <= 59 && second <= 59 &&
|
|
42
|
+
offsetHours <= 23 && offsetMinutes <= 59;
|
|
43
|
+
if (!inRange)
|
|
44
|
+
return null;
|
|
45
|
+
// Counted, not built from a Date: a value at the edge of the range a Date holds would leave it on the way.
|
|
46
|
+
// An offset east of UTC is that much earlier in UTC.
|
|
47
|
+
const offset = (zone?.[0] === "-" ? -1 : 1) * (offsetHours * 60 + offsetMinutes);
|
|
48
|
+
const time = daysFromCivil(year, month, day) * 86_400_000 + ((hour * 60 + minute - offset) * 60 + second) * 1000 +
|
|
49
|
+
Number(fraction.slice(0, 3).padEnd(3, "0"));
|
|
50
|
+
const date = new Date(time);
|
|
51
|
+
return Number.isNaN(date.getTime()) ? null : { date, written: !zone };
|
|
52
|
+
}
|
|
53
|
+
/** Days from 1970-01-01 to a date of the proleptic Gregorian calendar (H. Hinnant's days_from_civil). */
|
|
54
|
+
function daysFromCivil(year, month, day) {
|
|
55
|
+
const y = month <= 2 ? year - 1 : year;
|
|
56
|
+
const era = Math.floor(y / 400);
|
|
57
|
+
const yearOfEra = y - era * 400;
|
|
58
|
+
const dayOfYear = Math.floor((153 * (month + (month > 2 ? -3 : 9)) + 2) / 5) + day - 1;
|
|
59
|
+
const dayOfEra = yearOfEra * 365 + Math.floor(yearOfEra / 4) - Math.floor(yearOfEra / 100) + dayOfYear;
|
|
60
|
+
return era * 146_097 + dayOfEra - 719_468;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Formats a cell's value: in the reader's zone once mounted, and on the server and while hydrating in a zone that
|
|
64
|
+
* does not depend on where they run. The text can still differ between engines (Node joins a date and a time with
|
|
65
|
+
* ", ", WebKit with " at "), so the cell lets hydration differ in its text and writes the reader's text once mounted.
|
|
66
|
+
*/
|
|
67
|
+
function dateTimeFormatter(options) {
|
|
68
|
+
const formatOptions = options ?? {
|
|
24
69
|
year: "numeric",
|
|
25
70
|
month: "short",
|
|
26
71
|
day: "numeric",
|
|
27
72
|
hour: "2-digit",
|
|
28
73
|
minute: "2-digit",
|
|
29
74
|
};
|
|
30
|
-
const
|
|
75
|
+
const reader = new Intl.DateTimeFormat("en-US", formatOptions);
|
|
76
|
+
// The server knows no reader's time zone: without a timeZone in the options it writes an instant in UTC, and
|
|
77
|
+
// so does the render that takes over the server's markup; the reader's own zone follows once it is mounted.
|
|
78
|
+
const server = formatOptions.timeZone ? reader : new Intl.DateTimeFormat("en-US", { ...formatOptions, timeZone: "UTC" });
|
|
79
|
+
// A written date names no zone, so none is printed: a long or full time would add one, a medium one does not.
|
|
80
|
+
const zoneless = formatOptions.timeStyle === "long" || formatOptions.timeStyle === "full" ? "medium" : formatOptions.timeStyle;
|
|
81
|
+
const written = new Intl.DateTimeFormat("en-US", { ...formatOptions, timeZone: "UTC", timeZoneName: undefined, timeStyle: zoneless });
|
|
82
|
+
return (value, mounted) => {
|
|
83
|
+
const iso = readIsoDate(value);
|
|
84
|
+
if (iso === null)
|
|
85
|
+
return value;
|
|
86
|
+
if (iso)
|
|
87
|
+
return (iso.written ? written : mounted ? reader : server).format(iso.date);
|
|
88
|
+
// Any other way of writing a date each runtime reads its own way, and one that is no date at all none can
|
|
89
|
+
// format: the server and the render that takes over its markup show it as written, the reader's runtime
|
|
90
|
+
// reads it once mounted.
|
|
91
|
+
const date = new Date(value);
|
|
92
|
+
return mounted && !Number.isNaN(date.getTime()) ? reader.format(date) : value;
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/** One formatted cell: the server's format until it is mounted, then the reader's. */
|
|
96
|
+
const DateTimeText = defineComponent({
|
|
97
|
+
name: "DateTimeText",
|
|
98
|
+
props: {
|
|
99
|
+
value: { type: String, default: undefined },
|
|
100
|
+
format: { type: Function, required: true },
|
|
101
|
+
},
|
|
102
|
+
setup(props) {
|
|
103
|
+
const mounted = ref(false);
|
|
104
|
+
onMounted(() => { mounted.value = true; });
|
|
105
|
+
// Hydration may take the server's text in another engine's words (Vue writes its own over it); once mounted,
|
|
106
|
+
// the reader's zone follows.
|
|
107
|
+
return () => h("span", { "data-allow-mismatch": "text", style: { color: "var(--color-text-secondary)" } }, props.value ? props.format(props.value, mounted.value) : "—");
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
/** Date and time formatted with Intl.DateTimeFormat ("en-US"); "—" when empty. */
|
|
111
|
+
export function dateTimeCell(accessor, options) {
|
|
112
|
+
const format = dateTimeFormatter(options);
|
|
31
113
|
const DateTimeCell = ({ row }) => {
|
|
32
114
|
const val = accessor(row.original);
|
|
33
|
-
return h(
|
|
115
|
+
return h(DateTimeText, { value: val ?? undefined, format });
|
|
34
116
|
};
|
|
35
117
|
DateTimeCell.displayName = "DateTimeCell";
|
|
36
118
|
return DateTimeCell;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"columnHelpers.js","sourceRoot":"","sources":["../../../../src/components/DataTable/columnHelpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAc,MAAM,KAAK,CAAA;AAEnC,OAAO,EAAE,KAAK,EAAmB,MAAM,mBAAmB,CAAA;AAC1D,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAe1D,qEAAqE;AACrE,MAAM,UAAU,MAAM,CAAI,QAA4B;IACpD,MAAM,MAAM,GAAqB,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE;QAC3C,MAAM,KAAK,GAAG,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;QACpC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\"@tanstack/vue-table\"\nimport { Badge, type BadgeColor } from \"../Badge/index.js\"\nimport { CopyTooltip, Tooltip } from \"../Tooltip/index.js\"\n\n// Vue port of packages/ui/src/components/DataTable/columnHelpers.tsx. Each\n// helper returns a functional component for a column's `cell` or `header`;\n// FlexRender renders it with the cell or header context as props, as\n// flexRender does in React.\n\ntype StatusColor = Extract<BadgeColor, \"secondary\" | \"success\" | \"danger\" | \"warning\" | \"info\" | \"discovery\" | \"caution\">\n\n/** A cell renderer: FlexRender calls it with the cell context. */\nexport type CellComponent<T> = ((context: CellContext<T, unknown>) => VNode) & { displayName?: string }\n\n/** A header renderer: FlexRender calls it with the header context. */\nexport type HeaderComponent<T> = ((context: HeaderContext<T, unknown>) => VNode) & { displayName?: string }\n\n/** Monospace ID that copies itself on click, with a copy tooltip. */\nexport function idCell<T>(accessor: (row: T) => string): CellComponent<T> {\n const IdCell: CellComponent<T> = ({ row }) => {\n const value = accessor(row.original)\n return h(\n CopyTooltip,\n { copyValue: value },\n {\n default: () =>\n h(\n \"span\",\n {\n style: {\n fontFamily: \"var(--font-mono, ui-monospace, monospace)\",\n color: \"var(--color-text-secondary)\",\n cursor: \"pointer\",\n },\n },\n value,\n ),\n },\n )\n }\n IdCell.displayName = \"IdCell\"\n return IdCell\n}\n\n/** Date and time formatted with Intl.DateTimeFormat (\"en-US\"); \"—\" when empty. */\nexport function dateTimeCell<T>(\n accessor: (row: T) => string | null | undefined,\n options?: Intl.DateTimeFormatOptions,\n): CellComponent<T> {\n const defaultOptions: Intl.DateTimeFormatOptions = {\n year: \"numeric\",\n month: \"short\",\n day: \"numeric\",\n hour: \"2-digit\",\n minute: \"2-digit\",\n }\n const fmt = new Intl.DateTimeFormat(\"en-US\", options ?? defaultOptions)\n\n const DateTimeCell: CellComponent<T> = ({ row }) => {\n const val = accessor(row.original)\n return h(\"span\", { style: { color: \"var(--color-text-secondary)\" } }, val ? fmt.format(new Date(val)) : \"—\")\n }\n DateTimeCell.displayName = \"DateTimeCell\"\n return DateTimeCell\n}\n\n/** Soft Badge whose color comes from the lowercased status (`colorMap`, or the default map). */\nexport function statusCell<T>(accessor: (row: T) => string, colorMap?: Record<string, StatusColor>): CellComponent<T> {\n const defaultColorMap: Record<string, StatusColor> = {\n active: \"success\",\n completed: \"success\",\n paid: \"success\",\n pending: \"warning\",\n processing: \"info\",\n inactive: \"secondary\",\n cancelled: \"danger\",\n failed: \"danger\",\n unpaid: \"danger\",\n }\n\n const StatusCell: CellComponent<T> = ({ row }) => {\n const status = accessor(row.original)\n const map = colorMap ?? defaultColorMap\n const color = map[status.toLowerCase()] ?? \"secondary\"\n return h(Badge, { color, variant: \"soft\" }, { default: () => status })\n }\n StatusCell.displayName = \"StatusCell\"\n return StatusCell\n}\n\n/** Header label with a dashed underline and a tooltip carrying `description`. */\nexport function tooltipHeader<T = any>(label: string, description: string): HeaderComponent<T> {\n const TooltipHeader: HeaderComponent<T> = () =>\n h(\n Tooltip,\n { content: description, side: \"bottom\", maxWidth: 260 },\n {\n default: () => h(\"span\", { style: { cursor: \"help\", borderBottom: \"1px dashed currentColor\" } }, label),\n },\n )\n TooltipHeader.displayName = \"TooltipHeader\"\n return TooltipHeader\n}\n"]}
|
|
1
|
+
{"version":3,"file":"columnHelpers.js","sourceRoot":"","sources":["../../../../src/components/DataTable/columnHelpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,CAAC,EAAE,SAAS,EAAE,GAAG,EAA6B,MAAM,KAAK,CAAA;AAEnF,OAAO,EAAE,KAAK,EAAmB,MAAM,mBAAmB,CAAA;AAC1D,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAe1D,qEAAqE;AACrE,MAAM,UAAU,MAAM,CAAI,QAA4B;IACpD,MAAM,MAAM,GAAqB,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE;QAC3C,MAAM,KAAK,GAAG,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;QACpC,OAA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CACC,OAAO,EACP,EAAE,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,EAAE,EACvD;QACE,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,yBAAyB,EAAE,EAAE,EAAE,KAAK,CAAC;KACxG,CACF,CAAA;IACH,aAAa,CAAC,WAAW,GAAG,eAAe,CAAA;IAC3C,OAAO,aAAa,CAAA;AACtB,CAAC","sourcesContent":["import { defineComponent, h, onMounted, ref, type PropType, type VNode } from \"vue\"\nimport type { CellContext, HeaderContext } from \"@tanstack/vue-table\"\nimport { Badge, type BadgeColor } from \"../Badge/index.js\"\nimport { CopyTooltip, Tooltip } from \"../Tooltip/index.js\"\n\n// Vue port of packages/ui/src/components/DataTable/columnHelpers.tsx. Each\n// helper returns a functional component for a column's `cell` or `header`;\n// FlexRender renders it with the cell or header context as props, as\n// flexRender does in React.\n\ntype StatusColor = Extract<BadgeColor, \"secondary\" | \"success\" | \"danger\" | \"warning\" | \"info\" | \"discovery\" | \"caution\">\n\n/** A cell renderer: FlexRender calls it with the cell context. */\nexport type CellComponent<T> = ((context: CellContext<T, unknown>) => VNode) & { displayName?: string }\n\n/** A header renderer: FlexRender calls it with the header context. */\nexport type HeaderComponent<T> = ((context: HeaderContext<T, unknown>) => VNode) & { displayName?: string }\n\n/** Monospace ID that copies itself on click, with a copy tooltip. */\nexport function idCell<T>(accessor: (row: T) => string): CellComponent<T> {\n const IdCell: CellComponent<T> = ({ row }) => {\n const value = accessor(row.original)\n return h(\n CopyTooltip,\n { copyValue: value },\n {\n default: () =>\n h(\n \"span\",\n {\n style: {\n fontFamily: \"var(--font-mono, ui-monospace, monospace)\",\n color: \"var(--color-text-secondary)\",\n cursor: \"pointer\",\n },\n },\n value,\n ),\n },\n )\n }\n IdCell.displayName = \"IdCell\"\n return IdCell\n}\n\n// ISO 8601: a date, a time, and a zone (Z or an offset) when the value names an instant.\nconst ISO_DATE = /^([+-]\\d{6}|\\d{4})-(\\d{2})-(\\d{2})(?:[T ](\\d{2}):(\\d{2})(?::(\\d{2})(?:\\.(\\d+))?)?(Z|[+-]\\d{2}(?::?\\d{2})?)?)?$/\n\n/**\n * An ISO date read field by field, the same in every runtime (engines read the edges of the format each their own\n * way), null when it is no date (the 30th of February, an hour of 25; 24:00 is the next midnight). A date, or a\n * date and time, written without a zone (\"2023-01-15\", \"2023-01-15T09:00\") names no instant, and a runtime would\n * read it in its own zone, the server's in one and the reader's in another: it is `written`, shown as written in\n * every zone.\n */\nfunction readIsoDate(value: string): { date: Date; written: boolean } | null | undefined {\n const match = ISO_DATE.exec(value)\n if (!match) return undefined\n const [, yearText, monthText, dayText, hourText = \"0\", minuteText = \"0\", secondText = \"0\", fraction = \"0\", zone] = match\n const [year, month, day, hour, minute, second] = [yearText, monthText, dayText, hourText, minuteText, secondText].map(Number)\n const leap = (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0\n const monthDays = [31, leap ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month - 1]\n const endOfDay = hour === 24 && minute + second + Number(fraction) === 0\n const offsetHours = zone && zone !== \"Z\" ? Number(zone.slice(1, 3)) : 0\n const offsetMinutes = zone && zone.length > 3 ? Number(zone.slice(-2)) : 0\n const inRange =\n monthDays !== undefined && day >= 1 && day <= monthDays && (hour <= 23 || endOfDay) && minute <= 59 && second <= 59 &&\n offsetHours <= 23 && offsetMinutes <= 59\n if (!inRange) return null\n // Counted, not built from a Date: a value at the edge of the range a Date holds would leave it on the way.\n // An offset east of UTC is that much earlier in UTC.\n const offset = (zone?.[0] === \"-\" ? -1 : 1) * (offsetHours * 60 + offsetMinutes)\n const time =\n daysFromCivil(year, month, day) * 86_400_000 + ((hour * 60 + minute - offset) * 60 + second) * 1000 +\n Number(fraction.slice(0, 3).padEnd(3, \"0\"))\n const date = new Date(time)\n return Number.isNaN(date.getTime()) ? null : { date, written: !zone }\n}\n\n/** Days from 1970-01-01 to a date of the proleptic Gregorian calendar (H. Hinnant's days_from_civil). */\nfunction daysFromCivil(year: number, month: number, day: number) {\n const y = month <= 2 ? year - 1 : year\n const era = Math.floor(y / 400)\n const yearOfEra = y - era * 400\n const dayOfYear = Math.floor((153 * (month + (month > 2 ? -3 : 9)) + 2) / 5) + day - 1\n const dayOfEra = yearOfEra * 365 + Math.floor(yearOfEra / 4) - Math.floor(yearOfEra / 100) + dayOfYear\n return era * 146_097 + dayOfEra - 719_468\n}\n\n/**\n * Formats a cell's value: in the reader's zone once mounted, and on the server and while hydrating in a zone that\n * does not depend on where they run. The text can still differ between engines (Node joins a date and a time with\n * \", \", WebKit with \" at \"), so the cell lets hydration differ in its text and writes the reader's text once mounted.\n */\nfunction dateTimeFormatter(options?: Intl.DateTimeFormatOptions) {\n const formatOptions: Intl.DateTimeFormatOptions = options ?? {\n year: \"numeric\",\n month: \"short\",\n day: \"numeric\",\n hour: \"2-digit\",\n minute: \"2-digit\",\n }\n const reader = new Intl.DateTimeFormat(\"en-US\", formatOptions)\n // The server knows no reader's time zone: without a timeZone in the options it writes an instant in UTC, and\n // so does the render that takes over the server's markup; the reader's own zone follows once it is mounted.\n const server = formatOptions.timeZone ? reader : new Intl.DateTimeFormat(\"en-US\", { ...formatOptions, timeZone: \"UTC\" })\n // A written date names no zone, so none is printed: a long or full time would add one, a medium one does not.\n const zoneless = formatOptions.timeStyle === \"long\" || formatOptions.timeStyle === \"full\" ? \"medium\" : formatOptions.timeStyle\n const written = new Intl.DateTimeFormat(\"en-US\", { ...formatOptions, timeZone: \"UTC\", timeZoneName: undefined, timeStyle: zoneless })\n return (value: string, mounted: boolean) => {\n const iso = readIsoDate(value)\n if (iso === null) return value\n if (iso) return (iso.written ? written : mounted ? reader : server).format(iso.date)\n // Any other way of writing a date each runtime reads its own way, and one that is no date at all none can\n // format: the server and the render that takes over its markup show it as written, the reader's runtime\n // reads it once mounted.\n const date = new Date(value)\n return mounted && !Number.isNaN(date.getTime()) ? reader.format(date) : value\n }\n}\n\n/** One formatted cell: the server's format until it is mounted, then the reader's. */\nconst DateTimeText = defineComponent({\n name: \"DateTimeText\",\n props: {\n value: { type: String, default: undefined },\n format: { type: Function as PropType<(value: string, mounted: boolean) => string>, required: true },\n },\n setup(props) {\n const mounted = ref(false)\n onMounted(() => { mounted.value = true })\n // Hydration may take the server's text in another engine's words (Vue writes its own over it); once mounted,\n // the reader's zone follows.\n return () =>\n h(\n \"span\",\n { \"data-allow-mismatch\": \"text\", style: { color: \"var(--color-text-secondary)\" } },\n props.value ? props.format(props.value, mounted.value) : \"—\",\n )\n },\n})\n\n/** Date and time formatted with Intl.DateTimeFormat (\"en-US\"); \"—\" when empty. */\nexport function dateTimeCell<T>(\n accessor: (row: T) => string | null | undefined,\n options?: Intl.DateTimeFormatOptions,\n): CellComponent<T> {\n const format = dateTimeFormatter(options)\n\n const DateTimeCell: CellComponent<T> = ({ row }) => {\n const val = accessor(row.original)\n return h(DateTimeText, { value: val ?? undefined, format })\n }\n DateTimeCell.displayName = \"DateTimeCell\"\n return DateTimeCell\n}\n\n/** Soft Badge whose color comes from the lowercased status (`colorMap`, or the default map). */\nexport function statusCell<T>(accessor: (row: T) => string, colorMap?: Record<string, StatusColor>): CellComponent<T> {\n const defaultColorMap: Record<string, StatusColor> = {\n active: \"success\",\n completed: \"success\",\n paid: \"success\",\n pending: \"warning\",\n processing: \"info\",\n inactive: \"secondary\",\n cancelled: \"danger\",\n failed: \"danger\",\n unpaid: \"danger\",\n }\n\n const StatusCell: CellComponent<T> = ({ row }) => {\n const status = accessor(row.original)\n const map = colorMap ?? defaultColorMap\n const color = map[status.toLowerCase()] ?? \"secondary\"\n return h(Badge, { color, variant: \"soft\" }, { default: () => status })\n }\n StatusCell.displayName = \"StatusCell\"\n return StatusCell\n}\n\n/** Header label with a dashed underline and a tooltip carrying `description`. */\nexport function tooltipHeader<T = any>(label: string, description: string): HeaderComponent<T> {\n const TooltipHeader: HeaderComponent<T> = () =>\n h(\n Tooltip,\n { content: description, side: \"bottom\", maxWidth: 260 },\n {\n default: () => h(\"span\", { style: { cursor: \"help\", borderBottom: \"1px dashed currentColor\" } }, label),\n },\n )\n TooltipHeader.displayName = \"TooltipHeader\"\n return TooltipHeader\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plexui/vue",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.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.1.
|
|
80
|
+
"@plexui/styles": "^0.1.46",
|
|
81
81
|
"@tanstack/table-core": "8.21.3",
|
|
82
82
|
"@tanstack/vue-table": "8.21.3",
|
|
83
83
|
"@tiptap/core": "3.21.0",
|