@makoai/app-sdk 2.27.0 → 2.29.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/README.md +142 -1
- package/components/combobox.tsx +150 -0
- package/components/filter-bar.tsx +15 -6
- package/components/index.ts +4 -1
- package/components/period-picker.tsx +54 -24
- package/components/period.ts +54 -5
- package/index.d.ts +4 -2
- package/index.js +10 -1
- package/locale.d.ts +122 -0
- package/locale.js +178 -0
- package/menu/filter-menu.tsx +26 -8
- package/package.json +7 -1
- package/ui-core.js +3 -1
- package/ui.css +53 -0
- package/ui.d.ts +77 -1
- package/ui.js +319 -46
package/ui.js
CHANGED
|
@@ -53,7 +53,9 @@ import {
|
|
|
53
53
|
tooltipSeriesRows,
|
|
54
54
|
tooltipValueState,
|
|
55
55
|
} from "./ui-core.js";
|
|
56
|
+
import { localeLang, localeStrings } from "./locale.js";
|
|
56
57
|
|
|
58
|
+
export { LOCALES, STRINGS, localeLang, localeStrings } from "./locale.js";
|
|
57
59
|
export { formatDate, formatTime, toDayKey, toInstant } from "./time.js";
|
|
58
60
|
export {
|
|
59
61
|
closePopovers,
|
|
@@ -145,28 +147,26 @@ const IconRefresh = () =>
|
|
|
145
147
|
const PHONE = "(max-width: 640px)";
|
|
146
148
|
|
|
147
149
|
/**
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
* their pointerdown, so an outside mousedown/click listener never hears them.
|
|
153
|
-
*
|
|
154
|
-
* It also keeps the `.mk-pop` inside `wrapRef` within the viewport: it opens
|
|
155
|
-
* under its trigger aligned to `align`, flips to the other edge when that
|
|
156
|
-
* would overflow, and as a last resort is pinned to the viewport margin. On
|
|
157
|
-
* phones the popover is a bottom sheet (CSS) and is left alone.
|
|
150
|
+
* The closing half of usePopover: one kit popover at a time, Escape, a
|
|
151
|
+
* pointerdown or focus outside `wrapRef`. A portalled panel passes its own
|
|
152
|
+
* ref as `panelRef`, so a click inside it counts as inside. `onEscape` runs
|
|
153
|
+
* after an Escape close (the header info returns focus to its button).
|
|
158
154
|
*/
|
|
159
|
-
function
|
|
155
|
+
function usePopoverDismiss(open, setOpen, wrapRef, panelRef, onEscape) {
|
|
160
156
|
React.useEffect(() => {
|
|
161
157
|
if (!open) return undefined;
|
|
162
158
|
const close = () => setOpen(false);
|
|
163
159
|
claimPopover(close);
|
|
164
160
|
const outside = e => {
|
|
165
161
|
const wrap = wrapRef.current;
|
|
162
|
+
if (panelRef?.current && e.target instanceof Node && panelRef.current.contains(e.target)) return;
|
|
166
163
|
if (wrap && e.target instanceof Node && !wrap.contains(e.target)) close();
|
|
167
164
|
};
|
|
168
165
|
const onKey = e => {
|
|
169
|
-
if (e.key === "Escape")
|
|
166
|
+
if (e.key === "Escape") {
|
|
167
|
+
close();
|
|
168
|
+
onEscape?.();
|
|
169
|
+
}
|
|
170
170
|
};
|
|
171
171
|
document.addEventListener("pointerdown", outside, true);
|
|
172
172
|
document.addEventListener("focusin", outside, true);
|
|
@@ -177,7 +177,23 @@ function usePopover(open, setOpen, wrapRef, align) {
|
|
|
177
177
|
document.removeEventListener("focusin", outside, true);
|
|
178
178
|
document.removeEventListener("keydown", onKey);
|
|
179
179
|
};
|
|
180
|
-
}, [open, setOpen, wrapRef]);
|
|
180
|
+
}, [open, setOpen, wrapRef]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* One kit popover is open at a time: opening this one closes any other (a
|
|
185
|
+
* module-level registry, see claimPopover). It closes on Escape, on a
|
|
186
|
+
* pointerdown outside it, and when focus moves outside it. Pointerdown, in
|
|
187
|
+
* the capture phase, because Radix menu triggers cancel the mouse events of
|
|
188
|
+
* their pointerdown, so an outside mousedown/click listener never hears them.
|
|
189
|
+
*
|
|
190
|
+
* It also keeps the `.mk-pop` inside `wrapRef` within the viewport: it opens
|
|
191
|
+
* under its trigger aligned to `align`, flips to the other edge when that
|
|
192
|
+
* would overflow, and as a last resort is pinned to the viewport margin. On
|
|
193
|
+
* phones the popover is a bottom sheet (CSS) and is left alone.
|
|
194
|
+
*/
|
|
195
|
+
function usePopover(open, setOpen, wrapRef, align) {
|
|
196
|
+
usePopoverDismiss(open, setOpen, wrapRef);
|
|
181
197
|
|
|
182
198
|
React.useLayoutEffect(() => {
|
|
183
199
|
if (!open) return undefined;
|
|
@@ -414,6 +430,98 @@ const IconSort = ({ dir }) =>
|
|
|
414
430
|
dir ? undefined : "mk-dt-faint",
|
|
415
431
|
);
|
|
416
432
|
|
|
433
|
+
const IconInfo = () =>
|
|
434
|
+
svg(12, 2, [
|
|
435
|
+
h("circle", { key: "c", cx: 12, cy: 12, r: 10 }),
|
|
436
|
+
h("path", { key: "a", d: "M12 16v-4" }),
|
|
437
|
+
h("path", { key: "b", d: "M12 8h.01" }),
|
|
438
|
+
]);
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* A column's "i" (`column.info`): a button beside the header's sort button,
|
|
442
|
+
* never inside it, so a click on it never sorts. It opens a kit popover
|
|
443
|
+
* (`.mk-pop`) portalled to <body>, so the table's scroll box never clips it.
|
|
444
|
+
* Like a Radix Popover, focus moves into the panel on open and Escape returns
|
|
445
|
+
* it to the button. A click or focus outside closes it, as every kit popover.
|
|
446
|
+
*/
|
|
447
|
+
function HeaderInfo({ title, label, children }) {
|
|
448
|
+
const [open, setOpen] = React.useState(false);
|
|
449
|
+
const wrapRef = React.useRef(null);
|
|
450
|
+
const panelRef = React.useRef(null);
|
|
451
|
+
const id = React.useId();
|
|
452
|
+
const refocus = React.useCallback(() => wrapRef.current?.querySelector("button")?.focus(), []);
|
|
453
|
+
usePopoverDismiss(open, setOpen, wrapRef, panelRef, refocus);
|
|
454
|
+
|
|
455
|
+
React.useLayoutEffect(() => {
|
|
456
|
+
if (!open) return undefined;
|
|
457
|
+
const place = () => {
|
|
458
|
+
const pop = panelRef.current;
|
|
459
|
+
const btn = wrapRef.current;
|
|
460
|
+
if (!pop || !btn) return;
|
|
461
|
+
pop.style.left = "";
|
|
462
|
+
pop.style.top = "";
|
|
463
|
+
if (window.matchMedia(PHONE).matches) return;
|
|
464
|
+
const margin = 8;
|
|
465
|
+
const r = btn.getBoundingClientRect();
|
|
466
|
+
const w = pop.offsetWidth;
|
|
467
|
+
const ht = pop.offsetHeight;
|
|
468
|
+
const left = Math.min(Math.max(margin, r.left + r.width / 2 - w / 2), window.innerWidth - w - margin);
|
|
469
|
+
const below = r.bottom + 6;
|
|
470
|
+
const top = below + ht > window.innerHeight - margin && r.top - 6 - ht >= margin ? r.top - 6 - ht : below;
|
|
471
|
+
pop.style.left = `${left}px`;
|
|
472
|
+
pop.style.top = `${top}px`;
|
|
473
|
+
};
|
|
474
|
+
place();
|
|
475
|
+
panelRef.current?.focus({ preventScroll: true });
|
|
476
|
+
window.addEventListener("resize", place);
|
|
477
|
+
window.addEventListener("scroll", place, true);
|
|
478
|
+
return () => {
|
|
479
|
+
window.removeEventListener("resize", place);
|
|
480
|
+
window.removeEventListener("scroll", place, true);
|
|
481
|
+
};
|
|
482
|
+
}, [open]);
|
|
483
|
+
|
|
484
|
+
return h(
|
|
485
|
+
"span",
|
|
486
|
+
{ className: "mk-dt-info-wrap", ref: wrapRef },
|
|
487
|
+
h(
|
|
488
|
+
"button",
|
|
489
|
+
{
|
|
490
|
+
type: "button",
|
|
491
|
+
className: cx("mk-dt-info", open && "open"),
|
|
492
|
+
"aria-label": label,
|
|
493
|
+
"aria-haspopup": "dialog",
|
|
494
|
+
"aria-expanded": open,
|
|
495
|
+
"aria-controls": open ? id : undefined,
|
|
496
|
+
onClick: e => {
|
|
497
|
+
e.stopPropagation();
|
|
498
|
+
setOpen(o => !o);
|
|
499
|
+
},
|
|
500
|
+
},
|
|
501
|
+
h(IconInfo),
|
|
502
|
+
),
|
|
503
|
+
open &&
|
|
504
|
+
typeof document !== "undefined" &&
|
|
505
|
+
createPortal(
|
|
506
|
+
h(
|
|
507
|
+
"div",
|
|
508
|
+
{
|
|
509
|
+
ref: panelRef,
|
|
510
|
+
id,
|
|
511
|
+
className: "mk-pop mk-dt-info-pop",
|
|
512
|
+
role: "dialog",
|
|
513
|
+
"aria-label": label,
|
|
514
|
+
tabIndex: -1,
|
|
515
|
+
onClick: e => e.stopPropagation(),
|
|
516
|
+
},
|
|
517
|
+
title != null && h("strong", { className: "mk-dt-info-title" }, title),
|
|
518
|
+
h("div", { className: "mk-dt-info-body" }, children),
|
|
519
|
+
),
|
|
520
|
+
document.body,
|
|
521
|
+
),
|
|
522
|
+
);
|
|
523
|
+
}
|
|
524
|
+
|
|
417
525
|
/** A value that is controlled when `value !== undefined`, local state otherwise. */
|
|
418
526
|
function useControlled(value, initial, onChange) {
|
|
419
527
|
const [local, setLocal] = React.useState(initial);
|
|
@@ -452,6 +560,7 @@ export function saveCsv(filename, text) {
|
|
|
452
560
|
}
|
|
453
561
|
|
|
454
562
|
const fmtCount = n => n.toLocaleString("en-US");
|
|
563
|
+
const EMPTY_EXPANDED = Object.freeze({});
|
|
455
564
|
|
|
456
565
|
/**
|
|
457
566
|
* The English text of a DataTable's footer, sort hints and export button.
|
|
@@ -477,7 +586,30 @@ export const DATA_TABLE_LABELS = {
|
|
|
477
586
|
exportCsv: "Export CSV",
|
|
478
587
|
exportTitle: "Export every row on every page, as sorted",
|
|
479
588
|
exportFailed: "The browser blocked the download. Open the app in a new tab and export again.",
|
|
589
|
+
expand: () => "Show details",
|
|
590
|
+
collapse: () => "Hide details",
|
|
591
|
+
info: label => `About ${label}`,
|
|
480
592
|
};
|
|
593
|
+
/**
|
|
594
|
+
* DataTable's texts for a locale (2.29), `labels` on top. No locale and no
|
|
595
|
+
* labels: DATA_TABLE_LABELS itself. A locale also formats the footer's
|
|
596
|
+
* numbers ("1 234" in fr-CH) and names the rows ("lignes") when `noun` is unset.
|
|
597
|
+
*/
|
|
598
|
+
export function dataTableLabels(locale, labels) {
|
|
599
|
+
const T = localeLang(locale) === "en" ? null : localeStrings("dataTable", locale);
|
|
600
|
+
const base = { ...DATA_TABLE_LABELS, rows: "rows" };
|
|
601
|
+
if (T) {
|
|
602
|
+
const n = x => x.toLocaleString(locale);
|
|
603
|
+
Object.assign(base, T, {
|
|
604
|
+
range: (from, to, total, noun) => [h("b", { key: "r" }, `${n(from)}–${n(to)}`), ` ${T.of} `, h("b", { key: "t" }, n(total)), ` ${noun}`],
|
|
605
|
+
none: noun => `0 ${noun}`,
|
|
606
|
+
expand: () => T.expand,
|
|
607
|
+
collapse: () => T.collapse,
|
|
608
|
+
});
|
|
609
|
+
delete base.of;
|
|
610
|
+
}
|
|
611
|
+
return labels ? { ...base, ...labels } : base;
|
|
612
|
+
}
|
|
481
613
|
// A click on a link, button or field inside a row is that control's, not the row's.
|
|
482
614
|
const INTERACTIVE = "a,button,input,select,textarea,label,[role=button]";
|
|
483
615
|
|
|
@@ -500,6 +632,12 @@ const INTERACTIVE = "a,button,input,select,textarea,label,[role=button]";
|
|
|
500
632
|
* label or class per group id). Ungrouped columns span both rows. A line
|
|
501
633
|
* separates the sections. Sort, the sticky header and the pinned column work
|
|
502
634
|
* the same.
|
|
635
|
+
*
|
|
636
|
+
* Four options, all off by default (the table then renders exactly as 2.27):
|
|
637
|
+
* `wrapHeaders` lets a header label take 2 lines; `renderExpanded` adds a
|
|
638
|
+
* chevron in each row's first cell that opens a full-width detail row under
|
|
639
|
+
* it; a column's `info` adds an "i" popover beside its header; `totalRow`
|
|
640
|
+
* pins a total row to the bottom of the scroll box.
|
|
503
641
|
*/
|
|
504
642
|
export function DataTable({
|
|
505
643
|
rows = [],
|
|
@@ -517,9 +655,10 @@ export function DataTable({
|
|
|
517
655
|
defaultPageSize = 50,
|
|
518
656
|
onPageSizeChange,
|
|
519
657
|
pageSizes = [25, 50, 100],
|
|
520
|
-
noun
|
|
658
|
+
noun: nounProp,
|
|
521
659
|
empty: emptyProp,
|
|
522
660
|
labels: labelsProp,
|
|
661
|
+
locale,
|
|
523
662
|
fill = false,
|
|
524
663
|
maxHeight,
|
|
525
664
|
onRowClick,
|
|
@@ -528,11 +667,21 @@ export function DataTable({
|
|
|
528
667
|
resetKey,
|
|
529
668
|
exportFilename,
|
|
530
669
|
groups,
|
|
670
|
+
wrapHeaders = false,
|
|
671
|
+
renderExpanded,
|
|
672
|
+
canExpand,
|
|
673
|
+
expanded: expandedProp,
|
|
674
|
+
defaultExpanded = EMPTY_EXPANDED,
|
|
675
|
+
onExpandedChange,
|
|
676
|
+
totalRow,
|
|
677
|
+
onTotalRowClick,
|
|
678
|
+
exportTotalRow = false,
|
|
531
679
|
className,
|
|
532
680
|
style,
|
|
533
681
|
}) {
|
|
534
|
-
const L =
|
|
682
|
+
const L = dataTableLabels(locale, labelsProp);
|
|
535
683
|
const empty = emptyProp ?? L.empty;
|
|
684
|
+
const noun = nounProp ?? L.rows;
|
|
536
685
|
const [sort, setSort] = useControlled(sortProp, defaultSort, onSortChange);
|
|
537
686
|
const [rawPage, setRawPage] = useControlled(pageProp, 1, onPageChange);
|
|
538
687
|
const [pageSize, setPageSize] = useControlled(pageSizeProp, defaultPageSize, onPageSizeChange);
|
|
@@ -548,6 +697,35 @@ export function DataTable({
|
|
|
548
697
|
const { page, pageCount, start, end } = pageSlice(sorted.length, rawPage, pageSize);
|
|
549
698
|
const visible = sorted.slice(start, end);
|
|
550
699
|
|
|
700
|
+
// Expandable rows. The state has TanStack Table's ExpandedState shape:
|
|
701
|
+
// `true` (every row) or `{ [rowId]: true }`, rowId being String(rowKey(row)).
|
|
702
|
+
// Detail rows are rendered under their parent only: never sorted, paged or
|
|
703
|
+
// exported, since they are not rows of `sorted`.
|
|
704
|
+
const expandable = typeof renderExpanded === "function";
|
|
705
|
+
const [expanded, setExpanded] = useControlled(expandedProp, defaultExpanded, onExpandedChange);
|
|
706
|
+
const uid = React.useId();
|
|
707
|
+
const keyOf = (row, i) => (rowKey ? rowKey(row) : (row?.id ?? i));
|
|
708
|
+
const isOpen = id => expanded === true || !!expanded?.[id];
|
|
709
|
+
const toggle = id => {
|
|
710
|
+
let next;
|
|
711
|
+
if (expanded === true) {
|
|
712
|
+
next = {};
|
|
713
|
+
sorted.forEach((r, i) => {
|
|
714
|
+
if (!canExpand || canExpand(r)) next[String(keyOf(r, i))] = true;
|
|
715
|
+
});
|
|
716
|
+
} else next = { ...expanded };
|
|
717
|
+
if (next[id]) delete next[id];
|
|
718
|
+
else next[id] = true;
|
|
719
|
+
setExpanded(next);
|
|
720
|
+
};
|
|
721
|
+
|
|
722
|
+
// The total row: an object, or a function over the rows the table got (the
|
|
723
|
+
// filtered rows). It never sorts or pages; CSV only with `exportTotalRow`.
|
|
724
|
+
const total = React.useMemo(
|
|
725
|
+
() => (typeof totalRow === "function" ? totalRow(rows) : (totalRow ?? null)),
|
|
726
|
+
[totalRow, rows],
|
|
727
|
+
);
|
|
728
|
+
|
|
551
729
|
const goTo = p => {
|
|
552
730
|
if (p !== rawPage) setRawPage(p);
|
|
553
731
|
scrollRef.current?.scrollTo?.({ top: 0 });
|
|
@@ -582,7 +760,7 @@ export function DataTable({
|
|
|
582
760
|
goTo(1);
|
|
583
761
|
};
|
|
584
762
|
const exportCsv = () => {
|
|
585
|
-
const res = saveCsv(exportFilename, toCsv(sorted, columns));
|
|
763
|
+
const res = saveCsv(exportFilename, toCsv(exportTotalRow && total ? [...sorted, total] : sorted, columns));
|
|
586
764
|
setNote(res === "failed" ? L.exportFailed : null);
|
|
587
765
|
};
|
|
588
766
|
|
|
@@ -624,7 +802,14 @@ export function DataTable({
|
|
|
624
802
|
className: cellClass(col, active && "mk-dt-sorted"),
|
|
625
803
|
"aria-sort": col.sortable === false ? undefined : active ? (sort.dir === "asc" ? "ascending" : "descending") : "none",
|
|
626
804
|
},
|
|
627
|
-
|
|
805
|
+
col.info == null
|
|
806
|
+
? label
|
|
807
|
+
: h(
|
|
808
|
+
"div",
|
|
809
|
+
{ className: "mk-dt-th-row" },
|
|
810
|
+
label,
|
|
811
|
+
h(HeaderInfo, { title: col.label, label: L.info(text) }, col.info),
|
|
812
|
+
),
|
|
628
813
|
);
|
|
629
814
|
};
|
|
630
815
|
|
|
@@ -662,6 +847,41 @@ export function DataTable({
|
|
|
662
847
|
const title = typeof v === "string" || typeof v === "number" || typeof v === "bigint" ? String(v) : undefined;
|
|
663
848
|
return h("div", { className: "mk-dt-cell", title: title || undefined }, content);
|
|
664
849
|
};
|
|
850
|
+
// The first cell of an expandable table: the chevron (or a spacer of its
|
|
851
|
+
// width, so every first cell lines up) before the cell's content.
|
|
852
|
+
const firstCell = (col, row, toggleEl) =>
|
|
853
|
+
h("div", { className: "mk-dt-xcell" }, toggleEl ?? h("span", { className: "mk-dt-expander-none", "aria-hidden": "true" }), cell(col, row));
|
|
854
|
+
const expander = (row, id, open, detailId) =>
|
|
855
|
+
h(
|
|
856
|
+
"button",
|
|
857
|
+
{
|
|
858
|
+
type: "button",
|
|
859
|
+
className: "mk-dt-expander",
|
|
860
|
+
"aria-expanded": open,
|
|
861
|
+
"aria-controls": open ? detailId : undefined,
|
|
862
|
+
"aria-label": open ? L.collapse(row) : L.expand(row),
|
|
863
|
+
onClick: () => toggle(id),
|
|
864
|
+
},
|
|
865
|
+
h(IconChevron),
|
|
866
|
+
);
|
|
867
|
+
// A row click (and Enter or Space on the focused row), for body rows and the total row.
|
|
868
|
+
const clickProps = (handler, row, label) =>
|
|
869
|
+
handler
|
|
870
|
+
? {
|
|
871
|
+
tabIndex: 0,
|
|
872
|
+
className: "mk-dt-click",
|
|
873
|
+
"aria-label": label,
|
|
874
|
+
onClick: e => {
|
|
875
|
+
if (!e.target.closest?.(INTERACTIVE)) handler(row, e);
|
|
876
|
+
},
|
|
877
|
+
onKeyDown: e => {
|
|
878
|
+
if ((e.key === "Enter" || e.key === " ") && e.target === e.currentTarget) {
|
|
879
|
+
e.preventDefault();
|
|
880
|
+
handler(row, e);
|
|
881
|
+
}
|
|
882
|
+
},
|
|
883
|
+
}
|
|
884
|
+
: null;
|
|
665
885
|
|
|
666
886
|
const body = h(
|
|
667
887
|
"tbody",
|
|
@@ -669,32 +889,67 @@ export function DataTable({
|
|
|
669
889
|
visible.length === 0
|
|
670
890
|
? h("tr", { key: "__empty" }, h("td", { colSpan: columns.length, className: "mk-dt-empty" }, empty))
|
|
671
891
|
: visible.map((row, i) => {
|
|
672
|
-
const key =
|
|
673
|
-
const click = onRowClick
|
|
674
|
-
? {
|
|
675
|
-
tabIndex: 0,
|
|
676
|
-
className: "mk-dt-click",
|
|
677
|
-
"aria-label": rowLabel ? rowLabel(row) : undefined,
|
|
678
|
-
onClick: e => {
|
|
679
|
-
if (!e.target.closest?.(INTERACTIVE)) onRowClick(row, e);
|
|
680
|
-
},
|
|
681
|
-
onKeyDown: e => {
|
|
682
|
-
if ((e.key === "Enter" || e.key === " ") && e.target === e.currentTarget) {
|
|
683
|
-
e.preventDefault();
|
|
684
|
-
onRowClick(row, e);
|
|
685
|
-
}
|
|
686
|
-
},
|
|
687
|
-
}
|
|
688
|
-
: null;
|
|
892
|
+
const key = keyOf(row, start + i);
|
|
893
|
+
const click = clickProps(onRowClick, row, rowLabel ? rowLabel(row) : undefined);
|
|
689
894
|
const rowClass = cx(click?.className, rowClassName?.(row)) || undefined;
|
|
690
|
-
|
|
895
|
+
if (!expandable) {
|
|
896
|
+
return h(
|
|
897
|
+
"tr",
|
|
898
|
+
{ key, ...click, className: rowClass },
|
|
899
|
+
...columns.map(col => h("td", { key: col.id, className: cellClass(col) || undefined }, cell(col, row))),
|
|
900
|
+
);
|
|
901
|
+
}
|
|
902
|
+
const id = String(key);
|
|
903
|
+
const can = !canExpand || canExpand(row);
|
|
904
|
+
const open = can && isOpen(id);
|
|
905
|
+
const detailId = `${uid}-x-${id.replace(/\s/g, "_")}`;
|
|
906
|
+
// Always a Fragment, open or not: a tr swapped for a Fragment would
|
|
907
|
+
// remount the row and drop the chevron's focus.
|
|
908
|
+
const tr = h(
|
|
691
909
|
"tr",
|
|
692
|
-
{ key, ...click, className: rowClass },
|
|
693
|
-
...columns.map(
|
|
910
|
+
{ key: "row", ...click, className: cx(rowClass, open && "mk-dt-open") || undefined },
|
|
911
|
+
...columns.map((col, c) =>
|
|
912
|
+
h(
|
|
913
|
+
"td",
|
|
914
|
+
{ key: col.id, className: cellClass(col) || undefined },
|
|
915
|
+
c === 0 ? firstCell(col, row, can ? expander(row, id, open, detailId) : null) : cell(col, row),
|
|
916
|
+
),
|
|
917
|
+
),
|
|
918
|
+
);
|
|
919
|
+
return h(
|
|
920
|
+
React.Fragment,
|
|
921
|
+
{ key },
|
|
922
|
+
tr,
|
|
923
|
+
open &&
|
|
924
|
+
h(
|
|
925
|
+
"tr",
|
|
926
|
+
{ key: "detail", className: "mk-dt-detail", id: detailId },
|
|
927
|
+
h("td", { colSpan: columns.length }, h("div", { className: "mk-dt-detail-body" }, renderExpanded(row))),
|
|
928
|
+
),
|
|
694
929
|
);
|
|
695
930
|
}),
|
|
696
931
|
);
|
|
697
932
|
|
|
933
|
+
// The pinned total row (a <tfoot> that sticks to the bottom), shown with rows only.
|
|
934
|
+
const foot =
|
|
935
|
+
total != null && sorted.length > 0
|
|
936
|
+
? h(
|
|
937
|
+
"tfoot",
|
|
938
|
+
null,
|
|
939
|
+
h(
|
|
940
|
+
"tr",
|
|
941
|
+
{ ...clickProps(onTotalRowClick, total, rowLabel ? rowLabel(total) : undefined), className: cx("mk-dt-total", onTotalRowClick && "mk-dt-click") },
|
|
942
|
+
...columns.map((col, c) =>
|
|
943
|
+
h(
|
|
944
|
+
"td",
|
|
945
|
+
{ key: col.id, className: cellClass(col) || undefined },
|
|
946
|
+
c === 0 && expandable ? firstCell(col, total, null) : cell(col, total),
|
|
947
|
+
),
|
|
948
|
+
),
|
|
949
|
+
),
|
|
950
|
+
)
|
|
951
|
+
: null;
|
|
952
|
+
|
|
698
953
|
const footer = h(
|
|
699
954
|
"footer",
|
|
700
955
|
{ className: "mk-dt-foot" },
|
|
@@ -744,7 +999,7 @@ export function DataTable({
|
|
|
744
999
|
title,
|
|
745
1000
|
description,
|
|
746
1001
|
actions: actions != null || exportButton ? h(React.Fragment, null, actions, exportButton) : undefined,
|
|
747
|
-
className: cx("mk-dt", fill && "mk-dt--fill", className),
|
|
1002
|
+
className: cx("mk-dt", fill && "mk-dt--fill", wrapHeaders && "mk-dt--wrap-heads", className),
|
|
748
1003
|
style,
|
|
749
1004
|
},
|
|
750
1005
|
note && h("p", { className: "mk-dt-note", role: "status" }, note),
|
|
@@ -761,6 +1016,7 @@ export function DataTable({
|
|
|
761
1016
|
),
|
|
762
1017
|
head,
|
|
763
1018
|
body,
|
|
1019
|
+
foot,
|
|
764
1020
|
),
|
|
765
1021
|
),
|
|
766
1022
|
footer,
|
|
@@ -806,11 +1062,14 @@ const asChecked = t => (t === "on" ? true : t === "mixed" ? "mixed" : false);
|
|
|
806
1062
|
* (several filters folded into one dropdown on a phone), so every filter
|
|
807
1063
|
* ticks and toggles alike.
|
|
808
1064
|
*
|
|
809
|
-
* Options are strings, `{ value, label, color }`, or groups with `children`
|
|
1065
|
+
* Options are strings, `{ value, label, color, count }`, or groups with `children`
|
|
810
1066
|
* (a flat list is a one-level tree). A group row ticks its whole group and
|
|
811
1067
|
* shows a dash when part of it is picked; its children follow it, indented.
|
|
812
1068
|
* A tree that needs hover submenus is a FilterMenu (`@makoai/app-sdk/menu`).
|
|
813
1069
|
*
|
|
1070
|
+
* `count` (2.28) is a number shown muted at the row's right edge, before
|
|
1071
|
+
* "Only". Search matches the label only, and the trigger never shows it.
|
|
1072
|
+
*
|
|
814
1073
|
* The All rule (2.20): with nothing filtered (`value` empty or holding every
|
|
815
1074
|
* option) every row is ticked. Unticking one leaves All in the partial (–)
|
|
816
1075
|
* state. A click on a full All unticks every row; a click on a partial All
|
|
@@ -831,17 +1090,23 @@ export function FilterItems({
|
|
|
831
1090
|
value: valueProp,
|
|
832
1091
|
selected: selectedProp,
|
|
833
1092
|
onChange,
|
|
834
|
-
allLabel
|
|
1093
|
+
allLabel: allLabelProp,
|
|
835
1094
|
emptyMeansAll = true,
|
|
836
1095
|
showOnly = false,
|
|
837
1096
|
none: noneProp,
|
|
838
1097
|
onNoneChange,
|
|
839
1098
|
searchable = false,
|
|
840
|
-
searchPlaceholder
|
|
841
|
-
searchEmpty
|
|
1099
|
+
searchPlaceholder: searchPlaceholderProp,
|
|
1100
|
+
searchEmpty: searchEmptyProp,
|
|
1101
|
+
locale,
|
|
1102
|
+
labels,
|
|
842
1103
|
className,
|
|
843
1104
|
"aria-label": ariaLabel,
|
|
844
1105
|
}) {
|
|
1106
|
+
const L = localeStrings("filter", locale, labels);
|
|
1107
|
+
const allLabel = allLabelProp ?? L.all;
|
|
1108
|
+
const searchPlaceholder = searchPlaceholderProp ?? L.search;
|
|
1109
|
+
const searchEmpty = searchEmptyProp ?? L.noMatch;
|
|
845
1110
|
const value = valueProp ?? selectedProp;
|
|
846
1111
|
const tree = options.map(toNode);
|
|
847
1112
|
const leaves = filterLeaves(tree);
|
|
@@ -956,7 +1221,8 @@ export function FilterItems({
|
|
|
956
1221
|
h(Checkbox, { checked: asChecked(tick) }),
|
|
957
1222
|
dot(node),
|
|
958
1223
|
h("span", { className: "mk-ms-label" }, node.label),
|
|
959
|
-
|
|
1224
|
+
node.count != null && h("span", { className: "mk-ms-count" }, typeof node.count === "number" ? (locale ? node.count.toLocaleString(locale) : fmtCount(node.count)) : node.count),
|
|
1225
|
+
showOnly && filterLeavesOf(node).length > 0 && h("button", { type: "button", className: "mk-ms-only", tabIndex: -1, onClick: only(node) }, L.only),
|
|
960
1226
|
);
|
|
961
1227
|
return group ? [el, ...node.children.flatMap(c => row(c, depth + 1))] : [el];
|
|
962
1228
|
};
|
|
@@ -1054,8 +1320,8 @@ export function MultiSelect({
|
|
|
1054
1320
|
value: valueProp,
|
|
1055
1321
|
selected: selectedProp,
|
|
1056
1322
|
onChange,
|
|
1057
|
-
allLabel
|
|
1058
|
-
noneLabel
|
|
1323
|
+
allLabel: allLabelProp,
|
|
1324
|
+
noneLabel: noneLabelProp,
|
|
1059
1325
|
emptyMeansAll = true,
|
|
1060
1326
|
showOnly = false,
|
|
1061
1327
|
formatMany,
|
|
@@ -1066,11 +1332,16 @@ export function MultiSelect({
|
|
|
1066
1332
|
searchable = false,
|
|
1067
1333
|
searchPlaceholder,
|
|
1068
1334
|
searchEmpty,
|
|
1335
|
+
locale,
|
|
1336
|
+
labels,
|
|
1069
1337
|
className,
|
|
1070
1338
|
triggerClassName,
|
|
1071
1339
|
label,
|
|
1072
1340
|
"aria-label": ariaLabelProp,
|
|
1073
1341
|
}) {
|
|
1342
|
+
const L = localeStrings("filter", locale, labels);
|
|
1343
|
+
const allLabel = allLabelProp ?? L.all;
|
|
1344
|
+
const noneLabel = noneLabelProp ?? L.none;
|
|
1074
1345
|
const value = valueProp ?? selectedProp;
|
|
1075
1346
|
const ariaLabel = ariaLabelProp ?? label;
|
|
1076
1347
|
const [open, setOpen] = React.useState(false);
|
|
@@ -1082,7 +1353,7 @@ export function MultiSelect({
|
|
|
1082
1353
|
}, [open]);
|
|
1083
1354
|
const tree = options.map(toNode);
|
|
1084
1355
|
const selected = filterNormalize(tree, value ?? []);
|
|
1085
|
-
const many = formatMany ??
|
|
1356
|
+
const many = formatMany ?? L.many;
|
|
1086
1357
|
const text = none ? noneLabel : (summary ?? filterText(tree, selected, allLabel, many));
|
|
1087
1358
|
const sizes = [...(sizeTo ?? [allLabel, ...tree.map(o => o.label), many(filterLeaves(tree).length), noneLabel]), ...probes];
|
|
1088
1359
|
const single = selected.length ? filterPickedNode(tree, selected) : null;
|
|
@@ -1131,6 +1402,8 @@ export function MultiSelect({
|
|
|
1131
1402
|
showOnly,
|
|
1132
1403
|
none,
|
|
1133
1404
|
onNoneChange: setNone,
|
|
1405
|
+
locale,
|
|
1406
|
+
labels,
|
|
1134
1407
|
"aria-label": ariaLabel,
|
|
1135
1408
|
...(searchable ? { searchable, searchPlaceholder, searchEmpty } : null),
|
|
1136
1409
|
}),
|