@eifi1/ui-kit 0.9.0 → 0.11.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 +37 -23
- package/dist/components/alert-banner.d.ts +57 -5
- package/dist/components/alert-banner.js +63 -17
- package/dist/components/alert-banner.js.map +1 -1
- package/dist/components/amount-input.d.ts +6 -0
- package/dist/components/breadcrumbs.d.ts +60 -0
- package/dist/components/breadcrumbs.js +88 -0
- package/dist/components/breadcrumbs.js.map +1 -0
- package/dist/components/bulk-action-bar.d.ts +112 -0
- package/dist/components/bulk-action-bar.js +196 -0
- package/dist/components/bulk-action-bar.js.map +1 -0
- package/dist/components/button-group.d.ts +58 -3
- package/dist/components/button-group.js +56 -5
- package/dist/components/button-group.js.map +1 -1
- package/dist/components/calculator.d.ts +6 -0
- package/dist/components/calendar-heatmap.d.ts +124 -0
- package/dist/components/calendar-heatmap.js +295 -0
- package/dist/components/calendar-heatmap.js.map +1 -0
- package/dist/components/chip.d.ts +31 -5
- package/dist/components/chip.js +85 -5
- package/dist/components/chip.js.map +1 -1
- package/dist/components/choice-card.d.ts +34 -2
- package/dist/components/choice-card.js +49 -0
- package/dist/components/choice-card.js.map +1 -1
- package/dist/components/copy-button.d.ts +14 -4
- package/dist/components/copy-button.js +17 -4
- package/dist/components/copy-button.js.map +1 -1
- package/dist/components/data-table.js +2 -0
- package/dist/components/data-table.js.map +1 -1
- package/dist/components/date-picker.d.ts +22 -2
- package/dist/components/date-picker.js +11 -3
- package/dist/components/date-picker.js.map +1 -1
- package/dist/components/description-list.d.ts +43 -6
- package/dist/components/description-list.js +91 -11
- package/dist/components/description-list.js.map +1 -1
- package/dist/components/dialog-frame.d.ts +7 -0
- package/dist/components/dialog-frame.js.map +1 -1
- package/dist/components/disclosure.d.ts +57 -2
- package/dist/components/disclosure.js +24 -12
- package/dist/components/disclosure.js.map +1 -1
- package/dist/components/field.d.ts +43 -0
- package/dist/components/field.js +52 -0
- package/dist/components/field.js.map +1 -0
- package/dist/components/file-button.d.ts +1 -0
- package/dist/components/file-dropzone.d.ts +4 -4
- package/dist/components/file-dropzone.js +2 -1
- package/dist/components/file-dropzone.js.map +1 -1
- package/dist/components/floating-panel.d.ts +147 -4
- package/dist/components/floating-panel.js +188 -28
- package/dist/components/floating-panel.js.map +1 -1
- package/dist/components/full-bleed-dialog.d.ts +23 -4
- package/dist/components/full-bleed-dialog.js +11 -2
- package/dist/components/full-bleed-dialog.js.map +1 -1
- package/dist/components/list.d.ts +187 -0
- package/dist/components/list.js +221 -0
- package/dist/components/list.js.map +1 -0
- package/dist/components/menu-item.d.ts +109 -0
- package/dist/components/menu-item.js +88 -0
- package/dist/components/menu-item.js.map +1 -0
- package/dist/components/mini-calendar.d.ts +70 -5
- package/dist/components/mini-calendar.js +166 -62
- package/dist/components/mini-calendar.js.map +1 -1
- package/dist/components/modal.d.ts +23 -1
- package/dist/components/modal.js +36 -10
- package/dist/components/modal.js.map +1 -1
- package/dist/components/nav-pills.d.ts +66 -0
- package/dist/components/nav-pills.js +65 -0
- package/dist/components/nav-pills.js.map +1 -0
- package/dist/components/number-field.d.ts +6 -0
- package/dist/components/number-input.d.ts +6 -0
- package/dist/components/numpad-sheet.d.ts +6 -0
- package/dist/components/page-contents.js +1 -2
- package/dist/components/page-contents.js.map +1 -1
- package/dist/components/page-header.d.ts +37 -0
- package/dist/components/page-header.js +36 -0
- package/dist/components/page-header.js.map +1 -0
- package/dist/components/progress-bar.d.ts +31 -2
- package/dist/components/progress-bar.js +73 -7
- package/dist/components/progress-bar.js.map +1 -1
- package/dist/components/series-chart-labels.d.ts +3 -0
- package/dist/components/series-chart-labels.js +2 -1
- package/dist/components/series-chart-labels.js.map +1 -1
- package/dist/components/series-chart.d.ts +32 -0
- package/dist/components/series-chart.js +141 -4
- package/dist/components/series-chart.js.map +1 -1
- package/dist/components/settings-fields.d.ts +1 -0
- package/dist/components/status-dot.d.ts +53 -0
- package/dist/components/status-dot.js +57 -0
- package/dist/components/status-dot.js.map +1 -0
- package/dist/components/table.d.ts +78 -13
- package/dist/components/table.js +84 -11
- package/dist/components/table.js.map +1 -1
- package/dist/components/text.d.ts +70 -0
- package/dist/components/text.js +24 -0
- package/dist/components/text.js.map +1 -0
- package/dist/components/time-input.d.ts +1 -0
- package/dist/components/toast.d.ts +167 -0
- package/dist/components/toast.js +226 -0
- package/dist/components/toast.js.map +1 -0
- package/dist/components/toggle-group.d.ts +44 -1
- package/dist/components/toggle-group.js +73 -4
- package/dist/components/toggle-group.js.map +1 -1
- package/dist/components/tooltip.d.ts +46 -15
- package/dist/components/tooltip.js +87 -47
- package/dist/components/tooltip.js.map +1 -1
- package/dist/components/ui.d.ts +158 -7
- package/dist/components/ui.js +191 -10
- package/dist/components/ui.js.map +1 -1
- package/dist/components/user-avatar.d.ts +25 -3
- package/dist/components/user-avatar.js +32 -3
- package/dist/components/user-avatar.js.map +1 -1
- package/dist/hooks/use-close-transition.d.ts +7 -1
- package/dist/hooks/use-close-transition.js +5 -2
- package/dist/hooks/use-close-transition.js.map +1 -1
- package/dist/hooks/use-copy-to-clipboard.js +1 -1
- package/dist/hooks/use-copy-to-clipboard.js.map +1 -1
- package/dist/hooks/use-file-drop.d.ts +1 -0
- package/dist/i18n/defaults.d.ts +6 -0
- package/dist/i18n/defaults.js +11 -1
- package/dist/i18n/defaults.js.map +1 -1
- package/dist/i18n/kit-labels.d.ts +11 -0
- package/dist/i18n/kit-labels.js.map +1 -1
- package/dist/i18n/locales/de-CH-informal.d.ts +6 -0
- package/dist/i18n/locales/de-CH.d.ts +6 -0
- package/dist/i18n/locales/de-informal.d.ts +6 -0
- package/dist/i18n/locales/de.d.ts +6 -0
- package/dist/i18n/locales/de.js +30 -2
- package/dist/i18n/locales/de.js.map +1 -1
- package/dist/i18n/locales/es.d.ts +6 -0
- package/dist/i18n/locales/es.js +30 -2
- package/dist/i18n/locales/es.js.map +1 -1
- package/dist/i18n/locales/fr.d.ts +6 -0
- package/dist/i18n/locales/fr.js +30 -2
- package/dist/i18n/locales/fr.js.map +1 -1
- package/dist/i18n/locales/hu.d.ts +6 -0
- package/dist/i18n/locales/hu.js +30 -2
- package/dist/i18n/locales/hu.js.map +1 -1
- package/dist/i18n/locales/it.d.ts +6 -0
- package/dist/i18n/locales/it.js +30 -2
- package/dist/i18n/locales/it.js.map +1 -1
- package/dist/i18n/locales/zh.d.ts +6 -0
- package/dist/i18n/locales/zh.js +30 -2
- package/dist/i18n/locales/zh.js.map +1 -1
- package/dist/index.d.ts +27 -15
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/clipping.d.ts +25 -0
- package/dist/lib/clipping.js +17 -0
- package/dist/lib/clipping.js.map +1 -0
- package/dist/lib/dates.d.ts +17 -1
- package/dist/lib/dates.js +19 -0
- package/dist/lib/dates.js.map +1 -1
- package/dist/rhf/form.d.ts +1 -0
- package/dist/rhf/use-rhf-wizard-step.d.ts +22 -0
- package/dist/rhf/use-rhf-wizard-step.js +38 -0
- package/dist/rhf/use-rhf-wizard-step.js.map +1 -0
- package/dist/rhf.d.ts +2 -0
- package/dist/rhf.js +1 -0
- package/dist/rhf.js.map +1 -1
- package/dist/search/command-palette.d.ts +19 -2
- package/dist/search/command-palette.js +16 -5
- package/dist/search/command-palette.js.map +1 -1
- package/dist/search/global-search.d.ts +26 -1
- package/dist/search/global-search.js +29 -13
- package/dist/search/global-search.js.map +1 -1
- package/dist/search.d.ts +1 -1
- package/dist/shell/topbar-action-menu.d.ts +73 -3
- package/dist/shell/topbar-action-menu.js +100 -27
- package/dist/shell/topbar-action-menu.js.map +1 -1
- package/dist/shell.d.ts +2 -1
- package/dist/wizard/stepper-nav.d.ts +1 -0
- package/dist/wizard/stepper-nav.js +1 -1
- package/dist/wizard/stepper-nav.js.map +1 -1
- package/dist/wizard/types.d.ts +2 -2
- package/dist/wizard/types.js.map +1 -1
- package/dist/wizard/use-wizard.js +1 -1
- package/dist/wizard/use-wizard.js.map +1 -1
- package/dist/wizard/wizard-context.d.ts +7 -1
- package/dist/wizard/wizard-context.js +4 -0
- package/dist/wizard/wizard-context.js.map +1 -1
- package/dist/wizard/wizard-summary.js +3 -3
- package/dist/wizard/wizard-summary.js.map +1 -1
- package/dist/wizard.d.ts +2 -1
- package/package.json +16 -12
- package/src/components/alert-banner.tsx +149 -21
- package/src/components/breadcrumbs.tsx +168 -0
- package/src/components/bulk-action-bar.tsx +362 -0
- package/src/components/button-group.tsx +124 -4
- package/src/components/calendar-heatmap.tsx +504 -0
- package/src/components/chip.tsx +128 -7
- package/src/components/choice-card.tsx +97 -1
- package/src/components/copy-button.tsx +29 -7
- package/src/components/data-table.tsx +7 -0
- package/src/components/date-picker.tsx +49 -1
- package/src/components/description-list.tsx +168 -15
- package/src/components/dialog-frame.tsx +7 -0
- package/src/components/disclosure.tsx +93 -21
- package/src/components/field.tsx +137 -0
- package/src/components/file-dropzone.tsx +9 -10
- package/src/components/floating-panel.tsx +366 -15
- package/src/components/full-bleed-dialog.tsx +42 -5
- package/src/components/list.tsx +443 -0
- package/src/components/menu-item.tsx +235 -0
- package/src/components/mini-calendar.tsx +245 -54
- package/src/components/modal.tsx +80 -17
- package/src/components/nav-pills.tsx +145 -0
- package/src/components/page-contents.tsx +4 -4
- package/src/components/page-header.tsx +68 -0
- package/src/components/progress-bar.tsx +129 -11
- package/src/components/series-chart-labels.ts +4 -0
- package/src/components/series-chart.tsx +274 -3
- package/src/components/status-dot.tsx +107 -0
- package/src/components/table.tsx +176 -17
- package/src/components/text.tsx +97 -0
- package/src/components/toast.tsx +441 -0
- package/src/components/toggle-group.tsx +128 -4
- package/src/components/tooltip.tsx +200 -100
- package/src/components/ui.tsx +381 -14
- package/src/components/user-avatar.tsx +57 -3
- package/src/hooks/use-close-transition.ts +14 -5
- package/src/hooks/use-copy-to-clipboard.ts +1 -1
- package/src/i18n/defaults.ts +10 -0
- package/src/i18n/kit-labels.tsx +10 -0
- package/src/i18n/locales/de.ts +29 -0
- package/src/i18n/locales/es.ts +29 -0
- package/src/i18n/locales/fr.ts +29 -0
- package/src/i18n/locales/hu.ts +29 -0
- package/src/i18n/locales/it.ts +29 -0
- package/src/i18n/locales/zh.ts +29 -0
- package/src/index.ts +31 -0
- package/src/lib/clipping.ts +34 -0
- package/src/lib/dates.ts +37 -0
- package/src/rhf/use-rhf-wizard-step.ts +113 -0
- package/src/rhf.ts +2 -0
- package/src/search/command-palette.tsx +42 -5
- package/src/search/global-search.tsx +59 -18
- package/src/shell/topbar-action-menu.tsx +239 -49
- package/src/wizard/stepper-nav.tsx +2 -1
- package/src/wizard/types.ts +2 -2
- package/src/wizard/use-wizard.ts +3 -3
- package/src/wizard/wizard-context.tsx +9 -0
- package/src/wizard/wizard-summary.tsx +14 -10
- package/tokens.css +97 -0
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
import { useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
2
|
+
import type { ComponentPropsWithoutRef, CSSProperties, KeyboardEvent, ReactNode } from "react";
|
|
3
|
+
import { X } from "lucide-react";
|
|
4
|
+
|
|
5
|
+
import { cn } from "../lib/cn";
|
|
6
|
+
import { horizontalStep } from "../lib/direction";
|
|
7
|
+
import { useKitLabels } from "../i18n/kit-labels";
|
|
8
|
+
import { useAnnounce } from "../hooks/use-announce";
|
|
9
|
+
import { useMediaQuery } from "../hooks/use-media-query";
|
|
10
|
+
import { OVERLAY_EXIT_MS, prefersReducedMotion } from "../hooks/use-close-transition";
|
|
11
|
+
import { Button, IconButton } from "./ui";
|
|
12
|
+
|
|
13
|
+
export interface BulkActionBarLabels {
|
|
14
|
+
/** The count, shown in the bar, spoken by its live region and used as the toolbar's
|
|
15
|
+
* name: "3 selected". */
|
|
16
|
+
selected: (count: number) => string;
|
|
17
|
+
/** The clear/cancel action's name — the X of the floating bar, the text button of the
|
|
18
|
+
* others. */
|
|
19
|
+
clear: string;
|
|
20
|
+
/** Spoken when the selection empties and the bar goes. */
|
|
21
|
+
cleared: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const DEFAULT_BULK_ACTION_BAR_LABELS: BulkActionBarLabels = {
|
|
25
|
+
selected: (count) => `${count} selected`,
|
|
26
|
+
clear: "Clear selection",
|
|
27
|
+
cleared: "Selection cleared",
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* `floating` — the phone's: fixed above `AppShell`'s bottom nav (`--app-nav-h`) and the
|
|
32
|
+
* home indicator, inset from both sides, a rounded card with a shadow. `sticky` — the
|
|
33
|
+
* desktop's: pinned to the top of its scroll container, over the rows it acts on.
|
|
34
|
+
* `inline` — in the flow, where the caller places it.
|
|
35
|
+
*/
|
|
36
|
+
export type BulkActionBarVariant = "floating" | "sticky" | "inline";
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* A variant per breakpoint, mobile first — `{ base: "floating", md: "sticky" }` is the
|
|
40
|
+
* phone's floating card below 768px and the desktop's sticky bar from there up. The
|
|
41
|
+
* breakpoints are Tailwind's (sm 640, md 768, lg 1024, xl 1280px), the ones the kit's
|
|
42
|
+
* classes already use. keksdose's payees selection bar (payees-selection-bar.tsx)
|
|
43
|
+
* computes exactly this with its own `useMediaQuery("(min-width: 768px)")`; every bar
|
|
44
|
+
* that is a card on a phone and a strip on a desktop would repeat it.
|
|
45
|
+
*
|
|
46
|
+
* Resolved in JS rather than with `md:` classes because the variants differ in more
|
|
47
|
+
* than classes: the floating bar's clear is an icon at the start, the others' a text
|
|
48
|
+
* button at the end, and the floating bar is positioned by inline style.
|
|
49
|
+
*/
|
|
50
|
+
export interface ResponsiveBulkActionBarVariant {
|
|
51
|
+
base: BulkActionBarVariant;
|
|
52
|
+
sm?: BulkActionBarVariant;
|
|
53
|
+
md?: BulkActionBarVariant;
|
|
54
|
+
lg?: BulkActionBarVariant;
|
|
55
|
+
xl?: BulkActionBarVariant;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const BREAKPOINTS = [
|
|
59
|
+
["xl", "(min-width: 1280px)"],
|
|
60
|
+
["lg", "(min-width: 1024px)"],
|
|
61
|
+
["md", "(min-width: 768px)"],
|
|
62
|
+
["sm", "(min-width: 640px)"],
|
|
63
|
+
] as const;
|
|
64
|
+
|
|
65
|
+
/** The variant in force: the widest breakpoint that matches AND names one, else
|
|
66
|
+
* `base`. The four queries are subscribed unconditionally — hooks cannot be skipped —
|
|
67
|
+
* and a plain string variant simply ignores them. Without `matchMedia` (SSR, tests)
|
|
68
|
+
* every query is false, so the bar renders its `base`, the phone's, first. */
|
|
69
|
+
function useResolvedVariant(variant: BulkActionBarVariant | ResponsiveBulkActionBarVariant): BulkActionBarVariant {
|
|
70
|
+
const matches = {
|
|
71
|
+
xl: useMediaQuery(BREAKPOINTS[0][1], false),
|
|
72
|
+
lg: useMediaQuery(BREAKPOINTS[1][1], false),
|
|
73
|
+
md: useMediaQuery(BREAKPOINTS[2][1], false),
|
|
74
|
+
sm: useMediaQuery(BREAKPOINTS[3][1], false),
|
|
75
|
+
};
|
|
76
|
+
if (typeof variant === "string") return variant;
|
|
77
|
+
for (const [key] of BREAKPOINTS) {
|
|
78
|
+
const v = variant[key];
|
|
79
|
+
if (matches[key] && v !== undefined) return v;
|
|
80
|
+
}
|
|
81
|
+
return variant.base;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface BulkActionBarProps extends Omit<ComponentPropsWithoutRef<"div">, "role" | "children"> {
|
|
85
|
+
/** How many items are selected. The bar shows only while this is above zero —
|
|
86
|
+
* unless {@link open} says otherwise. */
|
|
87
|
+
count: number;
|
|
88
|
+
/**
|
|
89
|
+
* Show the bar regardless of `count` — `true` for SELECTION MODE with nothing picked
|
|
90
|
+
* yet, `false` to hide it with rows still selected. Left out, `count > 0` decides, as
|
|
91
|
+
* before.
|
|
92
|
+
*
|
|
93
|
+
* keksdose's invoice lines (invoice-lines-bulk-bar.tsx) enter selection with a
|
|
94
|
+
* "Select" button, and the bar must be there at "0 selected" to hold the way out and
|
|
95
|
+
* a "Select all" (pass it as a child); gated on the count, the bar appeared only at
|
|
96
|
+
* the first tick, and the user who pressed "Select" saw nothing happen. The exit plays
|
|
97
|
+
* when it closes either way, and the count is still announced on every change.
|
|
98
|
+
*/
|
|
99
|
+
open?: boolean;
|
|
100
|
+
/** Clear the selection / leave selection mode. */
|
|
101
|
+
onClear: () => void;
|
|
102
|
+
/** The actions: buttons (`IconButton size="lg"` on a phone, `Button` from md up),
|
|
103
|
+
* in the caller's order. They are the toolbar's arrow-key stops, after the clear. */
|
|
104
|
+
children?: ReactNode;
|
|
105
|
+
/** Default `floating`. See {@link BulkActionBarVariant}; an object picks one per
|
|
106
|
+
* breakpoint, see {@link ResponsiveBulkActionBarVariant}. */
|
|
107
|
+
variant?: BulkActionBarVariant | ResponsiveBulkActionBarVariant;
|
|
108
|
+
/**
|
|
109
|
+
* Content BELOW the toolbar row, inside the same surface — the same floating card or
|
|
110
|
+
* sticky tinted strip — but OUTSIDE the toolbar: its fields keep their own Tab stops
|
|
111
|
+
* and arrow keys, and the toolbar's roving focus never walks into it. keksdose's
|
|
112
|
+
* desktop receipt-line bar (invoice-lines-bulk-bar.tsx) shows its `BulkFields` form —
|
|
113
|
+
* a category picker, an exclude checkbox, Apply — under the count and the clear; a
|
|
114
|
+
* form is not a toolbar's content (`role="toolbar"` promises one arrow-key widget),
|
|
115
|
+
* and set beside the bar it lost the sticky tint and scrolled away from it.
|
|
116
|
+
*
|
|
117
|
+
* On the floating variant the panel scrolls within 60% of the viewport's height, so a
|
|
118
|
+
* long form on a phone cannot push the bar off the top of the screen.
|
|
119
|
+
*/
|
|
120
|
+
panel?: ReactNode;
|
|
121
|
+
/** Default: `bulkActionBar` from the {@link UiKitProvider}, else English. */
|
|
122
|
+
labels?: Partial<BulkActionBarLabels>;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** Where the floating bar sits: clear of the phone nav and of the home indicator,
|
|
126
|
+
* whichever reaches higher — `FloatingPanel`'s rule, plus the bar's own 0.5rem gap.
|
|
127
|
+
* Set as inline style, so reposition it through `style` (which is merged over this,
|
|
128
|
+
* e.g. `style={{ insetInline: "auto 2rem", width: "24rem" }}`), not `className`. */
|
|
129
|
+
const FLOATING_STYLE: CSSProperties = {
|
|
130
|
+
bottom: "calc(max(var(--app-nav-h, 0px), env(safe-area-inset-bottom, 0px)) + 0.5rem)",
|
|
131
|
+
// Both insets on both sides: a logical side has no one physical inset to name, and
|
|
132
|
+
// the bar is symmetric, so RTL needs nothing more.
|
|
133
|
+
insetInline: "max(0.5rem, env(safe-area-inset-left, 0px), env(safe-area-inset-right, 0px))",
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
/** What the arrow keys walk: the toolbar's enabled controls. Matched by element, not by
|
|
137
|
+
* `tabindex`, because the roving below sets every one but the current to `-1` — a
|
|
138
|
+
* custom control joins with `data-toolbar-item`. */
|
|
139
|
+
const ITEMS =
|
|
140
|
+
"button:not([disabled]),a[href],input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[data-toolbar-item]";
|
|
141
|
+
|
|
142
|
+
/** Keys a text field needs for itself — the toolbar must not take its caret away. */
|
|
143
|
+
function ownsArrows(el: Element): boolean {
|
|
144
|
+
if (el instanceof HTMLTextAreaElement || el instanceof HTMLSelectElement) return true;
|
|
145
|
+
if (el instanceof HTMLInputElement) return !["button", "checkbox", "radio", "submit", "reset"].includes(el.type);
|
|
146
|
+
return (el as HTMLElement).isContentEditable;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* The bar that appears while rows are selected: the count, a way out, and what can be
|
|
151
|
+
* done to all of them at once.
|
|
152
|
+
*
|
|
153
|
+
* keksdose had written it three times — the transactions phone bar
|
|
154
|
+
* (mobile-bulk-bar.tsx), the invoice lines' phone and desktop bars
|
|
155
|
+
* (invoice-lines-bulk-bar.tsx) and the payees selection bar — and the copies had
|
|
156
|
+
* drifted where it matters: two parked themselves with a guessed `bottom-16` that the
|
|
157
|
+
* third had already found leaves a 24px gap (live #314: the nav is content-sized and
|
|
158
|
+
* `AppShell` publishes its height as `--app-nav-h`), none of them announced the count,
|
|
159
|
+
* and all three were `role="toolbar"` without the arrow keys that role promises.
|
|
160
|
+
*
|
|
161
|
+
* ## Keep it mounted
|
|
162
|
+
*
|
|
163
|
+
* Render it unconditionally and let `count` decide. At zero it renders only its live
|
|
164
|
+
* region — which must already be in the DOM for the first "3 selected" to be heard —
|
|
165
|
+
* and when the count drops to zero it plays its exit before it goes, which a
|
|
166
|
+
* `{count > 0 && <Bar/>}` gate would cut off.
|
|
167
|
+
*
|
|
168
|
+
* ## The toolbar
|
|
169
|
+
*
|
|
170
|
+
* One Tab stop: ←/→ (mirrored in RTL), Home and End move between the controls, and Tab
|
|
171
|
+
* leaves — the WAI-ARIA toolbar pattern, since that is what `role="toolbar"` tells a
|
|
172
|
+
* screen reader to expect. The stop remembers the control last used. Arrow keys inside
|
|
173
|
+
* a text field stay the field's.
|
|
174
|
+
*
|
|
175
|
+
* It is NOT a dialog: no focus trap, no scroll lock — the list behind stays live,
|
|
176
|
+
* because tapping more rows is how a selection grows.
|
|
177
|
+
*/
|
|
178
|
+
export function BulkActionBar({
|
|
179
|
+
count,
|
|
180
|
+
onClear,
|
|
181
|
+
children,
|
|
182
|
+
variant: variantProp = "floating",
|
|
183
|
+
open,
|
|
184
|
+
panel,
|
|
185
|
+
labels: labelsProp,
|
|
186
|
+
className,
|
|
187
|
+
style,
|
|
188
|
+
onKeyDown,
|
|
189
|
+
onFocus,
|
|
190
|
+
...rest
|
|
191
|
+
}: BulkActionBarProps) {
|
|
192
|
+
const labels = useKitLabels("bulkActionBar", DEFAULT_BULK_ACTION_BAR_LABELS, labelsProp);
|
|
193
|
+
const { announce, regionProps } = useAnnounce();
|
|
194
|
+
const barRef = useRef<HTMLDivElement>(null);
|
|
195
|
+
const variant = useResolvedVariant(variantProp);
|
|
196
|
+
const shown = open ?? count > 0;
|
|
197
|
+
|
|
198
|
+
// The count the bar last SHOWED, so a bar lowering itself after "clear" still reads
|
|
199
|
+
// "3 selected" on its way out rather than "0 selected". Adjusted during render
|
|
200
|
+
// (`Collapse`'s pattern), as is the exit below.
|
|
201
|
+
const [shownCount, setShownCount] = useState(count);
|
|
202
|
+
const [leaving, setLeaving] = useState(false);
|
|
203
|
+
const [prev, setPrev] = useState({ count, shown });
|
|
204
|
+
if (count !== prev.count || shown !== prev.shown) {
|
|
205
|
+
setPrev({ count, shown });
|
|
206
|
+
if (shown) {
|
|
207
|
+
setShownCount(count);
|
|
208
|
+
setLeaving(false);
|
|
209
|
+
} else if (prev.shown) {
|
|
210
|
+
setLeaving(!prefersReducedMotion());
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
useEffect(() => {
|
|
214
|
+
if (!leaving) return;
|
|
215
|
+
const timer = setTimeout(() => setLeaving(false), OVERLAY_EXIT_MS);
|
|
216
|
+
return () => clearTimeout(timer);
|
|
217
|
+
}, [leaving]);
|
|
218
|
+
|
|
219
|
+
// Spoken on every CHANGE, not on mount: a bar mounted with rows already selected
|
|
220
|
+
// was not the result of anything the user just did.
|
|
221
|
+
const spoken = useRef(count);
|
|
222
|
+
useEffect(() => {
|
|
223
|
+
if (spoken.current === count) return;
|
|
224
|
+
spoken.current = count;
|
|
225
|
+
// In selection mode the bar stays at zero, so zero is a count like any other.
|
|
226
|
+
announce(count > 0 || shown ? labels.selected(count) : labels.cleared);
|
|
227
|
+
}, [count, shown, labels, announce]);
|
|
228
|
+
|
|
229
|
+
// Roving tab stop. The controls are the caller's, so the stop is kept on the DOM
|
|
230
|
+
// rather than through props: after every render the remembered control (or the
|
|
231
|
+
// first) is the one with `tabindex=0`, every other one `-1`.
|
|
232
|
+
const active = useRef<HTMLElement | null>(null);
|
|
233
|
+
// Every render: the caller's controls come and go (a "remove added" that exists
|
|
234
|
+
// only while some are removable), and a stop on a control that left must move on.
|
|
235
|
+
useLayoutEffect(() => {
|
|
236
|
+
rove(barRef.current, active);
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
const handleKeyDown = (e: KeyboardEvent<HTMLDivElement>) => {
|
|
240
|
+
onKeyDown?.(e);
|
|
241
|
+
if (e.defaultPrevented || ownsArrows(e.target as Element)) return;
|
|
242
|
+
const list = itemsOf(barRef.current);
|
|
243
|
+
const at = list.indexOf(document.activeElement as HTMLElement);
|
|
244
|
+
if (at === -1 || list.length === 0) return;
|
|
245
|
+
const step = horizontalStep(e.key, barRef.current);
|
|
246
|
+
let next = -1;
|
|
247
|
+
if (step !== 0) next = (at + step + list.length) % list.length;
|
|
248
|
+
else if (e.key === "Home") next = 0;
|
|
249
|
+
else if (e.key === "End") next = list.length - 1;
|
|
250
|
+
if (next === -1) return;
|
|
251
|
+
e.preventDefault();
|
|
252
|
+
active.current = list[next];
|
|
253
|
+
rove(barRef.current, active);
|
|
254
|
+
list[next].focus();
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
if (!shown && !leaving) {
|
|
258
|
+
return <span {...regionProps} />;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
const floating = variant === "floating";
|
|
262
|
+
const clear = floating ? (
|
|
263
|
+
<IconButton size="lg" onClick={onClear} aria-label={labels.clear}>
|
|
264
|
+
<X />
|
|
265
|
+
</IconButton>
|
|
266
|
+
) : (
|
|
267
|
+
<Button type="button" variant="secondary" size="sm" onClick={onClear}>
|
|
268
|
+
{labels.clear}
|
|
269
|
+
</Button>
|
|
270
|
+
);
|
|
271
|
+
|
|
272
|
+
const hasPanel = panel !== undefined && panel !== null && panel !== false;
|
|
273
|
+
// The surface — where the bar sits and what it looks like — and the toolbar row's
|
|
274
|
+
// own layout. Without a panel they are one element, exactly as before 0.11.0; with
|
|
275
|
+
// one the surface wraps the row and the panel, so both share its tint and position.
|
|
276
|
+
const surfaceClass = floating
|
|
277
|
+
? cn(
|
|
278
|
+
"fixed z-30 rounded-2xl border border-[var(--border)] bg-[var(--bg-surface)] shadow-lg",
|
|
279
|
+
shown ? "animate-sheet" : "animate-sheet-out",
|
|
280
|
+
)
|
|
281
|
+
: cn(
|
|
282
|
+
variant === "sticky" &&
|
|
283
|
+
"sticky top-0 z-20 border-b border-[var(--border)] bg-[color-mix(in_srgb,var(--brand)_8%,var(--bg-surface))] backdrop-blur",
|
|
284
|
+
shown ? "animate-overlay" : "animate-overlay-out",
|
|
285
|
+
);
|
|
286
|
+
const rowClass = cn("flex items-center", floating ? "gap-1 px-2 py-1" : "gap-2 px-3 py-2");
|
|
287
|
+
const surfaceStyle = floating ? { ...FLOATING_STYLE, ...style } : style;
|
|
288
|
+
|
|
289
|
+
const toolbar = (
|
|
290
|
+
<div
|
|
291
|
+
{...(hasPanel ? null : rest)}
|
|
292
|
+
ref={barRef}
|
|
293
|
+
role="toolbar"
|
|
294
|
+
aria-label={labels.selected(shownCount)}
|
|
295
|
+
aria-orientation="horizontal"
|
|
296
|
+
data-bulk-action-bar={hasPanel ? undefined : variant}
|
|
297
|
+
// Leaving: out of the tab order and the accessibility tree at once, while the
|
|
298
|
+
// bar still animates. The selection it acted on is already gone.
|
|
299
|
+
inert={(!hasPanel && !shown) || undefined}
|
|
300
|
+
onKeyDown={handleKeyDown}
|
|
301
|
+
onFocus={(e) => {
|
|
302
|
+
onFocus?.(e);
|
|
303
|
+
// Clicking a control is using it: the stop follows the pointer too.
|
|
304
|
+
const hit = itemsOf(barRef.current).find((el) => el === e.target);
|
|
305
|
+
if (hit) {
|
|
306
|
+
active.current = hit;
|
|
307
|
+
rove(barRef.current, active);
|
|
308
|
+
}
|
|
309
|
+
}}
|
|
310
|
+
style={hasPanel ? undefined : surfaceStyle}
|
|
311
|
+
className={hasPanel ? rowClass : cn(rowClass, surfaceClass, className)}
|
|
312
|
+
>
|
|
313
|
+
{floating && clear}
|
|
314
|
+
<span className="min-w-0 flex-1 truncate text-sm font-medium text-[var(--text-primary)]">
|
|
315
|
+
{labels.selected(shownCount)}
|
|
316
|
+
</span>
|
|
317
|
+
{/* `contents`, so the caller's controls are flex items of the bar itself. */}
|
|
318
|
+
<div className="contents">{children}</div>
|
|
319
|
+
{!floating && clear}
|
|
320
|
+
</div>
|
|
321
|
+
);
|
|
322
|
+
|
|
323
|
+
return (
|
|
324
|
+
<>
|
|
325
|
+
<span {...regionProps} />
|
|
326
|
+
{hasPanel ? (
|
|
327
|
+
<div
|
|
328
|
+
{...rest}
|
|
329
|
+
data-bulk-action-bar={variant}
|
|
330
|
+
inert={!shown || undefined}
|
|
331
|
+
style={surfaceStyle}
|
|
332
|
+
className={cn("flex flex-col", surfaceClass, className)}
|
|
333
|
+
>
|
|
334
|
+
{toolbar}
|
|
335
|
+
<div
|
|
336
|
+
data-bulk-action-bar-panel=""
|
|
337
|
+
className={cn(
|
|
338
|
+
"border-t border-[var(--border)] px-3 py-3",
|
|
339
|
+
floating && "max-h-[60dvh] overflow-y-auto",
|
|
340
|
+
)}
|
|
341
|
+
>
|
|
342
|
+
{panel}
|
|
343
|
+
</div>
|
|
344
|
+
</div>
|
|
345
|
+
) : (
|
|
346
|
+
toolbar
|
|
347
|
+
)}
|
|
348
|
+
</>
|
|
349
|
+
);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
function itemsOf(bar: HTMLElement | null): HTMLElement[] {
|
|
353
|
+
return bar ? Array.from(bar.querySelectorAll<HTMLElement>(ITEMS)) : [];
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/** Put the one Tab stop on the remembered control — or the first, when that one has
|
|
357
|
+
* gone or was never set — and take it off every other. */
|
|
358
|
+
function rove(bar: HTMLElement | null, active: { current: HTMLElement | null }): void {
|
|
359
|
+
const list = itemsOf(bar);
|
|
360
|
+
if (!active.current || !list.includes(active.current)) active.current = list[0] ?? null;
|
|
361
|
+
for (const el of list) el.tabIndex = el === active.current ? 0 : -1;
|
|
362
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { ComponentPropsWithoutRef } from "react";
|
|
1
|
+
import type { ComponentPropsWithoutRef, MouseEvent, ReactElement, ReactNode, Ref } from "react";
|
|
2
2
|
import { cn } from "../lib/cn";
|
|
3
|
+
import { buttonClasses, type ButtonSize, type ButtonVariant } from "./ui";
|
|
3
4
|
|
|
4
5
|
// Every class below is spelled out in full rather than assembled from parts: the
|
|
5
6
|
// consumer's Tailwind build finds classes by scanning this package's source as text,
|
|
@@ -8,12 +9,15 @@ import { cn } from "../lib/cn";
|
|
|
8
9
|
// Each rule is written twice, once for a direct child and once for a `<button>` one
|
|
9
10
|
// level down. The second is for a Tooltip-wrapped IconButton — the map zoom's + and −
|
|
10
11
|
// both carry a tooltip — where the direct child is the tooltip's wrapper span and the
|
|
11
|
-
// button that draws the border and the corners sits inside it.
|
|
12
|
+
// button that draws the border and the corners sits inside it. The same again for an
|
|
13
|
+
// `<a>` one level down: a router link member (see {@link ButtonGroupLink}) under a
|
|
14
|
+
// tooltip. A bare link is a direct child and needs nothing extra.
|
|
12
15
|
const JOINED_COMMON = cn(
|
|
13
16
|
"inline-flex rounded-md border border-[var(--border)]",
|
|
14
17
|
// The group draws the frame; each member gives up its own border, radius and shadow.
|
|
15
18
|
"[&>*]:rounded-none [&>*]:border-0 [&>*]:shadow-none",
|
|
16
19
|
"[&>*>button]:rounded-none [&>*>button]:border-0 [&>*>button]:shadow-none",
|
|
20
|
+
"[&>*>a]:rounded-none [&>*>a]:border-0 [&>*>a]:shadow-none",
|
|
17
21
|
"[&>*]:border-[var(--border)]",
|
|
18
22
|
// A focused member rises above its neighbours so its ring is not painted over by
|
|
19
23
|
// the next one's background.
|
|
@@ -30,6 +34,7 @@ const JOINED: Record<"horizontal" | "vertical", string> = {
|
|
|
30
34
|
"[&>*:not(:first-child)]:border-s",
|
|
31
35
|
"[&>:first-child]:rounded-s-md [&>:last-child]:rounded-e-md",
|
|
32
36
|
"[&>:first-child>button]:rounded-s-md [&>:last-child>button]:rounded-e-md",
|
|
37
|
+
"[&>:first-child>a]:rounded-s-md [&>:last-child>a]:rounded-e-md",
|
|
33
38
|
),
|
|
34
39
|
// The block axis is top-to-bottom in both reading directions, so top/bottom are
|
|
35
40
|
// already the logical edges here.
|
|
@@ -39,13 +44,47 @@ const JOINED: Record<"horizontal" | "vertical", string> = {
|
|
|
39
44
|
"[&>*:not(:first-child)]:border-t",
|
|
40
45
|
"[&>:first-child]:rounded-t-md [&>:last-child]:rounded-b-md",
|
|
41
46
|
"[&>:first-child>button]:rounded-t-md [&>:last-child>button]:rounded-b-md",
|
|
47
|
+
"[&>:first-child>a]:rounded-t-md [&>:last-child>a]:rounded-b-md",
|
|
42
48
|
),
|
|
43
49
|
};
|
|
44
50
|
|
|
51
|
+
// `gapped`: the members keep their own shape — round overlay discs, each its own
|
|
52
|
+
// border and radius — and sit apart. Nothing is stripped, so there is nothing to
|
|
53
|
+
// restore per edge, and the gap is logical by nature.
|
|
54
|
+
const GAPPED: Record<"horizontal" | "vertical", string> = {
|
|
55
|
+
horizontal: "inline-flex flex-row items-center gap-1",
|
|
56
|
+
vertical: "inline-flex flex-col items-center gap-1",
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
// `elevated`, joined: the frame itself floats — a filled surface under the members (a
|
|
60
|
+
// ghost member would otherwise show the content through it) and the shadow of a
|
|
61
|
+
// control lifted over the page.
|
|
62
|
+
const ELEVATED_JOINED = "bg-[var(--bg-surface)] shadow-lg";
|
|
63
|
+
// `elevated`, gapped: there is no frame, so each disc carries the shadow. Aimed at the
|
|
64
|
+
// control, not the tooltip's square wrapper span, whose shadow would be a box round a
|
|
65
|
+
// round disc.
|
|
66
|
+
const ELEVATED_GAPPED =
|
|
67
|
+
"[&>button]:shadow-md [&>a]:shadow-md [&>*>button]:shadow-md [&>*>a]:shadow-md";
|
|
68
|
+
|
|
45
69
|
export interface ButtonGroupProps extends Omit<ComponentPropsWithoutRef<"div">, "role"> {
|
|
46
70
|
/** `horizontal` (default): side by side, in reading order. `vertical`: stacked —
|
|
47
71
|
* the map's zoom + over −. */
|
|
48
72
|
orientation?: "horizontal" | "vertical";
|
|
73
|
+
/**
|
|
74
|
+
* `joined` (default): one frame, hairline dividers, outer corners rounded. `gapped`:
|
|
75
|
+
* separate controls with a small gap, each keeping its own shape — the overlay
|
|
76
|
+
* discs of keksdose's receipt preview zoom (scan-file-preview.tsx:362, the − and +
|
|
77
|
+
* `IconButton variant="overlay"` in a hand-made `flex gap-1`), where a joined frame
|
|
78
|
+
* would be a box drawn over the photo.
|
|
79
|
+
*/
|
|
80
|
+
variant?: "joined" | "gapped";
|
|
81
|
+
/**
|
|
82
|
+
* Float it: a surface with a shadow, for a toolbar that sits OVER content (a map's
|
|
83
|
+
* zoom, a photo's controls) rather than in the page's flow — keksdose adds
|
|
84
|
+
* `shadow-sm` to each disc on the receipt preview by hand. On a joined group the
|
|
85
|
+
* frame is filled and shadowed; on a gapped one, each member.
|
|
86
|
+
*/
|
|
87
|
+
elevated?: boolean;
|
|
49
88
|
}
|
|
50
89
|
|
|
51
90
|
/**
|
|
@@ -63,13 +102,94 @@ export interface ButtonGroupProps extends Omit<ComponentPropsWithoutRef<"div">,
|
|
|
63
102
|
* roving, and every member keeps its own tab stop, as plain adjacent buttons do.
|
|
64
103
|
* For one-of-many selection use `ToggleGroup`, which has the radio semantics.
|
|
65
104
|
*/
|
|
66
|
-
export function ButtonGroup({
|
|
105
|
+
export function ButtonGroup({
|
|
106
|
+
orientation = "horizontal",
|
|
107
|
+
variant = "joined",
|
|
108
|
+
elevated = false,
|
|
109
|
+
className,
|
|
110
|
+
...rest
|
|
111
|
+
}: ButtonGroupProps) {
|
|
112
|
+
const joined = variant === "joined";
|
|
67
113
|
return (
|
|
68
114
|
<div
|
|
69
115
|
{...rest}
|
|
70
116
|
role="group"
|
|
71
117
|
data-orientation={orientation}
|
|
72
|
-
|
|
118
|
+
data-variant={variant}
|
|
119
|
+
className={cn(
|
|
120
|
+
joined ? JOINED[orientation] : GAPPED[orientation],
|
|
121
|
+
elevated && (joined ? ELEVATED_JOINED : ELEVATED_GAPPED),
|
|
122
|
+
className,
|
|
123
|
+
)}
|
|
73
124
|
/>
|
|
74
125
|
);
|
|
75
126
|
}
|
|
127
|
+
|
|
128
|
+
/** What {@link ButtonGroupLinkProps.renderLink} is handed. Spread it onto your router's
|
|
129
|
+
* link, mapping `href` — `renderLink={({ href, ...p }) => <Link to={href} {...p} />}`. */
|
|
130
|
+
export interface ButtonGroupLinkRenderProps {
|
|
131
|
+
href: string;
|
|
132
|
+
/** The button look — keep it, or the member is a bare link in the frame. */
|
|
133
|
+
className: string;
|
|
134
|
+
children: ReactNode;
|
|
135
|
+
ref?: Ref<HTMLAnchorElement>;
|
|
136
|
+
"aria-current"?: "page";
|
|
137
|
+
onClick?: (event: MouseEvent<HTMLAnchorElement>) => void;
|
|
138
|
+
[key: `aria-${string}`]: string | boolean | number | undefined;
|
|
139
|
+
[key: `data-${string}`]: unknown;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export interface ButtonGroupLinkProps extends Omit<ComponentPropsWithoutRef<"a">, "href" | "className" | "children"> {
|
|
143
|
+
href: string;
|
|
144
|
+
/** The {@link Button} variant it looks like. Default `secondary`, the usual member. */
|
|
145
|
+
variant?: ButtonVariant;
|
|
146
|
+
size?: ButtonSize;
|
|
147
|
+
/** The member for the page you are on: `aria-current="page"` and the "on" look of a
|
|
148
|
+
* pressed member, so a link row reads as a segmented switch between pages. */
|
|
149
|
+
current?: boolean;
|
|
150
|
+
/** Render through your router's `Link` — see {@link ButtonGroupLinkRenderProps}. */
|
|
151
|
+
renderLink?: (props: ButtonGroupLinkRenderProps) => ReactElement;
|
|
152
|
+
className?: string;
|
|
153
|
+
children: ReactNode;
|
|
154
|
+
ref?: Ref<HTMLAnchorElement>;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const LINK_CURRENT = "bg-[var(--brand-bg)] text-[var(--brand)] hover:bg-[var(--brand-bg-hover)]";
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* A {@link ButtonGroup} member that navigates: a link drawn as a {@link Button}, so it
|
|
161
|
+
* joins the frame like one. A group mixing actions and pages — "Export" beside "Open
|
|
162
|
+
* report" — had to either make the page a button with an `onClick` navigate (no
|
|
163
|
+
* middle-click, no "open in new tab", no link semantics) or style an `<a>` whose
|
|
164
|
+
* corners the group did not know about. Plain `<a>` by default; `renderLink` for the
|
|
165
|
+
* router's `Link`, the kit's usual shape (`Chip`, `MenuItem`, `StatTile`).
|
|
166
|
+
*/
|
|
167
|
+
export function ButtonGroupLink({
|
|
168
|
+
href,
|
|
169
|
+
variant = "secondary",
|
|
170
|
+
size,
|
|
171
|
+
current = false,
|
|
172
|
+
renderLink,
|
|
173
|
+
className,
|
|
174
|
+
children,
|
|
175
|
+
...rest
|
|
176
|
+
}: ButtonGroupLinkProps) {
|
|
177
|
+
const props: ButtonGroupLinkRenderProps = {
|
|
178
|
+
...rest,
|
|
179
|
+
href,
|
|
180
|
+
"aria-current": current ? "page" : undefined,
|
|
181
|
+
className: buttonClasses(variant, { size, className: cn(current && LINK_CURRENT, className) }),
|
|
182
|
+
children,
|
|
183
|
+
};
|
|
184
|
+
if (renderLink) return <RenderedGroupLink render={renderLink} {...props} />;
|
|
185
|
+
const { children: content, ...anchor } = props;
|
|
186
|
+
return <a {...anchor}>{content}</a>;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** Calls `renderLink` as a component, so the router link's hooks are its own. */
|
|
190
|
+
function RenderedGroupLink({
|
|
191
|
+
render,
|
|
192
|
+
...props
|
|
193
|
+
}: ButtonGroupLinkRenderProps & { render: (props: ButtonGroupLinkRenderProps) => ReactElement }) {
|
|
194
|
+
return render(props);
|
|
195
|
+
}
|