@makoai/app-sdk 2.27.0 → 2.28.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 CHANGED
@@ -472,6 +472,15 @@ The order is search, All, a separator, then the values.
472
472
  - `searchPlaceholder` sets the placeholder (default "Search").
473
473
  - Without `searchable` the menu is unchanged.
474
474
 
475
+ **Counts (2.28).** An option's `count` shows muted at the row's right edge.
476
+ It works in `MultiSelect` and `FilterItems`. Search matches the label only.
477
+ The trigger shows the label only. A number prints with thousands separators
478
+ (1,234). Put the count here, never in the label.
479
+
480
+ ```tsx
481
+ <MultiSelect searchable options={offices.map(o => ({ value: o.id, label: o.name, count: o.n }))} value={office} onChange={setOffice} allLabel="All offices" />
482
+ ```
483
+
475
484
  **Replacing an app's NestedFilterMenu: `FilterMenu`.** See "Menus" below:
476
485
  `FilterMenu` and `FilterMenuItems` from `@makoai/app-sdk/menu` take
477
486
  NestedFilterMenu's props (`label`, `options`, `selected`, `onChange`,
@@ -583,6 +592,29 @@ import { Calendar } from "@makoai/app-sdk/components/calendar";
583
592
  import { Command, CommandInput, CommandList } from "@makoai/app-sdk/components/command";
584
593
  ```
585
594
 
595
+ **Searchable single choice: `Combobox` (2.28).** shadcn's combobox recipe
596
+ (Popover + Command) on its own subpath, since it loads cmdk. A pick closes
597
+ it. Picking the picked row again clears the value to `null`. The trigger
598
+ shows `placeholder` while the value is `null`.
599
+
600
+ ```tsx
601
+ import { Combobox } from "@makoai/app-sdk/components/combobox";
602
+
603
+ <Combobox
604
+ aria-label="CSM"
605
+ placeholder="All CSMs"
606
+ searchPlaceholder="Filter CSMs..."
607
+ options={csms.map(r => ({ value: r.csm, label: r.csm, count: r.n, keywords: [r.countries] }))}
608
+ value={csm}
609
+ onChange={setCsm}
610
+ />
611
+ ```
612
+
613
+ - Search matches `label` and `keywords`. It never matches `value` or `count`.
614
+ - `count` shows muted at the row's right edge. The trigger never shows it.
615
+ - `icon` sits before the trigger text. `className` sizes the trigger (default `w-[200px]`).
616
+ - The keys are cmdk's: arrows move, Enter picks, Escape closes.
617
+
586
618
  shadcn's stock components pass refs as props, so they need React 19. On
587
619
  React 18 a ref is dropped: a Calendar's arrow keys stop moving focus. Apps
588
620
  that use them run React 19; `mako-app-lint --rules=react-version` flags any
@@ -698,6 +730,12 @@ rows.sort((a, b) => COUNTRY_ORDER.indexOf(a.country) - COUNTRY_ORDER.indexOf(b.c
698
730
  CH red, FR blue, IT green, ES amber, PT teal, PL rose. Other series in a
699
731
  country chart take `--chart-1…5`. Both objects are frozen.
700
732
 
733
+ 2.28 adds the 6 lead-only markets of dbt seed `markets` (valuation funnel
734
+ only, no agents): DE violet, AT lime, CZ ochre, NL orange, BE fuchsia, GB navy
735
+ (realadvisor.co.uk). `COUNTRY_ORDER` keeps the 6 site markets. The lead-only
736
+ markets follow them in the map's key order, so an app that lists markets from
737
+ data sorts by `COUNTRY_ORDER`, then by key order of `COUNTRY_COLORS`.
738
+
701
739
  ### Times and dates (2.21)
702
740
 
703
741
  DuckDB runs in UTC, and that stays. Display code decides the zone.
@@ -973,6 +1011,40 @@ const COLUMNS: DataTableColumn<Customer>[] = [
973
1011
  <DataTable rows={rows} columns={COLUMNS}
974
1012
  groups={[{ id: "activity", label: "Activity" }, { id: "money", label: "Money", className: "tone-positive" }]} />
975
1013
  ```
1014
+ - **Wrapped headers.** `wrapHeaders` lets a header label take 2 lines before
1015
+ it ellipsizes. The sort icon stays beside it. Use it for long or translated
1016
+ labels in narrow columns.
1017
+ - **Header info.** A column's `info` adds an "i" button after its header
1018
+ label. A click opens a popover with the label and this content. The button
1019
+ sits outside the sort button, so it never sorts. Focus moves into the
1020
+ popover. Escape closes it and returns focus to the "i".
1021
+ - **Expandable rows.** `renderExpanded(row)` puts a chevron in each row's
1022
+ first cell. The chevron opens a full-width detail row under its record.
1023
+ Enter or Space on a focused chevron toggles it too. `canExpand(row)` limits
1024
+ which rows get one. The pager, the sort and the CSV count records only. The
1025
+ open rows are uncontrolled (`defaultExpanded`) or controlled (`expanded` +
1026
+ `onExpandedChange`). The state is `{ [rowKey]: true }`, or `true` for every
1027
+ row: TanStack Table's `ExpandedState`. `labels.expand(row)` and
1028
+ `labels.collapse(row)` name the chevron for screen readers.
1029
+
1030
+ ```tsx
1031
+ <DataTable rows={records} columns={COLUMNS} rowKey={r => r.item_id}
1032
+ renderExpanded={r => <RecordFacts row={r} />}
1033
+ canExpand={r => r.detail != null}
1034
+ labels={{ expand: r => `Show details for ${r.item_label}`, collapse: r => `Hide details for ${r.item_label}` }} />
1035
+ ```
1036
+ - **Total row.** `totalRow` pins a bold row to the bottom of the scroll box,
1037
+ under a rule. Pass a row object or a function of the filtered `rows`. Each
1038
+ column renders it with its own `value` and `render`. The pinned first
1039
+ column holds in it. It never sorts or pages. It stays out of the CSV unless
1040
+ `exportTotalRow`. `onTotalRowClick(row)` makes it clickable for a
1041
+ drill-down. A `render` can return a button per cell, as on any row.
1042
+
1043
+ ```tsx
1044
+ <DataTable rows={reps} columns={COLUMNS}
1045
+ totalRow={rs => ({ name: "Total", demos: sum(rs, "demos"), cash: sum(rs, "cash") })}
1046
+ onTotalRowClick={() => openDrill(null)} />
1047
+ ```
976
1048
  - Pure helpers for custom tables: `sortRows`, `compareValues`, `nextSort`,
977
1049
  `pageSlice`, `pageToSync`, `toCsv`, `csvCell`, `csvDate`, `csvToTsv`,
978
1050
  `columnLayout`, `columnGroupRuns`.
@@ -0,0 +1,137 @@
1
+ "use client"
2
+
3
+ // Combobox (2.28): shadcn's combobox recipe (ui.shadcn.com/docs/components/combobox)
4
+ // as shipped: Popover + Command, a Button trigger, a Check on the picked row,
5
+ // a pick closes the popover and picking the picked row again clears it.
6
+ // The recipe is a demo, so its hard-coded list, labels and width become props.
7
+ // Mako thin props (2.28): `count` per option (muted, right-aligned, never
8
+ // searched, never in the trigger), `keywords` per option, `icon` in the trigger.
9
+ // Search matches the label and keywords only, never the value or the count.
10
+
11
+ import * as React from "react"
12
+ import { CheckIcon, ChevronsUpDownIcon } from "lucide-react"
13
+ import { defaultFilter } from "cmdk"
14
+ import { cn } from "../menu/utils"
15
+ import { Button } from "./button"
16
+ import {
17
+ Command,
18
+ CommandEmpty,
19
+ CommandGroup,
20
+ CommandInput,
21
+ CommandItem,
22
+ CommandList,
23
+ } from "./command"
24
+ import { Popover, PopoverContent, PopoverTrigger } from "./popover"
25
+
26
+ export type ComboboxOption<V extends string = string> = {
27
+ value: V
28
+ label: string
29
+ /** Mako thin prop (2.28): a number shown muted at the row's right edge. */
30
+ count?: number | string
31
+ /** Mako thin prop (2.28): extra words the search matches. */
32
+ keywords?: string[]
33
+ }
34
+
35
+ const formatCount = (n: number | string) =>
36
+ typeof n === "number" ? n.toLocaleString("en-US") : n
37
+
38
+ // The item's value is the option value (unique); its keywords hold the label
39
+ // first, so the search scores the label and keywords and never the value.
40
+ const filterByLabel = (_value: string, search: string, keywords?: string[]) =>
41
+ defaultFilter(keywords?.[0] ?? "", search, keywords?.slice(1))
42
+
43
+ function Combobox<V extends string = string>({
44
+ options,
45
+ value,
46
+ onChange,
47
+ placeholder = "Select...",
48
+ searchPlaceholder = "Search...",
49
+ emptyText = "No results found.",
50
+ icon,
51
+ disabled,
52
+ className,
53
+ contentClassName,
54
+ "aria-label": ariaLabel,
55
+ }: {
56
+ options: ReadonlyArray<V | ComboboxOption<V>>
57
+ value: V | null
58
+ onChange: (value: V | null) => void
59
+ placeholder?: string
60
+ searchPlaceholder?: string
61
+ emptyText?: React.ReactNode
62
+ icon?: React.ReactNode
63
+ disabled?: boolean
64
+ className?: string
65
+ contentClassName?: string
66
+ "aria-label"?: string
67
+ }) {
68
+ const [open, setOpen] = React.useState(false)
69
+ const items = options.map((o) =>
70
+ typeof o === "string" ? { value: o, label: o } : o
71
+ ) as ComboboxOption<V>[]
72
+ const picked = items.find((o) => o.value === value)
73
+ const text = picked?.label ?? value ?? placeholder
74
+
75
+ return (
76
+ <Popover open={open} onOpenChange={setOpen}>
77
+ <PopoverTrigger asChild>
78
+ <Button
79
+ data-slot="combobox-trigger"
80
+ variant="outline"
81
+ role="combobox"
82
+ aria-expanded={open}
83
+ aria-label={ariaLabel}
84
+ disabled={disabled}
85
+ title={text}
86
+ className={cn("w-[200px] justify-between", className)}
87
+ >
88
+ {icon}
89
+ <span className="min-w-0 flex-1 truncate text-left">{text}</span>
90
+ <ChevronsUpDownIcon className="opacity-50" />
91
+ </Button>
92
+ </PopoverTrigger>
93
+ <PopoverContent
94
+ className={cn("w-(--radix-popover-trigger-width) min-w-[200px] p-0", contentClassName)}
95
+ align="start"
96
+ >
97
+ <Command filter={filterByLabel}>
98
+ <CommandInput placeholder={searchPlaceholder} className="h-9" />
99
+ <CommandList>
100
+ <CommandEmpty>{emptyText}</CommandEmpty>
101
+ <CommandGroup>
102
+ {items.map((o) => (
103
+ <CommandItem
104
+ key={o.value}
105
+ value={o.value}
106
+ keywords={[o.label, ...(o.keywords ?? [])]}
107
+ onSelect={() => {
108
+ onChange(o.value === value ? null : o.value)
109
+ setOpen(false)
110
+ }}
111
+ >
112
+ <span className="min-w-0 flex-1 truncate">{o.label}</span>
113
+ {o.count != null && (
114
+ <span
115
+ data-slot="combobox-count"
116
+ className="text-xs text-muted-foreground tabular-nums"
117
+ >
118
+ {formatCount(o.count)}
119
+ </span>
120
+ )}
121
+ <CheckIcon
122
+ className={cn(
123
+ "ml-auto",
124
+ value === o.value ? "opacity-100" : "opacity-0"
125
+ )}
126
+ />
127
+ </CommandItem>
128
+ ))}
129
+ </CommandGroup>
130
+ </CommandList>
131
+ </Command>
132
+ </PopoverContent>
133
+ </Popover>
134
+ )
135
+ }
136
+
137
+ export { Combobox }
package/index.d.ts CHANGED
@@ -408,8 +408,10 @@ export function useTheme(): { theme: "light" | "dark" };
408
408
 
409
409
  /** A market's lowercase code, in COUNTRY_ORDER. */
410
410
  export type CountryCode = "ch" | "fr" | "es" | "it" | "pl" | "pt";
411
- /** One colour per market (2.27), keyed by lowercase code; `all` is the all-markets line. */
412
- export const COUNTRY_COLORS: Readonly<Record<CountryCode | "all", string>>;
411
+ /** A lead-only market (2.28): the valuation funnel runs there, no agents. In this order. */
412
+ export type LeadMarketCode = "de" | "at" | "cz" | "nl" | "be" | "gb";
413
+ /** One colour per market (2.27; lead-only markets 2.28), keyed by lowercase code; `all` is the all-markets line. */
414
+ export const COUNTRY_COLORS: Readonly<Record<CountryCode | LeadMarketCode | "all", string>>;
413
415
  /** CH, FR, ES, IT, PL, PT (2.27), as lowercase codes. */
414
416
  export const COUNTRY_ORDER: readonly CountryCode[];
415
417
 
package/index.js CHANGED
@@ -38,7 +38,7 @@ import {
38
38
  * in a page (or this export) says which SDK a deployed app actually runs.
39
39
  * Kept in step with package.json by snapshot.test.mjs.
40
40
  */
41
- export const SDK_VERSION = "2.27.0";
41
+ export const SDK_VERSION = "2.28.0";
42
42
  if (typeof window !== "undefined") {
43
43
  try {
44
44
  window.__MAKO_APP_SDK__ = SDK_VERSION;
@@ -2068,6 +2068,9 @@ if (
2068
2068
  // ---------------------------------------------------------------------------
2069
2069
  // Country colours (2.27): one colour per market in every app, deck and chart,
2070
2070
  // keyed by the lowercase country code. `all` is the all-markets / group line.
2071
+ // 2.28 adds the 6 lead-only markets (valuation funnel only since 18-19 Nov
2072
+ // 2026), in their order: DE, AT, CZ, NL, BE, GB (realadvisor.co.uk). Their
2073
+ // flags repeat the first six's hues, so they take free ones.
2071
2074
  // ---------------------------------------------------------------------------
2072
2075
  export const COUNTRY_COLORS = Object.freeze({
2073
2076
  ch: "#dc2626",
@@ -2076,6 +2079,12 @@ export const COUNTRY_COLORS = Object.freeze({
2076
2079
  es: "#f59e0b",
2077
2080
  pt: "#0891b2",
2078
2081
  pl: "#db2777",
2082
+ de: "#7c3aed",
2083
+ at: "#65a30d",
2084
+ cz: "#a16207",
2085
+ nl: "#ea580c",
2086
+ be: "#c026d3",
2087
+ gb: "#1e40af",
2079
2088
  all: "#475569",
2080
2089
  });
2081
2090
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@makoai/app-sdk",
3
- "version": "2.27.0",
3
+ "version": "2.28.0",
4
4
  "description": "Mako app SDK: data bindings (useQuery/useDuckDB), URL state, theme, and the house dashboard kit (/ui).",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -55,6 +55,10 @@
55
55
  "types": "./components/command.tsx",
56
56
  "default": "./components/command.tsx"
57
57
  },
58
+ "./components/combobox": {
59
+ "types": "./components/combobox.tsx",
60
+ "default": "./components/combobox.tsx"
61
+ },
58
62
  "./ui.css": "./ui.css",
59
63
  "./tailwind.css": "./tailwind.css"
60
64
  },
package/ui.css CHANGED
@@ -269,6 +269,57 @@ button, input, select, textarea { font-family: inherit; }
269
269
  /* `truncate: false`: the text wraps inside the column; the width still holds. */
270
270
  .mk-dt-wrap { white-space: normal; overflow-wrap: anywhere; }
271
271
  .mk-dt-table td.mk-dt-empty { text-align: center; color: var(--muted-foreground); padding: 48px 10px; white-space: normal; }
272
+ /* `wrapHeaders`: a header label takes up to 2 lines instead of one ellipsized
273
+ * line, so a client reads every word. The sort icon keeps its place beside it. */
274
+ .mk-dt--wrap-heads .mk-dt-sort, .mk-dt--wrap-heads .mk-dt-label { white-space: normal; }
275
+ .mk-dt--wrap-heads thead .mk-dt-th-text {
276
+ display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2;
277
+ white-space: normal; overflow-wrap: break-word; line-height: 1.3;
278
+ }
279
+ /* A column's `info`: the "i" sits after the sort button, never inside it. */
280
+ .mk-dt-th-row { display: flex; align-items: center; min-width: 0; }
281
+ .mk-dt-th-row > :is(.mk-dt-sort, .mk-dt-label) { flex: 1 1 auto; width: auto; min-width: 0; padding-right: 2px; }
282
+ .mk-dt-info-wrap { flex: none; display: inline-flex; padding-right: 6px; }
283
+ .mk-dt-info {
284
+ appearance: none; display: inline-flex; align-items: center; justify-content: center; width: 18px; height: 18px;
285
+ padding: 0; border: 0; border-radius: 50%; background: none; color: var(--muted-foreground); cursor: pointer;
286
+ }
287
+ .mk-dt-info:hover, .mk-dt-info.open { color: var(--foreground); background: var(--muted); }
288
+ .mk-dt-info:focus-visible { outline: 2px solid var(--ring); outline-offset: 0; }
289
+ .mk-dt-info-pop {
290
+ position: fixed; top: 0; left: 0; z-index: 90; width: max-content; max-width: min(320px, calc(100vw - 16px));
291
+ padding: 10px 12px; font-size: 12px; line-height: 1.45; white-space: normal; text-align: left;
292
+ }
293
+ .mk-dt-info-pop:focus { outline: none; }
294
+ .mk-dt-info-title { display: block; margin-bottom: 4px; font-weight: 600; }
295
+ .mk-dt-info-body > :first-child { margin-top: 0; }
296
+ .mk-dt-info-body > :last-child { margin-bottom: 0; }
297
+ @media (max-width: 640px) { .mk-dt-info-pop { top: auto; width: auto; max-width: none; padding: 16px; } }
298
+ /* Expandable rows: a chevron in the first cell opens a full-width detail row. */
299
+ .mk-dt-xcell { display: flex; align-items: center; gap: 4px; min-width: 0; }
300
+ .mk-dt-xcell > :is(.mk-dt-cell, .mk-dt-wrap) { flex: 1 1 auto; min-width: 0; }
301
+ .mk-dt-expander, .mk-dt-expander-none { flex: none; width: 20px; height: 20px; margin-left: -4px; }
302
+ .mk-dt-expander {
303
+ appearance: none; display: inline-flex; align-items: center; justify-content: center; padding: 0; border: 0;
304
+ border-radius: var(--mk-radius-sm); background: none; color: var(--muted-foreground); cursor: pointer;
305
+ }
306
+ .mk-dt-expander:hover { color: var(--foreground); background: var(--muted); }
307
+ .mk-dt-expander:focus-visible { outline: 2px solid var(--ring); outline-offset: -2px; }
308
+ .mk-dt-expander svg { transform: rotate(-90deg); transition: transform .14s var(--mk-ease); }
309
+ .mk-dt-expander[aria-expanded="true"] svg { transform: none; }
310
+ .mk-dt-table tbody tr.mk-dt-open > td { border-bottom-color: transparent; }
311
+ .mk-dt-table tbody tr.mk-dt-detail > td,
312
+ .mk-dt-table tbody tr.mk-dt-detail:hover > td { padding: 0; white-space: normal; background: color-mix(in srgb, var(--muted) 40%, var(--card)); }
313
+ .mk-dt-detail-body { position: sticky; left: 0; padding: 10px 16px 14px 34px; overflow-wrap: anywhere; }
314
+ /* `totalRow`: a <tfoot> pinned to the bottom of the scroll box, bold, with a
315
+ * rule on top. Its first cell stays pinned left with the column. */
316
+ .mk-dt-table tfoot td {
317
+ position: sticky; bottom: 0; z-index: 2; border-bottom: 0; font-weight: 600;
318
+ background: var(--card); box-shadow: inset 0 1px 0 var(--border);
319
+ }
320
+ .mk-dt-table tfoot td.mk-dt-pin { z-index: 3; box-shadow: inset -1px 0 0 var(--border), inset 0 1px 0 var(--border); }
321
+ .mk-dt-table tfoot tr.mk-dt-total.mk-dt-click:hover > td,
322
+ .mk-dt-table tfoot tr.mk-dt-total.mk-dt-click:focus-visible > td { background: color-mix(in srgb, var(--muted) 50%, var(--card)); }
272
323
  .mk-dt-foot {
273
324
  flex: none; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px;
274
325
  padding: 8px 12px; border-top: 1px solid var(--border); font-size: 12px; color: var(--muted-foreground);
@@ -336,6 +387,8 @@ button, input, select, textarea { font-family: inherit; }
336
387
  /* Ticked in the brand blue (white tick), --primary where a theme has no --brand. */
337
388
  .mk-ms-box.on { background: var(--brand, var(--primary)); border-color: var(--brand, var(--primary)); color: #fff; }
338
389
  .mk-ms-swatch { width: 8px; height: 8px; border-radius: 999px; flex-shrink: 0; }
390
+ /* An option's `count` (2.28): muted, right-aligned, tabular figures. */
391
+ .mk-ms-count { flex-shrink: 0; margin-left: auto; font-size: 12px; font-weight: 400; color: var(--muted-foreground); font-variant-numeric: tabular-nums; }
339
392
  .mk-ms-sep { height: 1px; background: var(--border); margin: 4px -4px; flex: none; }
340
393
  /* MultiSelect `searchable` (2.27): shadcn's CommandInput (36px, a search icon,
341
394
  * a hairline under it), pinned at the top while the rows scroll. The
package/ui.d.ts CHANGED
@@ -71,6 +71,8 @@ export interface MultiSelectOption<V extends string = string> {
71
71
  color?: string;
72
72
  /** What the option covers, shown on hover. */
73
73
  title?: string;
74
+ /** A count shown muted at the row's right edge (2.28). Search ignores it; the trigger never shows it. A number is formatted (1,234). */
75
+ count?: number | string;
74
76
  /** A group (2.20): its row ticks every leaf under it; hover submenus: FilterMenu in `@makoai/app-sdk/menu`. */
75
77
  children?: ReadonlyArray<MultiSelectOption<V>>;
76
78
  }
@@ -408,6 +410,12 @@ export interface DataTableColumn<R = any> {
408
410
  sortable?: boolean;
409
411
  /** Header hover text, e.g. the column's definition. */
410
412
  hint?: string;
413
+ /**
414
+ * The column's definition behind an "i" button beside its header. The
415
+ * button sits outside the sort button, so a click on it never sorts. It
416
+ * opens a popover with the label and this content. Default none.
417
+ */
418
+ info?: React.ReactNode;
411
419
  /**
412
420
  * The column group's id. Adjacent columns with the same `group` share one
413
421
  * label in a header row on top (see `DataTableProps.groups`); ungrouped
@@ -466,7 +474,19 @@ export interface DataTableLabels {
466
474
  exportTitle: string;
467
475
  /** Shown when the browser blocks the CSV download. */
468
476
  exportFailed: string;
477
+ /** An expand chevron's aria-label, per row. Default "Show details". */
478
+ expand: (row: any) => string;
479
+ /** An open chevron's aria-label, per row. Default "Hide details". */
480
+ collapse: (row: any) => string;
481
+ /** A header "i" button's aria-label. Default "About MRR". */
482
+ info: (label: string) => string;
469
483
  }
484
+ /**
485
+ * Which rows show their detail row: `true` for every row, or the open rows'
486
+ * ids, `{ [String(rowKey(row))]: true }`. The shape of TanStack Table's
487
+ * `ExpandedState`, so one state can drive both.
488
+ */
489
+ export type DataTableExpanded = true | Record<string, boolean>;
470
490
  /** The English defaults of `DataTableLabels`. */
471
491
  export const DATA_TABLE_LABELS: DataTableLabels;
472
492
  export interface DataTableProps<R = any> {
@@ -533,6 +553,34 @@ export interface DataTableProps<R = any> {
533
553
  exportFilename?: string;
534
554
  /** Labels and classes for the column groups, by `DataTableColumn.group`. A group not listed shows its id. */
535
555
  groups?: readonly DataTableGroup[];
556
+ /** Header labels wrap to 2 lines instead of ellipsizing on one. The sort icon stays beside them. Default false. */
557
+ wrapHeaders?: boolean;
558
+ /**
559
+ * Makes rows expandable: a chevron in each row's first cell opens a
560
+ * full-width detail row under it with this content. Enter or Space on the
561
+ * chevron toggles it. Detail rows never count in the pager, the sort or the
562
+ * CSV. Give rows a stable `rowKey` (or `id`): the state is keyed by it.
563
+ */
564
+ renderExpanded?: (row: R) => React.ReactNode;
565
+ /** Which rows get a chevron. Default every row. */
566
+ canExpand?: (row: R) => boolean;
567
+ /** Controlled open rows; pair with `onExpandedChange`. */
568
+ expanded?: DataTableExpanded;
569
+ /** The open rows when uncontrolled. Default `{}`. */
570
+ defaultExpanded?: DataTableExpanded;
571
+ onExpandedChange?: (expanded: Record<string, boolean>) => void;
572
+ /**
573
+ * A total row pinned to the bottom of the scroll box (a sticky `<tfoot>`),
574
+ * bold with a rule on top. A row object, or a function of `rows` (the
575
+ * filtered rows the table got). Each column renders it with its `value`
576
+ * and `render`. It never sorts or pages and stays out of the CSV unless
577
+ * `exportTotalRow`. Hidden while there are no rows.
578
+ */
579
+ totalRow?: R | ((rows: readonly R[]) => R | null | undefined) | null;
580
+ /** A click (or Enter or Space) on the total row, e.g. a drill-down. `rowLabel` names it. */
581
+ onTotalRowClick?: (row: R, event: React.SyntheticEvent) => void;
582
+ /** Append the total row to the CSV export. Default false. */
583
+ exportTotalRow?: boolean;
536
584
  className?: string;
537
585
  style?: React.CSSProperties;
538
586
  }
package/ui.js CHANGED
@@ -145,28 +145,26 @@ const IconRefresh = () =>
145
145
  const PHONE = "(max-width: 640px)";
146
146
 
147
147
  /**
148
- * One kit popover is open at a time: opening this one closes any other (a
149
- * module-level registry, see claimPopover). It closes on Escape, on a
150
- * pointerdown outside it, and when focus moves outside it. Pointerdown, in
151
- * the capture phase, because Radix menu triggers cancel the mouse events of
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.
148
+ * The closing half of usePopover: one kit popover at a time, Escape, a
149
+ * pointerdown or focus outside `wrapRef`. A portalled panel passes its own
150
+ * ref as `panelRef`, so a click inside it counts as inside. `onEscape` runs
151
+ * after an Escape close (the header info returns focus to its button).
158
152
  */
159
- function usePopover(open, setOpen, wrapRef, align) {
153
+ function usePopoverDismiss(open, setOpen, wrapRef, panelRef, onEscape) {
160
154
  React.useEffect(() => {
161
155
  if (!open) return undefined;
162
156
  const close = () => setOpen(false);
163
157
  claimPopover(close);
164
158
  const outside = e => {
165
159
  const wrap = wrapRef.current;
160
+ if (panelRef?.current && e.target instanceof Node && panelRef.current.contains(e.target)) return;
166
161
  if (wrap && e.target instanceof Node && !wrap.contains(e.target)) close();
167
162
  };
168
163
  const onKey = e => {
169
- if (e.key === "Escape") close();
164
+ if (e.key === "Escape") {
165
+ close();
166
+ onEscape?.();
167
+ }
170
168
  };
171
169
  document.addEventListener("pointerdown", outside, true);
172
170
  document.addEventListener("focusin", outside, true);
@@ -177,7 +175,23 @@ function usePopover(open, setOpen, wrapRef, align) {
177
175
  document.removeEventListener("focusin", outside, true);
178
176
  document.removeEventListener("keydown", onKey);
179
177
  };
180
- }, [open, setOpen, wrapRef]);
178
+ }, [open, setOpen, wrapRef]); // eslint-disable-line react-hooks/exhaustive-deps
179
+ }
180
+
181
+ /**
182
+ * One kit popover is open at a time: opening this one closes any other (a
183
+ * module-level registry, see claimPopover). It closes on Escape, on a
184
+ * pointerdown outside it, and when focus moves outside it. Pointerdown, in
185
+ * the capture phase, because Radix menu triggers cancel the mouse events of
186
+ * their pointerdown, so an outside mousedown/click listener never hears them.
187
+ *
188
+ * It also keeps the `.mk-pop` inside `wrapRef` within the viewport: it opens
189
+ * under its trigger aligned to `align`, flips to the other edge when that
190
+ * would overflow, and as a last resort is pinned to the viewport margin. On
191
+ * phones the popover is a bottom sheet (CSS) and is left alone.
192
+ */
193
+ function usePopover(open, setOpen, wrapRef, align) {
194
+ usePopoverDismiss(open, setOpen, wrapRef);
181
195
 
182
196
  React.useLayoutEffect(() => {
183
197
  if (!open) return undefined;
@@ -414,6 +428,98 @@ const IconSort = ({ dir }) =>
414
428
  dir ? undefined : "mk-dt-faint",
415
429
  );
416
430
 
431
+ const IconInfo = () =>
432
+ svg(12, 2, [
433
+ h("circle", { key: "c", cx: 12, cy: 12, r: 10 }),
434
+ h("path", { key: "a", d: "M12 16v-4" }),
435
+ h("path", { key: "b", d: "M12 8h.01" }),
436
+ ]);
437
+
438
+ /**
439
+ * A column's "i" (`column.info`): a button beside the header's sort button,
440
+ * never inside it, so a click on it never sorts. It opens a kit popover
441
+ * (`.mk-pop`) portalled to <body>, so the table's scroll box never clips it.
442
+ * Like a Radix Popover, focus moves into the panel on open and Escape returns
443
+ * it to the button. A click or focus outside closes it, as every kit popover.
444
+ */
445
+ function HeaderInfo({ title, label, children }) {
446
+ const [open, setOpen] = React.useState(false);
447
+ const wrapRef = React.useRef(null);
448
+ const panelRef = React.useRef(null);
449
+ const id = React.useId();
450
+ const refocus = React.useCallback(() => wrapRef.current?.querySelector("button")?.focus(), []);
451
+ usePopoverDismiss(open, setOpen, wrapRef, panelRef, refocus);
452
+
453
+ React.useLayoutEffect(() => {
454
+ if (!open) return undefined;
455
+ const place = () => {
456
+ const pop = panelRef.current;
457
+ const btn = wrapRef.current;
458
+ if (!pop || !btn) return;
459
+ pop.style.left = "";
460
+ pop.style.top = "";
461
+ if (window.matchMedia(PHONE).matches) return;
462
+ const margin = 8;
463
+ const r = btn.getBoundingClientRect();
464
+ const w = pop.offsetWidth;
465
+ const ht = pop.offsetHeight;
466
+ const left = Math.min(Math.max(margin, r.left + r.width / 2 - w / 2), window.innerWidth - w - margin);
467
+ const below = r.bottom + 6;
468
+ const top = below + ht > window.innerHeight - margin && r.top - 6 - ht >= margin ? r.top - 6 - ht : below;
469
+ pop.style.left = `${left}px`;
470
+ pop.style.top = `${top}px`;
471
+ };
472
+ place();
473
+ panelRef.current?.focus({ preventScroll: true });
474
+ window.addEventListener("resize", place);
475
+ window.addEventListener("scroll", place, true);
476
+ return () => {
477
+ window.removeEventListener("resize", place);
478
+ window.removeEventListener("scroll", place, true);
479
+ };
480
+ }, [open]);
481
+
482
+ return h(
483
+ "span",
484
+ { className: "mk-dt-info-wrap", ref: wrapRef },
485
+ h(
486
+ "button",
487
+ {
488
+ type: "button",
489
+ className: cx("mk-dt-info", open && "open"),
490
+ "aria-label": label,
491
+ "aria-haspopup": "dialog",
492
+ "aria-expanded": open,
493
+ "aria-controls": open ? id : undefined,
494
+ onClick: e => {
495
+ e.stopPropagation();
496
+ setOpen(o => !o);
497
+ },
498
+ },
499
+ h(IconInfo),
500
+ ),
501
+ open &&
502
+ typeof document !== "undefined" &&
503
+ createPortal(
504
+ h(
505
+ "div",
506
+ {
507
+ ref: panelRef,
508
+ id,
509
+ className: "mk-pop mk-dt-info-pop",
510
+ role: "dialog",
511
+ "aria-label": label,
512
+ tabIndex: -1,
513
+ onClick: e => e.stopPropagation(),
514
+ },
515
+ title != null && h("strong", { className: "mk-dt-info-title" }, title),
516
+ h("div", { className: "mk-dt-info-body" }, children),
517
+ ),
518
+ document.body,
519
+ ),
520
+ );
521
+ }
522
+
417
523
  /** A value that is controlled when `value !== undefined`, local state otherwise. */
418
524
  function useControlled(value, initial, onChange) {
419
525
  const [local, setLocal] = React.useState(initial);
@@ -452,6 +558,7 @@ export function saveCsv(filename, text) {
452
558
  }
453
559
 
454
560
  const fmtCount = n => n.toLocaleString("en-US");
561
+ const EMPTY_EXPANDED = Object.freeze({});
455
562
 
456
563
  /**
457
564
  * The English text of a DataTable's footer, sort hints and export button.
@@ -477,6 +584,9 @@ export const DATA_TABLE_LABELS = {
477
584
  exportCsv: "Export CSV",
478
585
  exportTitle: "Export every row on every page, as sorted",
479
586
  exportFailed: "The browser blocked the download. Open the app in a new tab and export again.",
587
+ expand: () => "Show details",
588
+ collapse: () => "Hide details",
589
+ info: label => `About ${label}`,
480
590
  };
481
591
  // A click on a link, button or field inside a row is that control's, not the row's.
482
592
  const INTERACTIVE = "a,button,input,select,textarea,label,[role=button]";
@@ -500,6 +610,12 @@ const INTERACTIVE = "a,button,input,select,textarea,label,[role=button]";
500
610
  * label or class per group id). Ungrouped columns span both rows. A line
501
611
  * separates the sections. Sort, the sticky header and the pinned column work
502
612
  * the same.
613
+ *
614
+ * Four options, all off by default (the table then renders exactly as 2.27):
615
+ * `wrapHeaders` lets a header label take 2 lines; `renderExpanded` adds a
616
+ * chevron in each row's first cell that opens a full-width detail row under
617
+ * it; a column's `info` adds an "i" popover beside its header; `totalRow`
618
+ * pins a total row to the bottom of the scroll box.
503
619
  */
504
620
  export function DataTable({
505
621
  rows = [],
@@ -528,6 +644,15 @@ export function DataTable({
528
644
  resetKey,
529
645
  exportFilename,
530
646
  groups,
647
+ wrapHeaders = false,
648
+ renderExpanded,
649
+ canExpand,
650
+ expanded: expandedProp,
651
+ defaultExpanded = EMPTY_EXPANDED,
652
+ onExpandedChange,
653
+ totalRow,
654
+ onTotalRowClick,
655
+ exportTotalRow = false,
531
656
  className,
532
657
  style,
533
658
  }) {
@@ -548,6 +673,35 @@ export function DataTable({
548
673
  const { page, pageCount, start, end } = pageSlice(sorted.length, rawPage, pageSize);
549
674
  const visible = sorted.slice(start, end);
550
675
 
676
+ // Expandable rows. The state has TanStack Table's ExpandedState shape:
677
+ // `true` (every row) or `{ [rowId]: true }`, rowId being String(rowKey(row)).
678
+ // Detail rows are rendered under their parent only: never sorted, paged or
679
+ // exported, since they are not rows of `sorted`.
680
+ const expandable = typeof renderExpanded === "function";
681
+ const [expanded, setExpanded] = useControlled(expandedProp, defaultExpanded, onExpandedChange);
682
+ const uid = React.useId();
683
+ const keyOf = (row, i) => (rowKey ? rowKey(row) : (row?.id ?? i));
684
+ const isOpen = id => expanded === true || !!expanded?.[id];
685
+ const toggle = id => {
686
+ let next;
687
+ if (expanded === true) {
688
+ next = {};
689
+ sorted.forEach((r, i) => {
690
+ if (!canExpand || canExpand(r)) next[String(keyOf(r, i))] = true;
691
+ });
692
+ } else next = { ...expanded };
693
+ if (next[id]) delete next[id];
694
+ else next[id] = true;
695
+ setExpanded(next);
696
+ };
697
+
698
+ // The total row: an object, or a function over the rows the table got (the
699
+ // filtered rows). It never sorts or pages; CSV only with `exportTotalRow`.
700
+ const total = React.useMemo(
701
+ () => (typeof totalRow === "function" ? totalRow(rows) : (totalRow ?? null)),
702
+ [totalRow, rows],
703
+ );
704
+
551
705
  const goTo = p => {
552
706
  if (p !== rawPage) setRawPage(p);
553
707
  scrollRef.current?.scrollTo?.({ top: 0 });
@@ -582,7 +736,7 @@ export function DataTable({
582
736
  goTo(1);
583
737
  };
584
738
  const exportCsv = () => {
585
- const res = saveCsv(exportFilename, toCsv(sorted, columns));
739
+ const res = saveCsv(exportFilename, toCsv(exportTotalRow && total ? [...sorted, total] : sorted, columns));
586
740
  setNote(res === "failed" ? L.exportFailed : null);
587
741
  };
588
742
 
@@ -624,7 +778,14 @@ export function DataTable({
624
778
  className: cellClass(col, active && "mk-dt-sorted"),
625
779
  "aria-sort": col.sortable === false ? undefined : active ? (sort.dir === "asc" ? "ascending" : "descending") : "none",
626
780
  },
627
- label,
781
+ col.info == null
782
+ ? label
783
+ : h(
784
+ "div",
785
+ { className: "mk-dt-th-row" },
786
+ label,
787
+ h(HeaderInfo, { title: col.label, label: L.info(text) }, col.info),
788
+ ),
628
789
  );
629
790
  };
630
791
 
@@ -662,6 +823,41 @@ export function DataTable({
662
823
  const title = typeof v === "string" || typeof v === "number" || typeof v === "bigint" ? String(v) : undefined;
663
824
  return h("div", { className: "mk-dt-cell", title: title || undefined }, content);
664
825
  };
826
+ // The first cell of an expandable table: the chevron (or a spacer of its
827
+ // width, so every first cell lines up) before the cell's content.
828
+ const firstCell = (col, row, toggleEl) =>
829
+ h("div", { className: "mk-dt-xcell" }, toggleEl ?? h("span", { className: "mk-dt-expander-none", "aria-hidden": "true" }), cell(col, row));
830
+ const expander = (row, id, open, detailId) =>
831
+ h(
832
+ "button",
833
+ {
834
+ type: "button",
835
+ className: "mk-dt-expander",
836
+ "aria-expanded": open,
837
+ "aria-controls": open ? detailId : undefined,
838
+ "aria-label": open ? L.collapse(row) : L.expand(row),
839
+ onClick: () => toggle(id),
840
+ },
841
+ h(IconChevron),
842
+ );
843
+ // A row click (and Enter or Space on the focused row), for body rows and the total row.
844
+ const clickProps = (handler, row, label) =>
845
+ handler
846
+ ? {
847
+ tabIndex: 0,
848
+ className: "mk-dt-click",
849
+ "aria-label": label,
850
+ onClick: e => {
851
+ if (!e.target.closest?.(INTERACTIVE)) handler(row, e);
852
+ },
853
+ onKeyDown: e => {
854
+ if ((e.key === "Enter" || e.key === " ") && e.target === e.currentTarget) {
855
+ e.preventDefault();
856
+ handler(row, e);
857
+ }
858
+ },
859
+ }
860
+ : null;
665
861
 
666
862
  const body = h(
667
863
  "tbody",
@@ -669,32 +865,67 @@ export function DataTable({
669
865
  visible.length === 0
670
866
  ? h("tr", { key: "__empty" }, h("td", { colSpan: columns.length, className: "mk-dt-empty" }, empty))
671
867
  : visible.map((row, i) => {
672
- const key = rowKey ? rowKey(row) : (row?.id ?? start + i);
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;
868
+ const key = keyOf(row, start + i);
869
+ const click = clickProps(onRowClick, row, rowLabel ? rowLabel(row) : undefined);
689
870
  const rowClass = cx(click?.className, rowClassName?.(row)) || undefined;
690
- return h(
871
+ if (!expandable) {
872
+ return h(
873
+ "tr",
874
+ { key, ...click, className: rowClass },
875
+ ...columns.map(col => h("td", { key: col.id, className: cellClass(col) || undefined }, cell(col, row))),
876
+ );
877
+ }
878
+ const id = String(key);
879
+ const can = !canExpand || canExpand(row);
880
+ const open = can && isOpen(id);
881
+ const detailId = `${uid}-x-${id.replace(/\s/g, "_")}`;
882
+ // Always a Fragment, open or not: a tr swapped for a Fragment would
883
+ // remount the row and drop the chevron's focus.
884
+ const tr = h(
691
885
  "tr",
692
- { key, ...click, className: rowClass },
693
- ...columns.map(col => h("td", { key: col.id, className: cellClass(col) || undefined }, cell(col, row))),
886
+ { key: "row", ...click, className: cx(rowClass, open && "mk-dt-open") || undefined },
887
+ ...columns.map((col, c) =>
888
+ h(
889
+ "td",
890
+ { key: col.id, className: cellClass(col) || undefined },
891
+ c === 0 ? firstCell(col, row, can ? expander(row, id, open, detailId) : null) : cell(col, row),
892
+ ),
893
+ ),
894
+ );
895
+ return h(
896
+ React.Fragment,
897
+ { key },
898
+ tr,
899
+ open &&
900
+ h(
901
+ "tr",
902
+ { key: "detail", className: "mk-dt-detail", id: detailId },
903
+ h("td", { colSpan: columns.length }, h("div", { className: "mk-dt-detail-body" }, renderExpanded(row))),
904
+ ),
694
905
  );
695
906
  }),
696
907
  );
697
908
 
909
+ // The pinned total row (a <tfoot> that sticks to the bottom), shown with rows only.
910
+ const foot =
911
+ total != null && sorted.length > 0
912
+ ? h(
913
+ "tfoot",
914
+ null,
915
+ h(
916
+ "tr",
917
+ { ...clickProps(onTotalRowClick, total, rowLabel ? rowLabel(total) : undefined), className: cx("mk-dt-total", onTotalRowClick && "mk-dt-click") },
918
+ ...columns.map((col, c) =>
919
+ h(
920
+ "td",
921
+ { key: col.id, className: cellClass(col) || undefined },
922
+ c === 0 && expandable ? firstCell(col, total, null) : cell(col, total),
923
+ ),
924
+ ),
925
+ ),
926
+ )
927
+ : null;
928
+
698
929
  const footer = h(
699
930
  "footer",
700
931
  { className: "mk-dt-foot" },
@@ -744,7 +975,7 @@ export function DataTable({
744
975
  title,
745
976
  description,
746
977
  actions: actions != null || exportButton ? h(React.Fragment, null, actions, exportButton) : undefined,
747
- className: cx("mk-dt", fill && "mk-dt--fill", className),
978
+ className: cx("mk-dt", fill && "mk-dt--fill", wrapHeaders && "mk-dt--wrap-heads", className),
748
979
  style,
749
980
  },
750
981
  note && h("p", { className: "mk-dt-note", role: "status" }, note),
@@ -761,6 +992,7 @@ export function DataTable({
761
992
  ),
762
993
  head,
763
994
  body,
995
+ foot,
764
996
  ),
765
997
  ),
766
998
  footer,
@@ -806,11 +1038,14 @@ const asChecked = t => (t === "on" ? true : t === "mixed" ? "mixed" : false);
806
1038
  * (several filters folded into one dropdown on a phone), so every filter
807
1039
  * ticks and toggles alike.
808
1040
  *
809
- * Options are strings, `{ value, label, color }`, or groups with `children`
1041
+ * Options are strings, `{ value, label, color, count }`, or groups with `children`
810
1042
  * (a flat list is a one-level tree). A group row ticks its whole group and
811
1043
  * shows a dash when part of it is picked; its children follow it, indented.
812
1044
  * A tree that needs hover submenus is a FilterMenu (`@makoai/app-sdk/menu`).
813
1045
  *
1046
+ * `count` (2.28) is a number shown muted at the row's right edge, before
1047
+ * "Only". Search matches the label only, and the trigger never shows it.
1048
+ *
814
1049
  * The All rule (2.20): with nothing filtered (`value` empty or holding every
815
1050
  * option) every row is ticked. Unticking one leaves All in the partial (–)
816
1051
  * state. A click on a full All unticks every row; a click on a partial All
@@ -956,6 +1191,7 @@ export function FilterItems({
956
1191
  h(Checkbox, { checked: asChecked(tick) }),
957
1192
  dot(node),
958
1193
  h("span", { className: "mk-ms-label" }, node.label),
1194
+ node.count != null && h("span", { className: "mk-ms-count" }, typeof node.count === "number" ? fmtCount(node.count) : node.count),
959
1195
  showOnly && filterLeavesOf(node).length > 0 && h("button", { type: "button", className: "mk-ms-only", tabIndex: -1, onClick: only(node) }, "Only"),
960
1196
  );
961
1197
  return group ? [el, ...node.children.flatMap(c => row(c, depth + 1))] : [el];