@plexui/ui 0.40.0 → 0.42.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,5 +1,6 @@
1
1
  "use client";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { useLayoutEffect, useRef, useSyncExternalStore } from "react";
3
4
  import { Badge } from "../Badge/index.js";
4
5
  import { CopyTooltip } from "../Tooltip/index.js";
5
6
  import { Tooltip } from "../Tooltip/index.js";
@@ -15,18 +16,98 @@ export function idCell(accessor) {
15
16
  IdCell.displayName = "IdCell";
16
17
  return IdCell;
17
18
  }
18
- export function dateTimeCell(accessor, options) {
19
- const defaultOptions = {
19
+ const subscribeNever = () => () => { };
20
+ const isClient = () => true;
21
+ const isServer = () => false;
22
+ // ISO 8601: a date, a time, and a zone (Z or an offset) when the value names an instant.
23
+ const ISO_DATE = /^([+-]\d{6}|\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2})(?:\.(\d+))?)?(Z|[+-]\d{2}(?::?\d{2})?)?)?$/;
24
+ /**
25
+ * An ISO date read field by field, the same in every runtime (engines read the edges of the format each their own
26
+ * 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
27
+ * date and time, written without a zone ("2023-01-15", "2023-01-15T09:00") names no instant, and a runtime would
28
+ * read it in its own zone, the server's in one and the reader's in another: it is `written`, shown as written in
29
+ * every zone.
30
+ */
31
+ function readIsoDate(value) {
32
+ const match = ISO_DATE.exec(value);
33
+ if (!match)
34
+ return undefined;
35
+ const [, yearText, monthText, dayText, hourText = "0", minuteText = "0", secondText = "0", fraction = "0", zone] = match;
36
+ const [year, month, day, hour, minute, second] = [yearText, monthText, dayText, hourText, minuteText, secondText].map(Number);
37
+ const leap = (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
38
+ const monthDays = [31, leap ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month - 1];
39
+ const endOfDay = hour === 24 && minute + second + Number(fraction) === 0;
40
+ const offsetHours = zone && zone !== "Z" ? Number(zone.slice(1, 3)) : 0;
41
+ const offsetMinutes = zone && zone.length > 3 ? Number(zone.slice(-2)) : 0;
42
+ const inRange = monthDays !== undefined && day >= 1 && day <= monthDays && (hour <= 23 || endOfDay) && minute <= 59 && second <= 59 &&
43
+ offsetHours <= 23 && offsetMinutes <= 59;
44
+ if (!inRange)
45
+ return null;
46
+ // Counted, not built from a Date: a value at the edge of the range a Date holds would leave it on the way.
47
+ // An offset east of UTC is that much earlier in UTC.
48
+ const offset = (zone?.[0] === "-" ? -1 : 1) * (offsetHours * 60 + offsetMinutes);
49
+ const time = daysFromCivil(year, month, day) * 86_400_000 + ((hour * 60 + minute - offset) * 60 + second) * 1000 +
50
+ Number(fraction.slice(0, 3).padEnd(3, "0"));
51
+ const date = new Date(time);
52
+ return Number.isNaN(date.getTime()) ? null : { date, written: !zone };
53
+ }
54
+ /** Days from 1970-01-01 to a date of the proleptic Gregorian calendar (H. Hinnant's days_from_civil). */
55
+ function daysFromCivil(year, month, day) {
56
+ const y = month <= 2 ? year - 1 : year;
57
+ const era = Math.floor(y / 400);
58
+ const yearOfEra = y - era * 400;
59
+ const dayOfYear = Math.floor((153 * (month + (month > 2 ? -3 : 9)) + 2) / 5) + day - 1;
60
+ const dayOfEra = yearOfEra * 365 + Math.floor(yearOfEra / 4) - Math.floor(yearOfEra / 100) + dayOfYear;
61
+ return era * 146_097 + dayOfEra - 719_468;
62
+ }
63
+ /**
64
+ * Formats a cell's value: in the reader's zone once mounted, and on the server and while hydrating in a zone that
65
+ * does not depend on where they run. The text can still differ between engines (Node joins a date and a time with
66
+ * ", ", WebKit with " at "), so the cell lets hydration differ in its text and writes the reader's text once mounted.
67
+ */
68
+ function dateTimeFormatter(options) {
69
+ const formatOptions = options ?? {
20
70
  year: "numeric",
21
71
  month: "short",
22
72
  day: "numeric",
23
73
  hour: "2-digit",
24
74
  minute: "2-digit",
25
75
  };
26
- const fmt = new Intl.DateTimeFormat("en-US", options ?? defaultOptions);
76
+ const reader = new Intl.DateTimeFormat("en-US", formatOptions);
77
+ // The server knows no reader's time zone: without a timeZone in the options it writes an instant in UTC, and
78
+ // so does the render that takes over the server's markup; the reader's own zone follows right after it.
79
+ const server = formatOptions.timeZone ? reader : new Intl.DateTimeFormat("en-US", { ...formatOptions, timeZone: "UTC" });
80
+ // A written date names no zone, so none is printed: a long or full time would add one, a medium one does not.
81
+ const zoneless = formatOptions.timeStyle === "long" || formatOptions.timeStyle === "full" ? "medium" : formatOptions.timeStyle;
82
+ const written = new Intl.DateTimeFormat("en-US", { ...formatOptions, timeZone: "UTC", timeZoneName: undefined, timeStyle: zoneless });
83
+ return (value, mounted) => {
84
+ const iso = readIsoDate(value);
85
+ if (iso === null)
86
+ return value;
87
+ if (iso)
88
+ return (iso.written ? written : mounted ? reader : server).format(iso.date);
89
+ // Any other way of writing a date each runtime reads its own way, and one that is no date at all none can
90
+ // format: the server and the render that takes over its markup show it as written, the reader's runtime
91
+ // reads it once mounted.
92
+ const date = new Date(value);
93
+ return mounted && !Number.isNaN(date.getTime()) ? reader.format(date) : value;
94
+ };
95
+ }
96
+ export function dateTimeCell(accessor, options) {
97
+ const format = dateTimeFormatter(options);
27
98
  function DateTimeCell({ row }) {
28
99
  const val = accessor(row.original);
29
- return _jsx("span", { style: { color: "var(--color-text-secondary)" }, children: val ? fmt.format(new Date(val)) : "—" });
100
+ const client = useSyncExternalStore(subscribeNever, isClient, isServer);
101
+ const text = val ? format(val, client) : "—";
102
+ const span = useRef(null);
103
+ // React keeps the server's words through hydration (it does not patch text it was told may differ) and later
104
+ // writes only what changed since its own first render: where the server's words still stand, the reader's
105
+ // are written once, and a text that already reads the same is left alone, selection and all.
106
+ useLayoutEffect(() => {
107
+ if (span.current && span.current.textContent !== text)
108
+ span.current.textContent = text;
109
+ }, [text]);
110
+ return (_jsx("span", { ref: span, suppressHydrationWarning: true, style: { color: "var(--color-text-secondary)" }, children: text }));
30
111
  }
31
112
  DateTimeCell.displayName = "DateTimeCell";
32
113
  return DateTimeCell;
@@ -1 +1 @@
1
- {"version":3,"file":"columnHelpers.js","sourceRoot":"","sources":["../../../../src/components/DataTable/columnHelpers.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAGZ,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAChC,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAEpC,MAAM,UAAU,MAAM,CAAI,QAA4B;IACpD,SAAS,MAAM,CAAC,EAAE,GAAG,EAA2B;QAC9C,MAAM,KAAK,GAAG,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;QACpC,OAAO,CACL,KAAC,WAAW,IAAC,SAAS,EAAE,KAAK,YAC3B,eACE,KAAK,EAAE;oBACL,UAAU,EAAE,2CAA2C;oBACvD,KAAK,EAAE,6BAA6B;oBACpC,MAAM,EAAE,SAAS;iBAClB,YAEA,KAAK,GACD,GACK,CACf,CAAA;IACH,CAAC;IACD,MAAM,CAAC,WAAW,GAAG,QAAQ,CAAA;IAC7B,OAAO,MAAM,CAAA;AACf,CAAC;AAED,MAAM,UAAU,YAAY,CAC1B,QAA+C,EAC/C,OAAoC;IAEpC,MAAM,cAAc,GAA+B;QACjD,IAAI,EAAE,SAAS;QACf,KAAK,EAAE,OAAO;QACd,GAAG,EAAE,SAAS;QACd,IAAI,EAAE,SAAS;QACf,MAAM,EAAE,SAAS;KAClB,CAAA;IACD,MAAM,GAAG,GAAG,IAAI,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,OAAO,IAAI,cAAc,CAAC,CAAA;IAEvE,SAAS,YAAY,CAAC,EAAE,GAAG,EAA2B;QACpD,MAAM,GAAG,GAAG,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;QAClC,OAAO,eAAM,KAAK,EAAE,EAAE,KAAK,EAAE,6BAA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GAAQ,GAChF,CACX,CAAA;IACH,CAAC;IACD,aAAa,CAAC,WAAW,GAAG,eAAe,CAAA;IAC3C,OAAO,aAAa,CAAA;AACtB,CAAC","sourcesContent":["\"use client\"\n\nimport type { CellContext } from \"@tanstack/react-table\"\nimport { Badge } from \"../Badge\"\nimport { CopyTooltip } from \"../Tooltip\"\nimport { Tooltip } from \"../Tooltip\"\n\nexport function idCell<T>(accessor: (row: T) => string) {\n function IdCell({ row }: CellContext<T, unknown>) {\n const value = accessor(row.original)\n return (\n <CopyTooltip copyValue={value}>\n <span\n style={{\n fontFamily: \"var(--font-mono, ui-monospace, monospace)\",\n color: \"var(--color-text-secondary)\",\n cursor: \"pointer\",\n }}\n >\n {value}\n </span>\n </CopyTooltip>\n )\n }\n IdCell.displayName = \"IdCell\"\n return IdCell\n}\n\nexport function dateTimeCell<T>(\n accessor: (row: T) => string | null | undefined,\n options?: Intl.DateTimeFormatOptions,\n) {\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 function DateTimeCell({ row }: CellContext<T, unknown>) {\n const val = accessor(row.original)\n return <span style={{ color: \"var(--color-text-secondary)\" }}>{val ? fmt.format(new Date(val)) : \"—\"}</span>\n }\n DateTimeCell.displayName = \"DateTimeCell\"\n return DateTimeCell\n}\n\nexport function statusCell<T>(\n accessor: (row: T) => string,\n colorMap?: Record<\n string,\n \"secondary\" | \"success\" | \"danger\" | \"warning\" | \"info\" | \"discovery\" | \"caution\"\n >,\n) {\n const defaultColorMap: Record<\n string,\n \"secondary\" | \"success\" | \"danger\" | \"warning\" | \"info\" | \"discovery\" | \"caution\"\n > = {\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 function StatusCell({ row }: CellContext<T, unknown>) {\n const status = accessor(row.original)\n const map = colorMap ?? defaultColorMap\n const color = map[status.toLowerCase()] ?? \"secondary\"\n return (\n <Badge color={color} variant=\"soft\">\n {status}\n </Badge>\n )\n }\n StatusCell.displayName = \"StatusCell\"\n return StatusCell\n}\n\nexport function tooltipHeader(label: string, description: string) {\n function TooltipHeader() {\n return (\n <Tooltip content={description} side=\"bottom\" maxWidth={260}>\n <span style={{ cursor: \"help\", borderBottom: \"1px dashed currentColor\" }}>{label}</span>\n </Tooltip>\n )\n }\n TooltipHeader.displayName = \"TooltipHeader\"\n return TooltipHeader\n}\n"]}
1
+ {"version":3,"file":"columnHelpers.js","sourceRoot":"","sources":["../../../../src/components/DataTable/columnHelpers.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAGZ,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAA;AACrE,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAChC,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAEpC,MAAM,UAAU,MAAM,CAAI,QAA4B;IACpD,SAAS,MAAM,CAAC,EAAE,GAAG,EAA2B;QAC9C,MAAM,KAAK,GAAG,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;QACpC,OAAO,CACL,KAAC,WAAW,IAAC,SAAS,EAAE,KAAK,YAC3B,eACE,KAAK,EAAE;oBACL,UAAU,EAAE,2CAA2C;oBACvD,KAAK,EAAE,6BAA6B;oBACpC,MAAM,EAAE,SAAS;iBAClB,YAEA,KAAK,GACD,GACK,CACf,CAAA;IACH,CAAC;IACD,MAAM,CAAC,WAAW,GAAG,QAAQ,CAAA;IAC7B,OAAO,MAAM,CAAA;AACf,CAAC;AAED,MAAM,cAAc,GAAG,GAAG,EAAE,CAAC,GAAG,EAAE,GAAE,CAA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QAAQ,EAAE,WAAW;QACrB,SAAS,EAAE,QAAQ;QACnB,MAAM,EAAE,QAAQ;QAChB,MAAM,EAAE,QAAQ;KACjB,CAAA;IAED,SAAS,UAAU,CAAC,EAAE,GAAG,EAA2B;QAClD,MAAM,MAAM,GAAG,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;QACrC,MAAM,GAAG,GAAG,QAAQ,IAAI,eAAe,CAAA;QACvC,MAAM,KAAK,GAAG,GAAG,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,IAAI,WAAW,CAAA;QACtD,OAAO,CACL,KAAC,KAAK,IAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAC,MAAM,YAChC,MAAM,GACD,CACT,CAAA;IACH,CAAC;IACD,UAAU,CAAC,WAAW,GAAG,YAAY,CAAA;IACrC,OAAO,UAAU,CAAA;AACnB,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,KAAa,EAAE,WAAmB;IAC9D,SAAS,aAAa;QACpB,OAAO,CACL,KAAC,OAAO,IAAC,OAAO,EAAE,WAAW,EAAE,IAAI,EAAC,QAAQ,EAAC,QAAQ,EAAE,GAAG,YACxD,eAAM,KAAK,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,yBAAyB,EAAE,YAAG,KAAK,GAAQ,GAChF,CACX,CAAA;IACH,CAAC;IACD,aAAa,CAAC,WAAW,GAAG,eAAe,CAAA;IAC3C,OAAO,aAAa,CAAA;AACtB,CAAC","sourcesContent":["\"use client\"\n\nimport type { CellContext } from \"@tanstack/react-table\"\nimport { useLayoutEffect, useRef, useSyncExternalStore } from \"react\"\nimport { Badge } from \"../Badge\"\nimport { CopyTooltip } from \"../Tooltip\"\nimport { Tooltip } from \"../Tooltip\"\n\nexport function idCell<T>(accessor: (row: T) => string) {\n function IdCell({ row }: CellContext<T, unknown>) {\n const value = accessor(row.original)\n return (\n <CopyTooltip copyValue={value}>\n <span\n style={{\n fontFamily: \"var(--font-mono, ui-monospace, monospace)\",\n color: \"var(--color-text-secondary)\",\n cursor: \"pointer\",\n }}\n >\n {value}\n </span>\n </CopyTooltip>\n )\n }\n IdCell.displayName = \"IdCell\"\n return IdCell\n}\n\nconst subscribeNever = () => () => {}\nconst isClient = () => true\nconst isServer = () => false\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 right after it.\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\nexport function dateTimeCell<T>(\n accessor: (row: T) => string | null | undefined,\n options?: Intl.DateTimeFormatOptions,\n) {\n const format = dateTimeFormatter(options)\n\n function DateTimeCell({ row }: CellContext<T, unknown>) {\n const val = accessor(row.original)\n const client = useSyncExternalStore(subscribeNever, isClient, isServer)\n const text = val ? format(val, client) : \"—\"\n const span = useRef<HTMLSpanElement>(null)\n // React keeps the server's words through hydration (it does not patch text it was told may differ) and later\n // writes only what changed since its own first render: where the server's words still stand, the reader's\n // are written once, and a text that already reads the same is left alone, selection and all.\n useLayoutEffect(() => {\n if (span.current && span.current.textContent !== text) span.current.textContent = text\n }, [text])\n return (\n <span ref={span} suppressHydrationWarning style={{ color: \"var(--color-text-secondary)\" }}>\n {text}\n </span>\n )\n }\n DateTimeCell.displayName = \"DateTimeCell\"\n return DateTimeCell\n}\n\nexport function statusCell<T>(\n accessor: (row: T) => string,\n colorMap?: Record<\n string,\n \"secondary\" | \"success\" | \"danger\" | \"warning\" | \"info\" | \"discovery\" | \"caution\"\n >,\n) {\n const defaultColorMap: Record<\n string,\n \"secondary\" | \"success\" | \"danger\" | \"warning\" | \"info\" | \"discovery\" | \"caution\"\n > = {\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 function StatusCell({ row }: CellContext<T, unknown>) {\n const status = accessor(row.original)\n const map = colorMap ?? defaultColorMap\n const color = map[status.toLowerCase()] ?? \"secondary\"\n return (\n <Badge color={color} variant=\"soft\">\n {status}\n </Badge>\n )\n }\n StatusCell.displayName = \"StatusCell\"\n return StatusCell\n}\n\nexport function tooltipHeader(label: string, description: string) {\n function TooltipHeader() {\n return (\n <Tooltip content={description} side=\"bottom\" maxWidth={260}>\n <span style={{ cursor: \"help\", borderBottom: \"1px dashed currentColor\" }}>{label}</span>\n </Tooltip>\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/ui",
3
- "version": "0.40.0",
3
+ "version": "0.42.0",
4
4
  "description": "Modern design system for building high-quality applications",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -99,7 +99,7 @@
99
99
  "@maskito/core": "^5.2.2",
100
100
  "@maskito/kit": "^5.2.2",
101
101
  "@maskito/react": "^5.2.2",
102
- "@plexui/styles": "^0.1.44",
102
+ "@plexui/styles": "^0.1.46",
103
103
  "@radix-ui/react-dismissable-layer": "1.2.1",
104
104
  "@radix-ui/react-focus-guards": "1.2.0",
105
105
  "@radix-ui/react-focus-scope": "1.3.1",