@mediaradar/design-components 0.22.0 → 0.24.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/index.cjs +98 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +113 -4
- package/dist/index.d.ts +113 -4
- package/dist/index.js +97 -4
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
package/dist/index.cjs
CHANGED
|
@@ -34,6 +34,7 @@ __export(index_exports, {
|
|
|
34
34
|
ChipContent: () => ChipContent,
|
|
35
35
|
DEFAULT_SEARCH_MATCH: () => DEFAULT_SEARCH_MATCH,
|
|
36
36
|
DataScopeFilter: () => DataScopeFilter,
|
|
37
|
+
DataTable: () => DataTable,
|
|
37
38
|
DateRangeFilter: () => DateRangeFilter,
|
|
38
39
|
DateRangePicker: () => DateRangePicker,
|
|
39
40
|
Delta: () => Delta,
|
|
@@ -786,7 +787,7 @@ function slug2(value) {
|
|
|
786
787
|
return value.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/(^-|-$)/g, "");
|
|
787
788
|
}
|
|
788
789
|
function DateRangeFilter({
|
|
789
|
-
caption = "Date
|
|
790
|
+
caption = "Date range",
|
|
790
791
|
defaultValue,
|
|
791
792
|
value: controlledValue,
|
|
792
793
|
range: controlledRange,
|
|
@@ -924,9 +925,9 @@ function DateRangeFilter({
|
|
|
924
925
|
)) }),
|
|
925
926
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "flex flex-col p-4", children: [
|
|
926
927
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "flex items-end gap-3", children: [
|
|
927
|
-
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Field, { label: "Start
|
|
928
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Field, { label: "Start date", value: start ? fmt(start) : "\u2014" }),
|
|
928
929
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "pb-2.5 text-text-tertiary", children: "\u2014" }),
|
|
929
|
-
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Field, { label: "End
|
|
930
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Field, { label: "End date", value: end ? fmt(end) : start ? fmt(start) : "\u2014" })
|
|
930
931
|
] }),
|
|
931
932
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "my-4 border-t border-border-default" }),
|
|
932
933
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "flex gap-8", children: [0, 1].map((offset) => {
|
|
@@ -3744,7 +3745,7 @@ function DateRangePicker({
|
|
|
3744
3745
|
p
|
|
3745
3746
|
)),
|
|
3746
3747
|
/* @__PURE__ */ (0, import_jsx_runtime37.jsxs)("div", { className: "mt-1 border-t border-border-default px-3 pb-2 pt-2", children: [
|
|
3747
|
-
/* @__PURE__ */ (0, import_jsx_runtime37.jsx)("div", { className: "text-[13px] font-semibold text-text-primary", children: "Custom
|
|
3748
|
+
/* @__PURE__ */ (0, import_jsx_runtime37.jsx)("div", { className: "text-[13px] font-semibold text-text-primary", children: "Custom range" }),
|
|
3748
3749
|
/* @__PURE__ */ (0, import_jsx_runtime37.jsxs)("div", { className: "mt-2 flex flex-col gap-2", children: [
|
|
3749
3750
|
/* @__PURE__ */ (0, import_jsx_runtime37.jsxs)("label", { className: "flex items-center justify-between gap-2 text-[12px] text-text-secondary", children: [
|
|
3750
3751
|
"From",
|
|
@@ -4403,6 +4404,98 @@ var TextField = (0, import_react21.forwardRef)(
|
|
|
4403
4404
|
}
|
|
4404
4405
|
);
|
|
4405
4406
|
TextField.displayName = "TextField";
|
|
4407
|
+
|
|
4408
|
+
// src/DataTable.tsx
|
|
4409
|
+
var import_react22 = require("react");
|
|
4410
|
+
var import_jsx_runtime48 = require("react/jsx-runtime");
|
|
4411
|
+
var WIDTH2 = { fill: "", sm: "w-24", md: "w-36", lg: "w-48" };
|
|
4412
|
+
var MAX_H = { sm: "max-h-80", md: "max-h-120", lg: "max-h-160" };
|
|
4413
|
+
var HEAD_PAD = { default: "px-4 py-3", compact: "px-3 py-2" };
|
|
4414
|
+
var CELL_PAD = { default: "px-4 py-3.5", compact: "px-3 py-2" };
|
|
4415
|
+
function DataTable({
|
|
4416
|
+
columns,
|
|
4417
|
+
rows,
|
|
4418
|
+
rowKey,
|
|
4419
|
+
title,
|
|
4420
|
+
subtitle,
|
|
4421
|
+
action,
|
|
4422
|
+
sort = null,
|
|
4423
|
+
onSortChange,
|
|
4424
|
+
density = "default",
|
|
4425
|
+
loading = false,
|
|
4426
|
+
loadingRows = 5,
|
|
4427
|
+
empty,
|
|
4428
|
+
maxHeight,
|
|
4429
|
+
footer,
|
|
4430
|
+
className,
|
|
4431
|
+
...rest
|
|
4432
|
+
}) {
|
|
4433
|
+
const titleId = (0, import_react22.useId)();
|
|
4434
|
+
const head = HEAD_PAD[density];
|
|
4435
|
+
const pad = CELL_PAD[density];
|
|
4436
|
+
const align = (c) => c.numeric ? "text-right" : "text-left";
|
|
4437
|
+
const width = (c) => WIDTH2[c.width ?? (c.numeric ? "md" : "fill")];
|
|
4438
|
+
const onSort = (key) => {
|
|
4439
|
+
const col = columns.find((c) => c.key === key);
|
|
4440
|
+
onSortChange?.(cycleSort(sort, key, col?.firstDir ?? (col?.numeric ? "desc" : "asc")));
|
|
4441
|
+
};
|
|
4442
|
+
return /* @__PURE__ */ (0, import_jsx_runtime48.jsxs)("div", { className: cn("flex w-full flex-col overflow-hidden rounded-card border border-border-default bg-surface", className), children: [
|
|
4443
|
+
title && /* @__PURE__ */ (0, import_jsx_runtime48.jsxs)("div", { className: "flex items-start justify-between gap-2 p-card-padding", children: [
|
|
4444
|
+
/* @__PURE__ */ (0, import_jsx_runtime48.jsxs)("div", { className: "min-w-0", children: [
|
|
4445
|
+
/* @__PURE__ */ (0, import_jsx_runtime48.jsx)("h3", { id: titleId, className: "text-style-card-title", children: title }),
|
|
4446
|
+
subtitle && /* @__PURE__ */ (0, import_jsx_runtime48.jsx)("p", { className: "mt-0.5 text-xs text-text-tertiary", children: subtitle })
|
|
4447
|
+
] }),
|
|
4448
|
+
action && /* @__PURE__ */ (0, import_jsx_runtime48.jsx)("div", { className: "shrink-0", children: action })
|
|
4449
|
+
] }),
|
|
4450
|
+
/* @__PURE__ */ (0, import_jsx_runtime48.jsx)("div", { className: cn("overflow-x-auto", maxHeight && cn("overflow-y-auto", MAX_H[maxHeight])), children: /* @__PURE__ */ (0, import_jsx_runtime48.jsxs)(
|
|
4451
|
+
"table",
|
|
4452
|
+
{
|
|
4453
|
+
"aria-labelledby": title ? titleId : void 0,
|
|
4454
|
+
"aria-label": title ? void 0 : rest["aria-label"],
|
|
4455
|
+
"aria-busy": loading || void 0,
|
|
4456
|
+
className: "w-full border-collapse text-left",
|
|
4457
|
+
children: [
|
|
4458
|
+
/* @__PURE__ */ (0, import_jsx_runtime48.jsx)("thead", { className: cn(maxHeight && "sticky top-0 z-10"), children: /* @__PURE__ */ (0, import_jsx_runtime48.jsx)("tr", { className: "bg-subtle text-micro font-semibold uppercase tracking-wider text-text-secondary", children: columns.map((c) => /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(
|
|
4459
|
+
"th",
|
|
4460
|
+
{
|
|
4461
|
+
scope: "col",
|
|
4462
|
+
"aria-sort": c.sortable ? ariaSortFor(sort, c.key) : void 0,
|
|
4463
|
+
className: cn("border-b border-border-default font-semibold", head, align(c), width(c)),
|
|
4464
|
+
children: c.sortable && onSortChange ? /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(
|
|
4465
|
+
SortButton,
|
|
4466
|
+
{
|
|
4467
|
+
label: c.label,
|
|
4468
|
+
sortKey: c.key,
|
|
4469
|
+
align: c.numeric ? "right" : "left",
|
|
4470
|
+
sort: sortProp(sort),
|
|
4471
|
+
onSort
|
|
4472
|
+
}
|
|
4473
|
+
) : c.label
|
|
4474
|
+
},
|
|
4475
|
+
c.key
|
|
4476
|
+
)) }) }),
|
|
4477
|
+
/* @__PURE__ */ (0, import_jsx_runtime48.jsx)("tbody", { className: "text-dense text-text-primary", children: loading ? Array.from({ length: loadingRows }, (_, i) => /* @__PURE__ */ (0, import_jsx_runtime48.jsx)("tr", { "aria-hidden": "true", className: "[&:last-child>td]:border-b-0", children: columns.map((c) => /* @__PURE__ */ (0, import_jsx_runtime48.jsx)("td", { className: cn("border-b border-border-default", pad, align(c)), children: /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(
|
|
4478
|
+
"span",
|
|
4479
|
+
{
|
|
4480
|
+
className: cn(
|
|
4481
|
+
"inline-block h-3 animate-pulse rounded-full bg-subtle",
|
|
4482
|
+
c.numeric ? "w-12" : "w-2/3"
|
|
4483
|
+
)
|
|
4484
|
+
}
|
|
4485
|
+
) }, c.key)) }, i)) : rows.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime48.jsx)("tr", { children: /* @__PURE__ */ (0, import_jsx_runtime48.jsx)("td", { colSpan: columns.length, children: empty ?? /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(NoResultsEmptyState, {}) }) }) : rows.map((row) => /* @__PURE__ */ (0, import_jsx_runtime48.jsx)("tr", { className: "hover:bg-subtle [&:last-child>td]:border-b-0", children: columns.map((c) => /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(
|
|
4486
|
+
"td",
|
|
4487
|
+
{
|
|
4488
|
+
className: cn("border-b border-border-default", pad, align(c), c.numeric && "tabular-nums"),
|
|
4489
|
+
children: c.cell(row)
|
|
4490
|
+
},
|
|
4491
|
+
c.key
|
|
4492
|
+
)) }, rowKey(row))) })
|
|
4493
|
+
]
|
|
4494
|
+
}
|
|
4495
|
+
) }),
|
|
4496
|
+
footer && /* @__PURE__ */ (0, import_jsx_runtime48.jsx)("div", { className: "border-t border-border-default px-4 py-3", children: footer })
|
|
4497
|
+
] });
|
|
4498
|
+
}
|
|
4406
4499
|
// Annotate the CommonJS export names for ESM import in node:
|
|
4407
4500
|
0 && (module.exports = {
|
|
4408
4501
|
AISpark,
|
|
@@ -4418,6 +4511,7 @@ TextField.displayName = "TextField";
|
|
|
4418
4511
|
ChipContent,
|
|
4419
4512
|
DEFAULT_SEARCH_MATCH,
|
|
4420
4513
|
DataScopeFilter,
|
|
4514
|
+
DataTable,
|
|
4421
4515
|
DateRangeFilter,
|
|
4422
4516
|
DateRangePicker,
|
|
4423
4517
|
Delta,
|