@underpin/ui 0.0.0 → 2.1.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/LICENSE +21 -0
- package/README.md +44 -1
- package/components/autocomplete.d.ts +25 -0
- package/components/autocomplete.js +71 -0
- package/components/autocomplete.js.map +1 -0
- package/components/avatar.d.ts +5 -0
- package/components/avatar.js +26 -0
- package/components/avatar.js.map +1 -0
- package/components/badge.d.ts +36 -0
- package/components/badge.js +140 -0
- package/components/badge.js.map +1 -0
- package/components/bar-list.d.ts +133 -0
- package/components/bar-list.js +204 -0
- package/components/bar-list.js.map +1 -0
- package/components/breakdown-card.d.ts +30 -0
- package/components/breakdown-card.js +43 -0
- package/components/breakdown-card.js.map +1 -0
- package/components/bulk-action-bar.d.ts +21 -0
- package/components/bulk-action-bar.js +38 -0
- package/components/bulk-action-bar.js.map +1 -0
- package/components/button-group.d.ts +21 -0
- package/components/button-group.js +32 -0
- package/components/button-group.js.map +1 -0
- package/components/button.d.ts +39 -0
- package/components/button.js +145 -0
- package/components/button.js.map +1 -0
- package/components/calendar.d.ts +27 -0
- package/components/calendar.js +95 -0
- package/components/calendar.js.map +1 -0
- package/components/callout.d.ts +26 -0
- package/components/callout.js +71 -0
- package/components/callout.js.map +1 -0
- package/components/card.d.ts +55 -0
- package/components/card.js +96 -0
- package/components/card.js.map +1 -0
- package/components/chart.d.ts +32 -0
- package/components/chart.js +43 -0
- package/components/chart.js.map +1 -0
- package/components/checkbox.d.ts +15 -0
- package/components/checkbox.js +42 -0
- package/components/checkbox.js.map +1 -0
- package/components/code-block.d.ts +21 -0
- package/components/code-block.js +35 -0
- package/components/code-block.js.map +1 -0
- package/components/collapse.d.ts +14 -0
- package/components/collapse.js +25 -0
- package/components/collapse.js.map +1 -0
- package/components/combobox.d.ts +71 -0
- package/components/combobox.js +155 -0
- package/components/combobox.js.map +1 -0
- package/components/copy-button.d.ts +29 -0
- package/components/copy-button.js +100 -0
- package/components/copy-button.js.map +1 -0
- package/components/copy-input.d.ts +15 -0
- package/components/copy-input.js +51 -0
- package/components/copy-input.js.map +1 -0
- package/components/data-table.d.ts +120 -0
- package/components/data-table.js +336 -0
- package/components/data-table.js.map +1 -0
- package/components/date-picker-trigger.d.ts +12 -0
- package/components/date-picker-trigger.js +30 -0
- package/components/date-picker-trigger.js.map +1 -0
- package/components/date-picker.d.ts +36 -0
- package/components/date-picker.js +70 -0
- package/components/date-picker.js.map +1 -0
- package/components/detail-row.d.ts +51 -0
- package/components/detail-row.js +77 -0
- package/components/detail-row.js.map +1 -0
- package/components/dialog.d.ts +121 -0
- package/components/dialog.js +327 -0
- package/components/dialog.js.map +1 -0
- package/components/disabled-reason.d.ts +31 -0
- package/components/disabled-reason.js +67 -0
- package/components/disabled-reason.js.map +1 -0
- package/components/empty-state.d.ts +41 -0
- package/components/empty-state.js +84 -0
- package/components/empty-state.js.map +1 -0
- package/components/entity-avatar.d.ts +54 -0
- package/components/entity-avatar.js +68 -0
- package/components/entity-avatar.js.map +1 -0
- package/components/form-section.d.ts +22 -0
- package/components/form-section.js +38 -0
- package/components/form-section.js.map +1 -0
- package/components/form.d.ts +199 -0
- package/components/form.js +456 -0
- package/components/form.js.map +1 -0
- package/components/formatted-number.d.ts +21 -0
- package/components/formatted-number.js +13 -0
- package/components/formatted-number.js.map +1 -0
- package/components/heading.d.ts +23 -0
- package/components/heading.js +44 -0
- package/components/heading.js.map +1 -0
- package/components/icon-swap.d.ts +15 -0
- package/components/icon-swap.js +29 -0
- package/components/icon-swap.js.map +1 -0
- package/components/inline-action.d.ts +21 -0
- package/components/inline-action.js +36 -0
- package/components/inline-action.js.map +1 -0
- package/components/input.d.ts +51 -0
- package/components/input.js +52 -0
- package/components/input.js.map +1 -0
- package/components/kbd.d.ts +17 -0
- package/components/kbd.js +34 -0
- package/components/kbd.js.map +1 -0
- package/components/label.d.ts +10 -0
- package/components/label.js +20 -0
- package/components/label.js.map +1 -0
- package/components/menu.d.ts +77 -0
- package/components/menu.js +189 -0
- package/components/menu.js.map +1 -0
- package/components/nav-button.d.ts +34 -0
- package/components/nav-button.js +71 -0
- package/components/nav-button.js.map +1 -0
- package/components/nav.d.ts +39 -0
- package/components/nav.js +68 -0
- package/components/nav.js.map +1 -0
- package/components/number-input.d.ts +16 -0
- package/components/number-input.js +25 -0
- package/components/number-input.js.map +1 -0
- package/components/page.d.ts +14 -0
- package/components/page.js +23 -0
- package/components/page.js.map +1 -0
- package/components/pagination.d.ts +73 -0
- package/components/pagination.js +212 -0
- package/components/pagination.js.map +1 -0
- package/components/ping.d.ts +38 -0
- package/components/ping.js +50 -0
- package/components/ping.js.map +1 -0
- package/components/popover.d.ts +5 -0
- package/components/popover.js +25 -0
- package/components/popover.js.map +1 -0
- package/components/radio-group.d.ts +35 -0
- package/components/radio-group.js +81 -0
- package/components/radio-group.js.map +1 -0
- package/components/relative-time.d.ts +25 -0
- package/components/relative-time.js +51 -0
- package/components/relative-time.js.map +1 -0
- package/components/saved-mark.d.ts +15 -0
- package/components/saved-mark.js +45 -0
- package/components/saved-mark.js.map +1 -0
- package/components/search-input.d.ts +13 -0
- package/components/search-input.js +44 -0
- package/components/search-input.js.map +1 -0
- package/components/section-header.d.ts +83 -0
- package/components/section-header.js +170 -0
- package/components/section-header.js.map +1 -0
- package/components/segmented-control.d.ts +24 -0
- package/components/segmented-control.js +70 -0
- package/components/segmented-control.js.map +1 -0
- package/components/select.d.ts +28 -0
- package/components/select.js +129 -0
- package/components/select.js.map +1 -0
- package/components/shortcut-keys.d.ts +14 -0
- package/components/shortcut-keys.js +32 -0
- package/components/shortcut-keys.js.map +1 -0
- package/components/shortcuts-dialog.d.ts +10 -0
- package/components/shortcuts-dialog.js +92 -0
- package/components/shortcuts-dialog.js.map +1 -0
- package/components/skeleton.d.ts +8 -0
- package/components/skeleton.js +23 -0
- package/components/skeleton.js.map +1 -0
- package/components/sparkline.d.ts +25 -0
- package/components/sparkline.js +70 -0
- package/components/sparkline.js.map +1 -0
- package/components/stack.d.ts +21 -0
- package/components/stack.js +45 -0
- package/components/stack.js.map +1 -0
- package/components/stat-strip.d.ts +43 -0
- package/components/stat-strip.js +151 -0
- package/components/stat-strip.js.map +1 -0
- package/components/steps.d.ts +19 -0
- package/components/steps.js +25 -0
- package/components/steps.js.map +1 -0
- package/components/switch.d.ts +16 -0
- package/components/switch.js +29 -0
- package/components/switch.js.map +1 -0
- package/components/table-toolbar.d.ts +55 -0
- package/components/table-toolbar.js +119 -0
- package/components/table-toolbar.js.map +1 -0
- package/components/table.d.ts +276 -0
- package/components/table.js +572 -0
- package/components/table.js.map +1 -0
- package/components/tabs.d.ts +36 -0
- package/components/tabs.js +120 -0
- package/components/tabs.js.map +1 -0
- package/components/text-link.d.ts +16 -0
- package/components/text-link.js +32 -0
- package/components/text-link.js.map +1 -0
- package/components/textarea.d.ts +10 -0
- package/components/textarea.js +23 -0
- package/components/textarea.js.map +1 -0
- package/components/theme.d.ts +28 -0
- package/components/theme.js +158 -0
- package/components/theme.js.map +1 -0
- package/components/time-series-chart.d.ts +122 -0
- package/components/time-series-chart.js +722 -0
- package/components/time-series-chart.js.map +1 -0
- package/components/toaster.d.ts +3 -0
- package/components/toaster.js +44 -0
- package/components/toaster.js.map +1 -0
- package/components/tooltip.d.ts +64 -0
- package/components/tooltip.js +126 -0
- package/components/tooltip.js.map +1 -0
- package/components/view-picker.d.ts +20 -0
- package/components/view-picker.js +24 -0
- package/components/view-picker.js.map +1 -0
- package/fonts/inter-OFL.txt +93 -0
- package/fonts/inter-cyrillic-ext.woff2 +0 -0
- package/fonts/inter-cyrillic.woff2 +0 -0
- package/fonts/inter-greek-ext.woff2 +0 -0
- package/fonts/inter-greek.woff2 +0 -0
- package/fonts/inter-latin-ext.woff2 +0 -0
- package/fonts/inter-latin.woff2 +0 -0
- package/fonts/inter-vietnamese.woff2 +0 -0
- package/fonts.css +83 -0
- package/lib/animation.d.ts +14 -0
- package/lib/animation.js +20 -0
- package/lib/animation.js.map +1 -0
- package/lib/aria.d.ts +5 -0
- package/lib/aria.js +12 -0
- package/lib/aria.js.map +1 -0
- package/lib/chart-curve.d.ts +13 -0
- package/lib/chart-curve.js +79 -0
- package/lib/chart-curve.js.map +1 -0
- package/lib/classes.d.ts +134 -0
- package/lib/classes.js +152 -0
- package/lib/classes.js.map +1 -0
- package/lib/color.d.ts +25 -0
- package/lib/color.js +149 -0
- package/lib/color.js.map +1 -0
- package/lib/data-table-state.d.ts +87 -0
- package/lib/data-table-state.js +92 -0
- package/lib/data-table-state.js.map +1 -0
- package/lib/day.d.ts +9 -0
- package/lib/day.js +20 -0
- package/lib/day.js.map +1 -0
- package/lib/design-tokens.d.ts +56 -0
- package/lib/design-tokens.js +196 -0
- package/lib/design-tokens.js.map +1 -0
- package/lib/icon.d.ts +17 -0
- package/lib/icon.js +34 -0
- package/lib/icon.js.map +1 -0
- package/lib/icons.d.ts +29 -0
- package/lib/icons.js +34 -0
- package/lib/icons.js.map +1 -0
- package/lib/interactive.d.ts +21 -0
- package/lib/interactive.js +31 -0
- package/lib/interactive.js.map +1 -0
- package/lib/load-more.d.ts +14 -0
- package/lib/load-more.js +27 -0
- package/lib/load-more.js.map +1 -0
- package/lib/media.d.ts +58 -0
- package/lib/media.js +116 -0
- package/lib/media.js.map +1 -0
- package/lib/segmented.d.ts +57 -0
- package/lib/segmented.js +83 -0
- package/lib/segmented.js.map +1 -0
- package/lib/shortcuts.d.ts +94 -0
- package/lib/shortcuts.js +271 -0
- package/lib/shortcuts.js.map +1 -0
- package/lib/slot.d.ts +9 -0
- package/lib/slot.js +18 -0
- package/lib/slot.js.map +1 -0
- package/lib/time-series.d.ts +100 -0
- package/lib/time-series.js +144 -0
- package/lib/time-series.js.map +1 -0
- package/lib/tone.d.ts +6 -0
- package/lib/tone.js +0 -0
- package/lib/variants.d.ts +12 -0
- package/lib/variants.js +14 -0
- package/lib/variants.js.map +1 -0
- package/package.json +122 -3
- package/styles.css +630 -0
- package/tokens.d.ts +104 -0
- package/tokens.js +108 -0
- package/tokens.js.map +1 -0
- package/publish.log +0 -1
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { CancelIcon } from "../lib/icons.js";
|
|
3
|
+
import { usePopupSheet } from "../lib/media.js";
|
|
4
|
+
import { cn, variants } from "../lib/variants.js";
|
|
5
|
+
import { Button } from "./button.js";
|
|
6
|
+
import { SectionHeader, SectionHeaderBody, SectionHeaderDescription, SectionHeaderTitle } from "./section-header.js";
|
|
7
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
import { createContext, use, useState } from "react";
|
|
9
|
+
import { Dialog as Dialog$1 } from "@base-ui/react/dialog";
|
|
10
|
+
import { Drawer } from "@base-ui/react/drawer";
|
|
11
|
+
// src/components/dialog.tsx
|
|
12
|
+
/**
|
|
13
|
+
* Whether this dialog is open as the phone bottom sheet: a Base UI Drawer popup, with the
|
|
14
|
+
* swipe-down-to-dismiss and rubber-banding a sheet is expected to have. `DialogContent` decides
|
|
15
|
+
* it as the dialog opens and holds it until the dialog closes; every part inside reads it.
|
|
16
|
+
*/
|
|
17
|
+
const SheetContext = createContext(false);
|
|
18
|
+
/**
|
|
19
|
+
* Whether the dialog this sits in is open as the phone bottom sheet, for content that differs
|
|
20
|
+
* between the two shapes. It follows the dialog, not the viewport, so it holds while open.
|
|
21
|
+
*/
|
|
22
|
+
function useDialogSheet() {
|
|
23
|
+
return use(SheetContext);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The root is a Base UI Drawer at every width. A drawer is a dialog with swipe parts added, so
|
|
27
|
+
* its root drives the dialog's own popup as well as the sheet. With one root type for both
|
|
28
|
+
* shapes, nothing above the popup changes when the viewport crosses `sm`.
|
|
29
|
+
*/
|
|
30
|
+
function Dialog(props) {
|
|
31
|
+
return /* @__PURE__ */ jsx(Drawer.Root, { ...props });
|
|
32
|
+
}
|
|
33
|
+
function DialogTrigger(props) {
|
|
34
|
+
return /* @__PURE__ */ jsx(Dialog$1.Trigger, { ...props });
|
|
35
|
+
}
|
|
36
|
+
/** `hideClose` from `DialogContent`, read by `DialogHeader` so its own X follows suit. */
|
|
37
|
+
const DialogCloseContext = createContext(false);
|
|
38
|
+
/** The one X: a ghost button in the header row when there is a header, else pinned to the corner. */
|
|
39
|
+
function DialogX({ className, ...props }) {
|
|
40
|
+
return /* @__PURE__ */ jsx(Dialog$1.Close, {
|
|
41
|
+
render: /* @__PURE__ */ jsx(Button, {
|
|
42
|
+
variant: "ghost",
|
|
43
|
+
"aria-label": "Close",
|
|
44
|
+
prefix: /* @__PURE__ */ jsx(CancelIcon, {})
|
|
45
|
+
}),
|
|
46
|
+
className,
|
|
47
|
+
...props
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
function DialogTitle(props) {
|
|
51
|
+
return /* @__PURE__ */ jsx(Dialog$1.Title, { ...props });
|
|
52
|
+
}
|
|
53
|
+
function DialogDescription(props) {
|
|
54
|
+
return /* @__PURE__ */ jsx(Dialog$1.Description, { ...props });
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The dialog's own timing, pinned rather than left to `tailwindcss-animate`'s 150ms on the
|
|
58
|
+
* browser default `ease`: a modal is the system's slowest move, so it enters on the one motion
|
|
59
|
+
* curve over 200ms and leaves faster and plainer, having nothing left to announce. The backdrop
|
|
60
|
+
* rides the same numbers so ink and panel arrive together. The exit holds its last frame, as the
|
|
61
|
+
* popups' does, so the panel cannot flash back before it unmounts.
|
|
62
|
+
*/
|
|
63
|
+
const dialogAnimationClasses = ["data-open:duration-200 data-open:animate-in data-open:ease-out-expo", "data-closed:duration-150 data-closed:animate-out data-closed:fill-mode-forwards data-closed:ease-out"];
|
|
64
|
+
const dialogOverlayAnimationClasses = [...dialogAnimationClasses, "data-open:fade-in-0 data-closed:fade-out-0"];
|
|
65
|
+
/**
|
|
66
|
+
* A sheet or side panel for a reader who asks for reduced motion: it fades where it stands
|
|
67
|
+
* instead of travelling. The stylesheet's reduced-motion rule already turns the transform
|
|
68
|
+
* transition into an opacity one, so the popup only has to keep its place (its off-screen
|
|
69
|
+
* transforms are `motion-safe:`) and go transparent. A swipe still follows the finger, and a
|
|
70
|
+
* dismissed popup fades from where the finger left it. The backdrop takes the same timing, so
|
|
71
|
+
* ink and panel still leave together.
|
|
72
|
+
*/
|
|
73
|
+
const drawerReducedTimingClasses = "motion-reduce:duration-200 motion-reduce:data-ending-style:duration-150";
|
|
74
|
+
const drawerReducedFadeClasses = [drawerReducedTimingClasses, "motion-reduce:data-starting-style:opacity-0 motion-reduce:data-ending-style:opacity-0"];
|
|
75
|
+
/**
|
|
76
|
+
* How a drawer's backdrop comes and goes: a transition, not a keyframe animation. The drawer
|
|
77
|
+
* stays mounted for its own longer close, and a `fade-out` animation would end early and hand
|
|
78
|
+
* the backdrop back at full strength for the rest of it. This also lets the backdrop thin out
|
|
79
|
+
* under the finger, and leave on the curve the swipe's own momentum sets.
|
|
80
|
+
*/
|
|
81
|
+
const drawerBackdropClasses = [
|
|
82
|
+
"opacity-[calc(1-var(--drawer-swipe-progress,0))]",
|
|
83
|
+
"transition-opacity duration-[450ms] ease-drawer data-swiping:duration-0",
|
|
84
|
+
"data-starting-style:opacity-0 data-ending-style:opacity-0",
|
|
85
|
+
"data-ending-style:duration-[calc(var(--drawer-swipe-strength)*400ms)]",
|
|
86
|
+
drawerReducedTimingClasses
|
|
87
|
+
];
|
|
88
|
+
/** The scrim behind the dialog. Rendered by `DialogContent`. */
|
|
89
|
+
function DialogOverlay({ className, ...props }) {
|
|
90
|
+
const sheet = useDialogSheet();
|
|
91
|
+
const Backdrop = sheet ? Drawer.Backdrop : Dialog$1.Backdrop;
|
|
92
|
+
return /* @__PURE__ */ jsx(Backdrop, {
|
|
93
|
+
forceRender: true,
|
|
94
|
+
className: cn("fixed inset-0 z-50 bg-scrim", sheet ? drawerBackdropClasses : dialogOverlayAnimationClasses, className),
|
|
95
|
+
...props
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
const dialogContentVariants = variants({
|
|
99
|
+
base: [
|
|
100
|
+
"fixed left-1/2 z-50 grid w-[calc(100vw-2rem)] -translate-x-1/2 overflow-y-auto rounded-xl border bg-surface shadow-modal outline-none",
|
|
101
|
+
"has-[[data-slot=dialog-header]]:[&>[data-slot=dialog-corner-close]]:hidden",
|
|
102
|
+
...dialogAnimationClasses,
|
|
103
|
+
"data-open:fade-in-0 data-closed:fade-out-0",
|
|
104
|
+
"data-open:zoom-in-98 data-closed:zoom-out-98",
|
|
105
|
+
"data-open:slide-in-from-bottom-4 data-closed:slide-out-to-bottom-4"
|
|
106
|
+
],
|
|
107
|
+
variants: {
|
|
108
|
+
size: {
|
|
109
|
+
xs: "max-w-xs",
|
|
110
|
+
sm: "max-w-sm",
|
|
111
|
+
md: "max-w-md",
|
|
112
|
+
lg: "max-w-lg",
|
|
113
|
+
xl: "max-w-xl",
|
|
114
|
+
"2xl": "max-w-2xl",
|
|
115
|
+
"3xl": "max-w-3xl",
|
|
116
|
+
"4xl": "max-w-4xl",
|
|
117
|
+
"5xl": "max-w-5xl"
|
|
118
|
+
},
|
|
119
|
+
/**
|
|
120
|
+
* Pin the dialog near the top of the viewport instead of centering it, so its height can
|
|
121
|
+
* change without the whole thing jumping. A dialog opened from inside another one carries
|
|
122
|
+
* Base UI's `data-nested` and sits a little lower, so the stack is visible as a stack. Each
|
|
123
|
+
* portal is its own subtree, so no sibling selector can see the one underneath.
|
|
124
|
+
*/
|
|
125
|
+
fixed: {
|
|
126
|
+
true: "top-[10dvh] max-h-[calc(90dvh-2rem)] data-nested:top-[calc(10dvh+2.5rem)] data-nested:max-h-[calc(90dvh-4.5rem)]",
|
|
127
|
+
false: "top-1/2 max-h-[calc(100dvh-2rem)] -translate-y-1/2"
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
defaultVariants: {
|
|
131
|
+
size: "md",
|
|
132
|
+
fixed: true
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
/**
|
|
136
|
+
* The sheet itself: full width against the bottom edge, following the finger down and then
|
|
137
|
+
* either springing back or riding the swipe's own momentum out. `touch-none` hands vertical
|
|
138
|
+
* drags to the drawer; the body inside takes them back with `touch-auto` and only gives them
|
|
139
|
+
* up once it is scrolled to the top, so a swipe on a scrolled list scrolls it.
|
|
140
|
+
*/
|
|
141
|
+
const sheetPopup = [
|
|
142
|
+
"flex max-h-[calc(100dvh-3rem)] w-full touch-none flex-col overflow-hidden rounded-t-xl border border-b-0 bg-surface shadow-modal outline-none",
|
|
143
|
+
"[transform:translateY(var(--drawer-swipe-movement-y))]",
|
|
144
|
+
"transition-transform duration-[450ms] ease-drawer",
|
|
145
|
+
"data-swiping:select-none data-swiping:duration-0",
|
|
146
|
+
"motion-safe:data-starting-style:[transform:translateY(100%)] motion-safe:data-ending-style:[transform:translateY(100%)]",
|
|
147
|
+
"data-ending-style:duration-[calc(var(--drawer-swipe-strength)*400ms)]",
|
|
148
|
+
...drawerReducedFadeClasses
|
|
149
|
+
];
|
|
150
|
+
const sheetContent = [
|
|
151
|
+
"relative grid min-h-0 flex-1 touch-auto overflow-y-auto overscroll-contain",
|
|
152
|
+
"has-[[data-slot=dialog-header]]:[&>[data-slot=dialog-corner-close]]:hidden",
|
|
153
|
+
"pb-[env(safe-area-inset-bottom)]"
|
|
154
|
+
];
|
|
155
|
+
/**
|
|
156
|
+
* The popup in the shape the viewport had when the dialog opened. It mounts inside the portal,
|
|
157
|
+
* which mounts as the dialog opens and unmounts once it has closed, so the shape is read then
|
|
158
|
+
* and held: crossing `sm` with the dialog open leaves it, and the form in it, as it is.
|
|
159
|
+
*/
|
|
160
|
+
function DialogSurface({ className, children, size, fixed, hideClose, instant, ...props }) {
|
|
161
|
+
const sheet = usePopupSheet();
|
|
162
|
+
const instantClasses = instant ? "data-open:animate-none! data-closed:animate-none!" : void 0;
|
|
163
|
+
const body = /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(DialogCloseContext, {
|
|
164
|
+
value: !!hideClose,
|
|
165
|
+
children
|
|
166
|
+
}), !hideClose && /* @__PURE__ */ jsx(DialogX, {
|
|
167
|
+
"data-slot": "dialog-corner-close",
|
|
168
|
+
className: "absolute top-3 right-3 z-20 pointer-coarse:top-1.5 pointer-coarse:right-1.5"
|
|
169
|
+
})] });
|
|
170
|
+
if (sheet) return /* @__PURE__ */ jsxs(SheetContext, {
|
|
171
|
+
value: true,
|
|
172
|
+
children: [/* @__PURE__ */ jsx(DialogOverlay, {}), /* @__PURE__ */ jsx(Drawer.Viewport, {
|
|
173
|
+
className: "fixed inset-0 z-50 flex items-end",
|
|
174
|
+
children: /* @__PURE__ */ jsxs(Drawer.Popup, {
|
|
175
|
+
className: cn(sheetPopup),
|
|
176
|
+
...props,
|
|
177
|
+
children: [/* @__PURE__ */ jsx(Drawer.Close, {
|
|
178
|
+
"aria-label": "Close",
|
|
179
|
+
tabIndex: -1,
|
|
180
|
+
className: "group/grabber relative mx-auto flex h-6 w-11 shrink-0 cursor-pointer items-center justify-center outline-none before:absolute before:inset-x-0 before:-inset-y-2.5",
|
|
181
|
+
children: /* @__PURE__ */ jsx("span", { className: "h-1.25 w-9 rounded-full border bg-surface shadow-control transition-[scale,box-shadow] duration-150 ease-out-expo group-active/grabber:scale-x-94 group-active/grabber:shadow-none" })
|
|
182
|
+
}), /* @__PURE__ */ jsx(Drawer.Content, {
|
|
183
|
+
className: cn(sheetContent, className),
|
|
184
|
+
children: body
|
|
185
|
+
})]
|
|
186
|
+
})
|
|
187
|
+
})]
|
|
188
|
+
});
|
|
189
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(DialogOverlay, { className: instantClasses }), /* @__PURE__ */ jsx(Dialog$1.Popup, {
|
|
190
|
+
className: dialogContentVariants({
|
|
191
|
+
size,
|
|
192
|
+
fixed,
|
|
193
|
+
className: cn(instantClasses, className)
|
|
194
|
+
}),
|
|
195
|
+
...props,
|
|
196
|
+
children: body
|
|
197
|
+
})] });
|
|
198
|
+
}
|
|
199
|
+
function DialogContent(props) {
|
|
200
|
+
return /* @__PURE__ */ jsx(Dialog$1.Portal, { children: /* @__PURE__ */ jsx(DialogSurface, { ...props }) });
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* What a dialog is showing, kept alive through its close animation. A dialog driven by
|
|
204
|
+
* `open={!!row}` loses `row` the instant it closes, so its body unmounts and the popup fades
|
|
205
|
+
* out as an empty box with a stray footer. Render what this returns instead of the state
|
|
206
|
+
* itself, and the last row stays on screen until the animation ends.
|
|
207
|
+
*/
|
|
208
|
+
function useDialogValue(value) {
|
|
209
|
+
const [last, setLast] = useState(value ?? null);
|
|
210
|
+
if (value != null && value !== last) setLast(value);
|
|
211
|
+
return value ?? last;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* The padded block a dialog's content sits in, holding its own header when that header has no
|
|
215
|
+
* hairline of its own. A dialog whose body scrolls or splits into panes lays out those regions
|
|
216
|
+
* itself instead, so the column names and the panes reach the popup's edges.
|
|
217
|
+
*/
|
|
218
|
+
function DialogBody({ className, ...props }) {
|
|
219
|
+
const sheet = useDialogSheet();
|
|
220
|
+
return /* @__PURE__ */ jsx("div", {
|
|
221
|
+
className: cn("flex flex-col gap-6 p-6", sheet && "first:pt-3", className),
|
|
222
|
+
...props
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
const dialogHeaderVariants = variants({
|
|
226
|
+
base: "relative",
|
|
227
|
+
variants: {
|
|
228
|
+
/**
|
|
229
|
+
* Give the header its own band: a hairline and the padding to sit on. It belongs to a
|
|
230
|
+
* dialog that owns its body as a region: one that scrolls under the header, or splits
|
|
231
|
+
* into panes. A dialog whose body is a single `DialogBody` block holds its header inside
|
|
232
|
+
* that block instead, with nothing drawn under it.
|
|
233
|
+
*/
|
|
234
|
+
bordered: { true: "border-b px-6 py-5" } }
|
|
235
|
+
});
|
|
236
|
+
/**
|
|
237
|
+
* The standard dialog heading: a card-scale `SectionHeader` whose title and description are wired to
|
|
238
|
+
* Base UI's `DialogTitle` / `DialogDescription` for accessibility. Extra children render after
|
|
239
|
+
* them, and the dialog's X sits at the end of the row, centred on the title line.
|
|
240
|
+
*/
|
|
241
|
+
function DialogHeader({ title, description, bordered, className, children, ...props }) {
|
|
242
|
+
const hideClose = use(DialogCloseContext);
|
|
243
|
+
return /* @__PURE__ */ jsxs(SectionHeader, {
|
|
244
|
+
size: "card",
|
|
245
|
+
"data-slot": "dialog-header",
|
|
246
|
+
className: dialogHeaderVariants({
|
|
247
|
+
bordered,
|
|
248
|
+
className
|
|
249
|
+
}),
|
|
250
|
+
...props,
|
|
251
|
+
children: [
|
|
252
|
+
/* @__PURE__ */ jsxs(SectionHeaderBody, { children: [/* @__PURE__ */ jsx(DialogTitle, {
|
|
253
|
+
render: /* @__PURE__ */ jsx(SectionHeaderTitle, { className: "max-sm:text-base" }),
|
|
254
|
+
children: title
|
|
255
|
+
}), description && /* @__PURE__ */ jsx(DialogDescription, {
|
|
256
|
+
render: /* @__PURE__ */ jsx(SectionHeaderDescription, {}),
|
|
257
|
+
children: description
|
|
258
|
+
})] }),
|
|
259
|
+
children,
|
|
260
|
+
!hideClose && /* @__PURE__ */ jsx("div", {
|
|
261
|
+
className: cn("-mr-1.5 flex h-7 shrink-0 items-center self-start max-sm:absolute max-sm:mr-0 max-sm:h-6", bordered ? "max-sm:top-5 max-sm:right-4.5" : "max-sm:top-0 max-sm:-right-1.5"),
|
|
262
|
+
children: /* @__PURE__ */ jsx(DialogX, {})
|
|
263
|
+
})
|
|
264
|
+
]
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* The band a dialog's actions sit in: a hairline, the canvas fill that sets it apart from the
|
|
269
|
+
* white body above, and room past the home indicator on a bottom sheet. Every dialog with
|
|
270
|
+
* actions wears it, whether or not its header has a hairline of its own.
|
|
271
|
+
*/
|
|
272
|
+
function DialogFooter({ className, ...props }) {
|
|
273
|
+
const sheet = useDialogSheet();
|
|
274
|
+
return /* @__PURE__ */ jsx("div", {
|
|
275
|
+
className: cn("flex flex-col flex-wrap gap-2 border-t bg-canvas px-6 py-4 sm:flex-row sm:justify-end", !sheet && "sticky bottom-0 z-10", "text-control", sheet && "-mb-[env(safe-area-inset-bottom)] pb-[calc(1.75rem+env(safe-area-inset-bottom))]", className),
|
|
276
|
+
...props
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
function DialogClose(props) {
|
|
280
|
+
return /* @__PURE__ */ jsx(Dialog$1.Close, { render: /* @__PURE__ */ jsx(Button, {
|
|
281
|
+
variant: "secondary",
|
|
282
|
+
...props
|
|
283
|
+
}) });
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* The side panel: pinned to the left edge at full height, following the finger left and then
|
|
287
|
+
* either springing back or riding the swipe's own momentum out, as the sheet does downward.
|
|
288
|
+
* `shadow-drawer` is the modal shadow cast sideways, with the edge first: that edge is the
|
|
289
|
+
* panel's right hairline, so the panel carries no border of its own.
|
|
290
|
+
*/
|
|
291
|
+
const sidePopup = [
|
|
292
|
+
"flex h-full w-70 touch-none flex-col border-r bg-canvas shadow-drawer outline-none",
|
|
293
|
+
"[transform:translateX(var(--drawer-swipe-movement-x))]",
|
|
294
|
+
"transition-transform duration-[450ms] ease-drawer",
|
|
295
|
+
"data-swiping:select-none data-swiping:duration-0",
|
|
296
|
+
"motion-safe:data-starting-style:[transform:translateX(-100%)] motion-safe:data-ending-style:[transform:translateX(-100%)]",
|
|
297
|
+
"data-ending-style:duration-[calc(var(--drawer-swipe-strength)*400ms)]",
|
|
298
|
+
...drawerReducedFadeClasses
|
|
299
|
+
];
|
|
300
|
+
/**
|
|
301
|
+
* A panel sliding in from the left edge over a scrim: the phone's navigation drawer. Escape,
|
|
302
|
+
* a tap on the scrim, a swipe to the left and a press on the trigger all close it.
|
|
303
|
+
*/
|
|
304
|
+
function SideDrawer({ trigger, offset, className, children, ...props }) {
|
|
305
|
+
const inset = { top: offset };
|
|
306
|
+
return /* @__PURE__ */ jsxs(Drawer.Root, {
|
|
307
|
+
swipeDirection: "left",
|
|
308
|
+
...props,
|
|
309
|
+
children: [/* @__PURE__ */ jsx(Drawer.Trigger, { render: trigger }), /* @__PURE__ */ jsxs(Drawer.Portal, { children: [/* @__PURE__ */ jsx(Drawer.Backdrop, {
|
|
310
|
+
style: inset,
|
|
311
|
+
className: cn("fixed inset-0 z-50 bg-scrim", drawerBackdropClasses)
|
|
312
|
+
}), /* @__PURE__ */ jsx(Drawer.Viewport, {
|
|
313
|
+
style: inset,
|
|
314
|
+
className: "fixed inset-0 z-50 flex",
|
|
315
|
+
children: /* @__PURE__ */ jsx(Drawer.Popup, {
|
|
316
|
+
className: cn(sidePopup, className),
|
|
317
|
+
children: /* @__PURE__ */ jsx(Drawer.Content, {
|
|
318
|
+
className: "flex min-h-0 flex-1 touch-auto flex-col overflow-y-auto overscroll-contain",
|
|
319
|
+
children
|
|
320
|
+
})
|
|
321
|
+
})
|
|
322
|
+
})] })]
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
export { Dialog, DialogBody, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, SideDrawer, useDialogSheet, useDialogValue };
|
|
326
|
+
|
|
327
|
+
//# sourceMappingURL=dialog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dialog.js","names":["DialogPrimitive"],"sources":["../../src/components/dialog.tsx"],"sourcesContent":["\"use client\"\n\nimport { Dialog as DialogPrimitive } from \"@base-ui/react/dialog\"\nimport { Drawer } from \"@base-ui/react/drawer\"\nimport {\n type ComponentProps,\n createContext,\n type CSSProperties,\n type ReactElement,\n type ReactNode,\n use,\n useState,\n} from \"react\"\nimport { CancelIcon } from \"../lib/icons\"\nimport { usePopupSheet } from \"../lib/media\"\nimport { cn, variants, type VariantProps } from \"../lib/variants\"\nimport { Button } from \"./button\"\nimport {\n SectionHeader,\n SectionHeaderBody,\n SectionHeaderDescription,\n SectionHeaderTitle,\n} from \"./section-header\"\n\n/**\n * Whether this dialog is open as the phone bottom sheet: a Base UI Drawer popup, with the\n * swipe-down-to-dismiss and rubber-banding a sheet is expected to have. `DialogContent` decides\n * it as the dialog opens and holds it until the dialog closes; every part inside reads it.\n */\nconst SheetContext = createContext(false)\n\n/**\n * Whether the dialog this sits in is open as the phone bottom sheet, for content that differs\n * between the two shapes. It follows the dialog, not the viewport, so it holds while open.\n */\nfunction useDialogSheet() {\n return use(SheetContext)\n}\n\n/** The drawer root's props less the swipe and snap ones, which only the sheet could use. */\ntype DialogProps = Omit<\n Drawer.Root.Props,\n | \"swipeDirection\"\n | \"snapPoints\"\n | \"snapPoint\"\n | \"defaultSnapPoint\"\n | \"onSnapPointChange\"\n | \"snapToSequentialPoints\"\n>\n\n/**\n * The root is a Base UI Drawer at every width. A drawer is a dialog with swipe parts added, so\n * its root drives the dialog's own popup as well as the sheet. With one root type for both\n * shapes, nothing above the popup changes when the viewport crosses `sm`.\n */\nfunction Dialog(props: DialogProps) {\n return <Drawer.Root {...props} />\n}\n\nfunction DialogTrigger(props: DialogPrimitive.Trigger.Props) {\n return <DialogPrimitive.Trigger {...props} />\n}\n\n/** `hideClose` from `DialogContent`, read by `DialogHeader` so its own X follows suit. */\nconst DialogCloseContext = createContext(false)\n\n/** The one X: a ghost button in the header row when there is a header, else pinned to the corner. */\nfunction DialogX({ className, ...props }: ComponentProps<\"button\">) {\n return (\n <DialogPrimitive.Close\n render={<Button variant=\"ghost\" aria-label=\"Close\" prefix={<CancelIcon />} />}\n className={className}\n {...props}\n />\n )\n}\n\nfunction DialogTitle(props: DialogPrimitive.Title.Props) {\n return <DialogPrimitive.Title {...props} />\n}\n\nfunction DialogDescription(props: DialogPrimitive.Description.Props) {\n return <DialogPrimitive.Description {...props} />\n}\n\n/**\n * The dialog's own timing, pinned rather than left to `tailwindcss-animate`'s 150ms on the\n * browser default `ease`: a modal is the system's slowest move, so it enters on the one motion\n * curve over 200ms and leaves faster and plainer, having nothing left to announce. The backdrop\n * rides the same numbers so ink and panel arrive together. The exit holds its last frame, as the\n * popups' does, so the panel cannot flash back before it unmounts.\n */\nconst dialogAnimationClasses = [\n \"data-open:duration-200 data-open:animate-in data-open:ease-out-expo\",\n \"data-closed:duration-150 data-closed:animate-out data-closed:fill-mode-forwards data-closed:ease-out\",\n]\n\nconst dialogOverlayAnimationClasses = [\n ...dialogAnimationClasses,\n \"data-open:fade-in-0 data-closed:fade-out-0\",\n]\n\n/**\n * A sheet or side panel for a reader who asks for reduced motion: it fades where it stands\n * instead of travelling. The stylesheet's reduced-motion rule already turns the transform\n * transition into an opacity one, so the popup only has to keep its place (its off-screen\n * transforms are `motion-safe:`) and go transparent. A swipe still follows the finger, and a\n * dismissed popup fades from where the finger left it. The backdrop takes the same timing, so\n * ink and panel still leave together.\n */\nconst drawerReducedTimingClasses =\n \"motion-reduce:duration-200 motion-reduce:data-ending-style:duration-150\"\n\nconst drawerReducedFadeClasses = [\n drawerReducedTimingClasses,\n \"motion-reduce:data-starting-style:opacity-0 motion-reduce:data-ending-style:opacity-0\",\n]\n\n/**\n * How a drawer's backdrop comes and goes: a transition, not a keyframe animation. The drawer\n * stays mounted for its own longer close, and a `fade-out` animation would end early and hand\n * the backdrop back at full strength for the rest of it. This also lets the backdrop thin out\n * under the finger, and leave on the curve the swipe's own momentum sets.\n */\nconst drawerBackdropClasses = [\n \"opacity-[calc(1-var(--drawer-swipe-progress,0))]\",\n \"transition-opacity duration-[450ms] ease-drawer data-swiping:duration-0\",\n \"data-starting-style:opacity-0 data-ending-style:opacity-0\",\n \"data-ending-style:duration-[calc(var(--drawer-swipe-strength)*400ms)]\",\n drawerReducedTimingClasses,\n]\n\n/** The scrim behind the dialog. Rendered by `DialogContent`. */\nfunction DialogOverlay({ className, ...props }: DialogPrimitive.Backdrop.Props) {\n const sheet = useDialogSheet()\n const Backdrop = sheet ? Drawer.Backdrop : DialogPrimitive.Backdrop\n\n return (\n <Backdrop\n // Base UI renders no backdrop for a dialog opened from inside another one. Each dialog\n // draws its own, so a stack reads as a stack: the one underneath sits behind a dim of\n // its own rather than staying as crisp as the dialog on top of it.\n forceRender\n className={cn(\n \"fixed inset-0 z-50 bg-scrim\",\n sheet ? drawerBackdropClasses : dialogOverlayAnimationClasses,\n className,\n )}\n {...props}\n />\n )\n}\n\nconst dialogContentVariants = variants({\n // The shape of a dialog opened from `sm` up; one opened under it is a drawer (`sheetPopup`).\n // The popup carries no padding of its own: every section owns its own band, a `DialogBody`\n // for the padded block, a `DialogHeader` and `DialogFooter` for the ones with a hairline.\n base: [\n \"fixed left-1/2 z-50 grid w-[calc(100vw-2rem)] -translate-x-1/2 overflow-y-auto rounded-xl border bg-surface shadow-modal outline-none\",\n // The corner X is the fallback for a dialog with no header; a header hosts its own. Matched\n // on the content rather than as the header's sibling, so a header wrapped in a `contents`\n // form still retires it instead of leaving two X's stacked in the corner.\n \"has-[[data-slot=dialog-header]]:[&>[data-slot=dialog-corner-close]]:hidden\",\n ...dialogAnimationClasses,\n \"data-open:fade-in-0 data-closed:fade-out-0\",\n \"data-open:zoom-in-98 data-closed:zoom-out-98\",\n \"data-open:slide-in-from-bottom-4 data-closed:slide-out-to-bottom-4\",\n ],\n\n variants: {\n size: {\n xs: \"max-w-xs\",\n sm: \"max-w-sm\",\n md: \"max-w-md\",\n lg: \"max-w-lg\",\n xl: \"max-w-xl\",\n \"2xl\": \"max-w-2xl\",\n \"3xl\": \"max-w-3xl\",\n \"4xl\": \"max-w-4xl\",\n \"5xl\": \"max-w-5xl\",\n },\n\n /**\n * Pin the dialog near the top of the viewport instead of centering it, so its height can\n * change without the whole thing jumping. A dialog opened from inside another one carries\n * Base UI's `data-nested` and sits a little lower, so the stack is visible as a stack. Each\n * portal is its own subtree, so no sibling selector can see the one underneath.\n */\n fixed: {\n true: \"top-[10dvh] max-h-[calc(90dvh-2rem)] data-nested:top-[calc(10dvh+2.5rem)] data-nested:max-h-[calc(90dvh-4.5rem)]\",\n false: \"top-1/2 max-h-[calc(100dvh-2rem)] -translate-y-1/2\",\n },\n },\n\n defaultVariants: {\n size: \"md\",\n fixed: true,\n },\n})\n\n/**\n * The sheet itself: full width against the bottom edge, following the finger down and then\n * either springing back or riding the swipe's own momentum out. `touch-none` hands vertical\n * drags to the drawer; the body inside takes them back with `touch-auto` and only gives them\n * up once it is scrolled to the top, so a swipe on a scrolled list scrolls it.\n */\nconst sheetPopup = [\n \"flex max-h-[calc(100dvh-3rem)] w-full touch-none flex-col overflow-hidden rounded-t-xl border border-b-0 bg-surface shadow-modal outline-none\",\n \"[transform:translateY(var(--drawer-swipe-movement-y))]\",\n \"transition-transform duration-[450ms] ease-drawer\",\n \"data-swiping:select-none data-swiping:duration-0\",\n \"motion-safe:data-starting-style:[transform:translateY(100%)] motion-safe:data-ending-style:[transform:translateY(100%)]\",\n \"data-ending-style:duration-[calc(var(--drawer-swipe-strength)*400ms)]\",\n ...drawerReducedFadeClasses,\n]\n\nconst sheetContent = [\n // `relative` anchors the corner X, as `fixed` does on the dialog's own popup.\n \"relative grid min-h-0 flex-1 touch-auto overflow-y-auto overscroll-contain\",\n // As on the dialog: a header brings its own X, so the corner fallback stands down.\n \"has-[[data-slot=dialog-header]]:[&>[data-slot=dialog-corner-close]]:hidden\",\n // Room past the home indicator under whatever section sits last; the grabber covers the top.\n // A footer band cancels this padding with a negative margin and carries the inset itself, so\n // its fill reaches the sheet's bottom edge instead of stopping short of it.\n \"pb-[env(safe-area-inset-bottom)]\",\n]\n\ninterface DialogContentProps\n extends\n Omit<DialogPrimitive.Popup.Props, \"className\" | \"render\" | \"style\">,\n VariantProps<typeof dialogContentVariants> {\n className?: string\n style?: CSSProperties\n\n /** The element the popup renders as, such as a form, in either shape. */\n render?: ReactElement\n\n /**\n * Hide the close button in the top right corner, for a dialog that must be dismissed\n * through one of its own actions.\n */\n hideClose?: boolean\n\n /** Open and close at once, for a dialog a shortcut summons. A sheet still slides. */\n instant?: boolean\n}\n\n/**\n * The popup in the shape the viewport had when the dialog opened. It mounts inside the portal,\n * which mounts as the dialog opens and unmounts once it has closed, so the shape is read then\n * and held: crossing `sm` with the dialog open leaves it, and the form in it, as it is.\n */\nfunction DialogSurface({\n className,\n children,\n size,\n fixed,\n hideClose,\n instant,\n ...props\n}: DialogContentProps) {\n const sheet = usePopupSheet()\n // Important, because `tailwindcss-animate` emits `animate-in` after `animate-none`.\n const instantClasses = instant ? \"data-open:animate-none! data-closed:animate-none!\" : undefined\n\n const body = (\n <>\n <DialogCloseContext value={!!hideClose}>{children}</DialogCloseContext>\n\n {/* Corner fallback for a dialog without a `DialogHeader`, which hosts the X itself. */}\n {!hideClose && (\n <DialogX\n data-slot=\"dialog-corner-close\"\n className=\"absolute top-3 right-3 z-20 pointer-coarse:top-1.5 pointer-coarse:right-1.5\"\n />\n )}\n </>\n )\n\n // A sheet spans the phone's width, so `size` has nothing to constrain and is dropped.\n if (sheet) {\n return (\n <SheetContext value>\n <DialogOverlay />\n\n <Drawer.Viewport className=\"fixed inset-0 z-50 flex items-end\">\n <Drawer.Popup className={cn(sheetPopup)} {...props}>\n {/* The grabber: says the sheet pulls down, and is the one part always in reach. A\n raised key rather than a line, and a tap on it closes the sheet. Its `::before`\n spills past the 24px band to a 44px target. Out of the tab order, since the\n header's X is the keyboard's way out. */}\n <Drawer.Close\n aria-label=\"Close\"\n tabIndex={-1}\n className=\"group/grabber relative mx-auto flex h-6 w-11 shrink-0 cursor-pointer items-center justify-center outline-none before:absolute before:inset-x-0 before:-inset-y-2.5\"\n >\n <span className=\"h-1.25 w-9 rounded-full border bg-surface shadow-control transition-[scale,box-shadow] duration-150 ease-out-expo group-active/grabber:scale-x-94 group-active/grabber:shadow-none\" />\n </Drawer.Close>\n\n <Drawer.Content className={cn(sheetContent, className)}>{body}</Drawer.Content>\n </Drawer.Popup>\n </Drawer.Viewport>\n </SheetContext>\n )\n }\n\n return (\n <>\n <DialogOverlay className={instantClasses} />\n\n <DialogPrimitive.Popup\n className={dialogContentVariants({ size, fixed, className: cn(instantClasses, className) })}\n {...props}\n >\n {body}\n </DialogPrimitive.Popup>\n </>\n )\n}\n\nfunction DialogContent(props: DialogContentProps) {\n return (\n <DialogPrimitive.Portal>\n <DialogSurface {...props} />\n </DialogPrimitive.Portal>\n )\n}\n\n/**\n * What a dialog is showing, kept alive through its close animation. A dialog driven by\n * `open={!!row}` loses `row` the instant it closes, so its body unmounts and the popup fades\n * out as an empty box with a stray footer. Render what this returns instead of the state\n * itself, and the last row stays on screen until the animation ends.\n */\nexport function useDialogValue<T>(value: T | null | undefined): T | null {\n // Adjusting state while rendering, which React supports for exactly this (deriving from a\n // value that changed), and which a ref written during render would only fake.\n const [last, setLast] = useState<T | null>(value ?? null)\n\n if (value != null && value !== last) {\n setLast(value)\n }\n\n return value ?? last\n}\n\n/**\n * The padded block a dialog's content sits in, holding its own header when that header has no\n * hairline of its own. A dialog whose body scrolls or splits into panes lays out those regions\n * itself instead, so the column names and the panes reach the popup's edges.\n */\nfunction DialogBody({ className, ...props }: ComponentProps<\"div\">) {\n const sheet = useDialogSheet()\n\n return (\n // `first:pt-3` closes the gap under the sheet's grabber, which stands in for the top\n // padding whenever the body is the sheet's first section.\n <div className={cn(\"flex flex-col gap-6 p-6\", sheet && \"first:pt-3\", className)} {...props} />\n )\n}\n\nconst dialogHeaderVariants = variants({\n // `relative` anchors the X, which leaves the row under `sm` where the card header stacks.\n base: \"relative\",\n\n variants: {\n /**\n * Give the header its own band: a hairline and the padding to sit on. It belongs to a\n * dialog that owns its body as a region: one that scrolls under the header, or splits\n * into panes. A dialog whose body is a single `DialogBody` block holds its header inside\n * that block instead, with nothing drawn under it.\n */\n bordered: {\n true: \"border-b px-6 py-5\",\n },\n },\n})\n\ntype DialogHeaderProps = Omit<ComponentProps<typeof SectionHeader>, \"title\" | \"description\"> &\n VariantProps<typeof dialogHeaderVariants> & {\n title: ReactNode\n description?: ReactNode\n }\n\n/**\n * The standard dialog heading: a card-scale `SectionHeader` whose title and description are wired to\n * Base UI's `DialogTitle` / `DialogDescription` for accessibility. Extra children render after\n * them, and the dialog's X sits at the end of the row, centred on the title line.\n */\nfunction DialogHeader({\n title,\n description,\n bordered,\n className,\n children,\n ...props\n}: DialogHeaderProps) {\n const hideClose = use(DialogCloseContext)\n\n return (\n <SectionHeader\n size=\"card\"\n data-slot=\"dialog-header\"\n className={dialogHeaderVariants({ bordered, className })}\n {...props}\n >\n <SectionHeaderBody>\n {/* A step smaller in the bottom sheet, where the title is a row label, not a page\n heading. */}\n <DialogTitle render={<SectionHeaderTitle className=\"max-sm:text-base\" />}>\n {title}\n </DialogTitle>\n\n {description && (\n <DialogDescription render={<SectionHeaderDescription />}>{description}</DialogDescription>\n )}\n </SectionHeaderBody>\n\n {children}\n\n {!hideClose && (\n // A box the height of the title line (28px, 24px in the sheet), so the X centres on the\n // title whatever sits under it; pulled out by 6px so the glyph's edge sits on the same\n // inset as the title's. Under `sm` the card header stacks into a column, so the box\n // leaves the flow and pins itself to the title line instead.\n <div\n className={cn(\n \"-mr-1.5 flex h-7 shrink-0 items-center self-start max-sm:absolute max-sm:mr-0 max-sm:h-6\",\n bordered ? \"max-sm:top-5 max-sm:right-4.5\" : \"max-sm:top-0 max-sm:-right-1.5\",\n )}\n >\n <DialogX />\n </div>\n )}\n </SectionHeader>\n )\n}\n\n/**\n * The band a dialog's actions sit in: a hairline, the canvas fill that sets it apart from the\n * white body above, and room past the home indicator on a bottom sheet. Every dialog with\n * actions wears it, whether or not its header has a hairline of its own.\n */\nfunction DialogFooter({ className, ...props }: ComponentProps<\"div\">) {\n const sheet = useDialogSheet()\n\n return (\n <div\n className={cn(\n \"flex flex-col flex-wrap gap-2 border-t bg-canvas px-6 py-4 sm:flex-row sm:justify-end\",\n // A long dialog scrolls under its actions rather than taking them out of view.\n !sheet && \"sticky bottom-0 z-10\",\n // The control type scale, as on a card's footer, so an `InlineAction` lines up with\n // the buttons beside it.\n \"text-control\",\n // On a sheet the band runs to the bottom edge: the negative margin swallows the\n // scroll container's home-indicator inset, and the padding gives that room back\n // inside the fill. The stack keeps the row's order, so the primary sits nearest the thumb.\n sheet && \"-mb-[env(safe-area-inset-bottom)] pb-[calc(1.75rem+env(safe-area-inset-bottom))]\",\n className,\n )}\n {...props}\n />\n )\n}\n\nfunction DialogClose(props: ComponentProps<typeof Button>) {\n return <DialogPrimitive.Close render={<Button variant=\"secondary\" {...props} />} />\n}\n\n/**\n * The side panel: pinned to the left edge at full height, following the finger left and then\n * either springing back or riding the swipe's own momentum out, as the sheet does downward.\n * `shadow-drawer` is the modal shadow cast sideways, with the edge first: that edge is the\n * panel's right hairline, so the panel carries no border of its own.\n */\nconst sidePopup = [\n \"flex h-full w-70 touch-none flex-col border-r bg-canvas shadow-drawer outline-none\",\n \"[transform:translateX(var(--drawer-swipe-movement-x))]\",\n \"transition-transform duration-[450ms] ease-drawer\",\n \"data-swiping:select-none data-swiping:duration-0\",\n \"motion-safe:data-starting-style:[transform:translateX(-100%)] motion-safe:data-ending-style:[transform:translateX(-100%)]\",\n \"data-ending-style:duration-[calc(var(--drawer-swipe-strength)*400ms)]\",\n ...drawerReducedFadeClasses,\n]\n\ntype SideDrawerProps = Omit<Drawer.Root.Props, \"children\"> & {\n /**\n * The element that opens the panel, and closes it while it is open. It stays outside the\n * panel, so a shell whose bar owns the toggle keeps one button for both states.\n */\n trigger: ReactElement\n\n /**\n * Where the panel and its scrim start, measured from the top of the viewport: a CSS length\n * for a shell with a sticky bar that stays above them. They span the full height by default.\n */\n offset?: string\n\n /** Classes for the panel itself. */\n className?: string\n children: ReactNode\n}\n\n/**\n * A panel sliding in from the left edge over a scrim: the phone's navigation drawer. Escape,\n * a tap on the scrim, a swipe to the left and a press on the trigger all close it.\n */\nfunction SideDrawer({ trigger, offset, className, children, ...props }: SideDrawerProps) {\n // The scrim and the panel hang below whatever the shell keeps above them, so the bar holding\n // the trigger is never dimmed and stays in reach.\n const inset = { top: offset }\n\n return (\n <Drawer.Root swipeDirection=\"left\" {...props}>\n <Drawer.Trigger render={trigger} />\n\n <Drawer.Portal>\n <Drawer.Backdrop\n style={inset}\n className={cn(\"fixed inset-0 z-50 bg-scrim\", drawerBackdropClasses)}\n />\n\n <Drawer.Viewport style={inset} className=\"fixed inset-0 z-50 flex\">\n <Drawer.Popup className={cn(sidePopup, className)}>\n <Drawer.Content className=\"flex min-h-0 flex-1 touch-auto flex-col overflow-y-auto overscroll-contain\">\n {children}\n </Drawer.Content>\n </Drawer.Popup>\n </Drawer.Viewport>\n </Drawer.Portal>\n </Drawer.Root>\n )\n}\n\nexport {\n Dialog,\n DialogBody,\n DialogClose,\n DialogContent,\n DialogDescription,\n DialogFooter,\n DialogHeader,\n DialogTitle,\n DialogTrigger,\n SideDrawer,\n useDialogSheet,\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA6BA,MAAM,eAAe,cAAc,KAAK;;;;;AAMxC,SAAS,iBAAiB;CACxB,OAAO,IAAI,YAAY;AACzB;;;;;;AAkBA,SAAS,OAAO,OAAoB;CAClC,OAAO,oBAAC,OAAO,MAAR,EAAa,GAAI,MAAQ,CAAA;AAClC;AAEA,SAAS,cAAc,OAAsC;CAC3D,OAAO,oBAACA,SAAgB,SAAjB,EAAyB,GAAI,MAAQ,CAAA;AAC9C;;AAGA,MAAM,qBAAqB,cAAc,KAAK;;AAG9C,SAAS,QAAQ,EAAE,WAAW,GAAG,SAAmC;CAClE,OACE,oBAACA,SAAgB,OAAjB;EACE,QAAQ,oBAAC,QAAD;GAAQ,SAAQ;GAAQ,cAAW;GAAQ,QAAQ,oBAAC,YAAD,CAAa,CAAA;EAAI,CAAA;EACjE;EACX,GAAI;CACL,CAAA;AAEL;AAEA,SAAS,YAAY,OAAoC;CACvD,OAAO,oBAACA,SAAgB,OAAjB,EAAuB,GAAI,MAAQ,CAAA;AAC5C;AAEA,SAAS,kBAAkB,OAA0C;CACnE,OAAO,oBAACA,SAAgB,aAAjB,EAA6B,GAAI,MAAQ,CAAA;AAClD;;;;;;;;AASA,MAAM,yBAAyB,CAC7B,uEACA,sGACF;AAEA,MAAM,gCAAgC,CACpC,GAAG,wBACH,4CACF;;;;;;;;;AAUA,MAAM,6BACJ;AAEF,MAAM,2BAA2B,CAC/B,4BACA,uFACF;;;;;;;AAQA,MAAM,wBAAwB;CAC5B;CACA;CACA;CACA;CACA;AACF;;AAGA,SAAS,cAAc,EAAE,WAAW,GAAG,SAAyC;CAC9E,MAAM,QAAQ,eAAe;CAC7B,MAAM,WAAW,QAAQ,OAAO,WAAWA,SAAgB;CAE3D,OACE,oBAAC,UAAD;EAIE,aAAA;EACA,WAAW,GACT,+BACA,QAAQ,wBAAwB,+BAChC,SACF;EACA,GAAI;CACL,CAAA;AAEL;AAEA,MAAM,wBAAwB,SAAS;CAIrC,MAAM;EACJ;EAIA;EACA,GAAG;EACH;EACA;EACA;CACF;CAEA,UAAU;EACR,MAAM;GACJ,IAAI;GACJ,IAAI;GACJ,IAAI;GACJ,IAAI;GACJ,IAAI;GACJ,OAAO;GACP,OAAO;GACP,OAAO;GACP,OAAO;EACT;;;;;;;EAQA,OAAO;GACL,MAAM;GACN,OAAO;EACT;CACF;CAEA,iBAAiB;EACf,MAAM;EACN,OAAO;CACT;AACF,CAAC;;;;;;;AAQD,MAAM,aAAa;CACjB;CACA;CACA;CACA;CACA;CACA;CACA,GAAG;AACL;AAEA,MAAM,eAAe;CAEnB;CAEA;CAIA;AACF;;;;;;AA2BA,SAAS,cAAc,EACrB,WACA,UACA,MACA,OACA,WACA,SACA,GAAG,SACkB;CACrB,MAAM,QAAQ,cAAc;CAE5B,MAAM,iBAAiB,UAAU,sDAAsD,KAAA;CAEvF,MAAM,OACJ,qBAAA,UAAA,EAAA,UAAA,CACE,oBAAC,oBAAD;EAAoB,OAAO,CAAC,CAAC;EAAY;CAA6B,CAAA,GAGrE,CAAC,aACA,oBAAC,SAAD;EACE,aAAU;EACV,WAAU;CACX,CAAA,CAEH,EAAA,CAAA;CAIJ,IAAI,OACF,OACE,qBAAC,cAAD;EAAc,OAAA;EAAd,UAAA,CACE,oBAAC,eAAD,CAAgB,CAAA,GAEhB,oBAAC,OAAO,UAAR;GAAiB,WAAU;GACzB,UAAA,qBAAC,OAAO,OAAR;IAAc,WAAW,GAAG,UAAU;IAAG,GAAI;IAA7C,UAAA,CAKE,oBAAC,OAAO,OAAR;KACE,cAAW;KACX,UAAU;KACV,WAAU;KAEV,UAAA,oBAAC,QAAD,EAAM,WAAU,qLAAsL,CAAA;IAC1L,CAAA,GAEd,oBAAC,OAAO,SAAR;KAAgB,WAAW,GAAG,cAAc,SAAS;KAAI,UAAA;IAAqB,CAAA,CAClE;;EACC,CAAA,CACL;;CAIlB,OACE,qBAAA,UAAA,EAAA,UAAA,CACE,oBAAC,eAAD,EAAe,WAAW,eAAiB,CAAA,GAE3C,oBAACA,SAAgB,OAAjB;EACE,WAAW,sBAAsB;GAAE;GAAM;GAAO,WAAW,GAAG,gBAAgB,SAAS;EAAE,CAAC;EAC1F,GAAI;EAEH,UAAA;CACoB,CAAA,CACvB,EAAA,CAAA;AAEN;AAEA,SAAS,cAAc,OAA2B;CAChD,OACE,oBAACA,SAAgB,QAAjB,EAAA,UACE,oBAAC,eAAD,EAAe,GAAI,MAAQ,CAAA,EACL,CAAA;AAE5B;;;;;;;AAQA,SAAgB,eAAkB,OAAuC;CAGvE,MAAM,CAAC,MAAM,WAAW,SAAmB,SAAS,IAAI;CAExD,IAAI,SAAS,QAAQ,UAAU,MAC7B,QAAQ,KAAK;CAGf,OAAO,SAAS;AAClB;;;;;;AAOA,SAAS,WAAW,EAAE,WAAW,GAAG,SAAgC;CAClE,MAAM,QAAQ,eAAe;CAE7B,OAGE,oBAAC,OAAD;EAAK,WAAW,GAAG,2BAA2B,SAAS,cAAc,SAAS;EAAG,GAAI;CAAQ,CAAA;AAEjG;AAEA,MAAM,uBAAuB,SAAS;CAEpC,MAAM;CAEN,UAAU;;;;;;;AAOR,UAAU,EACR,MAAM,qBACR,EACF;AACF,CAAC;;;;;;AAaD,SAAS,aAAa,EACpB,OACA,aACA,UACA,WACA,UACA,GAAG,SACiB;CACpB,MAAM,YAAY,IAAI,kBAAkB;CAExC,OACE,qBAAC,eAAD;EACE,MAAK;EACL,aAAU;EACV,WAAW,qBAAqB;GAAE;GAAU;EAAU,CAAC;EACvD,GAAI;EAJN,UAAA;GAME,qBAAC,mBAAD,EAAA,UAAA,CAGE,oBAAC,aAAD;IAAa,QAAQ,oBAAC,oBAAD,EAAoB,WAAU,mBAAoB,CAAA;IACpE,UAAA;GACU,CAAA,GAEZ,eACC,oBAAC,mBAAD;IAAmB,QAAQ,oBAAC,0BAAD,CAA2B,CAAA;IAAI,UAAA;GAA+B,CAAA,CAE1E,EAAA,CAAA;GAElB;GAEA,CAAC,aAKA,oBAAC,OAAD;IACE,WAAW,GACT,4FACA,WAAW,kCAAkC,gCAC/C;IAEA,UAAA,oBAAC,SAAD,CAAU,CAAA;GACP,CAAA;EAEM;;AAEnB;;;;;;AAOA,SAAS,aAAa,EAAE,WAAW,GAAG,SAAgC;CACpE,MAAM,QAAQ,eAAe;CAE7B,OACE,oBAAC,OAAD;EACE,WAAW,GACT,yFAEA,CAAC,SAAS,wBAGV,gBAIA,SAAS,oFACT,SACF;EACA,GAAI;CACL,CAAA;AAEL;AAEA,SAAS,YAAY,OAAsC;CACzD,OAAO,oBAACA,SAAgB,OAAjB,EAAuB,QAAQ,oBAAC,QAAD;EAAQ,SAAQ;EAAY,GAAI;CAAQ,CAAA,EAAI,CAAA;AACpF;;;;;;;AAQA,MAAM,YAAY;CAChB;CACA;CACA;CACA;CACA;CACA;CACA,GAAG;AACL;;;;;AAwBA,SAAS,WAAW,EAAE,SAAS,QAAQ,WAAW,UAAU,GAAG,SAA0B;CAGvF,MAAM,QAAQ,EAAE,KAAK,OAAO;CAE5B,OACE,qBAAC,OAAO,MAAR;EAAa,gBAAe;EAAO,GAAI;EAAvC,UAAA,CACE,oBAAC,OAAO,SAAR,EAAgB,QAAQ,QAAU,CAAA,GAElC,qBAAC,OAAO,QAAR,EAAA,UAAA,CACE,oBAAC,OAAO,UAAR;GACE,OAAO;GACP,WAAW,GAAG,+BAA+B,qBAAqB;EACnE,CAAA,GAED,oBAAC,OAAO,UAAR;GAAiB,OAAO;GAAO,WAAU;GACvC,UAAA,oBAAC,OAAO,OAAR;IAAc,WAAW,GAAG,WAAW,SAAS;IAC9C,UAAA,oBAAC,OAAO,SAAR;KAAgB,WAAU;KACvB;IACa,CAAA;GACJ,CAAA;EACC,CAAA,CACJ,EAAA,CAAA,CACJ;;AAEjB"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Tooltip } from "./tooltip.js";
|
|
2
|
+
import { ComponentProps, PointerEvent, ReactElement } from "react";
|
|
3
|
+
/**
|
|
4
|
+
* What a control needs to carry its reason: the id for its `Tooltip`, its `aria-describedby`
|
|
5
|
+
* with the reason added, the hidden element holding the reason, and a pointer-up handler that
|
|
6
|
+
* opens the tooltip on a tap, for a control kept `disabled`, which never turns a tap into a click.
|
|
7
|
+
*/
|
|
8
|
+
export declare function useDisabledReason(reason: string | undefined, describedBy?: string): {
|
|
9
|
+
triggerId: string;
|
|
10
|
+
describedBy: string | undefined;
|
|
11
|
+
onPointerUp: (event: PointerEvent) => void;
|
|
12
|
+
reasonText: "" | import("react").JSX.Element | undefined;
|
|
13
|
+
};
|
|
14
|
+
interface DisabledReasonProps {
|
|
15
|
+
/** Why the control cannot run. Left empty, the control renders as it is. */
|
|
16
|
+
reason?: string;
|
|
17
|
+
side?: ComponentProps<typeof Tooltip>["side"];
|
|
18
|
+
children: ReactElement<{
|
|
19
|
+
"aria-describedby"?: string;
|
|
20
|
+
}>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Keeps a control that cannot run in place and says why. The control takes `aria-disabled`
|
|
24
|
+
* instead of `disabled`, so it still takes focus and the pointer: a screen reader reads the
|
|
25
|
+
* reason through `aria-describedby`, a pointer or a keyboard focus gets it in a tooltip, and a
|
|
26
|
+
* tap opens the tooltip too. A click, or the Enter or Space that becomes one, does nothing
|
|
27
|
+
* while the reason stands, a link or a Base UI trigger included. A text field under a reason
|
|
28
|
+
* also needs `readOnly`, which only its own component can set.
|
|
29
|
+
*/
|
|
30
|
+
export declare function DisabledReason({ reason, side, children }: DisabledReasonProps): import("react").JSX.Element;
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { formatIdList } from "../lib/aria.js";
|
|
3
|
+
import { Tooltip, showTooltip } from "./tooltip.js";
|
|
4
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
import { cloneElement, useId } from "react";
|
|
6
|
+
// src/components/disabled-reason.tsx
|
|
7
|
+
/**
|
|
8
|
+
* Stops the handler a Base UI trigger runs after this one. A menu or a select opens on
|
|
9
|
+
* mousedown or an arrow key, not only on a click.
|
|
10
|
+
*/
|
|
11
|
+
function stopBaseUI(event) {
|
|
12
|
+
event.preventBaseUIHandler?.();
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* What a control needs to carry its reason: the id for its `Tooltip`, its `aria-describedby`
|
|
16
|
+
* with the reason added, the hidden element holding the reason, and a pointer-up handler that
|
|
17
|
+
* opens the tooltip on a tap, for a control kept `disabled`, which never turns a tap into a click.
|
|
18
|
+
*/
|
|
19
|
+
function useDisabledReason(reason, describedBy) {
|
|
20
|
+
const id = useId();
|
|
21
|
+
const triggerId = `${id}-trigger`;
|
|
22
|
+
function onPointerUp(event) {
|
|
23
|
+
if (reason && event.pointerType !== "mouse") showTooltip(triggerId);
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
triggerId,
|
|
27
|
+
describedBy: formatIdList(describedBy, !!reason && id),
|
|
28
|
+
onPointerUp,
|
|
29
|
+
reasonText: reason && /* @__PURE__ */ jsx("span", {
|
|
30
|
+
id,
|
|
31
|
+
hidden: true,
|
|
32
|
+
children: reason
|
|
33
|
+
})
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Keeps a control that cannot run in place and says why. The control takes `aria-disabled`
|
|
38
|
+
* instead of `disabled`, so it still takes focus and the pointer: a screen reader reads the
|
|
39
|
+
* reason through `aria-describedby`, a pointer or a keyboard focus gets it in a tooltip, and a
|
|
40
|
+
* tap opens the tooltip too. A click, or the Enter or Space that becomes one, does nothing
|
|
41
|
+
* while the reason stands, a link or a Base UI trigger included. A text field under a reason
|
|
42
|
+
* also needs `readOnly`, which only its own component can set.
|
|
43
|
+
*/
|
|
44
|
+
function DisabledReason({ reason, side = "top", children }) {
|
|
45
|
+
const { triggerId, describedBy, reasonText } = useDisabledReason(reason, children.props["aria-describedby"]);
|
|
46
|
+
if (!reason) return children;
|
|
47
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Tooltip, {
|
|
48
|
+
id: triggerId,
|
|
49
|
+
tooltip: reason,
|
|
50
|
+
side,
|
|
51
|
+
children: cloneElement(children, {
|
|
52
|
+
disabled: false,
|
|
53
|
+
"aria-disabled": true,
|
|
54
|
+
"aria-describedby": describedBy,
|
|
55
|
+
onClick: (event) => {
|
|
56
|
+
event.preventDefault();
|
|
57
|
+
stopBaseUI(event);
|
|
58
|
+
showTooltip(triggerId);
|
|
59
|
+
},
|
|
60
|
+
onMouseDown: stopBaseUI,
|
|
61
|
+
onKeyDown: stopBaseUI
|
|
62
|
+
})
|
|
63
|
+
}), reasonText] });
|
|
64
|
+
}
|
|
65
|
+
export { DisabledReason, useDisabledReason };
|
|
66
|
+
|
|
67
|
+
//# sourceMappingURL=disabled-reason.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"disabled-reason.js","names":[],"sources":["../../src/components/disabled-reason.tsx"],"sourcesContent":["\"use client\"\n\nimport {\n cloneElement,\n type ComponentProps,\n type PointerEvent,\n type ReactElement,\n type SyntheticEvent,\n useId,\n} from \"react\"\nimport { formatIdList } from \"../lib/aria\"\nimport { showTooltip, Tooltip } from \"./tooltip\"\n\ntype BaseUIEvent = SyntheticEvent & { preventBaseUIHandler?: () => void }\n\n/**\n * Stops the handler a Base UI trigger runs after this one. A menu or a select opens on\n * mousedown or an arrow key, not only on a click.\n */\nfunction stopBaseUI(event: BaseUIEvent) {\n event.preventBaseUIHandler?.()\n}\n\n/**\n * What a control needs to carry its reason: the id for its `Tooltip`, its `aria-describedby`\n * with the reason added, the hidden element holding the reason, and a pointer-up handler that\n * opens the tooltip on a tap, for a control kept `disabled`, which never turns a tap into a click.\n */\nexport function useDisabledReason(reason: string | undefined, describedBy?: string) {\n const id = useId()\n const triggerId = `${id}-trigger`\n\n function onPointerUp(event: PointerEvent) {\n if (reason && event.pointerType !== \"mouse\") showTooltip(triggerId)\n }\n\n return {\n triggerId,\n describedBy: formatIdList(describedBy, !!reason && id),\n onPointerUp,\n reasonText: reason && (\n <span id={id} hidden>\n {reason}\n </span>\n ),\n }\n}\n\ninterface DisabledReasonProps {\n /** Why the control cannot run. Left empty, the control renders as it is. */\n reason?: string\n side?: ComponentProps<typeof Tooltip>[\"side\"]\n children: ReactElement<{ \"aria-describedby\"?: string }>\n}\n\n/**\n * Keeps a control that cannot run in place and says why. The control takes `aria-disabled`\n * instead of `disabled`, so it still takes focus and the pointer: a screen reader reads the\n * reason through `aria-describedby`, a pointer or a keyboard focus gets it in a tooltip, and a\n * tap opens the tooltip too. A click, or the Enter or Space that becomes one, does nothing\n * while the reason stands, a link or a Base UI trigger included. A text field under a reason\n * also needs `readOnly`, which only its own component can set.\n */\nexport function DisabledReason({ reason, side = \"top\", children }: DisabledReasonProps) {\n const { triggerId, describedBy, reasonText } = useDisabledReason(\n reason,\n children.props[\"aria-describedby\"],\n )\n\n if (!reason) return children\n\n return (\n <>\n <Tooltip id={triggerId} tooltip={reason} side={side}>\n {cloneElement(children, {\n disabled: false,\n \"aria-disabled\": true,\n \"aria-describedby\": describedBy,\n onClick: (event: BaseUIEvent) => {\n event.preventDefault()\n stopBaseUI(event)\n showTooltip(triggerId)\n },\n onMouseDown: stopBaseUI,\n onKeyDown: stopBaseUI,\n } as Record<string, unknown>)}\n </Tooltip>\n\n {reasonText}\n </>\n )\n}\n"],"mappings":";;;;;;;;;;AAmBA,SAAS,WAAW,OAAoB;CACtC,MAAM,uBAAuB;AAC/B;;;;;;AAOA,SAAgB,kBAAkB,QAA4B,aAAsB;CAClF,MAAM,KAAK,MAAM;CACjB,MAAM,YAAY,GAAG,GAAG;CAExB,SAAS,YAAY,OAAqB;EACxC,IAAI,UAAU,MAAM,gBAAgB,SAAS,YAAY,SAAS;CACpE;CAEA,OAAO;EACL;EACA,aAAa,aAAa,aAAa,CAAC,CAAC,UAAU,EAAE;EACrD;EACA,YAAY,UACV,oBAAC,QAAD;GAAU;GAAI,QAAA;GACX,UAAA;EACG,CAAA;CAEV;AACF;;;;;;;;;AAiBA,SAAgB,eAAe,EAAE,QAAQ,OAAO,OAAO,YAAiC;CACtF,MAAM,EAAE,WAAW,aAAa,eAAe,kBAC7C,QACA,SAAS,MAAM,mBACjB;CAEA,IAAI,CAAC,QAAQ,OAAO;CAEpB,OACE,qBAAA,UAAA,EAAA,UAAA,CACE,oBAAC,SAAD;EAAS,IAAI;EAAW,SAAS;EAAc;EAC5C,UAAA,aAAa,UAAU;GACtB,UAAU;GACV,iBAAiB;GACjB,oBAAoB;GACpB,UAAU,UAAuB;IAC/B,MAAM,eAAe;IACrB,WAAW,KAAK;IAChB,YAAY,SAAS;GACvB;GACA,aAAa;GACb,WAAW;EACb,CAA4B;CACrB,CAAA,GAER,UACD,EAAA,CAAA;AAEN"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { VariantProps } from "../lib/variants.js";
|
|
2
|
+
import { ComponentProps, ReactNode } from "react";
|
|
3
|
+
declare const emptyStateVariants: import("tailwind-variants").TVReturnType<{
|
|
4
|
+
variant: {
|
|
5
|
+
block: {
|
|
6
|
+
root: string;
|
|
7
|
+
title: string;
|
|
8
|
+
description: string;
|
|
9
|
+
action: string;
|
|
10
|
+
};
|
|
11
|
+
inline: {
|
|
12
|
+
root: string;
|
|
13
|
+
title: string;
|
|
14
|
+
action: string;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
size: {
|
|
18
|
+
md: {};
|
|
19
|
+
sm: {};
|
|
20
|
+
};
|
|
21
|
+
}, {
|
|
22
|
+
root: string;
|
|
23
|
+
icon: string[];
|
|
24
|
+
content: string;
|
|
25
|
+
title: string;
|
|
26
|
+
description: string;
|
|
27
|
+
action: string;
|
|
28
|
+
}, undefined, undefined, undefined, undefined>;
|
|
29
|
+
type EmptyStateProps = Omit<ComponentProps<"div">, "title"> & VariantProps<typeof emptyStateVariants> & {
|
|
30
|
+
icon?: ReactNode;
|
|
31
|
+
title: ReactNode;
|
|
32
|
+
description?: ReactNode;
|
|
33
|
+
action?: ReactNode;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* The one empty state. `block` fills a card or list with a centered icon, title and
|
|
37
|
+
* description, `sm` for one inside a short list; `inline` is a single muted line inside a
|
|
38
|
+
* form section.
|
|
39
|
+
*/
|
|
40
|
+
export declare function EmptyState({ icon, title, description, action, variant, size, className, ...props }: EmptyStateProps): import("react").JSX.Element;
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { descriptionClasses, iconTileClasses } from "../lib/classes.js";
|
|
2
|
+
import { cn, variants } from "../lib/variants.js";
|
|
3
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
// src/components/empty-state.tsx
|
|
5
|
+
const emptyStateVariants = variants({
|
|
6
|
+
slots: {
|
|
7
|
+
root: "",
|
|
8
|
+
icon: [iconTileClasses, "size-10"],
|
|
9
|
+
content: "space-y-2",
|
|
10
|
+
title: "text-balance",
|
|
11
|
+
description: descriptionClasses,
|
|
12
|
+
action: ""
|
|
13
|
+
},
|
|
14
|
+
variants: {
|
|
15
|
+
variant: {
|
|
16
|
+
block: {
|
|
17
|
+
root: "flex flex-col items-center gap-3 px-6 py-12 text-center",
|
|
18
|
+
title: "font-medium text-sm",
|
|
19
|
+
description: "mx-auto max-w-80",
|
|
20
|
+
action: "mt-1"
|
|
21
|
+
},
|
|
22
|
+
inline: {
|
|
23
|
+
root: "py-5",
|
|
24
|
+
title: "text-ink-muted text-sm",
|
|
25
|
+
action: "mt-3"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
size: {
|
|
29
|
+
md: {},
|
|
30
|
+
sm: {}
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
compoundVariants: [{
|
|
34
|
+
variant: "block",
|
|
35
|
+
size: "sm",
|
|
36
|
+
class: {
|
|
37
|
+
root: "py-7",
|
|
38
|
+
icon: "size-9 [&_svg]:size-4.5",
|
|
39
|
+
description: "max-w-md"
|
|
40
|
+
}
|
|
41
|
+
}],
|
|
42
|
+
defaultVariants: {
|
|
43
|
+
variant: "block",
|
|
44
|
+
size: "md"
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
/**
|
|
48
|
+
* The one empty state. `block` fills a card or list with a centered icon, title and
|
|
49
|
+
* description, `sm` for one inside a short list; `inline` is a single muted line inside a
|
|
50
|
+
* form section.
|
|
51
|
+
*/
|
|
52
|
+
function EmptyState({ icon, title, description, action, variant, size, className, ...props }) {
|
|
53
|
+
const styles = emptyStateVariants({
|
|
54
|
+
variant,
|
|
55
|
+
size
|
|
56
|
+
});
|
|
57
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
58
|
+
className: cn(styles.root(), className),
|
|
59
|
+
...props,
|
|
60
|
+
children: [
|
|
61
|
+
icon && /* @__PURE__ */ jsx("div", {
|
|
62
|
+
className: styles.icon(),
|
|
63
|
+
children: icon
|
|
64
|
+
}),
|
|
65
|
+
/* @__PURE__ */ jsxs("div", {
|
|
66
|
+
className: styles.content(),
|
|
67
|
+
children: [/* @__PURE__ */ jsx("p", {
|
|
68
|
+
className: styles.title(),
|
|
69
|
+
children: title
|
|
70
|
+
}), description && /* @__PURE__ */ jsx("p", {
|
|
71
|
+
className: styles.description(),
|
|
72
|
+
children: description
|
|
73
|
+
})]
|
|
74
|
+
}),
|
|
75
|
+
action && /* @__PURE__ */ jsx("div", {
|
|
76
|
+
className: styles.action(),
|
|
77
|
+
children: action
|
|
78
|
+
})
|
|
79
|
+
]
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
export { EmptyState };
|
|
83
|
+
|
|
84
|
+
//# sourceMappingURL=empty-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"empty-state.js","names":[],"sources":["../../src/components/empty-state.tsx"],"sourcesContent":["import type { ComponentProps, ReactNode } from \"react\"\nimport { descriptionClasses, iconTileClasses } from \"../lib/classes\"\nimport { cn, variants, type VariantProps } from \"../lib/variants\"\n\nconst emptyStateVariants = variants({\n slots: {\n root: \"\",\n icon: [iconTileClasses, \"size-10\"],\n content: \"space-y-2\",\n title: \"text-balance\",\n description: descriptionClasses,\n action: \"\",\n },\n\n variants: {\n variant: {\n block: {\n root: \"flex flex-col items-center gap-3 px-6 py-12 text-center\",\n title: \"font-medium text-sm\",\n description: \"mx-auto max-w-80\",\n action: \"mt-1\",\n },\n inline: {\n // No horizontal padding: an inline state always sits inside a panel, card or dialog\n // that already pads its own content, and a second inset reads as an indent.\n root: \"py-5\",\n title: \"text-ink-muted text-sm\",\n action: \"mt-3\",\n },\n },\n size: {\n md: {},\n sm: {},\n },\n },\n\n compoundVariants: [\n // The block at the scale of a short list: a 36px tile with an 18px glyph, a wider sentence.\n {\n variant: \"block\",\n size: \"sm\",\n class: { root: \"py-7\", icon: \"size-9 [&_svg]:size-4.5\", description: \"max-w-md\" },\n },\n ],\n\n defaultVariants: {\n variant: \"block\",\n size: \"md\",\n },\n})\n\ntype EmptyStateProps = Omit<ComponentProps<\"div\">, \"title\"> &\n VariantProps<typeof emptyStateVariants> & {\n icon?: ReactNode\n title: ReactNode\n description?: ReactNode\n action?: ReactNode\n }\n\n/**\n * The one empty state. `block` fills a card or list with a centered icon, title and\n * description, `sm` for one inside a short list; `inline` is a single muted line inside a\n * form section.\n */\nexport function EmptyState({\n icon,\n title,\n description,\n action,\n variant,\n size,\n className,\n ...props\n}: EmptyStateProps) {\n const styles = emptyStateVariants({ variant, size })\n\n return (\n <div className={cn(styles.root(), className)} {...props}>\n {icon && <div className={styles.icon()}>{icon}</div>}\n\n <div className={styles.content()}>\n <p className={styles.title()}>{title}</p>\n {description && <p className={styles.description()}>{description}</p>}\n </div>\n\n {action && <div className={styles.action()}>{action}</div>}\n </div>\n )\n}\n"],"mappings":";;;;AAIA,MAAM,qBAAqB,SAAS;CAClC,OAAO;EACL,MAAM;EACN,MAAM,CAAC,iBAAiB,SAAS;EACjC,SAAS;EACT,OAAO;EACP,aAAa;EACb,QAAQ;CACV;CAEA,UAAU;EACR,SAAS;GACP,OAAO;IACL,MAAM;IACN,OAAO;IACP,aAAa;IACb,QAAQ;GACV;GACA,QAAQ;IAGN,MAAM;IACN,OAAO;IACP,QAAQ;GACV;EACF;EACA,MAAM;GACJ,IAAI,CAAC;GACL,IAAI,CAAC;EACP;CACF;CAEA,kBAAkB,CAEhB;EACE,SAAS;EACT,MAAM;EACN,OAAO;GAAE,MAAM;GAAQ,MAAM;GAA2B,aAAa;EAAW;CAClF,CACF;CAEA,iBAAiB;EACf,SAAS;EACT,MAAM;CACR;AACF,CAAC;;;;;;AAeD,SAAgB,WAAW,EACzB,MACA,OACA,aACA,QACA,SACA,MACA,WACA,GAAG,SACe;CAClB,MAAM,SAAS,mBAAmB;EAAE;EAAS;CAAK,CAAC;CAEnD,OACE,qBAAC,OAAD;EAAK,WAAW,GAAG,OAAO,KAAK,GAAG,SAAS;EAAG,GAAI;EAAlD,UAAA;GACG,QAAQ,oBAAC,OAAD;IAAK,WAAW,OAAO,KAAK;IAAI,UAAA;GAAU,CAAA;GAEnD,qBAAC,OAAD;IAAK,WAAW,OAAO,QAAQ;IAA/B,UAAA,CACE,oBAAC,KAAD;KAAG,WAAW,OAAO,MAAM;KAAI,UAAA;IAAS,CAAA,GACvC,eAAe,oBAAC,KAAD;KAAG,WAAW,OAAO,YAAY;KAAI,UAAA;IAAe,CAAA,CACjE;;GAEJ,UAAU,oBAAC,OAAD;IAAK,WAAW,OAAO,OAAO;IAAI,UAAA;GAAY,CAAA;EACtD;;AAET"}
|