@mediaradar/design-components 0.55.0 → 0.57.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/approved-components.json +1 -1
- package/dist/index.cjs +150 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +84 -2
- package/dist/index.d.ts +84 -2
- package/dist/index.js +138 -14
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -97,6 +97,18 @@ __export(index_exports, {
|
|
|
97
97
|
buttonVariants: () => buttonVariants,
|
|
98
98
|
chipTriggerClass: () => chipTriggerClass,
|
|
99
99
|
cycleSort: () => cycleSort,
|
|
100
|
+
defaultDateOrder: () => defaultDateOrder,
|
|
101
|
+
formatDate: () => formatDate,
|
|
102
|
+
formatDateRange: () => formatDateRange,
|
|
103
|
+
formatDateTime: () => formatDateTime,
|
|
104
|
+
formatIsoDate: () => formatIsoDate,
|
|
105
|
+
formatMonth: () => formatMonth,
|
|
106
|
+
formatMonthAxis: () => formatMonthAxis,
|
|
107
|
+
formatOpenRange: () => formatOpenRange,
|
|
108
|
+
formatQuarter: () => formatQuarter,
|
|
109
|
+
formatRelative: () => formatRelative,
|
|
110
|
+
formatTime: () => formatTime,
|
|
111
|
+
formatWeek: () => formatWeek,
|
|
100
112
|
noResultsBody: () => noResultsBody,
|
|
101
113
|
resolveRange: () => resolveRange,
|
|
102
114
|
sortProp: () => sortProp
|
|
@@ -965,12 +977,12 @@ function DateRangeFilter({
|
|
|
965
977
|
className,
|
|
966
978
|
testIdPrefix,
|
|
967
979
|
granularity = "day",
|
|
968
|
-
formatDate,
|
|
980
|
+
formatDate: formatDate2,
|
|
969
981
|
formatRange
|
|
970
982
|
}) {
|
|
971
983
|
const monthly = granularity === "month";
|
|
972
|
-
const formatted = !!(
|
|
973
|
-
const showDate =
|
|
984
|
+
const formatted = !!(formatDate2 || formatRange);
|
|
985
|
+
const showDate = formatDate2 ?? fmt;
|
|
974
986
|
const showRange = (s, e) => formatRange ? formatRange(s, e) : sameDay(s, e) ? showDate(s) : `${showDate(s)} \u2013 ${showDate(e)}`;
|
|
975
987
|
const showValue = (v, s, e) => formatted && !monthly && (v === `${fmt(s)} \u2014 ${fmt(e)}` || v === `${fmt(s)} \u2013 ${fmt(e)}`) ? showRange(s, e) : v;
|
|
976
988
|
const snap = (s, e) => monthly ? [firstOfMonth(s), lastOfMonth(e)] : [s, e];
|
|
@@ -2113,10 +2125,12 @@ function SelectFilter({
|
|
|
2113
2125
|
onRetry,
|
|
2114
2126
|
size = "md",
|
|
2115
2127
|
inlineCaption = false,
|
|
2128
|
+
hideCaption = false,
|
|
2116
2129
|
disabled = false,
|
|
2117
2130
|
renderIcon
|
|
2118
2131
|
}) {
|
|
2119
2132
|
const sm = size === "sm";
|
|
2133
|
+
const bare = !sm && hideCaption;
|
|
2120
2134
|
const [open, setOpen] = (0, import_react8.useState)(false);
|
|
2121
2135
|
const [pos, setPos] = (0, import_react8.useState)(null);
|
|
2122
2136
|
const ref = (0, import_react8.useRef)(null);
|
|
@@ -2177,16 +2191,16 @@ function SelectFilter({
|
|
|
2177
2191
|
onClick: () => setOpen((o) => !o),
|
|
2178
2192
|
"aria-expanded": open,
|
|
2179
2193
|
"aria-haspopup": "listbox",
|
|
2180
|
-
"aria-label": sm && !inlineCaption ? caption : void 0,
|
|
2194
|
+
"aria-label": sm && !inlineCaption || bare ? caption : void 0,
|
|
2181
2195
|
disabled,
|
|
2182
2196
|
className: cn(
|
|
2183
|
-
sm ? "flex h-8 items-center gap-1.5 rounded-control border border-border-strong bg-input pl-2.5 pr-2 text-dense font-medium text-text-primary transition-colors hover:bg-subtle focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-border-focus" : chipTriggerClass(),
|
|
2197
|
+
sm ? "flex h-8 items-center gap-1.5 rounded-control border border-border-strong bg-input pl-2.5 pr-2 text-dense font-medium text-text-primary transition-colors hover:bg-subtle focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-border-focus" : bare ? "flex h-10 items-center gap-2 rounded-control border border-border-strong bg-input pl-3 pr-2.5 text-sm font-medium text-text-primary transition-colors hover:bg-subtle focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-border-focus" : chipTriggerClass(),
|
|
2184
2198
|
"disabled:pointer-events-none disabled:opacity-40",
|
|
2185
2199
|
fullWidth && "w-full justify-between",
|
|
2186
2200
|
className
|
|
2187
2201
|
),
|
|
2188
2202
|
children: [
|
|
2189
|
-
sm ? triggerValue : /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(ChipContent, { caption, value: triggerValue }),
|
|
2203
|
+
sm || bare ? triggerValue : /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(ChipContent, { caption, value: triggerValue }),
|
|
2190
2204
|
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
2191
2205
|
import_lucide_react11.ChevronDown,
|
|
2192
2206
|
{
|
|
@@ -4511,10 +4525,10 @@ function resolveRange(label, today = startOfToday()) {
|
|
|
4511
4525
|
}
|
|
4512
4526
|
return [new Date(end.getFullYear(), end.getMonth() - 6, 1), end];
|
|
4513
4527
|
}
|
|
4514
|
-
function spanLabel2(label, today,
|
|
4528
|
+
function spanLabel2(label, today, formatDate2, formatRange) {
|
|
4515
4529
|
const [s, e] = resolveRange(label, today);
|
|
4516
4530
|
if (formatRange) return formatRange(s, e);
|
|
4517
|
-
const f =
|
|
4531
|
+
const f = formatDate2 ?? fmtDate;
|
|
4518
4532
|
return `${f(s)} \u2013 ${f(e)}`;
|
|
4519
4533
|
}
|
|
4520
4534
|
function MiniSelect({ value, onChange, options }) {
|
|
@@ -4541,7 +4555,7 @@ function DateRangePicker({
|
|
|
4541
4555
|
showFooter = false,
|
|
4542
4556
|
today,
|
|
4543
4557
|
years,
|
|
4544
|
-
formatDate,
|
|
4558
|
+
formatDate: formatDate2,
|
|
4545
4559
|
formatRange,
|
|
4546
4560
|
className,
|
|
4547
4561
|
testIdPrefix
|
|
@@ -4603,7 +4617,7 @@ function DateRangePicker({
|
|
|
4603
4617
|
className: chipTriggerClass(),
|
|
4604
4618
|
children: [
|
|
4605
4619
|
/* @__PURE__ */ (0, import_jsx_runtime43.jsxs)("span", { className: "flex flex-col gap-1 text-left leading-none", children: [
|
|
4606
|
-
/* @__PURE__ */ (0, import_jsx_runtime43.jsx)("span", { className: "text-control-caption leading-none text-text-tertiary", children: spanLabel2(value, end,
|
|
4620
|
+
/* @__PURE__ */ (0, import_jsx_runtime43.jsx)("span", { className: "text-control-caption leading-none text-text-tertiary", children: spanLabel2(value, end, formatDate2, formatRange) }),
|
|
4607
4621
|
/* @__PURE__ */ (0, import_jsx_runtime43.jsx)("span", { className: "text-xs leading-none font-medium text-text-primary", children: value })
|
|
4608
4622
|
] }),
|
|
4609
4623
|
/* @__PURE__ */ (0, import_jsx_runtime43.jsx)(import_lucide_react23.ChevronDown, { size: 14, "aria-hidden": "true", className: cn("shrink-0 text-text-secondary transition-transform", open && "rotate-180") })
|
|
@@ -5371,7 +5385,7 @@ function DataTable({
|
|
|
5371
5385
|
}) {
|
|
5372
5386
|
const titleId = (0, import_react28.useId)();
|
|
5373
5387
|
const head = HEAD_PAD[density];
|
|
5374
|
-
const
|
|
5388
|
+
const pad2 = CELL_PAD[density];
|
|
5375
5389
|
const align = (c) => c.numeric ? "text-right" : "text-left";
|
|
5376
5390
|
const width = (c) => WIDTH3[c.width ?? (c.numeric ? "md" : "fill")];
|
|
5377
5391
|
const onSort = (key) => {
|
|
@@ -5404,7 +5418,7 @@ function DataTable({
|
|
|
5404
5418
|
{
|
|
5405
5419
|
scope: "col",
|
|
5406
5420
|
"aria-sort": c.sortable ? ariaSortFor(sort, c.key) : void 0,
|
|
5407
|
-
className: cn("border-b border-border-default font-semibold", head, align(c), width(c)),
|
|
5421
|
+
className: cn("whitespace-nowrap border-b border-border-default font-semibold", head, align(c), width(c)),
|
|
5408
5422
|
children: c.sortable && onSortChange ? /* @__PURE__ */ (0, import_jsx_runtime54.jsx)(
|
|
5409
5423
|
SortButton,
|
|
5410
5424
|
{
|
|
@@ -5419,7 +5433,7 @@ function DataTable({
|
|
|
5419
5433
|
},
|
|
5420
5434
|
c.key
|
|
5421
5435
|
)) }) }),
|
|
5422
|
-
/* @__PURE__ */ (0, import_jsx_runtime54.jsx)("tbody", { className: "text-dense text-text-primary", children: loading ? Array.from({ length: loadingRows }, (_, i) => /* @__PURE__ */ (0, import_jsx_runtime54.jsx)("tr", { "aria-hidden": "true", className: "[&:last-child>td]:border-b-0", children: columns.map((c) => /* @__PURE__ */ (0, import_jsx_runtime54.jsx)("td", { className: cn("border-b border-border-default",
|
|
5436
|
+
/* @__PURE__ */ (0, import_jsx_runtime54.jsx)("tbody", { className: "text-dense text-text-primary", children: loading ? Array.from({ length: loadingRows }, (_, i) => /* @__PURE__ */ (0, import_jsx_runtime54.jsx)("tr", { "aria-hidden": "true", className: "[&:last-child>td]:border-b-0", children: columns.map((c) => /* @__PURE__ */ (0, import_jsx_runtime54.jsx)("td", { className: cn("border-b border-border-default", pad2, align(c)), children: /* @__PURE__ */ (0, import_jsx_runtime54.jsx)(
|
|
5423
5437
|
"span",
|
|
5424
5438
|
{
|
|
5425
5439
|
className: cn(
|
|
@@ -5430,7 +5444,7 @@ function DataTable({
|
|
|
5430
5444
|
) }, c.key)) }, i)) : rows.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime54.jsx)("tr", { children: /* @__PURE__ */ (0, import_jsx_runtime54.jsx)("td", { colSpan: columns.length, className: "px-6 py-12", children: empty ?? /* @__PURE__ */ (0, import_jsx_runtime54.jsx)(NoResultsEmptyState, {}) }) }) : rows.map((row) => /* @__PURE__ */ (0, import_jsx_runtime54.jsx)("tr", { className: "hover:bg-subtle [&:last-child>td]:border-b-0", children: columns.map((c) => /* @__PURE__ */ (0, import_jsx_runtime54.jsx)(
|
|
5431
5445
|
"td",
|
|
5432
5446
|
{
|
|
5433
|
-
className: cn("border-b border-border-default",
|
|
5447
|
+
className: cn("border-b border-border-default", pad2, align(c), c.numeric && "tabular-nums"),
|
|
5434
5448
|
children: c.cell(row)
|
|
5435
5449
|
},
|
|
5436
5450
|
c.key
|
|
@@ -5893,6 +5907,116 @@ function MenuLabel({ className, testIdPrefix, children }) {
|
|
|
5893
5907
|
function MenuSeparator({ className, testIdPrefix }) {
|
|
5894
5908
|
return /* @__PURE__ */ (0, import_jsx_runtime62.jsx)("div", { role: "separator", "data-testid": testIdPrefix, className: cn("-mx-1 my-1 border-t border-border-default", className) });
|
|
5895
5909
|
}
|
|
5910
|
+
|
|
5911
|
+
// src/dates.ts
|
|
5912
|
+
var MONTHS2 = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
|
5913
|
+
var MONTHS_LONG = [
|
|
5914
|
+
"January",
|
|
5915
|
+
"February",
|
|
5916
|
+
"March",
|
|
5917
|
+
"April",
|
|
5918
|
+
"May",
|
|
5919
|
+
"June",
|
|
5920
|
+
"July",
|
|
5921
|
+
"August",
|
|
5922
|
+
"September",
|
|
5923
|
+
"October",
|
|
5924
|
+
"November",
|
|
5925
|
+
"December"
|
|
5926
|
+
];
|
|
5927
|
+
var WEEKDAYS2 = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
|
5928
|
+
var EN_DASH = "\u2013";
|
|
5929
|
+
var pad = (n) => String(n).padStart(2, "0");
|
|
5930
|
+
function formatIsoDate(d) {
|
|
5931
|
+
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
|
|
5932
|
+
}
|
|
5933
|
+
function showYear(d, opts) {
|
|
5934
|
+
if (opts.year !== "auto") return true;
|
|
5935
|
+
return d.getFullYear() !== (opts.now ?? /* @__PURE__ */ new Date()).getFullYear();
|
|
5936
|
+
}
|
|
5937
|
+
function formatDate(d, opts = {}) {
|
|
5938
|
+
const order = opts.order ?? "mdy";
|
|
5939
|
+
const weekday = opts.weekday ? `${WEEKDAYS2[d.getDay()]}, ` : "";
|
|
5940
|
+
if (order === "ymd") return weekday + formatIsoDate(d);
|
|
5941
|
+
const mon = (opts.long ? MONTHS_LONG : MONTHS2)[d.getMonth()];
|
|
5942
|
+
const day = d.getDate();
|
|
5943
|
+
const year = showYear(d, opts);
|
|
5944
|
+
if (order === "dmy") return weekday + (year ? `${day} ${mon} ${d.getFullYear()}` : `${day} ${mon}`);
|
|
5945
|
+
return weekday + (year ? `${mon} ${day}, ${d.getFullYear()}` : `${mon} ${day}`);
|
|
5946
|
+
}
|
|
5947
|
+
var sameDay2 = (a, b) => a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate();
|
|
5948
|
+
function formatDateRange(start, end, opts = {}) {
|
|
5949
|
+
const order = opts.order ?? "mdy";
|
|
5950
|
+
if (sameDay2(start, end)) return formatDate(start, opts);
|
|
5951
|
+
const join = (a, b, tight = false) => opts.sentence ? `${a} to ${b}` : tight ? `${a}${EN_DASH}${b}` : `${a} ${EN_DASH} ${b}`;
|
|
5952
|
+
if (order === "ymd") return join(formatIsoDate(start), formatIsoDate(end));
|
|
5953
|
+
const sameYear = start.getFullYear() === end.getFullYear();
|
|
5954
|
+
if (!sameYear) {
|
|
5955
|
+
const full = { ...opts, year: "always" };
|
|
5956
|
+
return join(formatDate(start, full), formatDate(end, full));
|
|
5957
|
+
}
|
|
5958
|
+
const year = showYear(end, opts) ? end.getFullYear() : void 0;
|
|
5959
|
+
const mons = opts.long ? MONTHS_LONG : MONTHS2;
|
|
5960
|
+
const ms = mons[start.getMonth()];
|
|
5961
|
+
const me = mons[end.getMonth()];
|
|
5962
|
+
const sameMonth = start.getMonth() === end.getMonth();
|
|
5963
|
+
const s = start.getDate();
|
|
5964
|
+
const e = end.getDate();
|
|
5965
|
+
if (order === "dmy") {
|
|
5966
|
+
const tail2 = year === void 0 ? "" : ` ${year}`;
|
|
5967
|
+
return sameMonth ? `${join(String(s), String(e), true)} ${me}${tail2}` : `${join(`${s} ${ms}`, `${e} ${me}`)}${tail2}`;
|
|
5968
|
+
}
|
|
5969
|
+
const tail = year === void 0 ? "" : `, ${year}`;
|
|
5970
|
+
return sameMonth ? `${join(`${ms} ${s}`, String(e))}${tail}` : `${join(`${ms} ${s}`, `${me} ${e}`)}${tail}`;
|
|
5971
|
+
}
|
|
5972
|
+
function formatOpenRange(start, end, opts = {}) {
|
|
5973
|
+
if (start && end) return formatDateRange(start, end, opts);
|
|
5974
|
+
if (start) return `Since ${formatDate(start, opts)}`;
|
|
5975
|
+
if (end) return `Until ${formatDate(end, opts)}`;
|
|
5976
|
+
return "";
|
|
5977
|
+
}
|
|
5978
|
+
function formatTime(d, opts = {}) {
|
|
5979
|
+
const h = d.getHours();
|
|
5980
|
+
const m = pad(d.getMinutes());
|
|
5981
|
+
if ((opts.order ?? "mdy") !== "mdy") return `${pad(h)}:${m}`;
|
|
5982
|
+
return `${h % 12 || 12}:${m} ${h < 12 ? "AM" : "PM"}`;
|
|
5983
|
+
}
|
|
5984
|
+
function formatDateTime(d, opts = {}) {
|
|
5985
|
+
return `${formatDate(d, opts)}, ${formatTime(d, opts)}`;
|
|
5986
|
+
}
|
|
5987
|
+
function formatMonth(d) {
|
|
5988
|
+
return `${MONTHS2[d.getMonth()]} ${d.getFullYear()}`;
|
|
5989
|
+
}
|
|
5990
|
+
function formatQuarter(d) {
|
|
5991
|
+
return `Q${Math.floor(d.getMonth() / 3) + 1} ${d.getFullYear()}`;
|
|
5992
|
+
}
|
|
5993
|
+
function formatWeek(firstDay, opts = {}) {
|
|
5994
|
+
return `Week of ${formatDate(firstDay, { ...opts, year: opts.year ?? "auto" })}`;
|
|
5995
|
+
}
|
|
5996
|
+
function formatMonthAxis(months) {
|
|
5997
|
+
return months.map((d, i) => {
|
|
5998
|
+
const changed = i === 0 || d.getFullYear() !== months[i - 1].getFullYear();
|
|
5999
|
+
return { month: MONTHS2[d.getMonth()], year: changed ? String(d.getFullYear()) : void 0 };
|
|
6000
|
+
});
|
|
6001
|
+
}
|
|
6002
|
+
var DAY_MS = 864e5;
|
|
6003
|
+
var startOfDay2 = (d) => new Date(d.getFullYear(), d.getMonth(), d.getDate()).getTime();
|
|
6004
|
+
function formatRelative(d, opts = {}) {
|
|
6005
|
+
const now = opts.now ?? /* @__PURE__ */ new Date();
|
|
6006
|
+
const ms = now.getTime() - d.getTime();
|
|
6007
|
+
if (ms < 0) return formatDate(d, opts);
|
|
6008
|
+
if (ms < 6e4) return "Just now";
|
|
6009
|
+
if (ms < 36e5) return `${Math.floor(ms / 6e4)} min ago`;
|
|
6010
|
+
if (ms < DAY_MS) return `${Math.floor(ms / 36e5)} hr ago`;
|
|
6011
|
+
const days = Math.round((startOfDay2(now) - startOfDay2(d)) / DAY_MS);
|
|
6012
|
+
if (days <= 1) return "Yesterday";
|
|
6013
|
+
if (days <= 7) return `${days} days ago`;
|
|
6014
|
+
return formatDate(d, opts);
|
|
6015
|
+
}
|
|
6016
|
+
function defaultDateOrder(country) {
|
|
6017
|
+
const c = (country ?? "").toUpperCase();
|
|
6018
|
+
return c === "US" || c === "CA" || c === "" ? "mdy" : "dmy";
|
|
6019
|
+
}
|
|
5896
6020
|
// Annotate the CommonJS export names for ESM import in node:
|
|
5897
6021
|
0 && (module.exports = {
|
|
5898
6022
|
AISpark,
|
|
@@ -5971,6 +6095,18 @@ function MenuSeparator({ className, testIdPrefix }) {
|
|
|
5971
6095
|
buttonVariants,
|
|
5972
6096
|
chipTriggerClass,
|
|
5973
6097
|
cycleSort,
|
|
6098
|
+
defaultDateOrder,
|
|
6099
|
+
formatDate,
|
|
6100
|
+
formatDateRange,
|
|
6101
|
+
formatDateTime,
|
|
6102
|
+
formatIsoDate,
|
|
6103
|
+
formatMonth,
|
|
6104
|
+
formatMonthAxis,
|
|
6105
|
+
formatOpenRange,
|
|
6106
|
+
formatQuarter,
|
|
6107
|
+
formatRelative,
|
|
6108
|
+
formatTime,
|
|
6109
|
+
formatWeek,
|
|
5974
6110
|
noResultsBody,
|
|
5975
6111
|
resolveRange,
|
|
5976
6112
|
sortProp
|