@makoai/app-sdk 2.27.0 → 2.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +142 -1
- package/components/combobox.tsx +150 -0
- package/components/filter-bar.tsx +15 -6
- package/components/index.ts +4 -1
- package/components/period-picker.tsx +54 -24
- package/components/period.ts +54 -5
- package/index.d.ts +4 -2
- package/index.js +10 -1
- package/locale.d.ts +122 -0
- package/locale.js +178 -0
- package/menu/filter-menu.tsx +26 -8
- package/package.json +7 -1
- package/ui-core.js +3 -1
- package/ui.css +53 -0
- package/ui.d.ts +77 -1
- package/ui.js +319 -46
package/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
|
|
@@ -683,6 +715,73 @@ phone sheet each control takes the full width. The sheet sits at z-index 50,
|
|
|
683
715
|
so the Radix popovers of `/components` and `/menu` open above it. Escape
|
|
684
716
|
closes an open popover first and the sheet on the next press.
|
|
685
717
|
|
|
718
|
+
### Languages: `locale` and `labels` (2.29)
|
|
719
|
+
|
|
720
|
+
One `locale` prop puts a component's own texts in French, German, Italian,
|
|
721
|
+
Spanish, Polish or Portuguese. Pass a BCP 47 tag such as `"fr-CH"`. The SDK
|
|
722
|
+
matches the language part, so `"fr-CH"` reads French. An unknown language
|
|
723
|
+
reads English. The texts live in one table in the SDK (`STRINGS`), never in
|
|
724
|
+
the app. Month names come from `Intl` in the full locale. Counts and footer
|
|
725
|
+
numbers format in it too.
|
|
726
|
+
|
|
727
|
+
`labels` overrides single texts on top of the locale. The explicit props that
|
|
728
|
+
already existed (`allLabel`, `noneLabel`, `formatMany`, `searchPlaceholder`,
|
|
729
|
+
`searchEmpty`, `placeholder`, `emptyText`, `label`, `noun`, `empty`) win over
|
|
730
|
+
both. With no `locale` and no `labels`, every component renders byte for byte
|
|
731
|
+
as 2.28.
|
|
732
|
+
|
|
733
|
+
```tsx
|
|
734
|
+
const LOCALE = "fr-CH";
|
|
735
|
+
<FilterBar locale={LOCALE} dirty={dirty} onReset={reset}>
|
|
736
|
+
<FilterField label="Période">
|
|
737
|
+
<PeriodPicker locale={LOCALE} value={period} onChange={setPeriod} presets={["7d", "28d", "mtd", "ytd"]} />
|
|
738
|
+
</FilterField>
|
|
739
|
+
<FilterField label="Marché">
|
|
740
|
+
<MultiSelect locale={LOCALE} options={MARKETS} value={markets} onChange={setMarkets} />
|
|
741
|
+
</FilterField>
|
|
742
|
+
</FilterBar>
|
|
743
|
+
<DataTable locale={LOCALE} rows={rows} columns={COLUMNS} labels={{ exportCsv: "Exporter" }} />
|
|
744
|
+
```
|
|
745
|
+
|
|
746
|
+
The components and their `labels` keys:
|
|
747
|
+
|
|
748
|
+
- **PeriodPicker** (`PeriodPickerLabels`): `time` (the trigger's name when
|
|
749
|
+
`label` is unset), `previous`, `next`, `menu`, `week`, `month`, `quarter`,
|
|
750
|
+
`year`, `custom`, `presets` (the presets tab), `inProgress`,
|
|
751
|
+
`inProgressTitle`, `from`, `to`, `apply`, `quarterLabel(q, year)` ("T4
|
|
752
|
+
2026" in French), `lastDays(n)`, `mtd`, `qtd`, `ytd`. The period reads
|
|
753
|
+
"nov. 2026" in fr-CH and "16.–22. Nov 2026" in de-CH.
|
|
754
|
+
- **FilterBar** (`FilterBarLabels`): `filters` (chip, sheet title, aria-label),
|
|
755
|
+
`reset`, `resetTitle`, `done`.
|
|
756
|
+
- **MultiSelect, FilterItems** (`/ui`) and **FilterMenu, FilterMenuItems**
|
|
757
|
+
(`/menu`) (`FilterLabels`): `all`, `none`, `many(n)`, `only`, `search`,
|
|
758
|
+
`noMatch`, `groupAll(label)` ("Bots (tout)", FilterMenu's group row).
|
|
759
|
+
`allLabel` is optional on FilterMenu now.
|
|
760
|
+
- **Combobox** (`ComboboxLabels`): `placeholder`, `search`, `empty`.
|
|
761
|
+
- **DataTable**: the `DataTableLabels` keys. A locale also formats the
|
|
762
|
+
footer's numbers and names the rows ("1–50 sur 312 lignes") while `noun` is
|
|
763
|
+
unset. `dataTableLabels(locale, labels)` returns the full set.
|
|
764
|
+
|
|
765
|
+
`localeStrings(section, locale, labels)` returns one section for your own
|
|
766
|
+
controls: `localeStrings("filterBar", "de-CH").reset` is "Zurücksetzen".
|
|
767
|
+
|
|
768
|
+
**Rolling presets.** `presets` on PeriodPicker adds a first tab of windows
|
|
769
|
+
that end today: `"7d"`, `"28d"`, `"90d"`, `"365d"` (any `"<N>d"`) and `"mtd"`,
|
|
770
|
+
`"qtd"`, `"ytd"` (month, quarter and year to date). A pick emits
|
|
771
|
+
`presetPeriod(id)`: `{ unit: "custom", from, to: today, preset: "28d" }`. The
|
|
772
|
+
trigger reads the preset's name ("28 derniers jours"). ‹ from a to-date
|
|
773
|
+
preset goes to the whole unit before it; from N days, to the N days before.
|
|
774
|
+
|
|
775
|
+
A preset keeps rolling only if the URL holds its id, not its dates. Write
|
|
776
|
+
`period=28d` for a preset and keep `from=&to=` for everything else, so every
|
|
777
|
+
existing link still opens the same range:
|
|
778
|
+
|
|
779
|
+
```tsx
|
|
780
|
+
const period = presetPeriod(params.get("period")) ?? rangePeriod(params.get("from"), params.get("to"));
|
|
781
|
+
const onChange = (p: Period) =>
|
|
782
|
+
update(p.preset ? { period: p.preset, from: null, to: null } : { period: null, from: p.from, to: p.to });
|
|
783
|
+
```
|
|
784
|
+
|
|
686
785
|
### Country colours: `COUNTRY_COLORS`, `COUNTRY_ORDER` (2.27)
|
|
687
786
|
|
|
688
787
|
A market has one colour in every app. Keys are lowercase codes.
|
|
@@ -698,6 +797,12 @@ rows.sort((a, b) => COUNTRY_ORDER.indexOf(a.country) - COUNTRY_ORDER.indexOf(b.c
|
|
|
698
797
|
CH red, FR blue, IT green, ES amber, PT teal, PL rose. Other series in a
|
|
699
798
|
country chart take `--chart-1…5`. Both objects are frozen.
|
|
700
799
|
|
|
800
|
+
2.28 adds the 6 lead-only markets of dbt seed `markets` (valuation funnel
|
|
801
|
+
only, no agents): DE violet, AT lime, CZ ochre, NL orange, BE fuchsia, GB navy
|
|
802
|
+
(realadvisor.co.uk). `COUNTRY_ORDER` keeps the 6 site markets. The lead-only
|
|
803
|
+
markets follow them in the map's key order, so an app that lists markets from
|
|
804
|
+
data sorts by `COUNTRY_ORDER`, then by key order of `COUNTRY_COLORS`.
|
|
805
|
+
|
|
701
806
|
### Times and dates (2.21)
|
|
702
807
|
|
|
703
808
|
DuckDB runs in UTC, and that stays. Display code decides the zone.
|
|
@@ -870,7 +975,9 @@ const COLUMNS: DataTableColumn<Customer>[] = [
|
|
|
870
975
|
values (null, "", NaN) sort last both ways. `sticky` (pin the first column),
|
|
871
976
|
`sortable: false`, `hint` (header hover text), `csv` (`false` to leave a
|
|
872
977
|
column out, a function for a readable cell such as a level name). Numeric
|
|
873
|
-
strings ("1.25", "-10") sort as numbers.
|
|
978
|
+
strings ("1.25", "-10") sort as numbers. `sortDescFirst` (2.29, TanStack
|
|
979
|
+
Table's name) sets the first click's direction: `sortDescFirst: false` on a
|
|
980
|
+
"Renewal (d)" column sorts soonest first. The next click flips it.
|
|
874
981
|
- **Widths: no layout shift.** The table uses `table-layout: fixed` and a
|
|
875
982
|
`<colgroup>`, so a column's width never depends on the rows on screen.
|
|
876
983
|
Sorting, filtering, paging, the empty state and loading all keep the same
|
|
@@ -973,6 +1080,40 @@ const COLUMNS: DataTableColumn<Customer>[] = [
|
|
|
973
1080
|
<DataTable rows={rows} columns={COLUMNS}
|
|
974
1081
|
groups={[{ id: "activity", label: "Activity" }, { id: "money", label: "Money", className: "tone-positive" }]} />
|
|
975
1082
|
```
|
|
1083
|
+
- **Wrapped headers.** `wrapHeaders` lets a header label take 2 lines before
|
|
1084
|
+
it ellipsizes. The sort icon stays beside it. Use it for long or translated
|
|
1085
|
+
labels in narrow columns.
|
|
1086
|
+
- **Header info.** A column's `info` adds an "i" button after its header
|
|
1087
|
+
label. A click opens a popover with the label and this content. The button
|
|
1088
|
+
sits outside the sort button, so it never sorts. Focus moves into the
|
|
1089
|
+
popover. Escape closes it and returns focus to the "i".
|
|
1090
|
+
- **Expandable rows.** `renderExpanded(row)` puts a chevron in each row's
|
|
1091
|
+
first cell. The chevron opens a full-width detail row under its record.
|
|
1092
|
+
Enter or Space on a focused chevron toggles it too. `canExpand(row)` limits
|
|
1093
|
+
which rows get one. The pager, the sort and the CSV count records only. The
|
|
1094
|
+
open rows are uncontrolled (`defaultExpanded`) or controlled (`expanded` +
|
|
1095
|
+
`onExpandedChange`). The state is `{ [rowKey]: true }`, or `true` for every
|
|
1096
|
+
row: TanStack Table's `ExpandedState`. `labels.expand(row)` and
|
|
1097
|
+
`labels.collapse(row)` name the chevron for screen readers.
|
|
1098
|
+
|
|
1099
|
+
```tsx
|
|
1100
|
+
<DataTable rows={records} columns={COLUMNS} rowKey={r => r.item_id}
|
|
1101
|
+
renderExpanded={r => <RecordFacts row={r} />}
|
|
1102
|
+
canExpand={r => r.detail != null}
|
|
1103
|
+
labels={{ expand: r => `Show details for ${r.item_label}`, collapse: r => `Hide details for ${r.item_label}` }} />
|
|
1104
|
+
```
|
|
1105
|
+
- **Total row.** `totalRow` pins a bold row to the bottom of the scroll box,
|
|
1106
|
+
under a rule. Pass a row object or a function of the filtered `rows`. Each
|
|
1107
|
+
column renders it with its own `value` and `render`. The pinned first
|
|
1108
|
+
column holds in it. It never sorts or pages. It stays out of the CSV unless
|
|
1109
|
+
`exportTotalRow`. `onTotalRowClick(row)` makes it clickable for a
|
|
1110
|
+
drill-down. A `render` can return a button per cell, as on any row.
|
|
1111
|
+
|
|
1112
|
+
```tsx
|
|
1113
|
+
<DataTable rows={reps} columns={COLUMNS}
|
|
1114
|
+
totalRow={rs => ({ name: "Total", demos: sum(rs, "demos"), cash: sum(rs, "cash") })}
|
|
1115
|
+
onTotalRowClick={() => openDrill(null)} />
|
|
1116
|
+
```
|
|
976
1117
|
- Pure helpers for custom tables: `sortRows`, `compareValues`, `nextSort`,
|
|
977
1118
|
`pageSlice`, `pageToSync`, `toCsv`, `csvCell`, `csvDate`, `csvToTsv`,
|
|
978
1119
|
`columnLayout`, `columnGroupRuns`.
|
|
@@ -0,0 +1,150 @@
|
|
|
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
|
+
// 2.29: `locale` and `labels` translate the placeholder, search and empty
|
|
11
|
+
// texts, and `locale` formats the counts.
|
|
12
|
+
|
|
13
|
+
import * as React from "react"
|
|
14
|
+
import { CheckIcon, ChevronsUpDownIcon } from "lucide-react"
|
|
15
|
+
import { defaultFilter } from "cmdk"
|
|
16
|
+
import { cn } from "../menu/utils"
|
|
17
|
+
import { localeStrings, type ComboboxLabels } from "../locale.js"
|
|
18
|
+
import { Button } from "./button"
|
|
19
|
+
import {
|
|
20
|
+
Command,
|
|
21
|
+
CommandEmpty,
|
|
22
|
+
CommandGroup,
|
|
23
|
+
CommandInput,
|
|
24
|
+
CommandItem,
|
|
25
|
+
CommandList,
|
|
26
|
+
} from "./command"
|
|
27
|
+
import { Popover, PopoverContent, PopoverTrigger } from "./popover"
|
|
28
|
+
|
|
29
|
+
export type ComboboxOption<V extends string = string> = {
|
|
30
|
+
value: V
|
|
31
|
+
label: string
|
|
32
|
+
/** Mako thin prop (2.28): a number shown muted at the row's right edge. */
|
|
33
|
+
count?: number | string
|
|
34
|
+
/** Mako thin prop (2.28): extra words the search matches. */
|
|
35
|
+
keywords?: string[]
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const formatCount = (n: number | string, locale = "en-US") =>
|
|
39
|
+
typeof n === "number" ? n.toLocaleString(locale) : n
|
|
40
|
+
|
|
41
|
+
// The item's value is the option value (unique); its keywords hold the label
|
|
42
|
+
// first, so the search scores the label and keywords and never the value.
|
|
43
|
+
const filterByLabel = (_value: string, search: string, keywords?: string[]) =>
|
|
44
|
+
defaultFilter(keywords?.[0] ?? "", search, keywords?.slice(1))
|
|
45
|
+
|
|
46
|
+
function Combobox<V extends string = string>({
|
|
47
|
+
options,
|
|
48
|
+
value,
|
|
49
|
+
onChange,
|
|
50
|
+
placeholder: placeholderProp,
|
|
51
|
+
searchPlaceholder: searchProp,
|
|
52
|
+
emptyText: emptyProp,
|
|
53
|
+
locale,
|
|
54
|
+
labels,
|
|
55
|
+
icon,
|
|
56
|
+
disabled,
|
|
57
|
+
className,
|
|
58
|
+
contentClassName,
|
|
59
|
+
"aria-label": ariaLabel,
|
|
60
|
+
}: {
|
|
61
|
+
options: ReadonlyArray<V | ComboboxOption<V>>
|
|
62
|
+
value: V | null
|
|
63
|
+
onChange: (value: V | null) => void
|
|
64
|
+
placeholder?: string
|
|
65
|
+
searchPlaceholder?: string
|
|
66
|
+
emptyText?: React.ReactNode
|
|
67
|
+
/** Mako thin prop (2.29): BCP 47 tag, e.g. "fr-CH": the three texts in that language. Default English. */
|
|
68
|
+
locale?: string
|
|
69
|
+
/** Mako thin prop (2.29): override single texts on top of the locale. The explicit props win. */
|
|
70
|
+
labels?: Partial<ComboboxLabels>
|
|
71
|
+
icon?: React.ReactNode
|
|
72
|
+
disabled?: boolean
|
|
73
|
+
className?: string
|
|
74
|
+
contentClassName?: string
|
|
75
|
+
"aria-label"?: string
|
|
76
|
+
}) {
|
|
77
|
+
const L = localeStrings("combobox", locale, labels)
|
|
78
|
+
const placeholder = placeholderProp ?? L.placeholder
|
|
79
|
+
const searchPlaceholder = searchProp ?? L.search
|
|
80
|
+
const emptyText = emptyProp ?? L.empty
|
|
81
|
+
const [open, setOpen] = React.useState(false)
|
|
82
|
+
const items = options.map((o) =>
|
|
83
|
+
typeof o === "string" ? { value: o, label: o } : o
|
|
84
|
+
) as ComboboxOption<V>[]
|
|
85
|
+
const picked = items.find((o) => o.value === value)
|
|
86
|
+
const text = picked?.label ?? value ?? placeholder
|
|
87
|
+
|
|
88
|
+
return (
|
|
89
|
+
<Popover open={open} onOpenChange={setOpen}>
|
|
90
|
+
<PopoverTrigger asChild>
|
|
91
|
+
<Button
|
|
92
|
+
data-slot="combobox-trigger"
|
|
93
|
+
variant="outline"
|
|
94
|
+
role="combobox"
|
|
95
|
+
aria-expanded={open}
|
|
96
|
+
aria-label={ariaLabel}
|
|
97
|
+
disabled={disabled}
|
|
98
|
+
title={text}
|
|
99
|
+
className={cn("w-[200px] justify-between", className)}
|
|
100
|
+
>
|
|
101
|
+
{icon}
|
|
102
|
+
<span className="min-w-0 flex-1 truncate text-left">{text}</span>
|
|
103
|
+
<ChevronsUpDownIcon className="opacity-50" />
|
|
104
|
+
</Button>
|
|
105
|
+
</PopoverTrigger>
|
|
106
|
+
<PopoverContent
|
|
107
|
+
className={cn("w-(--radix-popover-trigger-width) min-w-[200px] p-0", contentClassName)}
|
|
108
|
+
align="start"
|
|
109
|
+
>
|
|
110
|
+
<Command filter={filterByLabel}>
|
|
111
|
+
<CommandInput placeholder={searchPlaceholder} className="h-9" />
|
|
112
|
+
<CommandList>
|
|
113
|
+
<CommandEmpty>{emptyText}</CommandEmpty>
|
|
114
|
+
<CommandGroup>
|
|
115
|
+
{items.map((o) => (
|
|
116
|
+
<CommandItem
|
|
117
|
+
key={o.value}
|
|
118
|
+
value={o.value}
|
|
119
|
+
keywords={[o.label, ...(o.keywords ?? [])]}
|
|
120
|
+
onSelect={() => {
|
|
121
|
+
onChange(o.value === value ? null : o.value)
|
|
122
|
+
setOpen(false)
|
|
123
|
+
}}
|
|
124
|
+
>
|
|
125
|
+
<span className="min-w-0 flex-1 truncate">{o.label}</span>
|
|
126
|
+
{o.count != null && (
|
|
127
|
+
<span
|
|
128
|
+
data-slot="combobox-count"
|
|
129
|
+
className="text-xs text-muted-foreground tabular-nums"
|
|
130
|
+
>
|
|
131
|
+
{formatCount(o.count, locale)}
|
|
132
|
+
</span>
|
|
133
|
+
)}
|
|
134
|
+
<CheckIcon
|
|
135
|
+
className={cn(
|
|
136
|
+
"ml-auto",
|
|
137
|
+
value === o.value ? "opacity-100" : "opacity-0"
|
|
138
|
+
)}
|
|
139
|
+
/>
|
|
140
|
+
</CommandItem>
|
|
141
|
+
))}
|
|
142
|
+
</CommandGroup>
|
|
143
|
+
</CommandList>
|
|
144
|
+
</Command>
|
|
145
|
+
</PopoverContent>
|
|
146
|
+
</Popover>
|
|
147
|
+
)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export { Combobox }
|
|
@@ -13,8 +13,10 @@
|
|
|
13
13
|
// every width. Two changes from the reference: the sheet sits at z-50 (scrim
|
|
14
14
|
// z-49), so the SDK's Radix popovers (z-50, portalled after it) open above it;
|
|
15
15
|
// and Escape leaves the sheet open when a popover inside it took the key.
|
|
16
|
+
// 2.29: `locale` and `labels` translate Filters, Reset and Done.
|
|
16
17
|
import * as React from "react"
|
|
17
18
|
import { createPortal } from "react-dom"
|
|
19
|
+
import { localeStrings, type FilterBarLabels } from "../locale.js"
|
|
18
20
|
import { cn } from "../menu/utils"
|
|
19
21
|
|
|
20
22
|
type Entry = { dirty: boolean; reset: () => void }
|
|
@@ -50,13 +52,20 @@ function FilterBar({
|
|
|
50
52
|
children,
|
|
51
53
|
dirty,
|
|
52
54
|
onReset,
|
|
55
|
+
locale,
|
|
56
|
+
labels,
|
|
53
57
|
className,
|
|
54
58
|
}: {
|
|
55
59
|
children: React.ReactNode
|
|
56
60
|
dirty: boolean
|
|
57
61
|
onReset: () => void
|
|
62
|
+
/** Mako thin prop (2.29): BCP 47 tag, e.g. "fr-CH": Filters, Reset and Done in that language. Default English. */
|
|
63
|
+
locale?: string
|
|
64
|
+
/** Mako thin prop (2.29): override single texts on top of the locale. */
|
|
65
|
+
labels?: Partial<FilterBarLabels>
|
|
58
66
|
className?: string
|
|
59
67
|
}) {
|
|
68
|
+
const L = localeStrings("filterBar", locale, labels)
|
|
60
69
|
const { setSlot, entries } = React.useContext(FilterCtx)
|
|
61
70
|
const active = (dirty ? 1 : 0) + Object.values(entries).filter(e => e.dirty).length
|
|
62
71
|
const [sheet, setSheet] = React.useState(false)
|
|
@@ -84,7 +93,7 @@ function FilterBar({
|
|
|
84
93
|
onClick={() => setSheet(!sheet)}
|
|
85
94
|
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
95
|
>
|
|
87
|
-
|
|
96
|
+
{L.filters}{" "}
|
|
88
97
|
{active > 0 && (
|
|
89
98
|
<span
|
|
90
99
|
data-slot="filter-count"
|
|
@@ -109,7 +118,7 @@ function FilterBar({
|
|
|
109
118
|
data-slot="filter-bar"
|
|
110
119
|
data-open={sheet || undefined}
|
|
111
120
|
role="group"
|
|
112
|
-
aria-label=
|
|
121
|
+
aria-label={L.filters}
|
|
113
122
|
className={cn(
|
|
114
123
|
"group/fb flex flex-wrap items-end gap-x-3 gap-y-2.5",
|
|
115
124
|
sheet
|
|
@@ -122,14 +131,14 @@ function FilterBar({
|
|
|
122
131
|
data-slot="filter-sheet-head"
|
|
123
132
|
className="hidden items-center justify-between border-b border-border pt-3 pb-2 font-semibold max-[769px]:group-data-[open]/fb:flex"
|
|
124
133
|
>
|
|
125
|
-
<span>
|
|
134
|
+
<span>{L.filters}</span>
|
|
126
135
|
<button
|
|
127
136
|
type="button"
|
|
128
137
|
data-slot="filter-done"
|
|
129
138
|
onClick={() => setSheet(false)}
|
|
130
139
|
className="h-8 rounded-[8px] border-0 bg-brand px-4 font-semibold text-white"
|
|
131
140
|
>
|
|
132
|
-
|
|
141
|
+
{L.done}
|
|
133
142
|
</button>
|
|
134
143
|
</div>
|
|
135
144
|
{children}
|
|
@@ -139,13 +148,13 @@ function FilterBar({
|
|
|
139
148
|
data-slot="filter-reset"
|
|
140
149
|
disabled={active === 0}
|
|
141
150
|
onClick={reset}
|
|
142
|
-
title=
|
|
151
|
+
title={L.resetTitle}
|
|
143
152
|
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
153
|
>
|
|
145
154
|
<svg width="14" height="14" viewBox="0 0 24 24" aria-hidden>
|
|
146
155
|
<path d="M3 12a9 9 0 1 0 3-6.7L3 8M3 3v5h5" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" />
|
|
147
156
|
</svg>
|
|
148
|
-
|
|
157
|
+
{L.reset}
|
|
149
158
|
</button>
|
|
150
159
|
</div>
|
|
151
160
|
</>
|
package/components/index.ts
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
// never an app copy. TypeScript source: the app's Vite compiles it, and the
|
|
7
7
|
// app's CSS imports "@makoai/app-sdk/tailwind.css" so Tailwind sees it.
|
|
8
8
|
// One house component sits beside them: the page filter bar (filter-bar.tsx).
|
|
9
|
+
// 2.29: `locale` + `labels` on PeriodPicker, FilterBar, Combobox and FilterMenu
|
|
10
|
+
// read the SDK's one strings table (../locale.js).
|
|
9
11
|
export * from "./alert";
|
|
10
12
|
export * from "./avatar";
|
|
11
13
|
export * from "./badge";
|
|
@@ -17,7 +19,8 @@ export * from "./filter-bar";
|
|
|
17
19
|
export * from "./input";
|
|
18
20
|
export * from "./label";
|
|
19
21
|
export * from "./period-picker";
|
|
20
|
-
export { clipToday, isCurrent, periodLabel, periodOf, shift, todayIso, type Period, type Unit } from "./period"
|
|
22
|
+
export { clipToday, isCurrent, periodLabel, periodOf, presetLabel, presetPeriod, shift, todayIso, type Period, type PeriodPreset, type Unit } from "./period"
|
|
23
|
+
export { LOCALES, STRINGS, localeLang, localeStrings, type ComboboxLabels, type FilterBarLabels, type FilterLabels, type LocaleLang, type PeriodPickerLabels } from "../locale.js";
|
|
21
24
|
export * from "./popover";
|
|
22
25
|
export * from "./progress";
|
|
23
26
|
export * from "./select";
|
|
@@ -7,11 +7,17 @@
|
|
|
7
7
|
// and its `.pp` styles. The app's hand-rolled popover became the stock
|
|
8
8
|
// shadcn Popover (./popover): it portals the menu, moves focus into it on
|
|
9
9
|
// open and back to the trigger on close.
|
|
10
|
+
//
|
|
11
|
+
// 2.29: `locale` translates every fixed text (from the SDK's strings table,
|
|
12
|
+
// ../locale.js) and the month names (Intl); `labels` overrides single
|
|
13
|
+
// strings; `presets` adds a tab of rolling windows. Without them the output
|
|
14
|
+
// is byte-identical to 2.28.
|
|
10
15
|
import * as React from "react"
|
|
11
16
|
import { closePopovers } from "../ui.js"
|
|
17
|
+
import { localeStrings, type PeriodPickerLabels } from "../locale.js"
|
|
12
18
|
import { cn } from "../menu/utils"
|
|
13
19
|
import { Popover, PopoverAnchor, PopoverContent, PopoverTrigger } from "./popover"
|
|
14
|
-
import {
|
|
20
|
+
import { addDays, isCurrent, periodLabel, periodOf, presetPeriod, shift, todayIso, type Period, type PeriodPreset, type Unit } from "./period"
|
|
15
21
|
|
|
16
22
|
const RECENT: Record<Unit, number> = { week: 12, month: 12, quarter: 8, year: 4 }
|
|
17
23
|
|
|
@@ -25,14 +31,28 @@ export interface PeriodPickerProps {
|
|
|
25
31
|
/** Earliest and latest day a period may reach. Default: no limit back, today forward. */
|
|
26
32
|
min?: string
|
|
27
33
|
max?: string
|
|
28
|
-
/** The trigger's screen-reader name, read as "<label>: Nov 2026". */
|
|
34
|
+
/** The trigger's screen-reader name, read as "<label>: Nov 2026". Default "Time" (`labels.time`). */
|
|
29
35
|
label?: string
|
|
36
|
+
/** Mako thin prop (2.29): BCP 47 tag, e.g. "fr-CH". Translates every text and the month names. Default English. */
|
|
37
|
+
locale?: string
|
|
38
|
+
/** Mako thin prop (2.29): override single texts on top of the locale, e.g. `{ apply: "OK" }`. */
|
|
39
|
+
labels?: Partial<PeriodPickerLabels>
|
|
40
|
+
/**
|
|
41
|
+
* Mako thin prop (2.29): rolling windows in their own tab, first: "7d", "28d", "90d" (the last N days),
|
|
42
|
+
* "mtd", "qtd", "ytd" (month, quarter, year to date). A pick emits `presetPeriod(id)`: a custom range
|
|
43
|
+
* ending today with `preset: id`. Default none.
|
|
44
|
+
*/
|
|
45
|
+
presets?: readonly PeriodPreset[]
|
|
30
46
|
/** Mako thin prop (2.27): classes on the stepper's frame, e.g. `w-full` in a phone sheet. */
|
|
31
47
|
className?: string
|
|
32
48
|
}
|
|
33
49
|
|
|
34
50
|
/** 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
|
|
51
|
+
export function PeriodPicker({ value, onChange, units = ["month", "quarter", "year"], custom = "month", min, max, label: labelProp, locale, labels, presets, className }: PeriodPickerProps) {
|
|
52
|
+
const L = localeStrings("period", locale, labels)
|
|
53
|
+
const label = labelProp ?? L.time
|
|
54
|
+
const text = periodLabel(value, locale)
|
|
55
|
+
const wide = !!(locale || presets?.length)
|
|
36
56
|
const today = todayIso()
|
|
37
57
|
const hi = max ?? today
|
|
38
58
|
const [open, setOpen] = React.useState(false)
|
|
@@ -57,22 +77,22 @@ export function PeriodPicker({ value, onChange, units = ["month", "quarter", "ye
|
|
|
57
77
|
className,
|
|
58
78
|
)}
|
|
59
79
|
>
|
|
60
|
-
<button type="button" data-slot="period-picker-prev" className={cn(step, "rounded-l-[7px]")} aria-label=
|
|
80
|
+
<button type="button" data-slot="period-picker-prev" className={cn(step, "rounded-l-[7px]")} aria-label={L.previous} disabled={!okPrev} onClick={() => onChange(prev)}>‹</button>
|
|
61
81
|
<PopoverTrigger asChild>
|
|
62
82
|
<button
|
|
63
83
|
type="button"
|
|
64
84
|
data-slot="period-picker-trigger"
|
|
65
85
|
data-current={current || undefined}
|
|
66
86
|
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}: ${
|
|
68
|
-
title={current ?
|
|
87
|
+
aria-label={`${label}: ${text}`}
|
|
88
|
+
title={current ? L.inProgressTitle : undefined}
|
|
69
89
|
>
|
|
70
90
|
{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">{
|
|
91
|
+
<span className="flex-1 whitespace-nowrap text-left tabular-nums">{text}</span>
|
|
72
92
|
<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
93
|
</button>
|
|
74
94
|
</PopoverTrigger>
|
|
75
|
-
<button type="button" data-slot="period-picker-next" className={cn(step, "rounded-r-[7px]")} aria-label=
|
|
95
|
+
<button type="button" data-slot="period-picker-next" className={cn(step, "rounded-r-[7px]")} aria-label={L.next} disabled={!okNext} onClick={() => onChange(next)}>›</button>
|
|
76
96
|
</div>
|
|
77
97
|
</PopoverAnchor>
|
|
78
98
|
<PopoverContent
|
|
@@ -80,26 +100,34 @@ export function PeriodPicker({ value, onChange, units = ["month", "quarter", "ye
|
|
|
80
100
|
// The app's menu sat 6px under the frame's inner edge, flush with its inner left.
|
|
81
101
|
sideOffset={5}
|
|
82
102
|
alignOffset={1}
|
|
83
|
-
aria-label=
|
|
84
|
-
className=
|
|
103
|
+
aria-label={L.menu}
|
|
104
|
+
className={cn(
|
|
105
|
+
"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)]",
|
|
106
|
+
// Longer tab names ("Personnalisé") or a sixth tab: the menu grows to fit its tabs,
|
|
107
|
+
// and on a phone too narrow for them the tab row scrolls.
|
|
108
|
+
wide && "w-max min-w-[320px] grid-cols-[minmax(0,1fr)]",
|
|
109
|
+
)}
|
|
85
110
|
// The arrows sit outside the menu but inside the stepper: they step the period and leave it open.
|
|
86
111
|
onInteractOutside={e => { if (ref.current?.contains(e.target as Node)) e.preventDefault() }}
|
|
87
112
|
>
|
|
88
|
-
<PickerMenu value={value} units={units} custom={custom} min={min} max={hi} today={today}
|
|
113
|
+
<PickerMenu value={value} units={units} custom={custom} min={min} max={hi} today={today} L={L} locale={locale} presets={presets} wide={wide}
|
|
89
114
|
onPick={p => { onChange(p); setOpen(false) }} />
|
|
90
115
|
</PopoverContent>
|
|
91
116
|
</Popover>
|
|
92
117
|
)
|
|
93
118
|
}
|
|
94
119
|
|
|
95
|
-
function PickerMenu({ value, units, custom, min, max, today, onPick }: {
|
|
120
|
+
function PickerMenu({ value, units, custom, min, max, today, L, locale, presets, wide, onPick }: {
|
|
96
121
|
value: Period; units: Unit[]; custom: "month" | "day" | false; min?: string; max: string; today: string; onPick: (p: Period) => void
|
|
122
|
+
L: PeriodPickerLabels; locale?: string; presets?: readonly PeriodPreset[]; wide: boolean
|
|
97
123
|
}) {
|
|
98
|
-
const
|
|
124
|
+
const rolling = presets?.length ? presets : null
|
|
125
|
+
const [tab, setTab] = React.useState<Unit | "custom" | "presets">(
|
|
126
|
+
rolling && value.preset && rolling.includes(value.preset) ? "presets" : value.unit === "custom" && !custom ? units[0] : value.unit)
|
|
99
127
|
const asMonth = custom === "month"
|
|
100
128
|
const [from, setFrom] = React.useState(asMonth ? value.from.slice(0, 7) : value.from)
|
|
101
129
|
const [to, setTo] = React.useState(asMonth ? value.to.slice(0, 7) : value.to)
|
|
102
|
-
const list = tab === "custom" ? [] : (() => {
|
|
130
|
+
const list = tab === "custom" ? [] : tab === "presets" ? (rolling ?? []).flatMap(id => presetPeriod(id, today) ?? []) : (() => {
|
|
103
131
|
const out: Period[] = []
|
|
104
132
|
let p = periodOf(tab, max)
|
|
105
133
|
for (let i = 0; i < RECENT[tab] && (!min || p.to >= min); i++, p = shift(p, -1)) out.push(p)
|
|
@@ -119,33 +147,35 @@ function PickerMenu({ value, units, custom, min, max, today, onPick }: {
|
|
|
119
147
|
const input = "h-8 rounded-[6px] border border-border bg-card px-2 text-[14px] text-foreground [font:inherit]"
|
|
120
148
|
return (
|
|
121
149
|
<>
|
|
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
|
-
{
|
|
124
|
-
{
|
|
150
|
+
{units.length + (custom ? 1 : 0) + (rolling ? 1 : 0) > 1 && <div data-slot="period-picker-tabs" className={cn("flex gap-[2px] rounded-[8px] bg-muted p-[3px]", wide && "overflow-x-auto")} role="tablist">
|
|
151
|
+
{rolling && <button type="button" role="tab" aria-selected={tab === "presets"} className={tabClass(tab === "presets")} onClick={() => setTab("presets")}>{L.presets}</button>}
|
|
152
|
+
{units.map(u => <button key={u} type="button" role="tab" aria-selected={tab === u} className={tabClass(tab === u)} onClick={() => setTab(u)}>{L[u]}</button>)}
|
|
153
|
+
{custom && <button type="button" role="tab" aria-selected={tab === "custom"} className={tabClass(tab === "custom")} onClick={() => setTab("custom")}>{L.custom}</button>}
|
|
125
154
|
</div>}
|
|
126
155
|
{tab !== "custom" ? (
|
|
127
156
|
<div data-slot="period-picker-grid" className={cn("grid gap-1", tab === "month" ? "grid-cols-3" : "grid-cols-2")}>
|
|
128
157
|
{list.map(p => {
|
|
129
|
-
const on = value.unit === p.unit && value.from === p.from
|
|
130
|
-
|
|
158
|
+
const on = p.preset ? value.preset === p.preset : value.unit === p.unit && value.from === p.from && !value.preset
|
|
159
|
+
// Every preset runs to today: "in progress" under each would say nothing.
|
|
160
|
+
const live = !p.preset && isCurrent(p, today)
|
|
131
161
|
return (
|
|
132
|
-
<button key={p.from} type="button" data-current={live || undefined}
|
|
162
|
+
<button key={p.preset ?? p.from} type="button" data-current={live || undefined}
|
|
133
163
|
className={cn(
|
|
134
164
|
"grid cursor-pointer justify-items-center rounded-[6px] border border-transparent bg-transparent px-[6px] py-[7px] text-[13px] text-inherit tabular-nums",
|
|
135
165
|
live && "text-brand",
|
|
136
166
|
on ? "border-brand bg-[color-mix(in_srgb,var(--brand)_8%,transparent)] font-semibold" : "hover:bg-accent",
|
|
137
167
|
)}
|
|
138
168
|
onClick={() => onPick(p)}>
|
|
139
|
-
{periodLabel(p)}{live && <small className="text-[10px] font-normal text-muted-foreground">
|
|
169
|
+
{periodLabel(p, locale)}{live && <small className="text-[10px] font-normal text-muted-foreground">{L.inProgress}</small>}
|
|
140
170
|
</button>
|
|
141
171
|
)
|
|
142
172
|
})}
|
|
143
173
|
</div>
|
|
144
174
|
) : (
|
|
145
175
|
<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">
|
|
147
|
-
<label className="grid gap-1 text-[12px] text-muted-foreground">
|
|
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}>
|
|
176
|
+
<label className="grid gap-1 text-[12px] text-muted-foreground">{L.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>
|
|
177
|
+
<label className="grid gap-1 text-[12px] text-muted-foreground">{L.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>
|
|
178
|
+
<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}>{L.apply}</button>
|
|
149
179
|
</form>
|
|
150
180
|
)}
|
|
151
181
|
</>
|