@makoai/app-sdk 2.26.0 → 2.27.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 +201 -1
- package/components/filter-bar.tsx +218 -0
- package/components/index.ts +6 -1
- package/components/period-picker.tsx +153 -0
- package/components/period.ts +83 -0
- package/index.d.ts +7 -0
- package/index.js +18 -1
- package/lint.js +81 -5
- package/package.json +1 -1
- package/ui-core.js +66 -3
- package/ui.css +33 -2
- package/ui.d.ts +95 -0
- package/ui.js +260 -58
package/ui.js
CHANGED
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
claimPopover,
|
|
16
16
|
closePopovers,
|
|
17
17
|
COLUMN_WIDTHS,
|
|
18
|
+
columnGroupRuns,
|
|
18
19
|
columnLayout,
|
|
19
20
|
compareValues,
|
|
20
21
|
csvCell,
|
|
@@ -29,6 +30,7 @@ import {
|
|
|
29
30
|
filterLeavesOf,
|
|
30
31
|
filterNormalize,
|
|
31
32
|
filterPickedNode,
|
|
33
|
+
filterSearch,
|
|
32
34
|
filterText,
|
|
33
35
|
filterTick,
|
|
34
36
|
filterToggle,
|
|
@@ -56,6 +58,7 @@ export { formatDate, formatTime, toDayKey, toInstant } from "./time.js";
|
|
|
56
58
|
export {
|
|
57
59
|
closePopovers,
|
|
58
60
|
COLUMN_WIDTHS,
|
|
61
|
+
columnGroupRuns,
|
|
59
62
|
columnLayout,
|
|
60
63
|
compareValues,
|
|
61
64
|
csvCell,
|
|
@@ -124,6 +127,8 @@ const IconMinus = ({ size = 11 }) =>
|
|
|
124
127
|
svg(size, 3.2, [h("line", { key: "l", x1: 6, y1: 12, x2: 18, y2: 12 })]);
|
|
125
128
|
const IconChevron = ({ className }) =>
|
|
126
129
|
svg(12, 2.2, [h("polyline", { key: "p", points: "6 9 12 15 18 9" })], className);
|
|
130
|
+
const IconSearch = () =>
|
|
131
|
+
svg(16, 2, [h("circle", { key: "c", cx: 11, cy: 11, r: 8 }), h("path", { key: "p", d: "m21 21-4.3-4.3" })], "mk-ms-search-icon");
|
|
127
132
|
const IconX = ({ size = 16 }) =>
|
|
128
133
|
svg(size, 2, [h("path", { key: "p", d: "M18 6 6 18M6 6l12 12" })]);
|
|
129
134
|
const IconRefresh = () =>
|
|
@@ -344,11 +349,16 @@ export function tooltipCell(value, format, opts) {
|
|
|
344
349
|
* minimum width, then a bold `total` row under a rule. `after` rows follow
|
|
345
350
|
* the total, apart (a value on another axis, such as an average next to a
|
|
346
351
|
* rate). A null or undefined cell shows a muted "–"; "" stays blank.
|
|
352
|
+
* `colWidth` sets the value columns' minimum width (default 7ch; a number is
|
|
353
|
+
* px), so the box keeps its size while the pointer moves.
|
|
347
354
|
*/
|
|
348
|
-
export function TableTooltip({ title, columns = [], rows = [], total, after, className }) {
|
|
355
|
+
export function TableTooltip({ title, columns = [], rows = [], total, after, className, colWidth }) {
|
|
349
356
|
return h(
|
|
350
357
|
"div",
|
|
351
|
-
{
|
|
358
|
+
{
|
|
359
|
+
className: cx("mk-tip", className),
|
|
360
|
+
style: colWidth == null ? undefined : { "--mk-tip-col": typeof colWidth === "number" ? `${colWidth}px` : colWidth },
|
|
361
|
+
},
|
|
352
362
|
title != null && h("div", { className: "mk-tip-title" }, title),
|
|
353
363
|
h(
|
|
354
364
|
"table",
|
|
@@ -442,6 +452,32 @@ export function saveCsv(filename, text) {
|
|
|
442
452
|
}
|
|
443
453
|
|
|
444
454
|
const fmtCount = n => n.toLocaleString("en-US");
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* The English text of a DataTable's footer, sort hints and export button.
|
|
458
|
+
* `labels` overrides any of them. Text with numbers is a function.
|
|
459
|
+
*/
|
|
460
|
+
export const DATA_TABLE_LABELS = {
|
|
461
|
+
range: (from, to, total, noun) => [
|
|
462
|
+
h("b", { key: "r" }, `${fmtCount(from)}–${fmtCount(to)}`),
|
|
463
|
+
" of ",
|
|
464
|
+
h("b", { key: "t" }, fmtCount(total)),
|
|
465
|
+
` ${noun}`,
|
|
466
|
+
],
|
|
467
|
+
none: noun => `No ${noun}`,
|
|
468
|
+
empty: "No rows match these filters.",
|
|
469
|
+
page: (page, pageCount) => `Page ${page} of ${pageCount}`,
|
|
470
|
+
perPage: size => `${size} per page`,
|
|
471
|
+
rowsPerPage: "Rows per page",
|
|
472
|
+
first: "First page",
|
|
473
|
+
previous: "Previous page",
|
|
474
|
+
next: "Next page",
|
|
475
|
+
last: "Last page",
|
|
476
|
+
sortHint: label => `${label} · click to sort`,
|
|
477
|
+
exportCsv: "Export CSV",
|
|
478
|
+
exportTitle: "Export every row on every page, as sorted",
|
|
479
|
+
exportFailed: "The browser blocked the download. Open the app in a new tab and export again.",
|
|
480
|
+
};
|
|
445
481
|
// A click on a link, button or field inside a row is that control's, not the row's.
|
|
446
482
|
const INTERACTIVE = "a,button,input,select,textarea,label,[role=button]";
|
|
447
483
|
|
|
@@ -458,6 +494,12 @@ const INTERACTIVE = "a,button,input,select,textarea,label,[role=button]";
|
|
|
458
494
|
* each column's `width` or a default by kind (see `columnLayout`). The rows
|
|
459
495
|
* on screen never change a width, so sorting, filtering and paging never
|
|
460
496
|
* shift the layout. Cells ellipsize at their width with the full value on hover.
|
|
497
|
+
*
|
|
498
|
+
* Column groups: give columns a `group` and the header gets a second row on
|
|
499
|
+
* top, where each group's label spans its adjacent columns (`groups` sets a
|
|
500
|
+
* label or class per group id). Ungrouped columns span both rows. A line
|
|
501
|
+
* separates the sections. Sort, the sticky header and the pinned column work
|
|
502
|
+
* the same.
|
|
461
503
|
*/
|
|
462
504
|
export function DataTable({
|
|
463
505
|
rows = [],
|
|
@@ -476,16 +518,21 @@ export function DataTable({
|
|
|
476
518
|
onPageSizeChange,
|
|
477
519
|
pageSizes = [25, 50, 100],
|
|
478
520
|
noun = "rows",
|
|
479
|
-
empty
|
|
521
|
+
empty: emptyProp,
|
|
522
|
+
labels: labelsProp,
|
|
480
523
|
fill = false,
|
|
481
524
|
maxHeight,
|
|
482
525
|
onRowClick,
|
|
483
526
|
rowLabel,
|
|
527
|
+
rowClassName,
|
|
484
528
|
resetKey,
|
|
485
529
|
exportFilename,
|
|
530
|
+
groups,
|
|
486
531
|
className,
|
|
487
532
|
style,
|
|
488
533
|
}) {
|
|
534
|
+
const L = labelsProp ? { ...DATA_TABLE_LABELS, ...labelsProp } : DATA_TABLE_LABELS;
|
|
535
|
+
const empty = emptyProp ?? L.empty;
|
|
489
536
|
const [sort, setSort] = useControlled(sortProp, defaultSort, onSortChange);
|
|
490
537
|
const [rawPage, setRawPage] = useControlled(pageProp, 1, onPageChange);
|
|
491
538
|
const [pageSize, setPageSize] = useControlled(pageSizeProp, defaultPageSize, onPageSizeChange);
|
|
@@ -496,6 +543,8 @@ export function DataTable({
|
|
|
496
543
|
|
|
497
544
|
const sorted = React.useMemo(() => sortRows(rows, columns, sort), [rows, columns, sort]);
|
|
498
545
|
const layout = React.useMemo(() => columnLayout(columns), [columns]);
|
|
546
|
+
const runs = React.useMemo(() => columnGroupRuns(columns), [columns]);
|
|
547
|
+
const sections = React.useMemo(() => new Set(runs?.filter(r => r.start).map(r => r.columns[0].id)), [runs]);
|
|
499
548
|
const { page, pageCount, start, end } = pageSlice(sorted.length, rawPage, pageSize);
|
|
500
549
|
const visible = sorted.slice(start, end);
|
|
501
550
|
|
|
@@ -534,48 +583,75 @@ export function DataTable({
|
|
|
534
583
|
};
|
|
535
584
|
const exportCsv = () => {
|
|
536
585
|
const res = saveCsv(exportFilename, toCsv(sorted, columns));
|
|
537
|
-
setNote(res === "failed" ?
|
|
586
|
+
setNote(res === "failed" ? L.exportFailed : null);
|
|
538
587
|
};
|
|
539
588
|
|
|
540
589
|
const cellClass = (col, extra) =>
|
|
541
|
-
cx(
|
|
590
|
+
cx(
|
|
591
|
+
col.num && "mk-dt-num",
|
|
592
|
+
col.align === "right" && "mk-dt-num",
|
|
593
|
+
col.align === "center" && "mk-dt-center",
|
|
594
|
+
col.sticky && "mk-dt-pin",
|
|
595
|
+
sections.has(col.id) && "mk-dt-section",
|
|
596
|
+
extra,
|
|
597
|
+
);
|
|
542
598
|
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
)
|
|
578
|
-
|
|
599
|
+
// One column's header cell: a sort button (or a plain label). In a grouped
|
|
600
|
+
// header an ungrouped column spans both rows (`rowSpan` 2).
|
|
601
|
+
const headCell = (col, rowSpan) => {
|
|
602
|
+
const active = sort?.id === col.id;
|
|
603
|
+
const text = typeof col.label === "string" ? col.label : col.id;
|
|
604
|
+
const label =
|
|
605
|
+
col.sortable === false
|
|
606
|
+
? h("span", { className: "mk-dt-label", title: col.hint ?? text }, h("span", { className: "mk-dt-th-text" }, col.label))
|
|
607
|
+
: h(
|
|
608
|
+
"button",
|
|
609
|
+
{
|
|
610
|
+
type: "button",
|
|
611
|
+
className: "mk-dt-sort",
|
|
612
|
+
onClick: () => sortBy(col),
|
|
613
|
+
title: L.sortHint(col.hint ?? text),
|
|
614
|
+
},
|
|
615
|
+
h("span", { className: "mk-dt-th-text" }, col.label),
|
|
616
|
+
h(IconSort, { dir: active ? sort.dir : null }),
|
|
617
|
+
);
|
|
618
|
+
return h(
|
|
619
|
+
"th",
|
|
620
|
+
{
|
|
621
|
+
key: col.id,
|
|
622
|
+
scope: "col",
|
|
623
|
+
rowSpan,
|
|
624
|
+
className: cellClass(col, active && "mk-dt-sorted"),
|
|
625
|
+
"aria-sort": col.sortable === false ? undefined : active ? (sort.dir === "asc" ? "ascending" : "descending") : "none",
|
|
626
|
+
},
|
|
627
|
+
label,
|
|
628
|
+
);
|
|
629
|
+
};
|
|
630
|
+
|
|
631
|
+
// Column groups: a top row of group labels, each spanning its columns.
|
|
632
|
+
const groupCell = run => {
|
|
633
|
+
const info = groups?.find(g => g.id === run.group);
|
|
634
|
+
const label = info?.label ?? run.group;
|
|
635
|
+
return h(
|
|
636
|
+
"th",
|
|
637
|
+
{
|
|
638
|
+
key: `__group_${run.columns[0].id}`,
|
|
639
|
+
scope: "colgroup",
|
|
640
|
+
colSpan: run.columns.length,
|
|
641
|
+
className: cx("mk-dt-group", run.start && "mk-dt-section", info?.className),
|
|
642
|
+
title: typeof label === "string" ? label : undefined,
|
|
643
|
+
},
|
|
644
|
+
h("span", { className: "mk-dt-th-text" }, label),
|
|
645
|
+
);
|
|
646
|
+
};
|
|
647
|
+
const head = runs
|
|
648
|
+
? h(
|
|
649
|
+
"thead",
|
|
650
|
+
null,
|
|
651
|
+
h("tr", null, ...runs.map(run => (run.group == null ? headCell(run.columns[0], 2) : groupCell(run)))),
|
|
652
|
+
h("tr", null, ...runs.flatMap(run => (run.group == null ? [] : run.columns.map(col => headCell(col))))),
|
|
653
|
+
)
|
|
654
|
+
: h("thead", null, h("tr", null, ...columns.map(col => headCell(col))));
|
|
579
655
|
|
|
580
656
|
// Every cell ellipsizes at its column's width, with the raw value (text or
|
|
581
657
|
// a number) as the hover title. `truncate: false` wraps instead.
|
|
@@ -610,9 +686,10 @@ export function DataTable({
|
|
|
610
686
|
},
|
|
611
687
|
}
|
|
612
688
|
: null;
|
|
689
|
+
const rowClass = cx(click?.className, rowClassName?.(row)) || undefined;
|
|
613
690
|
return h(
|
|
614
691
|
"tr",
|
|
615
|
-
{ key, ...click },
|
|
692
|
+
{ key, ...click, className: rowClass },
|
|
616
693
|
...columns.map(col => h("td", { key: col.id, className: cellClass(col) || undefined }, cell(col, row))),
|
|
617
694
|
);
|
|
618
695
|
}),
|
|
@@ -625,8 +702,8 @@ export function DataTable({
|
|
|
625
702
|
"span",
|
|
626
703
|
{ "aria-live": "polite" },
|
|
627
704
|
sorted.length
|
|
628
|
-
?
|
|
629
|
-
:
|
|
705
|
+
? L.range(start + 1, end, sorted.length, noun)
|
|
706
|
+
: L.none(noun),
|
|
630
707
|
),
|
|
631
708
|
h(
|
|
632
709
|
"div",
|
|
@@ -636,20 +713,20 @@ export function DataTable({
|
|
|
636
713
|
"select",
|
|
637
714
|
{
|
|
638
715
|
className: "mk-dt-size",
|
|
639
|
-
"aria-label":
|
|
716
|
+
"aria-label": L.rowsPerPage,
|
|
640
717
|
value: pageSize,
|
|
641
718
|
onChange: e => {
|
|
642
719
|
setPageSize(Number(e.target.value));
|
|
643
720
|
goTo(1);
|
|
644
721
|
},
|
|
645
722
|
},
|
|
646
|
-
...sizeOptions.map(n => h("option", { key: n, value: n },
|
|
723
|
+
...sizeOptions.map(n => h("option", { key: n, value: n }, L.perPage(n))),
|
|
647
724
|
),
|
|
648
|
-
h(Button, { size: "sm", "aria-label":
|
|
649
|
-
h(Button, { size: "sm", "aria-label":
|
|
650
|
-
h("span", { className: "mk-dt-page" },
|
|
651
|
-
h(Button, { size: "sm", "aria-label":
|
|
652
|
-
h(Button, { size: "sm", "aria-label":
|
|
725
|
+
h(Button, { size: "sm", "aria-label": L.first, disabled: page <= 1, onClick: () => goTo(1) }, "«"),
|
|
726
|
+
h(Button, { size: "sm", "aria-label": L.previous, disabled: page <= 1, onClick: () => goTo(page - 1) }, "‹"),
|
|
727
|
+
h("span", { className: "mk-dt-page" }, L.page(page, pageCount)),
|
|
728
|
+
h(Button, { size: "sm", "aria-label": L.next, disabled: page >= pageCount, onClick: () => goTo(page + 1) }, "›"),
|
|
729
|
+
h(Button, { size: "sm", "aria-label": L.last, disabled: page >= pageCount, onClick: () => goTo(pageCount) }, "»"),
|
|
653
730
|
),
|
|
654
731
|
);
|
|
655
732
|
|
|
@@ -657,8 +734,8 @@ export function DataTable({
|
|
|
657
734
|
exportFilename != null &&
|
|
658
735
|
h(
|
|
659
736
|
Button,
|
|
660
|
-
{ key: "__export", disabled: !sorted.length, onClick: exportCsv, title:
|
|
661
|
-
|
|
737
|
+
{ key: "__export", disabled: !sorted.length, onClick: exportCsv, title: L.exportTitle },
|
|
738
|
+
L.exportCsv,
|
|
662
739
|
);
|
|
663
740
|
|
|
664
741
|
return h(
|
|
@@ -676,7 +753,7 @@ export function DataTable({
|
|
|
676
753
|
{ className: "mk-dt-scroll", ref: scrollRef, style: !fill && maxHeight != null ? { maxHeight } : undefined },
|
|
677
754
|
h(
|
|
678
755
|
"table",
|
|
679
|
-
{ className: "mk-dt-table", style: { minWidth: layout.minWidth } },
|
|
756
|
+
{ className: cx("mk-dt-table", runs && "mk-dt-table--grouped"), style: { minWidth: layout.minWidth } },
|
|
680
757
|
h(
|
|
681
758
|
"colgroup",
|
|
682
759
|
null,
|
|
@@ -717,6 +794,9 @@ function toNode(o) {
|
|
|
717
794
|
return n.children ? { ...n, children: n.children.map(toNode) } : n;
|
|
718
795
|
}
|
|
719
796
|
|
|
797
|
+
/** The All row's key in a search's highlight order (never an option value). */
|
|
798
|
+
const ALL_KEY = "\u0000all";
|
|
799
|
+
|
|
720
800
|
const asChecked = t => (t === "on" ? true : t === "mixed" ? "mixed" : false);
|
|
721
801
|
|
|
722
802
|
/**
|
|
@@ -738,6 +818,13 @@ const asChecked = t => (t === "on" ? true : t === "mixed" ? "mixed" : false);
|
|
|
738
818
|
* keeps its selection until a row is ticked, and the first tick picks that
|
|
739
819
|
* row alone. Pass `none` / `onNoneChange` to show the draft elsewhere (the
|
|
740
820
|
* trigger); otherwise FilterItems keeps it.
|
|
821
|
+
*
|
|
822
|
+
* `searchable` (2.27) puts a search input above the rows, as shadcn's
|
|
823
|
+
* Command does: it takes focus, filters the rows by label as you type, and
|
|
824
|
+
* hides All and its separator while a query is typed. Its keys are cmdk's:
|
|
825
|
+
* ArrowDown/ArrowUp (Ctrl+N/J, Ctrl+P/K) move the highlighted row, Home/End
|
|
826
|
+
* and Cmd+Arrow jump to the first or last, Enter ticks the highlighted row.
|
|
827
|
+
* Off (the default), FilterItems renders exactly as before.
|
|
741
828
|
*/
|
|
742
829
|
export function FilterItems({
|
|
743
830
|
options,
|
|
@@ -749,6 +836,9 @@ export function FilterItems({
|
|
|
749
836
|
showOnly = false,
|
|
750
837
|
none: noneProp,
|
|
751
838
|
onNoneChange,
|
|
839
|
+
searchable = false,
|
|
840
|
+
searchPlaceholder = "Search",
|
|
841
|
+
searchEmpty = "No match",
|
|
752
842
|
className,
|
|
753
843
|
"aria-label": ariaLabel,
|
|
754
844
|
}) {
|
|
@@ -775,7 +865,71 @@ export function FilterItems({
|
|
|
775
865
|
const dot = o => (o.color ? h("span", { className: "mk-ms-swatch", style: { background: o.color } }) : null);
|
|
776
866
|
const allTick = filterAllTick(selected, none);
|
|
777
867
|
|
|
868
|
+
// Search (2.27): cmdk's model. Focus stays in the input; one row is
|
|
869
|
+
// highlighted (the first after every keystroke) and Enter ticks it.
|
|
870
|
+
const [query, setQuery] = React.useState("");
|
|
871
|
+
const [activeKey, setActiveKey] = React.useState(null);
|
|
872
|
+
const uid = React.useId();
|
|
873
|
+
const shown = searchable ? filterSearch(tree, query) : null;
|
|
874
|
+
const keys = [];
|
|
875
|
+
const runs = new Map();
|
|
876
|
+
if (searchable) {
|
|
877
|
+
if (!shown) {
|
|
878
|
+
keys.push(ALL_KEY);
|
|
879
|
+
runs.set(ALL_KEY, () => apply(filterToggleAll(selected, none)));
|
|
880
|
+
}
|
|
881
|
+
const walk = node => {
|
|
882
|
+
if (shown && !shown.has(node.value)) return;
|
|
883
|
+
keys.push(node.value);
|
|
884
|
+
runs.set(node.value, () => flip(node));
|
|
885
|
+
node.children?.forEach(walk);
|
|
886
|
+
};
|
|
887
|
+
tree.forEach(walk);
|
|
888
|
+
}
|
|
889
|
+
const active = keys.includes(activeKey) ? activeKey : keys[0];
|
|
890
|
+
const rowId = key => `${uid}-o${keys.indexOf(key)}`;
|
|
891
|
+
const activeId = active === undefined ? undefined : rowId(active);
|
|
892
|
+
React.useEffect(() => {
|
|
893
|
+
if (!searchable || !activeId) return;
|
|
894
|
+
const el = document.getElementById(activeId);
|
|
895
|
+
if (el && typeof el.scrollIntoView === "function") el.scrollIntoView({ block: "nearest" });
|
|
896
|
+
}, [searchable, activeId]);
|
|
897
|
+
const searchProps = key =>
|
|
898
|
+
searchable
|
|
899
|
+
? { id: rowId(key), "data-selected": String(key === active), onPointerMove: () => setActiveKey(key) }
|
|
900
|
+
: null;
|
|
901
|
+
const onSearchKey = e => {
|
|
902
|
+
if (e.defaultPrevented || e.nativeEvent.isComposing || e.keyCode === 229) return;
|
|
903
|
+
const i = keys.indexOf(active);
|
|
904
|
+
const go = j => {
|
|
905
|
+
e.preventDefault();
|
|
906
|
+
if (j >= 0 && j < keys.length) setActiveKey(keys[j]);
|
|
907
|
+
};
|
|
908
|
+
switch (e.key) {
|
|
909
|
+
case "ArrowDown":
|
|
910
|
+
return go(e.metaKey ? keys.length - 1 : i + 1);
|
|
911
|
+
case "ArrowUp":
|
|
912
|
+
return go(e.metaKey ? 0 : i - 1);
|
|
913
|
+
case "n":
|
|
914
|
+
case "j":
|
|
915
|
+
return e.ctrlKey ? go(i + 1) : undefined;
|
|
916
|
+
case "p":
|
|
917
|
+
case "k":
|
|
918
|
+
return e.ctrlKey ? go(i - 1) : undefined;
|
|
919
|
+
case "Home":
|
|
920
|
+
return go(0);
|
|
921
|
+
case "End":
|
|
922
|
+
return go(keys.length - 1);
|
|
923
|
+
case "Enter":
|
|
924
|
+
e.preventDefault();
|
|
925
|
+
return runs.get(active)?.();
|
|
926
|
+
default:
|
|
927
|
+
return undefined;
|
|
928
|
+
}
|
|
929
|
+
};
|
|
930
|
+
|
|
778
931
|
const row = (node, depth) => {
|
|
932
|
+
if (shown && !shown.has(node.value)) return [];
|
|
779
933
|
const tick = filterTick(node, selected, none);
|
|
780
934
|
const group = Boolean(node.children);
|
|
781
935
|
const el = h(
|
|
@@ -789,6 +943,7 @@ export function FilterItems({
|
|
|
789
943
|
title: node.title,
|
|
790
944
|
className: cx("mk-ms-opt", tick !== "off" && "active", group && "mk-ms-group"),
|
|
791
945
|
style: depth ? { paddingLeft: 8 + depth * 20 } : undefined,
|
|
946
|
+
...searchProps(node.value),
|
|
792
947
|
onClick: () => flip(node),
|
|
793
948
|
onKeyDown: e => {
|
|
794
949
|
if (e.key === "Enter" || e.key === " ") {
|
|
@@ -806,10 +961,16 @@ export function FilterItems({
|
|
|
806
961
|
return group ? [el, ...node.children.flatMap(c => row(c, depth + 1))] : [el];
|
|
807
962
|
};
|
|
808
963
|
|
|
809
|
-
|
|
964
|
+
const list = h(
|
|
810
965
|
"div",
|
|
811
|
-
{
|
|
812
|
-
|
|
966
|
+
{
|
|
967
|
+
className: cx("mk-ms-items", className),
|
|
968
|
+
role: "listbox",
|
|
969
|
+
"aria-multiselectable": true,
|
|
970
|
+
"aria-label": ariaLabel,
|
|
971
|
+
...(searchable ? { id: `${uid}-list` } : null),
|
|
972
|
+
},
|
|
973
|
+
!shown && h(
|
|
813
974
|
"div",
|
|
814
975
|
{
|
|
815
976
|
role: "option",
|
|
@@ -817,6 +978,7 @@ export function FilterItems({
|
|
|
817
978
|
"aria-checked": asChecked(allTick),
|
|
818
979
|
tabIndex: 0,
|
|
819
980
|
className: cx("mk-ms-opt", "mk-ms-all", allTick !== "off" && "active"),
|
|
981
|
+
...searchProps(ALL_KEY),
|
|
820
982
|
onClick: () => apply(filterToggleAll(selected, none)),
|
|
821
983
|
onKeyDown: e => {
|
|
822
984
|
if (e.key === "Enter" || e.key === " ") {
|
|
@@ -829,8 +991,41 @@ export function FilterItems({
|
|
|
829
991
|
h(Checkbox, { checked: asChecked(allTick) }),
|
|
830
992
|
h("span", { className: "mk-ms-label" }, allLabel),
|
|
831
993
|
),
|
|
832
|
-
h("div", { className: "mk-ms-sep" }),
|
|
994
|
+
!shown && h("div", { className: "mk-ms-sep" }),
|
|
833
995
|
...tree.flatMap(o => row(o, 0)),
|
|
996
|
+
shown && keys.length === 0 && h("div", { className: "mk-ms-empty", role: "presentation" }, searchEmpty),
|
|
997
|
+
);
|
|
998
|
+
if (!searchable) return list;
|
|
999
|
+
return h(
|
|
1000
|
+
React.Fragment,
|
|
1001
|
+
null,
|
|
1002
|
+
h(
|
|
1003
|
+
"div",
|
|
1004
|
+
{ className: "mk-ms-search" },
|
|
1005
|
+
h(IconSearch),
|
|
1006
|
+
h("input", {
|
|
1007
|
+
type: "text",
|
|
1008
|
+
className: "mk-ms-search-input",
|
|
1009
|
+
autoFocus: true,
|
|
1010
|
+
value: query,
|
|
1011
|
+
placeholder: searchPlaceholder,
|
|
1012
|
+
"aria-label": searchPlaceholder,
|
|
1013
|
+
autoComplete: "off",
|
|
1014
|
+
autoCorrect: "off",
|
|
1015
|
+
spellCheck: false,
|
|
1016
|
+
role: "combobox",
|
|
1017
|
+
"aria-autocomplete": "list",
|
|
1018
|
+
"aria-expanded": true,
|
|
1019
|
+
"aria-controls": `${uid}-list`,
|
|
1020
|
+
"aria-activedescendant": activeId,
|
|
1021
|
+
onChange: e => {
|
|
1022
|
+
setQuery(e.target.value);
|
|
1023
|
+
setActiveKey(null);
|
|
1024
|
+
},
|
|
1025
|
+
onKeyDown: onSearchKey,
|
|
1026
|
+
}),
|
|
1027
|
+
),
|
|
1028
|
+
list,
|
|
834
1029
|
);
|
|
835
1030
|
}
|
|
836
1031
|
|
|
@@ -850,6 +1045,9 @@ export function FilterItems({
|
|
|
850
1045
|
*
|
|
851
1046
|
* Drop-in for the apps' NestedFilterMenu: `selected` = `value`, `label` =
|
|
852
1047
|
* `aria-label`, `triggerClassName`, `summary`, `probes`, `sizeTo`.
|
|
1048
|
+
*
|
|
1049
|
+
* `searchable` (2.27) adds FilterItems' search input at the top of the menu:
|
|
1050
|
+
* search, All, a separator, then the values.
|
|
853
1051
|
*/
|
|
854
1052
|
export function MultiSelect({
|
|
855
1053
|
options,
|
|
@@ -865,6 +1063,9 @@ export function MultiSelect({
|
|
|
865
1063
|
sizeTo,
|
|
866
1064
|
probes = [],
|
|
867
1065
|
align = "start",
|
|
1066
|
+
searchable = false,
|
|
1067
|
+
searchPlaceholder,
|
|
1068
|
+
searchEmpty,
|
|
868
1069
|
className,
|
|
869
1070
|
triggerClassName,
|
|
870
1071
|
label,
|
|
@@ -931,6 +1132,7 @@ export function MultiSelect({
|
|
|
931
1132
|
none,
|
|
932
1133
|
onNoneChange: setNone,
|
|
933
1134
|
"aria-label": ariaLabel,
|
|
1135
|
+
...(searchable ? { searchable, searchPlaceholder, searchEmpty } : null),
|
|
934
1136
|
}),
|
|
935
1137
|
),
|
|
936
1138
|
);
|