@bison-lab/ui 3.38.0 → 3.40.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/dist/index.mjs CHANGED
@@ -7,7 +7,7 @@ import { fontFaceCss, fontPreloads, fontStack, isFontId } from "@bison-lab/fonts
7
7
  import { AnimatePresence, motion } from "motion/react";
8
8
  import { Accordion as Accordion$1, AlertDialog as AlertDialog$1, AspectRatio as AspectRatio$1, Avatar as Avatar$1, Checkbox as Checkbox$1, Collapsible as Collapsible$1, ContextMenu as ContextMenu$1, Dialog as Dialog$1, DropdownMenu as DropdownMenu$1, Label as Label$1, NavigationMenu as NavigationMenu$1, Popover as Popover$1, Progress as Progress$1, RadioGroup as RadioGroup$1, ScrollArea as ScrollArea$1, Select as Select$1, Separator as Separator$1, Slider as Slider$1, Slot, Switch as Switch$1, Tabs as Tabs$1, Tooltip as Tooltip$1, unstable_PasswordToggleField } from "radix-ui";
9
9
  import { cva } from "class-variance-authority";
10
- import { AlignCenter, AlignLeft, AlignRight, ArrowDown, ArrowLeft, ArrowRight, ArrowUp, ArrowUpDown, Bold, Calendar as Calendar$1, Camera, Check, ChevronDown, ChevronLeft, ChevronRight, ChevronUp, ChevronsLeft, ChevronsRight, ChevronsUpDown, Circle, CircleAlert, CircleCheck, CircleHelp, CircleX, Code, Eye, EyeOff, Facebook, FastForward, FileQuestion, Heading1, Heading2, Heading3, Image, Inbox, Info, Instagram, Italic, Link, Linkedin, List, ListOrdered, LoaderCircle, LogOut, Mail, MapPin, Menu, Minus, MoreHorizontal, MoveUpRight, PanelLeft, Pause, Pencil, Phone, Play, Plus, Quote, Redo, Search, Server, Settings2, ShieldAlert, Star, Strikethrough, TriangleAlert, Twitter, Underline, Undo, Unlink, Wrench, X, Youtube } from "lucide-react";
10
+ import { AlignCenter, AlignLeft, AlignRight, ArrowDown, ArrowLeft, ArrowRight, ArrowUp, ArrowUpDown, Bold, Calendar as Calendar$1, Camera, Check, ChevronDown, ChevronLeft, ChevronRight, ChevronUp, ChevronsLeft, ChevronsRight, ChevronsUpDown, Circle, CircleAlert, CircleCheck, CircleHelp, CircleX, Code, Eye, EyeOff, Facebook, FastForward, FileQuestion, Heading1, Heading2, Heading3, Image, Inbox, Info, Instagram, Italic, Link, Linkedin, List, ListOrdered, LoaderCircle, LogOut, Mail, MapPin, Menu, Minus, MoreHorizontal, MoveUpRight, PanelLeft, Pause, Pencil, Phone, Play, Plus, Quote, Redo, Search, Server, Settings2, ShieldAlert, SlidersHorizontal, Star, Strikethrough, TriangleAlert, Twitter, Underline, Undo, Unlink, Wrench, X, Youtube } from "lucide-react";
11
11
  import { DayPicker, getDefaultClassNames } from "react-day-picker";
12
12
  import useEmblaCarousel from "embla-carousel-react";
13
13
  import { endOfMonth, endOfWeek, format, startOfMonth, startOfWeek, startOfYear, subDays, subMonths, subYears } from "date-fns";
@@ -18,6 +18,7 @@ import Link$1 from "@tiptap/extension-link";
18
18
  import Underline$1 from "@tiptap/extension-underline";
19
19
  import TextAlign from "@tiptap/extension-text-align";
20
20
  import { Toaster as Toaster$1, toast } from "sonner";
21
+ import { attachEdgeShade } from "@bison-lab/tokens/dom";
21
22
  import { flexRender, getCoreRowModel, getFilteredRowModel, getPaginationRowModel, getSortedRowModel, useReactTable } from "@tanstack/react-table";
22
23
  import { Command as Command$1 } from "cmdk";
23
24
  //#region src/lib/semantic-action-tones.ts
@@ -3050,6 +3051,213 @@ const DropdownMenuShortcut = ({ className, ...props }) => /* @__PURE__ */ jsx("s
3050
3051
  ...props
3051
3052
  });
3052
3053
  //#endregion
3054
+ //#region src/components/filter-button.tsx
3055
+ /**
3056
+ * FilterButton — a data-driven faceted filter menu.
3057
+ *
3058
+ * Chrome comes from `dropdown-menu.tsx` and `lib/surface-classes.ts`, so a
3059
+ * filter menu and a column-toggle menu stay in lockstep. What this adds over
3060
+ * a hand-rolled `DropdownMenuCheckboxItem` list is the data shape: sections,
3061
+ * a value keyed by section, and the pure helpers a toolbar needs to render
3062
+ * chips or feed a table's filter state.
3063
+ */
3064
+ /** Drop the key entirely when a group empties, so `{}` means "no filters". */
3065
+ function setGroup(value, name, next) {
3066
+ const result = { ...value };
3067
+ if (next.length === 0) delete result[name];
3068
+ else result[name] = next;
3069
+ return result;
3070
+ }
3071
+ /**
3072
+ * Add or remove one option. Pure — pass the result to `onValueChange`.
3073
+ * A `single` group replaces its pick; re-picking the current one clears it.
3074
+ */
3075
+ function toggleFilter(value, group, optionValue) {
3076
+ const current = value[group.name] ?? [];
3077
+ if (group.mode === "single") return setGroup(value, group.name, current[0] === optionValue ? [] : [optionValue]);
3078
+ return setGroup(value, group.name, current.includes(optionValue) ? current.filter((entry) => entry !== optionValue) : [...current, optionValue]);
3079
+ }
3080
+ /** How many options are picked in total, across every group. */
3081
+ function filterCount(value) {
3082
+ return Object.values(value).reduce((total, picks) => total + picks.length, 0);
3083
+ }
3084
+ /**
3085
+ * The active picks as chip data, in the order the groups declare them.
3086
+ * Each chip carries the `FilterValue` that dismissing it produces.
3087
+ */
3088
+ function filterChips(groups, value) {
3089
+ const chips = [];
3090
+ for (const group of groups) for (const picked of value[group.name] ?? []) {
3091
+ const option = group.options.find((entry) => entry.value === picked);
3092
+ chips.push({
3093
+ key: `${group.name}:${picked}`,
3094
+ group: group.name,
3095
+ value: picked,
3096
+ label: option ? option.label : picked,
3097
+ next: setGroup(value, group.name, (value[group.name] ?? []).filter((entry) => entry !== picked))
3098
+ });
3099
+ }
3100
+ return chips;
3101
+ }
3102
+ /**
3103
+ * The value as TanStack Table column filters, for `DataTable`'s `filterState`.
3104
+ * Group names are column ids.
3105
+ *
3106
+ * This is NOT a server-side-only path. `DataTable` enters manual mode on
3107
+ * `totalRows` alone, so passing `filterState` without it gives controlled
3108
+ * filters with the client row models still doing the filtering — which is how
3109
+ * a table opens pre-filtered without any server work.
3110
+ *
3111
+ * Client-side, the column needs `filterFn: "arrIncludesSome"`: the default
3112
+ * filter compares a string, and a `string[]` matches nothing.
3113
+ */
3114
+ function toColumnFilters(value) {
3115
+ return Object.entries(value).map(([id, picks]) => ({
3116
+ id,
3117
+ value: picks
3118
+ }));
3119
+ }
3120
+ /** The tick box, sized and painted like `Checkbox` so a menu row matches a form row. */
3121
+ function ItemBox({ round }) {
3122
+ return /* @__PURE__ */ jsx("span", {
3123
+ className: cn("absolute left-2 flex h-4 w-4 items-center justify-center border border-primary bg-background text-primary-foreground transition-[background-color,border-color] duration-fast ease-default", round ? "rounded-full" : "rounded-[2px]", "group-data-[state=checked]:bg-primary"),
3124
+ "aria-hidden": true,
3125
+ children: /* @__PURE__ */ jsx(DropdownMenu$1.ItemIndicator, { children: round ? /* @__PURE__ */ jsx("span", { className: "block h-1.5 w-1.5 rounded-full bg-current" }) : /* @__PURE__ */ jsx("svg", {
3126
+ viewBox: "0 0 12 12",
3127
+ fill: "none",
3128
+ xmlns: "http://www.w3.org/2000/svg",
3129
+ className: "h-[10px] w-[10px] shrink-0",
3130
+ children: /* @__PURE__ */ jsx("path", {
3131
+ d: "M2.5 6.25 5 8.75 9.5 3.25",
3132
+ stroke: "currentColor",
3133
+ strokeWidth: "1.5",
3134
+ strokeLinecap: "round",
3135
+ strokeLinejoin: "round"
3136
+ })
3137
+ }) })
3138
+ });
3139
+ }
3140
+ /** Label plus optional tally, shared by the checkbox and radio rows. */
3141
+ function FilterRowLabel({ option }) {
3142
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", {
3143
+ className: "flex-1",
3144
+ children: option.label
3145
+ }), option.count != null ? /* @__PURE__ */ jsx("span", {
3146
+ className: "ml-auto pl-2 text-xs tabular-nums text-muted-foreground",
3147
+ children: option.count
3148
+ }) : null] });
3149
+ }
3150
+ const FilterButton = React.forwardRef(({ groups, value, onValueChange, apply = false, clearable = true, label = "Filter", icon, showCount = true, applyLabel = "Apply", clearLabel = "Clear", emptyLabel = "No options", open: openProp, onOpenChange, align = "start", variant = "outline", size = "md", className, contentClassName, disabled, ...props }, ref) => {
3151
+ const [uncontrolledOpen, setUncontrolledOpen] = React.useState(false);
3152
+ const open = openProp ?? uncontrolledOpen;
3153
+ const [draft, setDraft] = React.useState(value);
3154
+ const [lastOpen, setLastOpen] = React.useState(open);
3155
+ if (open !== lastOpen) {
3156
+ setLastOpen(open);
3157
+ if (open) setDraft(value);
3158
+ }
3159
+ const current = apply ? draft : value;
3160
+ const setOpen = (next) => {
3161
+ if (openProp === void 0) setUncontrolledOpen(next);
3162
+ onOpenChange?.(next);
3163
+ };
3164
+ const commit = (next) => {
3165
+ if (apply) setDraft(next);
3166
+ else onValueChange(next);
3167
+ };
3168
+ const activeCount = filterCount(value);
3169
+ const stagedCount = filterCount(current);
3170
+ const fieldProps = useFieldControl(props);
3171
+ const groupLabelId = React.useId();
3172
+ const footer = apply || clearable && stagedCount > 0;
3173
+ return /* @__PURE__ */ jsxs(DropdownMenu, {
3174
+ open,
3175
+ onOpenChange: setOpen,
3176
+ children: [/* @__PURE__ */ jsx(DropdownMenuTrigger, {
3177
+ asChild: true,
3178
+ children: /* @__PURE__ */ jsxs(Button, {
3179
+ ref,
3180
+ type: "button",
3181
+ variant,
3182
+ size,
3183
+ disabled,
3184
+ icon: icon === void 0 ? /* @__PURE__ */ jsx(SlidersHorizontal, {}) : icon,
3185
+ className,
3186
+ ...fieldProps,
3187
+ children: [label, showCount && activeCount > 0 ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", {
3188
+ className: "ml-1 inline-flex h-5 min-w-5 items-center justify-center rounded-full bg-primary px-1.5 text-xs font-medium text-primary-foreground",
3189
+ "aria-hidden": true,
3190
+ children: activeCount
3191
+ }), /* @__PURE__ */ jsx("span", {
3192
+ className: "sr-only",
3193
+ children: `${activeCount} active`
3194
+ })] }) : null]
3195
+ })
3196
+ }), /* @__PURE__ */ jsxs(DropdownMenuContent, {
3197
+ align,
3198
+ className: cn("w-56", contentClassName),
3199
+ children: [groups.map((group, index) => {
3200
+ const picks = current[group.name] ?? [];
3201
+ const labelId = `${groupLabelId}-${group.name}`;
3202
+ return /* @__PURE__ */ jsxs(React.Fragment, { children: [index > 0 ? /* @__PURE__ */ jsx(DropdownMenuSeparator, {}) : null, /* @__PURE__ */ jsxs(DropdownMenu$1.Group, {
3203
+ "aria-labelledby": group.label ? labelId : void 0,
3204
+ children: [
3205
+ group.label ? /* @__PURE__ */ jsx(DropdownMenuLabel, {
3206
+ id: labelId,
3207
+ className: "text-[11px] font-medium uppercase tracking-wide text-muted-foreground",
3208
+ children: group.label
3209
+ }) : null,
3210
+ group.options.length === 0 ? /* @__PURE__ */ jsx(DropdownMenuItem, {
3211
+ disabled: true,
3212
+ children: emptyLabel
3213
+ }) : null,
3214
+ group.mode === "single" ? /* @__PURE__ */ jsx(DropdownMenu$1.RadioGroup, {
3215
+ value: picks[0] ?? "",
3216
+ children: group.options.map((option) => /* @__PURE__ */ jsxs(DropdownMenu$1.RadioItem, {
3217
+ value: option.value,
3218
+ disabled: option.disabled,
3219
+ className: cn("group", menuItemWithIndicatorClasses),
3220
+ onSelect: (event) => {
3221
+ event.preventDefault();
3222
+ commit(toggleFilter(current, group, option.value));
3223
+ },
3224
+ children: [/* @__PURE__ */ jsx(ItemBox, { round: true }), /* @__PURE__ */ jsx(FilterRowLabel, { option })]
3225
+ }, option.value))
3226
+ }) : group.options.map((option) => /* @__PURE__ */ jsxs(DropdownMenu$1.CheckboxItem, {
3227
+ checked: picks.includes(option.value),
3228
+ disabled: option.disabled,
3229
+ className: cn("group", menuItemWithIndicatorClasses),
3230
+ onSelect: (event) => {
3231
+ event.preventDefault();
3232
+ commit(toggleFilter(current, group, option.value));
3233
+ },
3234
+ children: [/* @__PURE__ */ jsx(ItemBox, {}), /* @__PURE__ */ jsx(FilterRowLabel, { option })]
3235
+ }, option.value))
3236
+ ]
3237
+ })] }, group.name);
3238
+ }), footer ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(DropdownMenuSeparator, {}), /* @__PURE__ */ jsxs("div", {
3239
+ className: "flex items-center gap-1",
3240
+ children: [/* @__PURE__ */ jsx(DropdownMenuItem, {
3241
+ className: "flex-1 justify-center font-medium",
3242
+ disabled: stagedCount === 0,
3243
+ onSelect: (event) => {
3244
+ if (apply) {
3245
+ event.preventDefault();
3246
+ setDraft({});
3247
+ } else onValueChange({});
3248
+ },
3249
+ children: clearLabel
3250
+ }), apply ? /* @__PURE__ */ jsx(DropdownMenuItem, {
3251
+ className: "flex-1 justify-center bg-primary font-medium text-primary-foreground focus:bg-primary-700 focus:text-primary-foreground",
3252
+ onSelect: () => onValueChange(draft),
3253
+ children: applyLabel
3254
+ }) : null]
3255
+ })] }) : null]
3256
+ })]
3257
+ });
3258
+ });
3259
+ FilterButton.displayName = "FilterButton";
3260
+ //#endregion
3053
3261
  //#region src/components/toast.tsx
3054
3262
  function Toaster({ position = "bottom-right", richColors = true, closeButton = true, ...props }) {
3055
3263
  return /* @__PURE__ */ jsx(Toaster$1, {
@@ -3463,14 +3671,60 @@ const AccordionContent = React.forwardRef(({ className, children, ...props }, re
3463
3671
  AccordionContent.displayName = Accordion$1.Content.displayName;
3464
3672
  //#endregion
3465
3673
  //#region src/components/table.tsx
3466
- const Table = React.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx("div", {
3467
- className: "relative w-full overflow-auto",
3468
- children: /* @__PURE__ */ jsx("table", {
3469
- ref,
3470
- className: cn("w-full caption-bottom text-sm", className),
3471
- ...props
3472
- })
3473
- }));
3674
+ /**
3675
+ * A pinned cell is sticky and opaque — without a background the scrolling rows
3676
+ * would show through it. The shadow fades in only once there is content hidden
3677
+ * under that edge; the 0..1 strength comes from the scroller (see `Table`).
3678
+ *
3679
+ * The shadow is mixed from `--foreground` rather than black: the library themes
3680
+ * light and dark, and a black shadow on a dark surface is no shadow at all.
3681
+ *
3682
+ * The divider carries the rest of the weight. A shadow that only appears once
3683
+ * you have already scrolled cannot tell you a column is anchored; the border
3684
+ * says so from the first glance, which is what a reader needs.
3685
+ *
3686
+ * The background is `--bl-table-row-bg`, which each row sets for itself, rather
3687
+ * than a fixed colour. A pinned cell must be opaque or the scrolling rows show
3688
+ * through it, but painting it `bg-background` cuts a pale hole in the row's
3689
+ * hover and selected tints — the pinned columns stay white while the middle of
3690
+ * the row highlights.
3691
+ *
3692
+ * It carries `transition-colors` for the same reason the row does. A custom
3693
+ * property is not itself animatable, but the `background-color` it resolves to
3694
+ * is, so without this the pinned cells snap while the rest of the row fades.
3695
+ */
3696
+ const pinClasses = (pin) => pin === "start" ? "sticky left-0 z-20 border-r transition-colors bg-[var(--bl-table-row-bg,hsl(var(--background)))] [box-shadow:8px_0_12px_-4px_color-mix(in_srgb,hsl(var(--foreground))_calc(22%*var(--bl-table-shade-start,0)),transparent)]" : pin === "end" ? "sticky right-0 z-20 border-l transition-colors bg-[var(--bl-table-row-bg,hsl(var(--background)))] [box-shadow:-8px_0_12px_-4px_color-mix(in_srgb,hsl(var(--foreground))_calc(22%*var(--bl-table-shade-end,0)),transparent)]" : void 0;
3697
+ /**
3698
+ * The composited equivalents of the row's own translucent tints. A pinned cell
3699
+ * cannot use `bg-muted/50` — stacked over the row's own tint it would double —
3700
+ * so each state names the colour the row actually ends up showing.
3701
+ */
3702
+ const ROW_BG = "[--bl-table-row-bg:hsl(var(--background))] hover:[--bl-table-row-bg:color-mix(in_srgb,hsl(var(--muted))_50%,hsl(var(--background)))] data-[state=selected]:[--bl-table-row-bg:hsl(var(--muted))]";
3703
+ const Table = React.forwardRef(({ className, ...props }, ref) => {
3704
+ const scroller = React.useRef(null);
3705
+ const [scrollable, setScrollable] = React.useState(false);
3706
+ React.useLayoutEffect(() => {
3707
+ const el = scroller.current;
3708
+ if (!el) return;
3709
+ return attachEdgeShade(el, {
3710
+ activeSelector: "[data-pinned]",
3711
+ onOverflowChange: setScrollable
3712
+ });
3713
+ });
3714
+ return /* @__PURE__ */ jsx("div", {
3715
+ ref: scroller,
3716
+ "data-slot": "table-scroller",
3717
+ className: "relative w-full overflow-auto rounded-[inherit] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
3718
+ tabIndex: scrollable ? 0 : void 0,
3719
+ role: scrollable ? "group" : void 0,
3720
+ "aria-label": scrollable ? "Scrollable table" : void 0,
3721
+ children: /* @__PURE__ */ jsx("table", {
3722
+ ref,
3723
+ className: cn("w-full caption-bottom text-sm", className),
3724
+ ...props
3725
+ })
3726
+ });
3727
+ });
3474
3728
  Table.displayName = "Table";
3475
3729
  const TableHeader = React.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx("thead", {
3476
3730
  ref,
@@ -3486,25 +3740,27 @@ const TableBody = React.forwardRef(({ className, ...props }, ref) => /* @__PURE_
3486
3740
  TableBody.displayName = "TableBody";
3487
3741
  const TableFooter = React.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx("tfoot", {
3488
3742
  ref,
3489
- className: cn("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0", className),
3743
+ className: cn("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0", "[&>tr]:[--bl-table-row-bg:color-mix(in_srgb,hsl(var(--muted))_50%,hsl(var(--background)))]", className),
3490
3744
  ...props
3491
3745
  }));
3492
3746
  TableFooter.displayName = "TableFooter";
3493
3747
  const TableRow = React.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx("tr", {
3494
3748
  ref,
3495
- className: cn("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted", className),
3749
+ className: cn("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted", ROW_BG, className),
3496
3750
  ...props
3497
3751
  }));
3498
3752
  TableRow.displayName = "TableRow";
3499
- const TableHead = React.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx("th", {
3753
+ const TableHead = React.forwardRef(({ className, pin, ...props }, ref) => /* @__PURE__ */ jsx("th", {
3500
3754
  ref,
3501
- className: cn("h-12 px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0", className),
3755
+ "data-pinned": pin,
3756
+ className: cn("h-12 px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0", pinClasses(pin), className),
3502
3757
  ...props
3503
3758
  }));
3504
3759
  TableHead.displayName = "TableHead";
3505
- const TableCell = React.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx("td", {
3760
+ const TableCell = React.forwardRef(({ className, pin, ...props }, ref) => /* @__PURE__ */ jsx("td", {
3506
3761
  ref,
3507
- className: cn("p-4 align-middle [&:has([role=checkbox])]:pr-0", className),
3762
+ "data-pinned": pin,
3763
+ className: cn("p-4 align-middle [&:has([role=checkbox])]:pr-0", pinClasses(pin), className),
3508
3764
  ...props
3509
3765
  }));
3510
3766
  TableCell.displayName = "TableCell";
@@ -3515,6 +3771,57 @@ const TableCaption = React.forwardRef(({ className, ...props }, ref) => /* @__PU
3515
3771
  }));
3516
3772
  TableCaption.displayName = "TableCaption";
3517
3773
  //#endregion
3774
+ //#region src/components/data-table-totals.ts
3775
+ /** A client-side table can total what it holds; a server-paginated one cannot. */
3776
+ function totalledRows(table) {
3777
+ if (table.options.manualPagination) return null;
3778
+ return table.getFilteredRowModel().rows.map((row) => row.original);
3779
+ }
3780
+ function numbersFrom(rows, accessor) {
3781
+ const values = [];
3782
+ for (const row of rows) {
3783
+ const value = accessor(row);
3784
+ if (typeof value === "number" && Number.isFinite(value)) values.push(value);
3785
+ }
3786
+ return values;
3787
+ }
3788
+ /** Round away float noise without pretending to more precision than we have. */
3789
+ const round = (value) => Math.round(value * 100) / 100;
3790
+ /** Sum of a column across every filtered row. */
3791
+ function sumFooter(accessor) {
3792
+ return ({ table }) => {
3793
+ const rows = totalledRows(table);
3794
+ if (!rows) return null;
3795
+ const total = numbersFrom(rows, accessor).reduce((sum, value) => sum + value, 0);
3796
+ return String(round(total));
3797
+ };
3798
+ }
3799
+ /** Mean of a column across every filtered row that holds a number. */
3800
+ function avgFooter(accessor) {
3801
+ return ({ table }) => {
3802
+ const rows = totalledRows(table);
3803
+ if (!rows) return null;
3804
+ const values = numbersFrom(rows, accessor);
3805
+ if (values.length === 0) return null;
3806
+ return String(round(values.reduce((sum, value) => sum + value, 0) / values.length));
3807
+ };
3808
+ }
3809
+ /**
3810
+ * How many rows the filter left behind.
3811
+ *
3812
+ * The result is always labelled (`"12 rows"`), because a count is not a total
3813
+ * of the column it sits under: a bare number beneath a column of email
3814
+ * addresses reads as a sum of that column. Pass a noun to name what is being
3815
+ * counted — `countFooter("payments")` renders `"12 payments"`.
3816
+ */
3817
+ function countFooter(noun = "rows") {
3818
+ return ({ table }) => {
3819
+ const rows = totalledRows(table);
3820
+ if (!rows) return null;
3821
+ return `${rows.length} ${noun}`;
3822
+ };
3823
+ }
3824
+ //#endregion
3518
3825
  //#region src/components/data-table.tsx
3519
3826
  const sizeClasses = {
3520
3827
  sm: {
@@ -3570,6 +3877,22 @@ function createSelectionColumn() {
3570
3877
  size: 40
3571
3878
  };
3572
3879
  }
3880
+ /**
3881
+ * Translate TanStack's pinning state into the primitives' `pin` prop plus the
3882
+ * offset that stacks a second pinned column beside the first.
3883
+ */
3884
+ function pinProps(column) {
3885
+ const pinned = column.getIsPinned();
3886
+ if (pinned === "left") return {
3887
+ pin: "start",
3888
+ style: { left: `${column.getStart("left")}px` }
3889
+ };
3890
+ if (pinned === "right") return {
3891
+ pin: "end",
3892
+ style: { right: `${column.getAfter("right")}px` }
3893
+ };
3894
+ return {};
3895
+ }
3573
3896
  function useDensitySize() {
3574
3897
  const ref = React.useRef(null);
3575
3898
  const [size, setSize] = React.useState("md");
@@ -3590,7 +3913,7 @@ function DataTableInner({ columns, data, filterColumn, filterPlaceholder = "Filt
3590
3913
  20,
3591
3914
  30,
3592
3915
  50
3593
- ], enableRowSelection = false, onRowSelectionChange, totalRows, paginationState: controlledPagination, onPaginationChange, sortingState: controlledSorting, onSortingChange: onSortingChangeProp, filterState: controlledFilters, onFilterChange, showColumnToggle = true, toolbarActions, size: sizeProp, emptyMessage = "No results.", className }, ref) {
3916
+ ], enableRowSelection = false, onRowSelectionChange, totalRows, paginationState: controlledPagination, onPaginationChange, sortingState: controlledSorting, onSortingChange: onSortingChangeProp, filterState: controlledFilters, onFilterChange, showColumnToggle = true, toolbarActions, pinnedColumns, showFooter = false, size: sizeProp, emptyMessage = "No results.", className }, ref) {
3594
3917
  const isServerSide = totalRows !== void 0;
3595
3918
  const [internalSorting, setInternalSorting] = React.useState([]);
3596
3919
  const [internalFilters, setInternalFilters] = React.useState([]);
@@ -3617,9 +3940,15 @@ function DataTableInner({ columns, data, filterColumn, filterPlaceholder = "Filt
3617
3940
  if (!enableRowSelection) return columns;
3618
3941
  return [createSelectionColumn(), ...columns];
3619
3942
  }, [columns, enableRowSelection]);
3943
+ const columnPinning = React.useMemo(() => ({
3944
+ left: pinnedColumns?.left ?? [],
3945
+ right: pinnedColumns?.right ?? []
3946
+ }), [pinnedColumns]);
3947
+ const hasPinnedColumns = columnPinning.left.length > 0 || columnPinning.right.length > 0;
3620
3948
  const table = useReactTable({
3621
3949
  data,
3622
3950
  columns: finalColumns,
3951
+ initialState: { columnPinning },
3623
3952
  state: {
3624
3953
  sorting,
3625
3954
  columnFilters,
@@ -3683,6 +4012,7 @@ function DataTableInner({ columns, data, filterColumn, filterPlaceholder = "Filt
3683
4012
  table.getAllColumns().filter((col) => col.getCanHide()).map((col) => /* @__PURE__ */ jsx(DropdownMenuCheckboxItem, {
3684
4013
  className: "capitalize",
3685
4014
  checked: col.getIsVisible(),
4015
+ onSelect: (event) => event.preventDefault(),
3686
4016
  onCheckedChange: (value) => col.toggleVisibility(!!value),
3687
4017
  children: col.id
3688
4018
  }, col.id))
@@ -3692,21 +4022,48 @@ function DataTableInner({ columns, data, filterColumn, filterPlaceholder = "Filt
3692
4022
  }),
3693
4023
  /* @__PURE__ */ jsx("div", {
3694
4024
  className: "rounded-md border",
3695
- children: /* @__PURE__ */ jsxs(Table, { children: [/* @__PURE__ */ jsx(TableHeader, { children: table.getHeaderGroups().map((headerGroup) => /* @__PURE__ */ jsx(TableRow, { children: headerGroup.headers.map((header) => /* @__PURE__ */ jsx(TableHead, {
3696
- className: sc.header,
3697
- style: { width: header.column.id === "_select" ? 40 : header.getSize() !== 150 ? header.getSize() : void 0 },
3698
- children: header.isPlaceholder ? null : flexRender(header.column.columnDef.header, header.getContext())
3699
- }, header.id)) }, headerGroup.id)) }), /* @__PURE__ */ jsx(TableBody, { children: table.getRowModel().rows?.length ? table.getRowModel().rows.map((row) => /* @__PURE__ */ jsx(TableRow, {
3700
- "data-state": row.getIsSelected() && "selected",
3701
- children: row.getVisibleCells().map((cell) => /* @__PURE__ */ jsx(TableCell, {
3702
- className: sc.cell,
3703
- children: flexRender(cell.column.columnDef.cell, cell.getContext())
3704
- }, cell.id))
3705
- }, row.id)) : /* @__PURE__ */ jsx(TableRow, { children: /* @__PURE__ */ jsx(TableCell, {
3706
- colSpan: finalColumns.length,
3707
- className: "h-24 text-center",
3708
- children: emptyMessage
3709
- }) }) })] })
4025
+ children: /* @__PURE__ */ jsxs(Table, {
4026
+ className: cn(hasPinnedColumns && "min-w-max"),
4027
+ children: [
4028
+ /* @__PURE__ */ jsx(TableHeader, { children: table.getHeaderGroups().map((headerGroup) => /* @__PURE__ */ jsx(TableRow, { children: headerGroup.headers.map((header) => {
4029
+ const pinned = pinProps(header.column);
4030
+ return /* @__PURE__ */ jsx(TableHead, {
4031
+ pin: pinned.pin,
4032
+ className: sc.header,
4033
+ style: {
4034
+ ...pinned.style,
4035
+ width: header.column.id === "_select" ? 40 : header.getSize() !== 150 ? header.getSize() : void 0
4036
+ },
4037
+ children: header.isPlaceholder ? null : flexRender(header.column.columnDef.header, header.getContext())
4038
+ }, header.id);
4039
+ }) }, headerGroup.id)) }),
4040
+ /* @__PURE__ */ jsx(TableBody, { children: table.getRowModel().rows?.length ? table.getRowModel().rows.map((row) => /* @__PURE__ */ jsx(TableRow, {
4041
+ "data-state": row.getIsSelected() && "selected",
4042
+ children: row.getVisibleCells().map((cell) => {
4043
+ const pinned = pinProps(cell.column);
4044
+ return /* @__PURE__ */ jsx(TableCell, {
4045
+ pin: pinned.pin,
4046
+ className: sc.cell,
4047
+ style: pinned.style,
4048
+ children: flexRender(cell.column.columnDef.cell, cell.getContext())
4049
+ }, cell.id);
4050
+ })
4051
+ }, row.id)) : /* @__PURE__ */ jsx(TableRow, { children: /* @__PURE__ */ jsx(TableCell, {
4052
+ colSpan: finalColumns.length,
4053
+ className: "h-24 text-center",
4054
+ children: emptyMessage
4055
+ }) }) }),
4056
+ showFooter && /* @__PURE__ */ jsx(TableFooter, { children: table.getFooterGroups().map((footerGroup) => /* @__PURE__ */ jsx(TableRow, { children: footerGroup.headers.map((header) => {
4057
+ const pinned = pinProps(header.column);
4058
+ return /* @__PURE__ */ jsx(TableCell, {
4059
+ pin: pinned.pin,
4060
+ className: sc.cell,
4061
+ style: pinned.style,
4062
+ children: header.isPlaceholder ? null : flexRender(header.column.columnDef.footer, header.getContext())
4063
+ }, header.id);
4064
+ }) }, footerGroup.id)) })
4065
+ ]
4066
+ })
3710
4067
  }),
3711
4068
  (pagination || enableRowSelection) && /* @__PURE__ */ jsxs("div", {
3712
4069
  className: "flex items-center justify-between px-2",
@@ -9131,6 +9488,6 @@ const ContrastStrip = React.forwardRef(({ checks, mode = "both", failingOnly = f
9131
9488
  });
9132
9489
  ContrastStrip.displayName = "ContrastStrip";
9133
9490
  //#endregion
9134
- export { Accordion, AccordionContent, AccordionItem, AccordionTrigger, AccountSettingsBlock, Alert, AlertDescription, AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogOverlay, AlertDialogPortal, AlertDialogTitle, AlertDialogTrigger, AlertTitle, AppSidebarBlock, AspectRatio, Avatar, AvatarFallback, AvatarImage, Badge, BisonProvider, Breadcrumb, BreadcrumbEllipsis, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator, Button, CHROME_LOOK_CLASSES, Calendar, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, Carousel, CarouselContent, CarouselItem, CarouselNext, CarouselPrevious, Checkbox, CodeInput, Collapsible, CollapsibleContent, CollapsibleTrigger, Command, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut, ContextMenu, ContextMenuCheckboxItem, ContextMenuContent, ContextMenuGroup, ContextMenuItem, ContextMenuLabel, ContextMenuPortal, ContextMenuRadioGroup, ContextMenuRadioItem, ContextMenuSeparator, ContextMenuShortcut, ContextMenuSub, ContextMenuSubContent, ContextMenuSubTrigger, ContextMenuTrigger, ContrastStrip, CurrencyInput, DataTable, DataTableColumnHeader, DatePicker, DateRangePicker, DensityProvider, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuPortal, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, EditableTitle, EmptyStateBlock, FAQColumnsBlock, FieldGroupScope, FieldProvider, FloatingNavBlock, FooterBlock, ForgotPasswordBlock, Form, FormError, FormField, HeaderBlock, Input, InputGroup, JsonLd, Kbd, Label, LookSurface, MaintenanceBlock, MediaCard, MegaMenuPanel, NapBlock, NavigationMenu, NavigationMenuContent, NavigationMenuIndicator, NavigationMenuItem, NavigationMenuLink, NavigationMenuList, NavigationMenuTrigger, NavigationMenuViewport, NotFoundBlock, NotificationSettingsBlock, OutlinedField, PageShell, Pagination, PaginationContent, PaginationEllipsis, PaginationItem, PaginationLink, PaginationNext, PaginationPrevious, PasswordInput, PhoneInput, Popover, PopoverContent, PopoverTrigger, ProcessStepsBlock, ProfileSettingsBlock, Progress, ProgressBar, RadioGroup, RadioGroupItem, Rating, ResetPasswordBlock, ResourcesBlock, ReviewsBlock, RotatingBadge, SavedPing, ScrollArea, ScrollBar, Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectSeparator, SelectTrigger, SelectValue, Separator, ServerErrorBlock, Sheet, SheetClose, SheetContent, SheetDescription, SheetFooter, SheetHeader, SheetOverlay, SheetPortal, SheetTitle, SheetTrigger, ShowcasePanelsBlock, Sidebar, SidebarBlock, SidebarContent, SidebarFooter, SidebarGroup, SidebarGroupAction, SidebarGroupContent, SidebarGroupLabel, SidebarHeader, SidebarInput, SidebarInset, SidebarMenu, SidebarMenuAction, SidebarMenuBadge, SidebarMenuButton, SidebarMenuItem, SidebarMenuSkeleton, SidebarMenuSub, SidebarMenuSubButton, SidebarMenuSubItem, SidebarProvider, SidebarRail, SidebarSeparator, SidebarTrigger, SignInBlock, SignUpBlock, Skeleton, Slider, SocialFeedBlock, SocialProviders, Spinner, StatsBandBlock, Stepper, StepperDescription, StepperIndicator, StepperItem, StepperLabel, StepperSeparator, Switch, Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow, Tabs, TabsContent, TabsList, TabsTrigger, TestimonialCarousel, TestimonialMasonry, TextContent, TextEditor, Textarea, ThemeProvider, ThemeScope, ThemeShowcase, TimePicker, Toaster, Tooltip, TooltipArrow, TooltipContent, TooltipDescription, TooltipMedia, TooltipProvider, TooltipShortcut, TooltipTitle, TooltipTrigger, VerifyBlock, actionNegativeToneClasses, actionNeutralIconChromeClasses, actionNeutralToneClasses, actionPositiveToneClasses, alertVariants, avatarVariants, badgeVariants, buttonVariants, cn, dateRangePresets, editableTitleVariants, formatUsPhone, megaMenuGridColumns, megaMenuToFloatingNavItems, megaMenuVariantsFromLooks, megaMenuVariantsFromTones, napRecordToJsonLd, navigationMenuTriggerStyle, newTabAttributes, outlinedFieldNestResetClasses, parseUsPhoneDigits, progressBarVariants, ratingVariants, renderPlainLink, spinnerVariants, stepperIndicatorVariants, stepperItemVariants, stepperLabelVariants, switchVariants, testimonialInitials, themeShowcaseSections, toast, useCarousel, useDensity, useField, useFieldControl, useFieldGroup, useFieldIds, useFormContext, useHideOnScroll, useIsMobile, useScrollReveal, useSidebar, useTheme };
9491
+ export { Accordion, AccordionContent, AccordionItem, AccordionTrigger, AccountSettingsBlock, Alert, AlertDescription, AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogOverlay, AlertDialogPortal, AlertDialogTitle, AlertDialogTrigger, AlertTitle, AppSidebarBlock, AspectRatio, Avatar, AvatarFallback, AvatarImage, Badge, BisonProvider, Breadcrumb, BreadcrumbEllipsis, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator, Button, CHROME_LOOK_CLASSES, Calendar, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, Carousel, CarouselContent, CarouselItem, CarouselNext, CarouselPrevious, Checkbox, CodeInput, Collapsible, CollapsibleContent, CollapsibleTrigger, Command, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut, ContextMenu, ContextMenuCheckboxItem, ContextMenuContent, ContextMenuGroup, ContextMenuItem, ContextMenuLabel, ContextMenuPortal, ContextMenuRadioGroup, ContextMenuRadioItem, ContextMenuSeparator, ContextMenuShortcut, ContextMenuSub, ContextMenuSubContent, ContextMenuSubTrigger, ContextMenuTrigger, ContrastStrip, CurrencyInput, DataTable, DataTableColumnHeader, DatePicker, DateRangePicker, DensityProvider, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuPortal, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, EditableTitle, EmptyStateBlock, FAQColumnsBlock, FieldGroupScope, FieldProvider, FilterButton, FloatingNavBlock, FooterBlock, ForgotPasswordBlock, Form, FormError, FormField, HeaderBlock, Input, InputGroup, JsonLd, Kbd, Label, LookSurface, MaintenanceBlock, MediaCard, MegaMenuPanel, NapBlock, NavigationMenu, NavigationMenuContent, NavigationMenuIndicator, NavigationMenuItem, NavigationMenuLink, NavigationMenuList, NavigationMenuTrigger, NavigationMenuViewport, NotFoundBlock, NotificationSettingsBlock, OutlinedField, PageShell, Pagination, PaginationContent, PaginationEllipsis, PaginationItem, PaginationLink, PaginationNext, PaginationPrevious, PasswordInput, PhoneInput, Popover, PopoverContent, PopoverTrigger, ProcessStepsBlock, ProfileSettingsBlock, Progress, ProgressBar, RadioGroup, RadioGroupItem, Rating, ResetPasswordBlock, ResourcesBlock, ReviewsBlock, RotatingBadge, SavedPing, ScrollArea, ScrollBar, Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectSeparator, SelectTrigger, SelectValue, Separator, ServerErrorBlock, Sheet, SheetClose, SheetContent, SheetDescription, SheetFooter, SheetHeader, SheetOverlay, SheetPortal, SheetTitle, SheetTrigger, ShowcasePanelsBlock, Sidebar, SidebarBlock, SidebarContent, SidebarFooter, SidebarGroup, SidebarGroupAction, SidebarGroupContent, SidebarGroupLabel, SidebarHeader, SidebarInput, SidebarInset, SidebarMenu, SidebarMenuAction, SidebarMenuBadge, SidebarMenuButton, SidebarMenuItem, SidebarMenuSkeleton, SidebarMenuSub, SidebarMenuSubButton, SidebarMenuSubItem, SidebarProvider, SidebarRail, SidebarSeparator, SidebarTrigger, SignInBlock, SignUpBlock, Skeleton, Slider, SocialFeedBlock, SocialProviders, Spinner, StatsBandBlock, Stepper, StepperDescription, StepperIndicator, StepperItem, StepperLabel, StepperSeparator, Switch, Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow, Tabs, TabsContent, TabsList, TabsTrigger, TestimonialCarousel, TestimonialMasonry, TextContent, TextEditor, Textarea, ThemeProvider, ThemeScope, ThemeShowcase, TimePicker, Toaster, Tooltip, TooltipArrow, TooltipContent, TooltipDescription, TooltipMedia, TooltipProvider, TooltipShortcut, TooltipTitle, TooltipTrigger, VerifyBlock, actionNegativeToneClasses, actionNeutralIconChromeClasses, actionNeutralToneClasses, actionPositiveToneClasses, alertVariants, avatarVariants, avgFooter, badgeVariants, buttonVariants, cn, countFooter, dateRangePresets, editableTitleVariants, filterChips, filterCount, formatUsPhone, megaMenuGridColumns, megaMenuToFloatingNavItems, megaMenuVariantsFromLooks, megaMenuVariantsFromTones, napRecordToJsonLd, navigationMenuTriggerStyle, newTabAttributes, outlinedFieldNestResetClasses, parseUsPhoneDigits, progressBarVariants, ratingVariants, renderPlainLink, spinnerVariants, stepperIndicatorVariants, stepperItemVariants, stepperLabelVariants, sumFooter, switchVariants, testimonialInitials, themeShowcaseSections, toColumnFilters, toast, toggleFilter, useCarousel, useDensity, useField, useFieldControl, useFieldGroup, useFieldIds, useFormContext, useHideOnScroll, useIsMobile, useScrollReveal, useSidebar, useTheme };
9135
9492
 
9136
9493
  //# sourceMappingURL=index.mjs.map