@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/README.md
CHANGED
|
@@ -455,6 +455,23 @@ an app's own menu that folds several filters into one dropdown on a phone.
|
|
|
455
455
|
</DropdownMenuSubContent>
|
|
456
456
|
```
|
|
457
457
|
|
|
458
|
+
**Search (2.27).** `searchable` puts a search input at the top of the menu.
|
|
459
|
+
The order is search, All, a separator, then the values.
|
|
460
|
+
|
|
461
|
+
```tsx
|
|
462
|
+
<MultiSelect searchable options={owners} value={owner} onChange={setOwner} allLabel="All owners" showOnly />
|
|
463
|
+
```
|
|
464
|
+
|
|
465
|
+
- The input takes focus when the menu opens.
|
|
466
|
+
- Typing filters the rows by label, case-insensitive. A group whose label matches keeps all its rows.
|
|
467
|
+
- All and its separator hide while a query is typed. "No match" shows when no row matches (`searchEmpty`).
|
|
468
|
+
- The keys are shadcn Command's (cmdk). ArrowDown and ArrowUp move the highlight. Home and End jump to the ends. Enter ticks the highlighted row.
|
|
469
|
+
- The first row is highlighted after every keystroke, so "type a name, Enter" ticks it.
|
|
470
|
+
- A tick follows the All rule above, as a click does.
|
|
471
|
+
- The query clears when the menu closes.
|
|
472
|
+
- `searchPlaceholder` sets the placeholder (default "Search").
|
|
473
|
+
- Without `searchable` the menu is unchanged.
|
|
474
|
+
|
|
458
475
|
**Replacing an app's NestedFilterMenu: `FilterMenu`.** See "Menus" below:
|
|
459
476
|
`FilterMenu` and `FilterMenuItems` from `@makoai/app-sdk/menu` take
|
|
460
477
|
NestedFilterMenu's props (`label`, `options`, `selected`, `onChange`,
|
|
@@ -589,6 +606,98 @@ house tokens onto Tailwind's colour names (`bg-popover`,
|
|
|
589
606
|
optional peer set: apps that import neither `/components` nor `/menu` need
|
|
590
607
|
none of it.
|
|
591
608
|
|
|
609
|
+
### Date filters: `PeriodPicker` (2.27)
|
|
610
|
+
|
|
611
|
+
A date filter reads **‹ Nov 2026 ›**. The arrows step one period. The middle
|
|
612
|
+
opens a picker with the units, the recent periods and a Custom range. The
|
|
613
|
+
period in progress is tinted and says "in progress": its numbers are not
|
|
614
|
+
final.
|
|
615
|
+
|
|
616
|
+
```tsx
|
|
617
|
+
import { PeriodPicker, clipToday, periodOf, todayIso, type Period } from "@makoai/app-sdk/components";
|
|
618
|
+
|
|
619
|
+
const [period, setPeriod] = useState<Period>(periodOf("month", todayIso()));
|
|
620
|
+
<PeriodPicker value={period} onChange={setPeriod}
|
|
621
|
+
units={["week", "month", "quarter", "year"]} min="2024-01-01" label="Hires" />
|
|
622
|
+
|
|
623
|
+
const { from, to } = clipToday(period); // the month in progress stops at today
|
|
624
|
+
```
|
|
625
|
+
|
|
626
|
+
- `units` defaults to month, quarter and year. The picker lists 12 weeks,
|
|
627
|
+
12 months, 8 quarters or 4 years.
|
|
628
|
+
- `custom` is `"month"` (whole months, the default), `"day"` (any days) or
|
|
629
|
+
`false`. The arrows move a custom range by its own length.
|
|
630
|
+
- ‹ stops at `min`, the first day with data. › stops at today, or at `max`
|
|
631
|
+
(next month's end for a capacity plan).
|
|
632
|
+
- `periodOf(unit, day)`, `shift(period, k)`, `isCurrent(period)`,
|
|
633
|
+
`clipToday(period)` and `periodLabel(period)` are the helpers. Dates are
|
|
634
|
+
"YYYY-MM-DD" UTC day keys, both ends inclusive. Weeks start on Monday.
|
|
635
|
+
- The menu is the stock `Popover`. Focus moves into it on open and back to
|
|
636
|
+
the middle on Escape.
|
|
637
|
+
|
|
638
|
+
### The page filter bar (2.27)
|
|
639
|
+
|
|
640
|
+
`FilterBar` puts the page-wide filters in one row under the tabs. Each control
|
|
641
|
+
gets a small-caps label over it. `FilterSep` draws the hairline between two
|
|
642
|
+
groups. Reset sits at the end and stays disabled while every filter is at its
|
|
643
|
+
default. The row wraps on a narrow window. At 768px and under the fields fold
|
|
644
|
+
behind one Filters chip that counts the active filters. The chip opens a
|
|
645
|
+
bottom sheet with Done.
|
|
646
|
+
|
|
647
|
+
A tab adds its own fields with `TabFilters`. They render into the same bar,
|
|
648
|
+
after the page's. `useResettable(id, dirty, reset)` tells Reset and the chip
|
|
649
|
+
about a tab's filter. Wrap the page in `FilterProvider`.
|
|
650
|
+
|
|
651
|
+
```tsx
|
|
652
|
+
import {
|
|
653
|
+
FilterBar, FilterField, FilterProvider, FilterSep, TabFilters, useResettable,
|
|
654
|
+
Select, SelectContent, SelectItem, SelectTrigger, SelectValue,
|
|
655
|
+
} from "@makoai/app-sdk/components";
|
|
656
|
+
|
|
657
|
+
function RoleTab() {
|
|
658
|
+
const [role, setRole] = useState("bdr");
|
|
659
|
+
useResettable("role", role !== "bdr", () => setRole("bdr"));
|
|
660
|
+
return (
|
|
661
|
+
<TabFilters>
|
|
662
|
+
<FilterSep />
|
|
663
|
+
<FilterField label="Role" hint="The role at hire">
|
|
664
|
+
<Select value={role} onValueChange={setRole}>
|
|
665
|
+
<SelectTrigger aria-label="Role" className="w-[210px]"><SelectValue /></SelectTrigger>
|
|
666
|
+
<SelectContent>{ROLES.map(r => <SelectItem key={r.value} value={r.value}>{r.label}</SelectItem>)}</SelectContent>
|
|
667
|
+
</Select>
|
|
668
|
+
</FilterField>
|
|
669
|
+
</TabFilters>
|
|
670
|
+
);
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
<FilterProvider>
|
|
674
|
+
<FilterBar dirty={market !== "ALL"} onReset={() => setMarket("ALL")}>
|
|
675
|
+
<FilterField label="Market">{/* Select, FilterMenu or MultiSelect */}</FilterField>
|
|
676
|
+
</FilterBar>
|
|
677
|
+
{tab === "role" && <RoleTab />}
|
|
678
|
+
</FilterProvider>
|
|
679
|
+
```
|
|
680
|
+
|
|
681
|
+
The bar holds any control: `Select`, `FilterMenu`, `MultiSelect`. In the
|
|
682
|
+
phone sheet each control takes the full width. The sheet sits at z-index 50,
|
|
683
|
+
so the Radix popovers of `/components` and `/menu` open above it. Escape
|
|
684
|
+
closes an open popover first and the sheet on the next press.
|
|
685
|
+
|
|
686
|
+
### Country colours: `COUNTRY_COLORS`, `COUNTRY_ORDER` (2.27)
|
|
687
|
+
|
|
688
|
+
A market has one colour in every app. Keys are lowercase codes.
|
|
689
|
+
|
|
690
|
+
```ts
|
|
691
|
+
import { COUNTRY_COLORS, COUNTRY_ORDER } from "@makoai/app-sdk";
|
|
692
|
+
|
|
693
|
+
COUNTRY_COLORS.ch; // "#dc2626"; `all` is "#475569", the all-markets line
|
|
694
|
+
COUNTRY_ORDER; // ["ch", "fr", "es", "it", "pl", "pt"]
|
|
695
|
+
rows.sort((a, b) => COUNTRY_ORDER.indexOf(a.country) - COUNTRY_ORDER.indexOf(b.country));
|
|
696
|
+
```
|
|
697
|
+
|
|
698
|
+
CH red, FR blue, IT green, ES amber, PT teal, PL rose. Other series in a
|
|
699
|
+
country chart take `--chart-1…5`. Both objects are frozen.
|
|
700
|
+
|
|
592
701
|
### Times and dates (2.21)
|
|
593
702
|
|
|
594
703
|
DuckDB runs in UTC, and that stays. Display code decides the zone.
|
|
@@ -624,6 +733,15 @@ Run it in an app folder (or pass several). It exits 1 on a finding;
|
|
|
624
733
|
anything inside a `<>` fragment: a chart loses its reference lines. The
|
|
625
734
|
fix is `"pnpm": { "overrides": { "react-is": "^19.1.10" } }`.
|
|
626
735
|
|
|
736
|
+
- `distinct-sum` (2.27, warning): a binding column that is a distinct count
|
|
737
|
+
(`COUNT(DISTINCT …)`, `uniq…`, `APPROX_COUNT_DISTINCT`) summed in `src/`
|
|
738
|
+
(`SUM(col)` in DuckDB SQL, or a JS `reduce`/`sum`/`pivot` next to it). One
|
|
739
|
+
person in several groups counts once per group: visibility-dashboard's unique
|
|
740
|
+
users read 13% high in Spain (19 Nov 2026). Return the total at the shown
|
|
741
|
+
grain from the binding (`GROUP BY GROUPING SETS`), or mark a deliberate sum
|
|
742
|
+
("user-days") with `// mako-lint-ignore distinct-sum` and the reason.
|
|
743
|
+
Warnings print and never fail the run.
|
|
744
|
+
|
|
627
745
|
`--rules=react-version` runs only the named rules (2.24).
|
|
628
746
|
|
|
629
747
|
### Chart tooltips: `TableTooltip` (2.10+, every series from 2.15)
|
|
@@ -683,6 +801,29 @@ const SEGMENTS = [ // bottom-up, as stacked; drives the bars, the legend AND the
|
|
|
683
801
|
- On a chart with an HTML overlay (a donut's centre label), lift the tooltip:
|
|
684
802
|
`<Tooltip wrapperStyle={{ zIndex: 20 }} … />`.
|
|
685
803
|
|
|
804
|
+
**Stacks: an absent segment is a zero, plus its share.** A stacked bar's
|
|
805
|
+
bucket often has no row for a segment (no 3xx requests that hour). That is a
|
|
806
|
+
zero, not missing data. `absentAsZero: true` turns a null or absent key into a
|
|
807
|
+
muted "0". NaN stays a "–" (a mean the bucket cannot compute). `share: true`
|
|
808
|
+
adds `share` to each row: its value over the sum of the non-missing values,
|
|
809
|
+
null when the value is missing or the sum is 0. `colWidth` on `TableTooltip`
|
|
810
|
+
sets the value columns' minimum width (`"9ch"`, or px as a number). Both
|
|
811
|
+
options are off by default, and with them off the rows are the same as before.
|
|
812
|
+
|
|
813
|
+
```tsx
|
|
814
|
+
content={tableTooltip((d) => {
|
|
815
|
+
const rows = tooltipSeriesRows(d, STACKS, { stacked: true, absentAsZero: true, share: true });
|
|
816
|
+
const total = rows.reduce((a, r) => a + (r.value ?? 0), 0);
|
|
817
|
+
return {
|
|
818
|
+
title: d.hour,
|
|
819
|
+
columns: ["Requests", "% of total"],
|
|
820
|
+
colWidth: "9ch",
|
|
821
|
+
rows: rows.map((r) => ({ ...r, cells: [tooltipCell(r.value, fmtInt), tooltipCell(r.share, fmtPct, { percent: true })] })),
|
|
822
|
+
total: { label: "Total", cells: [tooltipCell(total, fmtInt), total > 0 ? "100%" : tooltipCell(0, fmtPct, { percent: true })] },
|
|
823
|
+
};
|
|
824
|
+
})}
|
|
825
|
+
```
|
|
826
|
+
|
|
686
827
|
**Opt-out.** Before 2.15, `tooltipSeriesRows` dropped zero and missing values
|
|
687
828
|
and sorted line charts highest value first. A caller that truly needs that
|
|
688
829
|
passes `{ hideEmpty: true, byValue: true }`. `hideEmpty` drops zero and
|
|
@@ -767,6 +908,47 @@ const COLUMNS: DataTableColumn<Customer>[] = [
|
|
|
767
908
|
focused row); clicks on links and buttons inside a cell stay theirs.
|
|
768
909
|
`rowLabel(row)` names a clickable row for screen readers. `rowKey` defaults
|
|
769
910
|
to `row.id`.
|
|
911
|
+
- **Row tints.** `rowClassName(row)` adds a class to a body row. Set
|
|
912
|
+
`--mk-dt-row-bg` in that class and every cell paints it, the pinned first
|
|
913
|
+
column included. Pick an opaque colour so scrolled cells stay behind the
|
|
914
|
+
pin. Without `rowClassName` rows get no class.
|
|
915
|
+
|
|
916
|
+
```tsx
|
|
917
|
+
// app.css: .deal-lost { --mk-dt-row-bg: color-mix(in srgb, var(--negative) 12%, var(--card)); }
|
|
918
|
+
<DataTable rows={deals} columns={COLUMNS} rowClassName={d => (d.status === "lost" ? "deal-lost" : undefined)} />
|
|
919
|
+
```
|
|
920
|
+
- **Labels.** `labels` translates every string the table writes itself: the
|
|
921
|
+
footer, the empty state, the page-size select, the « ‹ › » aria-labels, the
|
|
922
|
+
sort hint and the export button. Pass any subset. Missing keys keep the
|
|
923
|
+
English defaults in `DATA_TABLE_LABELS`. Text with numbers is a function
|
|
924
|
+
that gets raw numbers, so format them in your locale. `noun` still names the
|
|
925
|
+
rows, and an `empty` prop wins over `labels.empty`.
|
|
926
|
+
|
|
927
|
+
```tsx
|
|
928
|
+
const fr = (n: number) => n.toLocaleString("fr-FR");
|
|
929
|
+
const FR: Partial<DataTableLabels> = {
|
|
930
|
+
range: (from, to, total, noun) => `${fr(from)}–${fr(to)} sur ${fr(total)} ${noun}`,
|
|
931
|
+
none: noun => `Aucun ${noun.replace(/s$/, "")}`,
|
|
932
|
+
empty: "Aucune ligne pour ces filtres.",
|
|
933
|
+
page: (page, pageCount) => `Page ${page} sur ${pageCount}`,
|
|
934
|
+
perPage: size => `${size} par page`,
|
|
935
|
+
rowsPerPage: "Lignes par page",
|
|
936
|
+
first: "Première page",
|
|
937
|
+
previous: "Page précédente",
|
|
938
|
+
next: "Page suivante",
|
|
939
|
+
last: "Dernière page",
|
|
940
|
+
sortHint: label => `${label} · cliquer pour trier`,
|
|
941
|
+
exportCsv: "Exporter en CSV",
|
|
942
|
+
exportTitle: "Exporter toutes les lignes, dans l'ordre du tri",
|
|
943
|
+
exportFailed: "Le navigateur a bloqué le téléchargement. Ouvrez l'app dans un nouvel onglet.",
|
|
944
|
+
};
|
|
945
|
+
|
|
946
|
+
<DataTable rows={list} columns={COLUMNS} noun="clients" labels={FR} />
|
|
947
|
+
// footer: 51–100 sur 1 234 clients · 50 par page · « ‹ Page 2 sur 25 › »
|
|
948
|
+
```
|
|
949
|
+
|
|
950
|
+
The English `range` bolds the two numbers. A custom `range` may return JSX
|
|
951
|
+
to do the same.
|
|
770
952
|
- **CSV.** `exportFilename` adds an "Export CSV" button that downloads every
|
|
771
953
|
row on every page, as sorted. Mako's app frames allow downloads. Numbers
|
|
772
954
|
export as is. Text starting with `=`, `+`, `-`, `@`, tab or CR gets a
|
|
@@ -774,8 +956,26 @@ const COLUMNS: DataTableColumn<Customer>[] = [
|
|
|
774
956
|
midnight exports as `YYYY-MM-DD`, any other Date as a UTC ISO timestamp. For
|
|
775
957
|
your own button: `saveCsv(filename, toCsv(rows, columns))` returns
|
|
776
958
|
`"downloaded"` or `"failed"`.
|
|
959
|
+
- **Column groups.** Give columns a `group` and the header gets a second row
|
|
960
|
+
on top. Each group's label spans its adjacent columns. Ungrouped columns
|
|
961
|
+
(the pinned name) span both rows. A line runs down the left of each section.
|
|
962
|
+
`groups` sets a label and a class per group id; a group not listed shows its
|
|
963
|
+
id. Sorting, the sticky header and the pinned column work as before. With
|
|
964
|
+
no `group` on any column the header is one row, as before.
|
|
965
|
+
|
|
966
|
+
```tsx
|
|
967
|
+
const COLUMNS = [
|
|
968
|
+
{ id: "country", label: "Country", value: r => r.country, sticky: true },
|
|
969
|
+
{ id: "calls", label: "Calls", num: true, value: r => r.calls, group: "activity" },
|
|
970
|
+
{ id: "demos", label: "Demos", num: true, value: r => r.demos, group: "activity" },
|
|
971
|
+
{ id: "cash", label: "Cash", num: true, value: r => r.cash, group: "money" },
|
|
972
|
+
];
|
|
973
|
+
<DataTable rows={rows} columns={COLUMNS}
|
|
974
|
+
groups={[{ id: "activity", label: "Activity" }, { id: "money", label: "Money", className: "tone-positive" }]} />
|
|
975
|
+
```
|
|
777
976
|
- Pure helpers for custom tables: `sortRows`, `compareValues`, `nextSort`,
|
|
778
|
-
`pageSlice`, `pageToSync`, `toCsv`, `csvCell`, `csvDate`, `csvToTsv
|
|
977
|
+
`pageSlice`, `pageToSync`, `toCsv`, `csvCell`, `csvDate`, `csvToTsv`,
|
|
978
|
+
`columnLayout`, `columnGroupRuns`.
|
|
779
979
|
|
|
780
980
|
`ui.css` is plain CSS (no Tailwind needed; it coexists with Tailwind) and
|
|
781
981
|
every kit class is prefixed `mk-`. It also sets the house base: Inter 14px on
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
// The page's filter bar (one row under the tabs): a small-caps label above each
|
|
4
|
+
// control, groups split by a hairline, Reset at the end. Each tab adds its own
|
|
5
|
+
// fields with <TabFilters>; they render into the bar, next to the global ones.
|
|
6
|
+
// Phones (768px and under): the fields fold behind one "Filters" chip that
|
|
7
|
+
// opens a bottom sheet with Done.
|
|
8
|
+
//
|
|
9
|
+
// A house component, not a shadcn one (2.27): ported 1:1 from the workspace's
|
|
10
|
+
// apps/attrition-por-cohorte/src/ui/FilterBar.tsx and its .fb CSS, written as
|
|
11
|
+
// Tailwind classes on the house tokens. The bar and the sheet are one element
|
|
12
|
+
// (CSS restyles it), so the tab fields portalled into its slot stay mounted on
|
|
13
|
+
// every width. Two changes from the reference: the sheet sits at z-50 (scrim
|
|
14
|
+
// z-49), so the SDK's Radix popovers (z-50, portalled after it) open above it;
|
|
15
|
+
// and Escape leaves the sheet open when a popover inside it took the key.
|
|
16
|
+
import * as React from "react"
|
|
17
|
+
import { createPortal } from "react-dom"
|
|
18
|
+
import { cn } from "../menu/utils"
|
|
19
|
+
|
|
20
|
+
type Entry = { dirty: boolean; reset: () => void }
|
|
21
|
+
type Ctx = {
|
|
22
|
+
slot: HTMLElement | null
|
|
23
|
+
setSlot: (el: HTMLElement | null) => void
|
|
24
|
+
entries: Record<string, Entry>
|
|
25
|
+
register: (id: string, e: Entry | null) => void
|
|
26
|
+
}
|
|
27
|
+
const FilterCtx = React.createContext<Ctx>({ slot: null, setSlot: () => {}, entries: {}, register: () => {} })
|
|
28
|
+
|
|
29
|
+
/** Wraps the page: the bar and every tab that adds fields to it. */
|
|
30
|
+
function FilterProvider({ children }: { children: React.ReactNode }) {
|
|
31
|
+
const [slot, setSlot] = React.useState<HTMLElement | null>(null)
|
|
32
|
+
const [entries, setEntries] = React.useState<Record<string, Entry>>({})
|
|
33
|
+
const register = React.useCallback((id: string, e: Entry | null) => {
|
|
34
|
+
setEntries(prev => {
|
|
35
|
+
if (e == null) {
|
|
36
|
+
if (!(id in prev)) return prev
|
|
37
|
+
const { [id]: _, ...rest } = prev
|
|
38
|
+
return rest
|
|
39
|
+
}
|
|
40
|
+
if (prev[id]?.dirty === e.dirty && prev[id]?.reset === e.reset) return prev
|
|
41
|
+
return { ...prev, [id]: e }
|
|
42
|
+
})
|
|
43
|
+
}, [])
|
|
44
|
+
const ctx = React.useMemo(() => ({ slot, setSlot, entries, register }), [slot, entries, register])
|
|
45
|
+
return <FilterCtx.Provider value={ctx}>{children}</FilterCtx.Provider>
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** The bar. `dirty`/`onReset` cover the page-wide fields; tabs register theirs with useResettable. */
|
|
49
|
+
function FilterBar({
|
|
50
|
+
children,
|
|
51
|
+
dirty,
|
|
52
|
+
onReset,
|
|
53
|
+
className,
|
|
54
|
+
}: {
|
|
55
|
+
children: React.ReactNode
|
|
56
|
+
dirty: boolean
|
|
57
|
+
onReset: () => void
|
|
58
|
+
className?: string
|
|
59
|
+
}) {
|
|
60
|
+
const { setSlot, entries } = React.useContext(FilterCtx)
|
|
61
|
+
const active = (dirty ? 1 : 0) + Object.values(entries).filter(e => e.dirty).length
|
|
62
|
+
const [sheet, setSheet] = React.useState(false)
|
|
63
|
+
React.useEffect(() => {
|
|
64
|
+
if (!sheet) return
|
|
65
|
+
// A Radix popover in the sheet marks the Escape it handled: only it closes.
|
|
66
|
+
const key = (e: KeyboardEvent) => {
|
|
67
|
+
if (e.key === "Escape" && !e.defaultPrevented) setSheet(false)
|
|
68
|
+
}
|
|
69
|
+
window.addEventListener("keydown", key)
|
|
70
|
+
return () => window.removeEventListener("keydown", key)
|
|
71
|
+
}, [sheet])
|
|
72
|
+
const reset = () => {
|
|
73
|
+
onReset()
|
|
74
|
+
Object.values(entries).forEach(e => e.reset())
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return (
|
|
78
|
+
<>
|
|
79
|
+
<div data-slot="filter-chipbar" className="hidden max-[769px]:flex">
|
|
80
|
+
<button
|
|
81
|
+
type="button"
|
|
82
|
+
data-slot="filter-chip"
|
|
83
|
+
aria-expanded={sheet}
|
|
84
|
+
onClick={() => setSheet(!sheet)}
|
|
85
|
+
className="inline-flex h-[34px] items-center gap-2 rounded-[8px] border border-border bg-card px-3 text-sm font-medium shadow-[0_1px_2px_rgb(0_0_0/.05)]"
|
|
86
|
+
>
|
|
87
|
+
Filters{" "}
|
|
88
|
+
{active > 0 && (
|
|
89
|
+
<span
|
|
90
|
+
data-slot="filter-count"
|
|
91
|
+
className="inline-flex h-[18px] min-w-[18px] items-center justify-center rounded-full bg-brand px-[5px] text-[11px] font-semibold text-white"
|
|
92
|
+
>
|
|
93
|
+
{active}
|
|
94
|
+
</span>
|
|
95
|
+
)}
|
|
96
|
+
<svg width="12" height="12" viewBox="0 0 24 24" aria-hidden>
|
|
97
|
+
<path d="m6 9 6 6 6-6" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" />
|
|
98
|
+
</svg>
|
|
99
|
+
</button>
|
|
100
|
+
</div>
|
|
101
|
+
{sheet && (
|
|
102
|
+
<div
|
|
103
|
+
data-slot="filter-scrim"
|
|
104
|
+
className="hidden max-[769px]:fixed max-[769px]:inset-0 max-[769px]:z-49 max-[769px]:block max-[769px]:bg-black/40"
|
|
105
|
+
onClick={() => setSheet(false)}
|
|
106
|
+
/>
|
|
107
|
+
)}
|
|
108
|
+
<div
|
|
109
|
+
data-slot="filter-bar"
|
|
110
|
+
data-open={sheet || undefined}
|
|
111
|
+
role="group"
|
|
112
|
+
aria-label="Filters"
|
|
113
|
+
className={cn(
|
|
114
|
+
"group/fb flex flex-wrap items-end gap-x-3 gap-y-2.5",
|
|
115
|
+
sheet
|
|
116
|
+
? "max-[769px]:fixed max-[769px]:inset-x-0 max-[769px]:bottom-0 max-[769px]:z-50 max-[769px]:max-h-[85dvh] max-[769px]:flex-col max-[769px]:items-stretch max-[769px]:gap-3.5 max-[769px]:overflow-auto max-[769px]:rounded-t-2xl max-[769px]:border-t max-[769px]:border-border max-[769px]:bg-background max-[769px]:px-4 max-[769px]:pt-1 max-[769px]:pb-[calc(16px+env(safe-area-inset-bottom,0px))] max-[769px]:shadow-[0_-12px_32px_rgb(0_0_0/.2)]"
|
|
117
|
+
: "max-[769px]:hidden",
|
|
118
|
+
className
|
|
119
|
+
)}
|
|
120
|
+
>
|
|
121
|
+
<div
|
|
122
|
+
data-slot="filter-sheet-head"
|
|
123
|
+
className="hidden items-center justify-between border-b border-border pt-3 pb-2 font-semibold max-[769px]:group-data-[open]/fb:flex"
|
|
124
|
+
>
|
|
125
|
+
<span>Filters</span>
|
|
126
|
+
<button
|
|
127
|
+
type="button"
|
|
128
|
+
data-slot="filter-done"
|
|
129
|
+
onClick={() => setSheet(false)}
|
|
130
|
+
className="h-8 rounded-[8px] border-0 bg-brand px-4 font-semibold text-white"
|
|
131
|
+
>
|
|
132
|
+
Done
|
|
133
|
+
</button>
|
|
134
|
+
</div>
|
|
135
|
+
{children}
|
|
136
|
+
<div ref={setSlot} data-slot="filter-slot" className="contents" />
|
|
137
|
+
<button
|
|
138
|
+
type="button"
|
|
139
|
+
data-slot="filter-reset"
|
|
140
|
+
disabled={active === 0}
|
|
141
|
+
onClick={reset}
|
|
142
|
+
title="Back to the default filters"
|
|
143
|
+
className="inline-flex h-[34px] items-center gap-1.5 self-end rounded-[8px] border border-border bg-card px-3 text-sm font-medium text-foreground enabled:hover:bg-accent disabled:cursor-default disabled:bg-transparent disabled:text-muted-foreground disabled:opacity-60 max-[769px]:self-start"
|
|
144
|
+
>
|
|
145
|
+
<svg width="14" height="14" viewBox="0 0 24 24" aria-hidden>
|
|
146
|
+
<path d="M3 12a9 9 0 1 0 3-6.7L3 8M3 3v5h5" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" />
|
|
147
|
+
</svg>
|
|
148
|
+
Reset
|
|
149
|
+
</button>
|
|
150
|
+
</div>
|
|
151
|
+
</>
|
|
152
|
+
)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** A tab's own fields, rendered into the page's filter bar. */
|
|
156
|
+
function TabFilters({ children }: { children: React.ReactNode }) {
|
|
157
|
+
const { slot } = React.useContext(FilterCtx)
|
|
158
|
+
return slot ? createPortal(children, slot) : null
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** Lets Reset (and the Filters badge) know about a tab's filter. */
|
|
162
|
+
function useResettable(id: string, dirty: boolean, reset: () => void) {
|
|
163
|
+
const { register } = React.useContext(FilterCtx)
|
|
164
|
+
const keep = React.useRef(reset)
|
|
165
|
+
keep.current = reset
|
|
166
|
+
const stable = React.useCallback(() => keep.current(), [])
|
|
167
|
+
React.useEffect(() => {
|
|
168
|
+
register(id, { dirty, reset: stable })
|
|
169
|
+
}, [id, dirty, stable, register])
|
|
170
|
+
React.useEffect(() => () => register(id, null), [id, register])
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** A small-caps label over its control. `hint` shows as the label's title, with an ⓘ. */
|
|
174
|
+
function FilterField({
|
|
175
|
+
label,
|
|
176
|
+
hint,
|
|
177
|
+
children,
|
|
178
|
+
className,
|
|
179
|
+
}: {
|
|
180
|
+
label: string
|
|
181
|
+
hint?: string
|
|
182
|
+
children: React.ReactNode
|
|
183
|
+
className?: string
|
|
184
|
+
}) {
|
|
185
|
+
return (
|
|
186
|
+
<div
|
|
187
|
+
data-slot="filter-field"
|
|
188
|
+
className={cn("flex min-w-0 flex-col gap-1.5 max-[769px]:group-data-[open]/fb:*:w-full!", className)}
|
|
189
|
+
>
|
|
190
|
+
<span
|
|
191
|
+
data-slot="filter-label"
|
|
192
|
+
title={hint}
|
|
193
|
+
className="inline-flex items-center gap-1 text-[11px] font-semibold tracking-[.06em] whitespace-nowrap text-muted-foreground uppercase"
|
|
194
|
+
>
|
|
195
|
+
{label}
|
|
196
|
+
{hint && (
|
|
197
|
+
<span aria-hidden className="cursor-help text-xs tracking-normal">
|
|
198
|
+
ⓘ
|
|
199
|
+
</span>
|
|
200
|
+
)}
|
|
201
|
+
</span>
|
|
202
|
+
{children}
|
|
203
|
+
</div>
|
|
204
|
+
)
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** The hairline between two groups of fields. */
|
|
208
|
+
function FilterSep() {
|
|
209
|
+
return (
|
|
210
|
+
<span
|
|
211
|
+
data-slot="filter-sep"
|
|
212
|
+
aria-hidden
|
|
213
|
+
className="mx-1 h-[34px] w-px self-end bg-border max-[769px]:group-data-[open]/fb:hidden"
|
|
214
|
+
/>
|
|
215
|
+
)
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export { FilterBar, FilterField, FilterProvider, FilterSep, TabFilters, useResettable }
|
package/components/index.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
// @makoai/app-sdk/components (2.21, 22 components from 2.22): stock shadcn/ui (new-york-v4, as
|
|
2
2
|
// shipped by the shadcn registry; only the `cn` import path changed). One
|
|
3
3
|
// copy per component: DropdownMenu and Checkbox live in ../menu and are
|
|
4
|
-
// re-exported here.
|
|
4
|
+
// re-exported here. PeriodPicker (2.27) is the house date filter built on
|
|
5
|
+
// the stock Popover; its helpers come from ./period. A missing component or prop is an SDK pull request,
|
|
5
6
|
// never an app copy. TypeScript source: the app's Vite compiles it, and the
|
|
6
7
|
// app's CSS imports "@makoai/app-sdk/tailwind.css" so Tailwind sees it.
|
|
8
|
+
// One house component sits beside them: the page filter bar (filter-bar.tsx).
|
|
7
9
|
export * from "./alert";
|
|
8
10
|
export * from "./avatar";
|
|
9
11
|
export * from "./badge";
|
|
@@ -11,8 +13,11 @@ export * from "./button";
|
|
|
11
13
|
export * from "./card";
|
|
12
14
|
export * from "./collapsible";
|
|
13
15
|
export * from "./dialog";
|
|
16
|
+
export * from "./filter-bar";
|
|
14
17
|
export * from "./input";
|
|
15
18
|
export * from "./label";
|
|
19
|
+
export * from "./period-picker";
|
|
20
|
+
export { clipToday, isCurrent, periodLabel, periodOf, shift, todayIso, type Period, type Unit } from "./period";
|
|
16
21
|
export * from "./popover";
|
|
17
22
|
export * from "./progress";
|
|
18
23
|
export * from "./select";
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
// PeriodPicker (2.27): the house date filter, ‹ Nov 2026 ›. The arrows step
|
|
4
|
+
// one period, the middle opens a picker (recent weeks / months / quarters /
|
|
5
|
+
// years, or a custom range), and the period in progress is tinted. Ported
|
|
6
|
+
// 1:1 from the workspace's apps/attrition-por-cohorte/src/ui/PeriodPicker.tsx
|
|
7
|
+
// and its `.pp` styles. The app's hand-rolled popover became the stock
|
|
8
|
+
// shadcn Popover (./popover): it portals the menu, moves focus into it on
|
|
9
|
+
// open and back to the trigger on close.
|
|
10
|
+
import * as React from "react"
|
|
11
|
+
import { closePopovers } from "../ui.js"
|
|
12
|
+
import { cn } from "../menu/utils"
|
|
13
|
+
import { Popover, PopoverAnchor, PopoverContent, PopoverTrigger } from "./popover"
|
|
14
|
+
import { UNIT_LABEL, addDays, isCurrent, periodLabel, periodOf, shift, todayIso, type Period, type Unit } from "./period"
|
|
15
|
+
|
|
16
|
+
const RECENT: Record<Unit, number> = { week: 12, month: 12, quarter: 8, year: 4 }
|
|
17
|
+
|
|
18
|
+
export interface PeriodPickerProps {
|
|
19
|
+
value: Period
|
|
20
|
+
onChange: (p: Period) => void
|
|
21
|
+
/** The units offered in the picker. Default month, quarter, year. */
|
|
22
|
+
units?: Unit[]
|
|
23
|
+
/** Custom ranges: whole months ("month"), any days ("day"), or none (false). */
|
|
24
|
+
custom?: "month" | "day" | false
|
|
25
|
+
/** Earliest and latest day a period may reach. Default: no limit back, today forward. */
|
|
26
|
+
min?: string
|
|
27
|
+
max?: string
|
|
28
|
+
/** The trigger's screen-reader name, read as "<label>: Nov 2026". */
|
|
29
|
+
label?: string
|
|
30
|
+
/** Mako thin prop (2.27): classes on the stepper's frame, e.g. `w-full` in a phone sheet. */
|
|
31
|
+
className?: string
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** The house date filter: ‹ Nov 2026 › with the period in progress tinted. */
|
|
35
|
+
export function PeriodPicker({ value, onChange, units = ["month", "quarter", "year"], custom = "month", min, max, label = "Time", className }: PeriodPickerProps) {
|
|
36
|
+
const today = todayIso()
|
|
37
|
+
const hi = max ?? today
|
|
38
|
+
const [open, setOpen] = React.useState(false)
|
|
39
|
+
const ref = React.useRef<HTMLDivElement>(null)
|
|
40
|
+
const prev = shift(value, -1), next = shift(value, 1)
|
|
41
|
+
const okPrev = !min || prev.to >= min
|
|
42
|
+
const okNext = next.from <= hi
|
|
43
|
+
const current = isCurrent(value, today)
|
|
44
|
+
const step = "w-8 border-0 bg-transparent px-0 pt-0 pb-[2px] text-[18px] leading-none text-muted-foreground enabled:cursor-pointer enabled:hover:bg-accent enabled:hover:text-foreground disabled:cursor-default disabled:opacity-30"
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<Popover open={open} onOpenChange={o => { if (o) closePopovers(); setOpen(o) }}>
|
|
48
|
+
<PopoverAnchor asChild>
|
|
49
|
+
<div
|
|
50
|
+
ref={ref}
|
|
51
|
+
data-slot="period-picker"
|
|
52
|
+
className={cn(
|
|
53
|
+
"relative inline-flex h-[34px] items-stretch rounded-[8px] border border-border bg-card p-0 text-[14px] font-medium text-foreground shadow-[0_1px_2px_rgb(0_0_0/0.05)] transition-[border-color,box-shadow] duration-150",
|
|
54
|
+
// The ring stays while the picker is open, though focus has moved into the portalled menu.
|
|
55
|
+
"focus-within:border-ring focus-within:shadow-[0_0_0_3px_color-mix(in_srgb,var(--ring)_35%,transparent)] focus-within:outline-none",
|
|
56
|
+
"has-[[data-state=open]]:border-ring has-[[data-state=open]]:shadow-[0_0_0_3px_color-mix(in_srgb,var(--ring)_35%,transparent)]",
|
|
57
|
+
className,
|
|
58
|
+
)}
|
|
59
|
+
>
|
|
60
|
+
<button type="button" data-slot="period-picker-prev" className={cn(step, "rounded-l-[7px]")} aria-label="Previous period" disabled={!okPrev} onClick={() => onChange(prev)}>‹</button>
|
|
61
|
+
<PopoverTrigger asChild>
|
|
62
|
+
<button
|
|
63
|
+
type="button"
|
|
64
|
+
data-slot="period-picker-trigger"
|
|
65
|
+
data-current={current || undefined}
|
|
66
|
+
className="inline-flex min-w-[156px] cursor-pointer items-center gap-2 border-x border-border bg-transparent py-0 pr-[10px] pl-3 font-medium text-inherit focus-visible:outline-none data-[current]:bg-[color-mix(in_srgb,var(--brand)_10%,transparent)] data-[current]:text-brand"
|
|
67
|
+
aria-label={`${label}: ${periodLabel(value)}`}
|
|
68
|
+
title={current ? "In progress: the numbers are not final yet" : undefined}
|
|
69
|
+
>
|
|
70
|
+
{current && <span className="size-[7px] flex-none rounded-full bg-brand shadow-[0_0_0_3px_color-mix(in_srgb,var(--brand)_22%,transparent)]" aria-hidden />}
|
|
71
|
+
<span className="flex-1 whitespace-nowrap text-left tabular-nums">{periodLabel(value)}</span>
|
|
72
|
+
<svg className={cn("flex-none text-muted-foreground transition-transform duration-150", open && "rotate-180")} width="12" height="12" viewBox="0 0 24 24" aria-hidden><path d="m6 9 6 6 6-6" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" /></svg>
|
|
73
|
+
</button>
|
|
74
|
+
</PopoverTrigger>
|
|
75
|
+
<button type="button" data-slot="period-picker-next" className={cn(step, "rounded-r-[7px]")} aria-label="Next period" disabled={!okNext} onClick={() => onChange(next)}>›</button>
|
|
76
|
+
</div>
|
|
77
|
+
</PopoverAnchor>
|
|
78
|
+
<PopoverContent
|
|
79
|
+
align="start"
|
|
80
|
+
// The app's menu sat 6px under the frame's inner edge, flush with its inner left.
|
|
81
|
+
sideOffset={5}
|
|
82
|
+
alignOffset={1}
|
|
83
|
+
aria-label="Pick a period"
|
|
84
|
+
className="z-[70] grid w-[320px] max-w-[calc(100vw-24px)] gap-[10px] rounded-[10px] p-[10px] shadow-[0_12px_28px_-8px_rgb(0_0_0/0.22)]"
|
|
85
|
+
// The arrows sit outside the menu but inside the stepper: they step the period and leave it open.
|
|
86
|
+
onInteractOutside={e => { if (ref.current?.contains(e.target as Node)) e.preventDefault() }}
|
|
87
|
+
>
|
|
88
|
+
<PickerMenu value={value} units={units} custom={custom} min={min} max={hi} today={today}
|
|
89
|
+
onPick={p => { onChange(p); setOpen(false) }} />
|
|
90
|
+
</PopoverContent>
|
|
91
|
+
</Popover>
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function PickerMenu({ value, units, custom, min, max, today, onPick }: {
|
|
96
|
+
value: Period; units: Unit[]; custom: "month" | "day" | false; min?: string; max: string; today: string; onPick: (p: Period) => void
|
|
97
|
+
}) {
|
|
98
|
+
const [tab, setTab] = React.useState<Unit | "custom">(value.unit === "custom" && !custom ? units[0] : value.unit)
|
|
99
|
+
const asMonth = custom === "month"
|
|
100
|
+
const [from, setFrom] = React.useState(asMonth ? value.from.slice(0, 7) : value.from)
|
|
101
|
+
const [to, setTo] = React.useState(asMonth ? value.to.slice(0, 7) : value.to)
|
|
102
|
+
const list = tab === "custom" ? [] : (() => {
|
|
103
|
+
const out: Period[] = []
|
|
104
|
+
let p = periodOf(tab, max)
|
|
105
|
+
for (let i = 0; i < RECENT[tab] && (!min || p.to >= min); i++, p = shift(p, -1)) out.push(p)
|
|
106
|
+
return out
|
|
107
|
+
})()
|
|
108
|
+
const range = (): Period | null => {
|
|
109
|
+
if (!from || !to) return null
|
|
110
|
+
const f = asMonth ? `${from}-01` : from
|
|
111
|
+
const t = asMonth ? addDays(periodOf("month", `${to}-01`).to, 0) : to
|
|
112
|
+
return f <= t ? { unit: "custom", from: f, to: t } : null
|
|
113
|
+
}
|
|
114
|
+
const r = range()
|
|
115
|
+
const tabClass = (on: boolean) => cn(
|
|
116
|
+
"flex-1 cursor-pointer rounded-[6px] border border-transparent bg-transparent px-[6px] py-1 text-[13px] font-medium text-muted-foreground",
|
|
117
|
+
on && "border-border bg-card text-foreground shadow-[0_1px_2px_rgb(0_0_0/0.05)]",
|
|
118
|
+
)
|
|
119
|
+
const input = "h-8 rounded-[6px] border border-border bg-card px-2 text-[14px] text-foreground [font:inherit]"
|
|
120
|
+
return (
|
|
121
|
+
<>
|
|
122
|
+
{units.length + (custom ? 1 : 0) > 1 && <div data-slot="period-picker-tabs" className="flex gap-[2px] rounded-[8px] bg-muted p-[3px]" role="tablist">
|
|
123
|
+
{units.map(u => <button key={u} type="button" role="tab" aria-selected={tab === u} className={tabClass(tab === u)} onClick={() => setTab(u)}>{UNIT_LABEL[u]}</button>)}
|
|
124
|
+
{custom && <button type="button" role="tab" aria-selected={tab === "custom"} className={tabClass(tab === "custom")} onClick={() => setTab("custom")}>Custom</button>}
|
|
125
|
+
</div>}
|
|
126
|
+
{tab !== "custom" ? (
|
|
127
|
+
<div data-slot="period-picker-grid" className={cn("grid gap-1", tab === "month" ? "grid-cols-3" : "grid-cols-2")}>
|
|
128
|
+
{list.map(p => {
|
|
129
|
+
const on = value.unit === p.unit && value.from === p.from
|
|
130
|
+
const live = isCurrent(p, today)
|
|
131
|
+
return (
|
|
132
|
+
<button key={p.from} type="button" data-current={live || undefined}
|
|
133
|
+
className={cn(
|
|
134
|
+
"grid cursor-pointer justify-items-center rounded-[6px] border border-transparent bg-transparent px-[6px] py-[7px] text-[13px] text-inherit tabular-nums",
|
|
135
|
+
live && "text-brand",
|
|
136
|
+
on ? "border-brand bg-[color-mix(in_srgb,var(--brand)_8%,transparent)] font-semibold" : "hover:bg-accent",
|
|
137
|
+
)}
|
|
138
|
+
onClick={() => onPick(p)}>
|
|
139
|
+
{periodLabel(p)}{live && <small className="text-[10px] font-normal text-muted-foreground">in progress</small>}
|
|
140
|
+
</button>
|
|
141
|
+
)
|
|
142
|
+
})}
|
|
143
|
+
</div>
|
|
144
|
+
) : (
|
|
145
|
+
<form data-slot="period-picker-custom" className="grid grid-cols-2 gap-2" onSubmit={e => { e.preventDefault(); if (r) onPick(r) }}>
|
|
146
|
+
<label className="grid gap-1 text-[12px] text-muted-foreground">From<input className={input} type={asMonth ? "month" : "date"} value={from} min={min ? (asMonth ? min.slice(0, 7) : min) : undefined} max={asMonth ? max.slice(0, 7) : max} onChange={e => setFrom(e.target.value)} /></label>
|
|
147
|
+
<label className="grid gap-1 text-[12px] text-muted-foreground">To<input className={input} type={asMonth ? "month" : "date"} value={to} min={from || undefined} max={asMonth ? max.slice(0, 7) : max} onChange={e => setTo(e.target.value)} /></label>
|
|
148
|
+
<button type="submit" className="col-span-full h-8 cursor-pointer rounded-[6px] border-0 bg-brand font-semibold text-white disabled:cursor-default disabled:opacity-45" disabled={!r}>Apply</button>
|
|
149
|
+
</form>
|
|
150
|
+
)}
|
|
151
|
+
</>
|
|
152
|
+
)
|
|
153
|
+
}
|