@slipstream-ui/core 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +135 -15
- package/dist/index.d.ts +135 -15
- package/dist/index.js +923 -710
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +922 -710
- package/dist/index.mjs.map +1 -1
- package/dist/manifests/accordion.manifest.json +7 -1
- package/dist/manifests/alert.manifest.json +1 -1
- package/dist/manifests/announcement-bar.manifest.json +1 -1
- package/dist/manifests/app-shell.manifest.json +1 -1
- package/dist/manifests/applied-filters.manifest.json +1 -1
- package/dist/manifests/article-card.manifest.json +1 -1
- package/dist/manifests/auth-layout.manifest.json +19 -1
- package/dist/manifests/autocomplete.manifest.json +1 -1
- package/dist/manifests/avatar.manifest.json +1 -1
- package/dist/manifests/badge.manifest.json +13 -1
- package/dist/manifests/block.manifest.json +1 -1
- package/dist/manifests/bottom-nav.manifest.json +130 -0
- package/dist/manifests/breadcrumb.manifest.json +1 -1
- package/dist/manifests/button-group.manifest.json +1 -1
- package/dist/manifests/button.manifest.json +1 -1
- package/dist/manifests/card.manifest.json +1 -1
- package/dist/manifests/checkbox.manifest.json +1 -1
- package/dist/manifests/comparison-table.manifest.json +1 -1
- package/dist/manifests/confirm-dialog.manifest.json +1 -1
- package/dist/manifests/contact-strip.manifest.json +1 -1
- package/dist/manifests/container.manifest.json +1 -1
- package/dist/manifests/cta-section.manifest.json +1 -1
- package/dist/manifests/data-table.manifest.json +1 -1
- package/dist/manifests/date-picker.manifest.json +1 -1
- package/dist/manifests/date-range-picker.manifest.json +1 -1
- package/dist/manifests/deal-card.manifest.json +1 -1
- package/dist/manifests/dialog.manifest.json +1 -1
- package/dist/manifests/document-card.manifest.json +1 -1
- package/dist/manifests/drawer.manifest.json +48 -2
- package/dist/manifests/empty-state.manifest.json +1 -1
- package/dist/manifests/entity-card.manifest.json +1 -1
- package/dist/manifests/feature-grid.manifest.json +1 -1
- package/dist/manifests/feature-row.manifest.json +1 -1
- package/dist/manifests/fieldset.manifest.json +1 -1
- package/dist/manifests/file-upload.manifest.json +1 -1
- package/dist/manifests/filter-bar.manifest.json +1 -1
- package/dist/manifests/filter-chips.manifest.json +1 -1
- package/dist/manifests/filter-panel.manifest.json +1 -1
- package/dist/manifests/flex.manifest.json +1 -1
- package/dist/manifests/form-field.manifest.json +1 -1
- package/dist/manifests/form-layout.manifest.json +1 -1
- package/dist/manifests/form.manifest.json +1 -1
- package/dist/manifests/grid.manifest.json +1 -1
- package/dist/manifests/heading.manifest.json +1 -1
- package/dist/manifests/hero.manifest.json +1 -1
- package/dist/manifests/input-group.manifest.json +1 -1
- package/dist/manifests/input.manifest.json +1 -1
- package/dist/manifests/label.manifest.json +1 -1
- package/dist/manifests/link-tabs.manifest.json +1 -1
- package/dist/manifests/link.manifest.json +1 -1
- package/dist/manifests/list.manifest.json +1 -1
- package/dist/manifests/load-more.manifest.json +1 -1
- package/dist/manifests/logo-cloud.manifest.json +1 -1
- package/dist/manifests/menu.manifest.json +1 -1
- package/dist/manifests/metric-card.manifest.json +36 -4
- package/dist/manifests/multi-select.manifest.json +1 -1
- package/dist/manifests/newsletter.manifest.json +1 -1
- package/dist/manifests/page-header.manifest.json +7 -1
- package/dist/manifests/pagination.manifest.json +1 -1
- package/dist/manifests/password-input.manifest.json +1 -1
- package/dist/manifests/popover.manifest.json +1 -1
- package/dist/manifests/process-steps.manifest.json +1 -1
- package/dist/manifests/progress.manifest.json +1 -1
- package/dist/manifests/prose.manifest.json +1 -1
- package/dist/manifests/radio.manifest.json +1 -1
- package/dist/manifests/range-slider.manifest.json +1 -1
- package/dist/manifests/search.manifest.json +1 -1
- package/dist/manifests/section-heading.manifest.json +1 -1
- package/dist/manifests/section.manifest.json +1 -1
- package/dist/manifests/segmented-control.manifest.json +1 -1
- package/dist/manifests/select-menu.manifest.json +1 -1
- package/dist/manifests/select.manifest.json +1 -1
- package/dist/manifests/separator.manifest.json +1 -1
- package/dist/manifests/site-footer.manifest.json +1 -1
- package/dist/manifests/site-header.manifest.json +1 -1
- package/dist/manifests/skeleton.manifest.json +1 -1
- package/dist/manifests/spinner.manifest.json +1 -1
- package/dist/manifests/stat-band.manifest.json +1 -1
- package/dist/manifests/stepper.manifest.json +1 -1
- package/dist/manifests/switch.manifest.json +1 -1
- package/dist/manifests/table-card.manifest.json +1 -1
- package/dist/manifests/table-of-contents.manifest.json +1 -1
- package/dist/manifests/table.manifest.json +1 -1
- package/dist/manifests/tabs.manifest.json +1 -1
- package/dist/manifests/testimonial.manifest.json +1 -1
- package/dist/manifests/text.manifest.json +1 -1
- package/dist/manifests/textarea.manifest.json +1 -1
- package/dist/manifests/theme-toggle.manifest.json +1 -1
- package/dist/manifests/time-picker.manifest.json +1 -1
- package/dist/manifests/timeline.manifest.json +1 -1
- package/dist/manifests/toast.manifest.json +1 -1
- package/dist/manifests/tombstone-card.manifest.json +1 -1
- package/dist/manifests/tooltip.manifest.json +1 -1
- package/dist/src/components/accordion/Accordion.d.ts +17 -1
- package/dist/src/components/accordion/Accordion.js +5 -1
- package/dist/src/components/accordion/Accordion.js.map +1 -1
- package/dist/src/components/accordion/Accordion.mjs +5 -1
- package/dist/src/components/accordion/Accordion.mjs.map +1 -1
- package/dist/src/components/auth-layout/AuthLayout.d.ts +14 -2
- package/dist/src/components/auth-layout/AuthLayout.js +10 -2
- package/dist/src/components/auth-layout/AuthLayout.js.map +1 -1
- package/dist/src/components/auth-layout/AuthLayout.mjs +10 -2
- package/dist/src/components/auth-layout/AuthLayout.mjs.map +1 -1
- package/dist/src/components/badge/Badge.d.ts +2 -0
- package/dist/src/components/badge/Badge.js +9 -3
- package/dist/src/components/badge/Badge.js.map +1 -1
- package/dist/src/components/badge/Badge.mjs +9 -3
- package/dist/src/components/badge/Badge.mjs.map +1 -1
- package/dist/src/components/bottom-nav/BottomNav.d.ts +36 -0
- package/dist/src/components/bottom-nav/BottomNav.js +90 -0
- package/dist/src/components/bottom-nav/BottomNav.js.map +1 -0
- package/dist/src/components/bottom-nav/BottomNav.mjs +66 -0
- package/dist/src/components/bottom-nav/BottomNav.mjs.map +1 -0
- package/dist/src/components/bottom-nav/index.d.ts +1 -0
- package/dist/src/components/bottom-nav/index.js +23 -0
- package/dist/src/components/bottom-nav/index.js.map +1 -0
- package/dist/src/components/bottom-nav/index.mjs +2 -0
- package/dist/src/components/bottom-nav/index.mjs.map +1 -0
- package/dist/src/components/drawer/Drawer.d.ts +25 -2
- package/dist/src/components/drawer/Drawer.js +97 -6
- package/dist/src/components/drawer/Drawer.js.map +1 -1
- package/dist/src/components/drawer/Drawer.mjs +97 -6
- package/dist/src/components/drawer/Drawer.mjs.map +1 -1
- package/dist/src/components/empty-state/EmptyState.d.ts +13 -4
- package/dist/src/components/empty-state/EmptyState.js +13 -1
- package/dist/src/components/empty-state/EmptyState.js.map +1 -1
- package/dist/src/components/empty-state/EmptyState.mjs +13 -1
- package/dist/src/components/empty-state/EmptyState.mjs.map +1 -1
- package/dist/src/components/metric-card/MetricCard.d.ts +23 -4
- package/dist/src/components/metric-card/MetricCard.js +32 -5
- package/dist/src/components/metric-card/MetricCard.js.map +1 -1
- package/dist/src/components/metric-card/MetricCard.mjs +32 -5
- package/dist/src/components/metric-card/MetricCard.mjs.map +1 -1
- package/dist/src/components/page-header/PageHeader.d.ts +4 -0
- package/dist/src/components/page-header/PageHeader.js +3 -2
- package/dist/src/components/page-header/PageHeader.js.map +1 -1
- package/dist/src/components/page-header/PageHeader.mjs +3 -2
- package/dist/src/components/page-header/PageHeader.mjs.map +1 -1
- package/dist/src/components/separator/Separator.d.ts +3 -3
- package/dist/src/index.d.ts +1 -0
- package/dist/styles-full.css +1 -1
- package/dist/styles.css +1 -1
- package/package.json +3 -3
- package/src/components/accordion/Accordion.test.tsx +31 -0
- package/src/components/accordion/Accordion.tsx +27 -2
- package/src/components/auth-layout/AuthLayout.test.tsx +36 -0
- package/src/components/auth-layout/AuthLayout.tsx +20 -3
- package/src/components/badge/Badge.test.tsx +7 -0
- package/src/components/badge/Badge.tsx +8 -2
- package/src/components/bottom-nav/BottomNav.test.tsx +48 -0
- package/src/components/bottom-nav/BottomNav.tsx +117 -0
- package/src/components/bottom-nav/index.ts +1 -0
- package/src/components/drawer/Drawer.test.tsx +86 -1
- package/src/components/drawer/Drawer.tsx +135 -7
- package/src/components/empty-state/EmptyState.test.tsx +26 -1
- package/src/components/empty-state/EmptyState.tsx +40 -3
- package/src/components/metric-card/MetricCard.test.tsx +32 -0
- package/src/components/metric-card/MetricCard.tsx +45 -7
- package/src/components/page-header/PageHeader.test.tsx +13 -0
- package/src/components/page-header/PageHeader.tsx +5 -2
- package/src/index.ts +1 -0
- package/src/manifests/accordion.manifest.json +7 -1
- package/src/manifests/alert.manifest.json +1 -1
- package/src/manifests/announcement-bar.manifest.json +1 -1
- package/src/manifests/app-shell.manifest.json +1 -1
- package/src/manifests/applied-filters.manifest.json +1 -1
- package/src/manifests/article-card.manifest.json +1 -1
- package/src/manifests/auth-layout.manifest.json +19 -1
- package/src/manifests/autocomplete.manifest.json +1 -1
- package/src/manifests/avatar.manifest.json +1 -1
- package/src/manifests/badge.manifest.json +13 -1
- package/src/manifests/block.manifest.json +1 -1
- package/src/manifests/bottom-nav.manifest.json +130 -0
- package/src/manifests/breadcrumb.manifest.json +1 -1
- package/src/manifests/button-group.manifest.json +1 -1
- package/src/manifests/button.manifest.json +1 -1
- package/src/manifests/card.manifest.json +1 -1
- package/src/manifests/checkbox.manifest.json +1 -1
- package/src/manifests/comparison-table.manifest.json +1 -1
- package/src/manifests/confirm-dialog.manifest.json +1 -1
- package/src/manifests/contact-strip.manifest.json +1 -1
- package/src/manifests/container.manifest.json +1 -1
- package/src/manifests/cta-section.manifest.json +1 -1
- package/src/manifests/data-table.manifest.json +1 -1
- package/src/manifests/date-picker.manifest.json +1 -1
- package/src/manifests/date-range-picker.manifest.json +1 -1
- package/src/manifests/deal-card.manifest.json +1 -1
- package/src/manifests/dialog.manifest.json +1 -1
- package/src/manifests/document-card.manifest.json +1 -1
- package/src/manifests/drawer.manifest.json +48 -2
- package/src/manifests/empty-state.manifest.json +1 -1
- package/src/manifests/entity-card.manifest.json +1 -1
- package/src/manifests/feature-grid.manifest.json +1 -1
- package/src/manifests/feature-row.manifest.json +1 -1
- package/src/manifests/fieldset.manifest.json +1 -1
- package/src/manifests/file-upload.manifest.json +1 -1
- package/src/manifests/filter-bar.manifest.json +1 -1
- package/src/manifests/filter-chips.manifest.json +1 -1
- package/src/manifests/filter-panel.manifest.json +1 -1
- package/src/manifests/flex.manifest.json +1 -1
- package/src/manifests/form-field.manifest.json +1 -1
- package/src/manifests/form-layout.manifest.json +1 -1
- package/src/manifests/form.manifest.json +1 -1
- package/src/manifests/grid.manifest.json +1 -1
- package/src/manifests/heading.manifest.json +1 -1
- package/src/manifests/hero.manifest.json +1 -1
- package/src/manifests/input-group.manifest.json +1 -1
- package/src/manifests/input.manifest.json +1 -1
- package/src/manifests/label.manifest.json +1 -1
- package/src/manifests/link-tabs.manifest.json +1 -1
- package/src/manifests/link.manifest.json +1 -1
- package/src/manifests/list.manifest.json +1 -1
- package/src/manifests/load-more.manifest.json +1 -1
- package/src/manifests/logo-cloud.manifest.json +1 -1
- package/src/manifests/menu.manifest.json +1 -1
- package/src/manifests/metric-card.manifest.json +36 -4
- package/src/manifests/multi-select.manifest.json +1 -1
- package/src/manifests/newsletter.manifest.json +1 -1
- package/src/manifests/page-header.manifest.json +7 -1
- package/src/manifests/pagination.manifest.json +1 -1
- package/src/manifests/password-input.manifest.json +1 -1
- package/src/manifests/popover.manifest.json +1 -1
- package/src/manifests/process-steps.manifest.json +1 -1
- package/src/manifests/progress.manifest.json +1 -1
- package/src/manifests/prose.manifest.json +1 -1
- package/src/manifests/radio.manifest.json +1 -1
- package/src/manifests/range-slider.manifest.json +1 -1
- package/src/manifests/search.manifest.json +1 -1
- package/src/manifests/section-heading.manifest.json +1 -1
- package/src/manifests/section.manifest.json +1 -1
- package/src/manifests/segmented-control.manifest.json +1 -1
- package/src/manifests/select-menu.manifest.json +1 -1
- package/src/manifests/select.manifest.json +1 -1
- package/src/manifests/separator.manifest.json +1 -1
- package/src/manifests/site-footer.manifest.json +1 -1
- package/src/manifests/site-header.manifest.json +1 -1
- package/src/manifests/skeleton.manifest.json +1 -1
- package/src/manifests/spinner.manifest.json +1 -1
- package/src/manifests/stat-band.manifest.json +1 -1
- package/src/manifests/stepper.manifest.json +1 -1
- package/src/manifests/switch.manifest.json +1 -1
- package/src/manifests/table-card.manifest.json +1 -1
- package/src/manifests/table-of-contents.manifest.json +1 -1
- package/src/manifests/table.manifest.json +1 -1
- package/src/manifests/tabs.manifest.json +1 -1
- package/src/manifests/testimonial.manifest.json +1 -1
- package/src/manifests/text.manifest.json +1 -1
- package/src/manifests/textarea.manifest.json +1 -1
- package/src/manifests/theme-toggle.manifest.json +1 -1
- package/src/manifests/time-picker.manifest.json +1 -1
- package/src/manifests/timeline.manifest.json +1 -1
- package/src/manifests/toast.manifest.json +1 -1
- package/src/manifests/tombstone-card.manifest.json +1 -1
- package/src/manifests/tooltip.manifest.json +1 -1
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var BottomNav_exports = {};
|
|
20
|
+
__export(BottomNav_exports, {
|
|
21
|
+
BottomNav: () => BottomNav
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(BottomNav_exports);
|
|
24
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
25
|
+
var import_cn = require("../../utils/cn.js");
|
|
26
|
+
const tabClass = "relative flex min-h-14 w-full flex-col items-center justify-center gap-0.5 px-2 py-2 text-[11px] font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset";
|
|
27
|
+
function BottomNav({
|
|
28
|
+
items,
|
|
29
|
+
linkComponent,
|
|
30
|
+
linkHrefProp = "href",
|
|
31
|
+
label = "Primary",
|
|
32
|
+
fixed = true,
|
|
33
|
+
mobileOnly = true,
|
|
34
|
+
className,
|
|
35
|
+
...props
|
|
36
|
+
}) {
|
|
37
|
+
const LinkEl = linkComponent ?? "a";
|
|
38
|
+
const destination = (href) => linkHrefProp === "to" ? { to: href } : { href };
|
|
39
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
40
|
+
"nav",
|
|
41
|
+
{
|
|
42
|
+
"aria-label": label,
|
|
43
|
+
className: (0, import_cn.cn)(
|
|
44
|
+
"w-full border-t border-border bg-background pb-[env(safe-area-inset-bottom)]",
|
|
45
|
+
fixed && "fixed inset-x-0 bottom-0 z-40",
|
|
46
|
+
mobileOnly && "md:hidden",
|
|
47
|
+
className
|
|
48
|
+
),
|
|
49
|
+
...props,
|
|
50
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
51
|
+
"ul",
|
|
52
|
+
{
|
|
53
|
+
className: "mx-auto grid w-full max-w-lg",
|
|
54
|
+
style: { gridTemplateColumns: `repeat(${Math.max(items.length, 1)}, minmax(0, 1fr))` },
|
|
55
|
+
children: items.map((item) => {
|
|
56
|
+
const content = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
57
|
+
item.icon && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { "aria-hidden": "true", className: "[&_svg]:size-5", children: item.icon }),
|
|
58
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: item.label }),
|
|
59
|
+
item.badge != null && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "absolute right-1/4 top-1 rounded-full bg-primary px-1.5 text-[10px] font-semibold leading-4 text-primary-foreground", children: item.badge })
|
|
60
|
+
] });
|
|
61
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", { children: item.disabled ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
62
|
+
"span",
|
|
63
|
+
{
|
|
64
|
+
"aria-disabled": "true",
|
|
65
|
+
className: (0, import_cn.cn)(tabClass, "text-muted-foreground opacity-50"),
|
|
66
|
+
children: content
|
|
67
|
+
}
|
|
68
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
69
|
+
LinkEl,
|
|
70
|
+
{
|
|
71
|
+
...destination(item.href),
|
|
72
|
+
"aria-current": item.active ? "page" : void 0,
|
|
73
|
+
className: (0, import_cn.cn)(
|
|
74
|
+
tabClass,
|
|
75
|
+
item.active ? "text-primary" : "text-muted-foreground hover:text-foreground"
|
|
76
|
+
),
|
|
77
|
+
children: content
|
|
78
|
+
}
|
|
79
|
+
) }, item.href);
|
|
80
|
+
})
|
|
81
|
+
}
|
|
82
|
+
)
|
|
83
|
+
}
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
87
|
+
0 && (module.exports = {
|
|
88
|
+
BottomNav
|
|
89
|
+
});
|
|
90
|
+
//# sourceMappingURL=BottomNav.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/bottom-nav/BottomNav.tsx"],"sourcesContent":["import * as React from 'react';\nimport { cn } from '../../utils/cn';\n\nexport type BottomNavItem = {\n /** Destination URL for the tab. */\n href: string;\n /** Visible tab label. */\n label: string;\n /** Icon shown above the label; always rendered aria-hidden. */\n icon?: React.ReactNode;\n /** Marks the current tab and sets aria-current=\"page\". */\n active?: boolean;\n /** Small count or dot shown in the tab's top corner. */\n badge?: React.ReactNode;\n /** Renders the tab as non-interactive. */\n disabled?: boolean;\n};\n\nexport type BottomNavProps = React.HTMLAttributes<HTMLElement> & {\n /** Tabs in order. Keep to 3-5 so every target stays thumb-reachable. */\n items: BottomNavItem[];\n /** Router link component (Next Link, react-router Link). */\n linkComponent?: React.ElementType;\n /** Prop used to pass the destination to `linkComponent`. */\n linkHrefProp?: 'href' | 'to';\n /** Landmark label. Default \"Primary\". */\n label?: string;\n /** Pin the bar to the bottom edge with safe-area padding (default true). */\n fixed?: boolean;\n /** Hide the bar from the md breakpoint up (default true). */\n mobileOnly?: boolean;\n};\n\nconst tabClass =\n 'relative flex min-h-14 w-full flex-col items-center justify-center gap-0.5 px-2 py-2 text-[11px] font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset';\n\n/**\n * Mobile bottom tab bar for the 3-5 primary destinations of an app shell.\n * A nav landmark with aria-current=\"page\" on the active tab, 44px minimum\n * targets, an optional count badge and safe-area padding so the bar clears\n * the iOS home indicator.\n */\nexport function BottomNav({\n items,\n linkComponent,\n linkHrefProp = 'href',\n label = 'Primary',\n fixed = true,\n mobileOnly = true,\n className,\n ...props\n}: BottomNavProps) {\n const LinkEl = linkComponent ?? 'a';\n const destination = (href: string) => (linkHrefProp === 'to' ? { to: href } : { href });\n\n return (\n <nav\n aria-label={label}\n className={cn(\n 'w-full border-t border-border bg-background pb-[env(safe-area-inset-bottom)]',\n fixed && 'fixed inset-x-0 bottom-0 z-40',\n mobileOnly && 'md:hidden',\n className\n )}\n {...props}\n >\n <ul\n className=\"mx-auto grid w-full max-w-lg\"\n style={{ gridTemplateColumns: `repeat(${Math.max(items.length, 1)}, minmax(0, 1fr))` }}\n >\n {items.map((item) => {\n const content = (\n <>\n {item.icon && (\n <span aria-hidden=\"true\" className=\"[&_svg]:size-5\">\n {item.icon}\n </span>\n )}\n <span>{item.label}</span>\n {item.badge != null && (\n <span className=\"absolute right-1/4 top-1 rounded-full bg-primary px-1.5 text-[10px] font-semibold leading-4 text-primary-foreground\">\n {item.badge}\n </span>\n )}\n </>\n );\n\n return (\n <li key={item.href}>\n {item.disabled ? (\n <span\n aria-disabled=\"true\"\n className={cn(tabClass, 'text-muted-foreground opacity-50')}\n >\n {content}\n </span>\n ) : (\n <LinkEl\n {...destination(item.href)}\n aria-current={item.active ? 'page' : undefined}\n className={cn(\n tabClass,\n item.active\n ? 'text-primary'\n : 'text-muted-foreground hover:text-foreground'\n )}\n >\n {content}\n </LinkEl>\n )}\n </li>\n );\n })}\n </ul>\n </nav>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAwEY;AAvEZ,gBAAmB;AAgCnB,MAAM,WACJ;AAQK,SAAS,UAAU;AAAA,EACxB;AAAA,EACA;AAAA,EACA,eAAe;AAAA,EACf,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,aAAa;AAAA,EACb;AAAA,EACA,GAAG;AACL,GAAmB;AACjB,QAAM,SAAS,iBAAiB;AAChC,QAAM,cAAc,CAAC,SAAkB,iBAAiB,OAAO,EAAE,IAAI,KAAK,IAAI,EAAE,KAAK;AAErF,SACE;AAAA,IAAC;AAAA;AAAA,MACC,cAAY;AAAA,MACZ,eAAW;AAAA,QACT;AAAA,QACA,SAAS;AAAA,QACT,cAAc;AAAA,QACd;AAAA,MACF;AAAA,MACC,GAAG;AAAA,MAEJ;AAAA,QAAC;AAAA;AAAA,UACC,WAAU;AAAA,UACV,OAAO,EAAE,qBAAqB,UAAU,KAAK,IAAI,MAAM,QAAQ,CAAC,CAAC,oBAAoB;AAAA,UAEpF,gBAAM,IAAI,CAAC,SAAS;AACnB,kBAAM,UACJ,4EACG;AAAA,mBAAK,QACJ,4CAAC,UAAK,eAAY,QAAO,WAAU,kBAChC,eAAK,MACR;AAAA,cAEF,4CAAC,UAAM,eAAK,OAAM;AAAA,cACjB,KAAK,SAAS,QACb,4CAAC,UAAK,WAAU,uHACb,eAAK,OACR;AAAA,eAEJ;AAGF,mBACE,4CAAC,QACE,eAAK,WACJ;AAAA,cAAC;AAAA;AAAA,gBACC,iBAAc;AAAA,gBACd,eAAW,cAAG,UAAU,kCAAkC;AAAA,gBAEzD;AAAA;AAAA,YACH,IAEA;AAAA,cAAC;AAAA;AAAA,gBACE,GAAG,YAAY,KAAK,IAAI;AAAA,gBACzB,gBAAc,KAAK,SAAS,SAAS;AAAA,gBACrC,eAAW;AAAA,kBACT;AAAA,kBACA,KAAK,SACD,iBACA;AAAA,gBACN;AAAA,gBAEC;AAAA;AAAA,YACH,KApBK,KAAK,IAsBd;AAAA,UAEJ,CAAC;AAAA;AAAA,MACH;AAAA;AAAA,EACF;AAEJ;","names":[]}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { cn } from "../../utils/cn.mjs";
|
|
3
|
+
const tabClass = "relative flex min-h-14 w-full flex-col items-center justify-center gap-0.5 px-2 py-2 text-[11px] font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset";
|
|
4
|
+
function BottomNav({
|
|
5
|
+
items,
|
|
6
|
+
linkComponent,
|
|
7
|
+
linkHrefProp = "href",
|
|
8
|
+
label = "Primary",
|
|
9
|
+
fixed = true,
|
|
10
|
+
mobileOnly = true,
|
|
11
|
+
className,
|
|
12
|
+
...props
|
|
13
|
+
}) {
|
|
14
|
+
const LinkEl = linkComponent ?? "a";
|
|
15
|
+
const destination = (href) => linkHrefProp === "to" ? { to: href } : { href };
|
|
16
|
+
return /* @__PURE__ */ jsx(
|
|
17
|
+
"nav",
|
|
18
|
+
{
|
|
19
|
+
"aria-label": label,
|
|
20
|
+
className: cn(
|
|
21
|
+
"w-full border-t border-border bg-background pb-[env(safe-area-inset-bottom)]",
|
|
22
|
+
fixed && "fixed inset-x-0 bottom-0 z-40",
|
|
23
|
+
mobileOnly && "md:hidden",
|
|
24
|
+
className
|
|
25
|
+
),
|
|
26
|
+
...props,
|
|
27
|
+
children: /* @__PURE__ */ jsx(
|
|
28
|
+
"ul",
|
|
29
|
+
{
|
|
30
|
+
className: "mx-auto grid w-full max-w-lg",
|
|
31
|
+
style: { gridTemplateColumns: `repeat(${Math.max(items.length, 1)}, minmax(0, 1fr))` },
|
|
32
|
+
children: items.map((item) => {
|
|
33
|
+
const content = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
34
|
+
item.icon && /* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: "[&_svg]:size-5", children: item.icon }),
|
|
35
|
+
/* @__PURE__ */ jsx("span", { children: item.label }),
|
|
36
|
+
item.badge != null && /* @__PURE__ */ jsx("span", { className: "absolute right-1/4 top-1 rounded-full bg-primary px-1.5 text-[10px] font-semibold leading-4 text-primary-foreground", children: item.badge })
|
|
37
|
+
] });
|
|
38
|
+
return /* @__PURE__ */ jsx("li", { children: item.disabled ? /* @__PURE__ */ jsx(
|
|
39
|
+
"span",
|
|
40
|
+
{
|
|
41
|
+
"aria-disabled": "true",
|
|
42
|
+
className: cn(tabClass, "text-muted-foreground opacity-50"),
|
|
43
|
+
children: content
|
|
44
|
+
}
|
|
45
|
+
) : /* @__PURE__ */ jsx(
|
|
46
|
+
LinkEl,
|
|
47
|
+
{
|
|
48
|
+
...destination(item.href),
|
|
49
|
+
"aria-current": item.active ? "page" : void 0,
|
|
50
|
+
className: cn(
|
|
51
|
+
tabClass,
|
|
52
|
+
item.active ? "text-primary" : "text-muted-foreground hover:text-foreground"
|
|
53
|
+
),
|
|
54
|
+
children: content
|
|
55
|
+
}
|
|
56
|
+
) }, item.href);
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
)
|
|
60
|
+
}
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
export {
|
|
64
|
+
BottomNav
|
|
65
|
+
};
|
|
66
|
+
//# sourceMappingURL=BottomNav.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/bottom-nav/BottomNav.tsx"],"sourcesContent":["import * as React from 'react';\nimport { cn } from '../../utils/cn';\n\nexport type BottomNavItem = {\n /** Destination URL for the tab. */\n href: string;\n /** Visible tab label. */\n label: string;\n /** Icon shown above the label; always rendered aria-hidden. */\n icon?: React.ReactNode;\n /** Marks the current tab and sets aria-current=\"page\". */\n active?: boolean;\n /** Small count or dot shown in the tab's top corner. */\n badge?: React.ReactNode;\n /** Renders the tab as non-interactive. */\n disabled?: boolean;\n};\n\nexport type BottomNavProps = React.HTMLAttributes<HTMLElement> & {\n /** Tabs in order. Keep to 3-5 so every target stays thumb-reachable. */\n items: BottomNavItem[];\n /** Router link component (Next Link, react-router Link). */\n linkComponent?: React.ElementType;\n /** Prop used to pass the destination to `linkComponent`. */\n linkHrefProp?: 'href' | 'to';\n /** Landmark label. Default \"Primary\". */\n label?: string;\n /** Pin the bar to the bottom edge with safe-area padding (default true). */\n fixed?: boolean;\n /** Hide the bar from the md breakpoint up (default true). */\n mobileOnly?: boolean;\n};\n\nconst tabClass =\n 'relative flex min-h-14 w-full flex-col items-center justify-center gap-0.5 px-2 py-2 text-[11px] font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset';\n\n/**\n * Mobile bottom tab bar for the 3-5 primary destinations of an app shell.\n * A nav landmark with aria-current=\"page\" on the active tab, 44px minimum\n * targets, an optional count badge and safe-area padding so the bar clears\n * the iOS home indicator.\n */\nexport function BottomNav({\n items,\n linkComponent,\n linkHrefProp = 'href',\n label = 'Primary',\n fixed = true,\n mobileOnly = true,\n className,\n ...props\n}: BottomNavProps) {\n const LinkEl = linkComponent ?? 'a';\n const destination = (href: string) => (linkHrefProp === 'to' ? { to: href } : { href });\n\n return (\n <nav\n aria-label={label}\n className={cn(\n 'w-full border-t border-border bg-background pb-[env(safe-area-inset-bottom)]',\n fixed && 'fixed inset-x-0 bottom-0 z-40',\n mobileOnly && 'md:hidden',\n className\n )}\n {...props}\n >\n <ul\n className=\"mx-auto grid w-full max-w-lg\"\n style={{ gridTemplateColumns: `repeat(${Math.max(items.length, 1)}, minmax(0, 1fr))` }}\n >\n {items.map((item) => {\n const content = (\n <>\n {item.icon && (\n <span aria-hidden=\"true\" className=\"[&_svg]:size-5\">\n {item.icon}\n </span>\n )}\n <span>{item.label}</span>\n {item.badge != null && (\n <span className=\"absolute right-1/4 top-1 rounded-full bg-primary px-1.5 text-[10px] font-semibold leading-4 text-primary-foreground\">\n {item.badge}\n </span>\n )}\n </>\n );\n\n return (\n <li key={item.href}>\n {item.disabled ? (\n <span\n aria-disabled=\"true\"\n className={cn(tabClass, 'text-muted-foreground opacity-50')}\n >\n {content}\n </span>\n ) : (\n <LinkEl\n {...destination(item.href)}\n aria-current={item.active ? 'page' : undefined}\n className={cn(\n tabClass,\n item.active\n ? 'text-primary'\n : 'text-muted-foreground hover:text-foreground'\n )}\n >\n {content}\n </LinkEl>\n )}\n </li>\n );\n })}\n </ul>\n </nav>\n );\n}\n"],"mappings":"AAwEY,mBAEI,KAFJ;AAvEZ,SAAS,UAAU;AAgCnB,MAAM,WACJ;AAQK,SAAS,UAAU;AAAA,EACxB;AAAA,EACA;AAAA,EACA,eAAe;AAAA,EACf,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,aAAa;AAAA,EACb;AAAA,EACA,GAAG;AACL,GAAmB;AACjB,QAAM,SAAS,iBAAiB;AAChC,QAAM,cAAc,CAAC,SAAkB,iBAAiB,OAAO,EAAE,IAAI,KAAK,IAAI,EAAE,KAAK;AAErF,SACE;AAAA,IAAC;AAAA;AAAA,MACC,cAAY;AAAA,MACZ,WAAW;AAAA,QACT;AAAA,QACA,SAAS;AAAA,QACT,cAAc;AAAA,QACd;AAAA,MACF;AAAA,MACC,GAAG;AAAA,MAEJ;AAAA,QAAC;AAAA;AAAA,UACC,WAAU;AAAA,UACV,OAAO,EAAE,qBAAqB,UAAU,KAAK,IAAI,MAAM,QAAQ,CAAC,CAAC,oBAAoB;AAAA,UAEpF,gBAAM,IAAI,CAAC,SAAS;AACnB,kBAAM,UACJ,iCACG;AAAA,mBAAK,QACJ,oBAAC,UAAK,eAAY,QAAO,WAAU,kBAChC,eAAK,MACR;AAAA,cAEF,oBAAC,UAAM,eAAK,OAAM;AAAA,cACjB,KAAK,SAAS,QACb,oBAAC,UAAK,WAAU,uHACb,eAAK,OACR;AAAA,eAEJ;AAGF,mBACE,oBAAC,QACE,eAAK,WACJ;AAAA,cAAC;AAAA;AAAA,gBACC,iBAAc;AAAA,gBACd,WAAW,GAAG,UAAU,kCAAkC;AAAA,gBAEzD;AAAA;AAAA,YACH,IAEA;AAAA,cAAC;AAAA;AAAA,gBACE,GAAG,YAAY,KAAK,IAAI;AAAA,gBACzB,gBAAc,KAAK,SAAS,SAAS;AAAA,gBACrC,WAAW;AAAA,kBACT;AAAA,kBACA,KAAK,SACD,iBACA;AAAA,gBACN;AAAA,gBAEC;AAAA;AAAA,YACH,KApBK,KAAK,IAsBd;AAAA,UAEJ,CAAC;AAAA;AAAA,MACH;AAAA;AAAA,EACF;AAEJ;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './BottomNav';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var bottom_nav_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(bottom_nav_exports);
|
|
18
|
+
__reExport(bottom_nav_exports, require("./BottomNav.js"), module.exports);
|
|
19
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
20
|
+
0 && (module.exports = {
|
|
21
|
+
...require("./BottomNav.js")
|
|
22
|
+
});
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/bottom-nav/index.ts"],"sourcesContent":["export * from './BottomNav';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,+BAAc,wBAAd;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/bottom-nav/index.ts"],"sourcesContent":["export * from './BottomNav';\n"],"mappings":"AAAA,cAAc;","names":[]}
|
|
@@ -3,7 +3,14 @@ export type DrawerSide = 'left' | 'right' | 'top' | 'bottom';
|
|
|
3
3
|
export type DrawerSize = 'sm' | 'md' | 'lg' | 'xl' | '2xl';
|
|
4
4
|
export type DrawerProps = {
|
|
5
5
|
open: boolean;
|
|
6
|
-
|
|
6
|
+
/** Called with the next open state. Alias: onClose (close requests only). */
|
|
7
|
+
onOpenChange?: (open: boolean) => void;
|
|
8
|
+
/**
|
|
9
|
+
* Called when the drawer asks to close: Escape, backdrop click or the close
|
|
10
|
+
* button. Alias for `onOpenChange(false)`, used when only a close handler is
|
|
11
|
+
* passed.
|
|
12
|
+
*/
|
|
13
|
+
onClose?: () => void;
|
|
7
14
|
title: string;
|
|
8
15
|
description?: string;
|
|
9
16
|
children?: React.ReactNode;
|
|
@@ -21,6 +28,22 @@ export type DrawerProps = {
|
|
|
21
28
|
* ("60vh"). Overrides `size`.
|
|
22
29
|
*/
|
|
23
30
|
height?: number | string;
|
|
31
|
+
/**
|
|
32
|
+
* Drag the inner edge to resize a left/right drawer. Keyboard: Arrow keys
|
|
33
|
+
* nudge 16px, Shift+Arrow 64px, Home/End jump to the bounds. Ignored for
|
|
34
|
+
* top/bottom drawers.
|
|
35
|
+
*/
|
|
36
|
+
resizable?: boolean;
|
|
37
|
+
/** Lower bound in pixels while resizable (default 240). */
|
|
38
|
+
minWidth?: number;
|
|
39
|
+
/** Upper bound in pixels while resizable (default 960). */
|
|
40
|
+
maxWidth?: number;
|
|
41
|
+
/** Initial width in pixels while resizable; defaults to the `size` preset. */
|
|
42
|
+
defaultWidth?: number;
|
|
43
|
+
/** Fired with the next width in pixels when a resize commits. */
|
|
44
|
+
onWidthChange?: (width: number) => void;
|
|
45
|
+
/** Accessible label for the resize handle (default "Resize drawer"). */
|
|
46
|
+
resizeLabel?: string;
|
|
24
47
|
/** Clicking the backdrop closes (default true). */
|
|
25
48
|
closeOnBackdrop?: boolean;
|
|
26
49
|
/** Hide the close (✕) button in the header (default true). */
|
|
@@ -45,4 +68,4 @@ export type DrawerProps = {
|
|
|
45
68
|
* restoration on close. Renders fixed to the chosen edge with a border
|
|
46
69
|
* against the backdrop.
|
|
47
70
|
*/
|
|
48
|
-
export declare function Drawer({ open, onOpenChange, title, description, children, side, size, width, height, closeOnBackdrop, showClose, closeLabel, initialFocusRef, ariaLabel, animate, }: DrawerProps): React.ReactPortal | null;
|
|
71
|
+
export declare function Drawer({ open, onOpenChange, onClose, title, description, children, side, size, width, height, resizable, minWidth, maxWidth, defaultWidth, onWidthChange, resizeLabel, closeOnBackdrop, showClose, closeLabel, initialFocusRef, ariaLabel, animate, }: DrawerProps): React.ReactPortal | null;
|
|
@@ -65,6 +65,13 @@ const sizeClasses = {
|
|
|
65
65
|
top: sideHeights,
|
|
66
66
|
bottom: sideHeights
|
|
67
67
|
};
|
|
68
|
+
const sizePx = {
|
|
69
|
+
sm: 288,
|
|
70
|
+
md: 384,
|
|
71
|
+
lg: 512,
|
|
72
|
+
xl: 640,
|
|
73
|
+
"2xl": 768
|
|
74
|
+
};
|
|
68
75
|
function extentStyle(value) {
|
|
69
76
|
if (value === void 0) return void 0;
|
|
70
77
|
return typeof value === "number" ? `${value}px` : value;
|
|
@@ -84,6 +91,7 @@ const slideOut = {
|
|
|
84
91
|
function Drawer({
|
|
85
92
|
open,
|
|
86
93
|
onOpenChange,
|
|
94
|
+
onClose,
|
|
87
95
|
title,
|
|
88
96
|
description,
|
|
89
97
|
children,
|
|
@@ -91,6 +99,12 @@ function Drawer({
|
|
|
91
99
|
size = "md",
|
|
92
100
|
width,
|
|
93
101
|
height,
|
|
102
|
+
resizable = false,
|
|
103
|
+
minWidth = 240,
|
|
104
|
+
maxWidth = 960,
|
|
105
|
+
defaultWidth,
|
|
106
|
+
onWidthChange,
|
|
107
|
+
resizeLabel = "Resize drawer",
|
|
94
108
|
closeOnBackdrop = true,
|
|
95
109
|
showClose = true,
|
|
96
110
|
closeLabel = "Close drawer",
|
|
@@ -104,6 +118,65 @@ function Drawer({
|
|
|
104
118
|
const descriptionId = React.useId();
|
|
105
119
|
const { present, exiting } = (0, import_presence.usePresence)(open, animate);
|
|
106
120
|
const isTopLayer = (0, import_modal_layer.useModalLayer)(open);
|
|
121
|
+
const requestClose = React.useCallback(() => {
|
|
122
|
+
if (onOpenChange) onOpenChange(false);
|
|
123
|
+
else onClose?.();
|
|
124
|
+
}, [onOpenChange, onClose]);
|
|
125
|
+
const isVerticalSide = side === "top" || side === "bottom";
|
|
126
|
+
const canResize = resizable && !isVerticalSide;
|
|
127
|
+
const clampWidth = React.useCallback(
|
|
128
|
+
(next) => Math.min(maxWidth, Math.max(minWidth, Math.round(next))),
|
|
129
|
+
[minWidth, maxWidth]
|
|
130
|
+
);
|
|
131
|
+
const [resizedWidth, setResizedWidth] = React.useState(null);
|
|
132
|
+
const initialWidth = clampWidth(
|
|
133
|
+
defaultWidth ?? (typeof width === "number" ? width : sizePx[size])
|
|
134
|
+
);
|
|
135
|
+
const resizeWidth = resizedWidth ?? initialWidth;
|
|
136
|
+
const widthRef = React.useRef(resizeWidth);
|
|
137
|
+
widthRef.current = resizeWidth;
|
|
138
|
+
const onWidthChangeRef = React.useRef(onWidthChange);
|
|
139
|
+
onWidthChangeRef.current = onWidthChange;
|
|
140
|
+
const commitWidth = (next) => {
|
|
141
|
+
const clamped = clampWidth(next);
|
|
142
|
+
setResizedWidth(clamped);
|
|
143
|
+
onWidthChangeRef.current?.(clamped);
|
|
144
|
+
};
|
|
145
|
+
const onResizePointerDown = (event) => {
|
|
146
|
+
if (event.button !== 0) return;
|
|
147
|
+
event.preventDefault();
|
|
148
|
+
const startX = event.clientX;
|
|
149
|
+
const startWidth = resizeWidth;
|
|
150
|
+
const onMove = (moveEvent) => {
|
|
151
|
+
const delta = side === "right" ? startX - moveEvent.clientX : moveEvent.clientX - startX;
|
|
152
|
+
setResizedWidth(clampWidth(startWidth + delta));
|
|
153
|
+
};
|
|
154
|
+
const onUp = () => {
|
|
155
|
+
window.removeEventListener("pointermove", onMove);
|
|
156
|
+
window.removeEventListener("pointerup", onUp);
|
|
157
|
+
onWidthChangeRef.current?.(widthRef.current);
|
|
158
|
+
};
|
|
159
|
+
window.addEventListener("pointermove", onMove);
|
|
160
|
+
window.addEventListener("pointerup", onUp);
|
|
161
|
+
};
|
|
162
|
+
const onResizeKeyDown = (event) => {
|
|
163
|
+
const step = event.shiftKey ? 64 : 16;
|
|
164
|
+
const grow = side === "right" ? "ArrowLeft" : "ArrowRight";
|
|
165
|
+
const shrink = side === "right" ? "ArrowRight" : "ArrowLeft";
|
|
166
|
+
if (event.key === grow) {
|
|
167
|
+
event.preventDefault();
|
|
168
|
+
commitWidth(resizeWidth + step);
|
|
169
|
+
} else if (event.key === shrink) {
|
|
170
|
+
event.preventDefault();
|
|
171
|
+
commitWidth(resizeWidth - step);
|
|
172
|
+
} else if (event.key === "Home") {
|
|
173
|
+
event.preventDefault();
|
|
174
|
+
commitWidth(minWidth);
|
|
175
|
+
} else if (event.key === "End") {
|
|
176
|
+
event.preventDefault();
|
|
177
|
+
commitWidth(maxWidth);
|
|
178
|
+
}
|
|
179
|
+
};
|
|
107
180
|
React.useEffect(() => {
|
|
108
181
|
if (open) {
|
|
109
182
|
previouslyFocused.current = document.activeElement;
|
|
@@ -124,7 +197,7 @@ function Drawer({
|
|
|
124
197
|
if (event.key === "Escape") {
|
|
125
198
|
if (!isTopLayer()) return;
|
|
126
199
|
event.stopPropagation();
|
|
127
|
-
|
|
200
|
+
requestClose();
|
|
128
201
|
return;
|
|
129
202
|
}
|
|
130
203
|
if (event.key !== "Tab") return;
|
|
@@ -148,10 +221,9 @@ function Drawer({
|
|
|
148
221
|
};
|
|
149
222
|
document.addEventListener("keydown", onKeyDown);
|
|
150
223
|
return () => document.removeEventListener("keydown", onKeyDown);
|
|
151
|
-
}, [open,
|
|
224
|
+
}, [open, requestClose, isTopLayer]);
|
|
152
225
|
if (!present || typeof document === "undefined") return null;
|
|
153
|
-
const
|
|
154
|
-
const customExtent = isVerticalSide ? extentStyle(height) : extentStyle(width);
|
|
226
|
+
const customExtent = canResize ? `${resizeWidth}px` : isVerticalSide ? extentStyle(height) : extentStyle(width);
|
|
155
227
|
const motion = animate ? (0, import_cn.cn)(
|
|
156
228
|
"duration-200 motion-reduce:animate-none",
|
|
157
229
|
exiting ? `animate-out ${slideOut[side]}` : `animate-in ${slideIn[side]}`
|
|
@@ -162,7 +234,7 @@ function Drawer({
|
|
|
162
234
|
{
|
|
163
235
|
className: "fixed inset-0 z-50",
|
|
164
236
|
onMouseDown: (event) => {
|
|
165
|
-
if (closeOnBackdrop && event.target === event.currentTarget)
|
|
237
|
+
if (closeOnBackdrop && event.target === event.currentTarget) requestClose();
|
|
166
238
|
},
|
|
167
239
|
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
168
240
|
"div",
|
|
@@ -182,6 +254,25 @@ function Drawer({
|
|
|
182
254
|
),
|
|
183
255
|
style: customExtent ? { [isVerticalSide ? "height" : "width"]: customExtent } : void 0,
|
|
184
256
|
children: [
|
|
257
|
+
canResize && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
258
|
+
"div",
|
|
259
|
+
{
|
|
260
|
+
role: "separator",
|
|
261
|
+
"aria-orientation": "vertical",
|
|
262
|
+
"aria-label": resizeLabel,
|
|
263
|
+
"aria-valuenow": resizeWidth,
|
|
264
|
+
"aria-valuemin": minWidth,
|
|
265
|
+
"aria-valuemax": maxWidth,
|
|
266
|
+
tabIndex: 0,
|
|
267
|
+
onPointerDown: onResizePointerDown,
|
|
268
|
+
onKeyDown: onResizeKeyDown,
|
|
269
|
+
className: (0, import_cn.cn)(
|
|
270
|
+
"absolute inset-y-0 z-10 w-2 cursor-col-resize touch-none rounded-sm bg-transparent",
|
|
271
|
+
"hover:bg-primary/20 focus-visible:bg-primary/30 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
|
|
272
|
+
side === "right" ? "-left-1" : "-right-1"
|
|
273
|
+
)
|
|
274
|
+
}
|
|
275
|
+
),
|
|
185
276
|
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex items-start justify-between gap-4 border-b border-border px-5 py-4", children: [
|
|
186
277
|
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
|
|
187
278
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", { id: titleId, className: "text-base font-semibold leading-tight", children: title }),
|
|
@@ -191,7 +282,7 @@ function Drawer({
|
|
|
191
282
|
"button",
|
|
192
283
|
{
|
|
193
284
|
type: "button",
|
|
194
|
-
onClick:
|
|
285
|
+
onClick: requestClose,
|
|
195
286
|
"aria-label": closeLabel,
|
|
196
287
|
className: "-me-1 rounded p-1 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
|
|
197
288
|
children: "\u2715"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/drawer/Drawer.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { createPortal } from 'react-dom';\nimport { cn } from '../../utils/cn';\nimport { usePresence } from '../../utils/presence';\nimport { useModalLayer } from '../../utils/modal-layer';\n\nexport type DrawerSide = 'left' | 'right' | 'top' | 'bottom';\nexport type DrawerSize = 'sm' | 'md' | 'lg' | 'xl' | '2xl';\n\nexport type DrawerProps = {\n open: boolean;\n onOpenChange: (open: boolean) => void;\n title: string;\n description?: string;\n children?: React.ReactNode;\n /** Edge the drawer slides from (default 'right'). */\n side?: DrawerSide;\n /** Preset extent along the side axis (width for left/right, height for top/bottom). */\n size?: DrawerSize;\n /**\n * Custom extent for left/right drawers: pixels (480) or any CSS length\n * (\"70vw\"). Overrides `size`.\n */\n width?: number | string;\n /**\n * Custom extent for top/bottom drawers: pixels (320) or any CSS length\n * (\"60vh\"). Overrides `size`.\n */\n height?: number | string;\n /** Clicking the backdrop closes (default true). */\n closeOnBackdrop?: boolean;\n /** Hide the close (✕) button in the header (default true). */\n showClose?: boolean;\n /** Accessible label for the close button (default \"Close drawer\"). */\n closeLabel?: string;\n /** Focused when the drawer opens; defaults to the first focusable element. */\n initialFocusRef?: React.RefObject<HTMLElement | null>;\n /** Overrides the accessible name (defaults to the title). */\n ariaLabel?: string;\n /**\n * Slide the panel in from its edge and out on close (requires the\n * tailwindcss-animate plugin). Off by default; reduced-motion users\n * get animate-none automatically.\n */\n animate?: boolean;\n};\n\nconst FOCUSABLE =\n 'a[href], button:not([disabled]), textarea:not([disabled]), input:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex=\"-1\"])';\n\nconst sideClasses: Record<DrawerSide, string> = {\n right: 'inset-y-0 right-0 border-l',\n left: 'inset-y-0 left-0 border-r',\n top: 'inset-x-0 top-0 border-b',\n bottom: 'inset-x-0 bottom-0 border-t',\n};\n\nconst sideWidths: Record<DrawerSize, string> = {\n sm: 'w-72',\n md: 'w-96',\n lg: 'w-[32rem]',\n xl: 'w-[40rem]',\n '2xl': 'w-[48rem]',\n};\n\nconst sideHeights: Record<DrawerSize, string> = {\n sm: 'h-48',\n md: 'h-80',\n lg: 'h-[32rem]',\n xl: 'h-[40rem]',\n '2xl': 'h-[48rem]',\n};\n\nconst sizeClasses: Record<DrawerSide, Record<DrawerSize, string>> = {\n right: sideWidths,\n left: sideWidths,\n top: sideHeights,\n bottom: sideHeights,\n};\n\n/** Custom extent wins over the preset; numbers are pixels. */\nfunction extentStyle(value: number | string | undefined): string | undefined {\n if (value === undefined) return undefined;\n return typeof value === 'number' ? `${value}px` : value;\n}\n\n// Literal class maps so Tailwind's scanner keeps every slide utility.\nconst slideIn: Record<DrawerSide, string> = {\n right: 'slide-in-from-right',\n left: 'slide-in-from-left',\n top: 'slide-in-from-top',\n bottom: 'slide-in-from-bottom',\n};\nconst slideOut: Record<DrawerSide, string> = {\n right: 'slide-out-to-right',\n left: 'slide-out-to-left',\n top: 'slide-out-to-top',\n bottom: 'slide-out-to-bottom',\n};\n\n/**\n * Edge sheet for secondary flows (filters, detail panes, mobile nav).\n * Modal semantics identical to Dialog: portal, aria-modal + labelled by\n * title, Escape and backdrop dismissal, focus move + Tab trap + focus\n * restoration on close. Renders fixed to the chosen edge with a border\n * against the backdrop.\n */\nexport function Drawer({\n open,\n onOpenChange,\n title,\n description,\n children,\n side = 'right',\n size = 'md',\n width,\n height,\n closeOnBackdrop = true,\n showClose = true,\n closeLabel = 'Close drawer',\n initialFocusRef,\n ariaLabel,\n animate = false,\n}: DrawerProps) {\n const drawerRef = React.useRef<HTMLDivElement | null>(null);\n const previouslyFocused = React.useRef<HTMLElement | null>(null);\n const titleId = React.useId();\n const descriptionId = React.useId();\n const { present, exiting } = usePresence(open, animate);\n const isTopLayer = useModalLayer(open);\n\n // Capture the opener before the panel takes focus; restore the moment\n // open flips false — even while an exit animation keeps the DOM up.\n React.useEffect(() => {\n if (open) {\n previouslyFocused.current = document.activeElement as HTMLElement | null;\n return;\n }\n previouslyFocused.current?.focus?.();\n previouslyFocused.current = null;\n }, [open]);\n\n // Move focus in once the panel is actually mounted (present can lag\n // open by a render when the presence gate starts closed).\n React.useEffect(() => {\n if (!open || !present) return;\n const node = drawerRef.current;\n const target =\n initialFocusRef?.current ?? node?.querySelector<HTMLElement>(FOCUSABLE) ?? node;\n target?.focus();\n }, [open, present, initialFocusRef]);\n\n React.useEffect(() => {\n if (!open) return;\n const onKeyDown = (event: KeyboardEvent) => {\n if (event.key === 'Escape') {\n if (!isTopLayer()) return;\n event.stopPropagation();\n onOpenChange(false);\n return;\n }\n if (event.key !== 'Tab') return;\n const node = drawerRef.current;\n if (!node) return;\n const focusable = Array.from(node.querySelectorAll<HTMLElement>(FOCUSABLE));\n if (focusable.length === 0) {\n event.preventDefault();\n return;\n }\n const first = focusable[0];\n const last = focusable[focusable.length - 1];\n const active = document.activeElement;\n if (event.shiftKey && (active === first || !node.contains(active))) {\n event.preventDefault();\n last.focus();\n } else if (!event.shiftKey && active === last) {\n event.preventDefault();\n first.focus();\n }\n };\n document.addEventListener('keydown', onKeyDown);\n return () => document.removeEventListener('keydown', onKeyDown);\n }, [open, onOpenChange, isTopLayer]);\n\n if (!present || typeof document === 'undefined') return null;\n\n const isVerticalSide = side === 'top' || side === 'bottom';\n const customExtent = isVerticalSide ? extentStyle(height) : extentStyle(width);\n\n const motion = animate\n ? cn(\n 'duration-200 motion-reduce:animate-none',\n exiting ? `animate-out ${slideOut[side]}` : `animate-in ${slideIn[side]}`,\n )\n : undefined;\n\n return createPortal(\n <div\n className=\"fixed inset-0 z-50\"\n onMouseDown={(event) => {\n if (closeOnBackdrop && event.target === event.currentTarget) onOpenChange(false);\n }}\n >\n <div\n ref={drawerRef}\n role=\"dialog\"\n aria-modal=\"true\"\n aria-label={ariaLabel ?? title}\n aria-labelledby={title ? titleId : undefined}\n aria-describedby={description ? descriptionId : undefined}\n tabIndex={-1}\n className={cn(\n 'fixed flex flex-col bg-background shadow-xl border-border',\n sideClasses[side],\n sizeClasses[side][size],\n motion\n )}\n style={customExtent ? { [isVerticalSide ? 'height' : 'width']: customExtent } : undefined}\n >\n <div className=\"flex items-start justify-between gap-4 border-b border-border px-5 py-4\">\n <div>\n <h2 id={titleId} className=\"text-base font-semibold leading-tight\">\n {title}\n </h2>\n {description && (\n <p id={descriptionId} className=\"mt-1 text-sm text-muted-foreground\">\n {description}\n </p>\n )}\n </div>\n {showClose && (\n <button\n type=\"button\"\n onClick={() => onOpenChange(false)}\n aria-label={closeLabel}\n className=\"-me-1 rounded p-1 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring\"\n >\n ✕\n </button>\n )}\n </div>\n <div className=\"flex-1 overflow-y-auto px-5 py-4\">{children}</div>\n </div>\n </div>,\n document.body\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA8NU;AA5NV,YAAuB;AACvB,uBAA6B;AAC7B,gBAAmB;AACnB,sBAA4B;AAC5B,yBAA8B;AA2C9B,MAAM,YACJ;AAEF,MAAM,cAA0C;AAAA,EAC9C,OAAO;AAAA,EACP,MAAM;AAAA,EACN,KAAK;AAAA,EACL,QAAQ;AACV;AAEA,MAAM,aAAyC;AAAA,EAC7C,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,OAAO;AACT;AAEA,MAAM,cAA0C;AAAA,EAC9C,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EAC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B,cAAI,mBAAmB,MAAM,WAAW,MAAM,cAAe,cAAa,KAAK;AAAA,QACjF;AAAA,QAEA;AAAA,UAAC;AAAA;AAAA,YACC,KAAK;AAAA,YACL,MAAK;AAAA,YACL,cAAW;AAAA,YACX,cAAY,aAAa;AAAA,YACzB,mBAAiB,QAAQ,UAAU;AAAA,YACnC,oBAAkB,cAAc,gBAAgB;AAAA,YAChD,UAAU;AAAA,YACV,eAAW;AAAA,cACT;AAAA,cACA,YAAY,IAAI;AAAA,cAChB,YAAY,IAAI,EAAE,IAAI;AAAA,cACtB;AAAA,YACF;AAAA,YACA,OAAO,eAAe,EAAE,CAAC,iBAAiB,WAAW,OAAO,GAAG,aAAa,IAAI;AAAA,YAEhF;AAAA,2DAAC,SAAI,WAAU,2EACb;AAAA,6DAAC,SACC;AAAA,8DAAC,QAAG,IAAI,SAAS,WAAU,yCACxB,iBACH;AAAA,kBACC,eACC,4CAAC,OAAE,IAAI,eAAe,WAAU,sCAC7B,uBACH;AAAA,mBAEJ;AAAA,gBACC,aACC;AAAA,kBAAC;AAAA;AAAA,oBACC,MAAK;AAAA,oBACL,SAAS,MAAM,aAAa,KAAK;AAAA,oBACjC,cAAY;AAAA,oBACZ,WAAU;AAAA,oBACX;AAAA;AAAA,gBAED;AAAA,iBAEJ;AAAA,cACA,4CAAC,SAAI,WAAU,oCAAoC,UAAS;AAAA;AAAA;AAAA,QAC9D;AAAA;AAAA,IACF;AAAA,IACA,SAAS;AAAA,EACX;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/drawer/Drawer.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { createPortal } from 'react-dom';\nimport { cn } from '../../utils/cn';\nimport { usePresence } from '../../utils/presence';\nimport { useModalLayer } from '../../utils/modal-layer';\n\nexport type DrawerSide = 'left' | 'right' | 'top' | 'bottom';\nexport type DrawerSize = 'sm' | 'md' | 'lg' | 'xl' | '2xl';\n\nexport type DrawerProps = {\n open: boolean;\n /** Called with the next open state. Alias: onClose (close requests only). */\n onOpenChange?: (open: boolean) => void;\n /**\n * Called when the drawer asks to close: Escape, backdrop click or the close\n * button. Alias for `onOpenChange(false)`, used when only a close handler is\n * passed.\n */\n onClose?: () => void;\n title: string;\n description?: string;\n children?: React.ReactNode;\n /** Edge the drawer slides from (default 'right'). */\n side?: DrawerSide;\n /** Preset extent along the side axis (width for left/right, height for top/bottom). */\n size?: DrawerSize;\n /**\n * Custom extent for left/right drawers: pixels (480) or any CSS length\n * (\"70vw\"). Overrides `size`.\n */\n width?: number | string;\n /**\n * Custom extent for top/bottom drawers: pixels (320) or any CSS length\n * (\"60vh\"). Overrides `size`.\n */\n height?: number | string;\n /**\n * Drag the inner edge to resize a left/right drawer. Keyboard: Arrow keys\n * nudge 16px, Shift+Arrow 64px, Home/End jump to the bounds. Ignored for\n * top/bottom drawers.\n */\n resizable?: boolean;\n /** Lower bound in pixels while resizable (default 240). */\n minWidth?: number;\n /** Upper bound in pixels while resizable (default 960). */\n maxWidth?: number;\n /** Initial width in pixels while resizable; defaults to the `size` preset. */\n defaultWidth?: number;\n /** Fired with the next width in pixels when a resize commits. */\n onWidthChange?: (width: number) => void;\n /** Accessible label for the resize handle (default \"Resize drawer\"). */\n resizeLabel?: string;\n /** Clicking the backdrop closes (default true). */\n closeOnBackdrop?: boolean;\n /** Hide the close (✕) button in the header (default true). */\n showClose?: boolean;\n /** Accessible label for the close button (default \"Close drawer\"). */\n closeLabel?: string;\n /** Focused when the drawer opens; defaults to the first focusable element. */\n initialFocusRef?: React.RefObject<HTMLElement | null>;\n /** Overrides the accessible name (defaults to the title). */\n ariaLabel?: string;\n /**\n * Slide the panel in from its edge and out on close (requires the\n * tailwindcss-animate plugin). Off by default; reduced-motion users\n * get animate-none automatically.\n */\n animate?: boolean;\n};\n\nconst FOCUSABLE =\n 'a[href], button:not([disabled]), textarea:not([disabled]), input:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex=\"-1\"])';\n\nconst sideClasses: Record<DrawerSide, string> = {\n right: 'inset-y-0 right-0 border-l',\n left: 'inset-y-0 left-0 border-r',\n top: 'inset-x-0 top-0 border-b',\n bottom: 'inset-x-0 bottom-0 border-t',\n};\n\nconst sideWidths: Record<DrawerSize, string> = {\n sm: 'w-72',\n md: 'w-96',\n lg: 'w-[32rem]',\n xl: 'w-[40rem]',\n '2xl': 'w-[48rem]',\n};\n\nconst sideHeights: Record<DrawerSize, string> = {\n sm: 'h-48',\n md: 'h-80',\n lg: 'h-[32rem]',\n xl: 'h-[40rem]',\n '2xl': 'h-[48rem]',\n};\n\nconst sizeClasses: Record<DrawerSide, Record<DrawerSize, string>> = {\n right: sideWidths,\n left: sideWidths,\n top: sideHeights,\n bottom: sideHeights,\n};\n\n/** Pixel equivalents of the width presets, used as the resize starting point. */\nconst sizePx: Record<DrawerSize, number> = {\n sm: 288,\n md: 384,\n lg: 512,\n xl: 640,\n '2xl': 768,\n};\n\n/** Custom extent wins over the preset; numbers are pixels. */\nfunction extentStyle(value: number | string | undefined): string | undefined {\n if (value === undefined) return undefined;\n return typeof value === 'number' ? `${value}px` : value;\n}\n\n// Literal class maps so Tailwind's scanner keeps every slide utility.\nconst slideIn: Record<DrawerSide, string> = {\n right: 'slide-in-from-right',\n left: 'slide-in-from-left',\n top: 'slide-in-from-top',\n bottom: 'slide-in-from-bottom',\n};\nconst slideOut: Record<DrawerSide, string> = {\n right: 'slide-out-to-right',\n left: 'slide-out-to-left',\n top: 'slide-out-to-top',\n bottom: 'slide-out-to-bottom',\n};\n\n/**\n * Edge sheet for secondary flows (filters, detail panes, mobile nav).\n * Modal semantics identical to Dialog: portal, aria-modal + labelled by\n * title, Escape and backdrop dismissal, focus move + Tab trap + focus\n * restoration on close. Renders fixed to the chosen edge with a border\n * against the backdrop.\n */\nexport function Drawer({\n open,\n onOpenChange,\n onClose,\n title,\n description,\n children,\n side = 'right',\n size = 'md',\n width,\n height,\n resizable = false,\n minWidth = 240,\n maxWidth = 960,\n defaultWidth,\n onWidthChange,\n resizeLabel = 'Resize drawer',\n closeOnBackdrop = true,\n showClose = true,\n closeLabel = 'Close drawer',\n initialFocusRef,\n ariaLabel,\n animate = false,\n}: DrawerProps) {\n const drawerRef = React.useRef<HTMLDivElement | null>(null);\n const previouslyFocused = React.useRef<HTMLElement | null>(null);\n const titleId = React.useId();\n const descriptionId = React.useId();\n const { present, exiting } = usePresence(open, animate);\n const isTopLayer = useModalLayer(open);\n\n // Prefer onOpenChange; fall back to the onClose alias so a migration code\n // path that only passes onClose still dismisses without double-firing.\n const requestClose = React.useCallback(() => {\n if (onOpenChange) onOpenChange(false);\n else onClose?.();\n }, [onOpenChange, onClose]);\n\n // Resizable left/right drawers. Width is state-local so dragging stays\n // smooth; `onWidthChange` fires once a drag commits or a key is pressed.\n const isVerticalSide = side === 'top' || side === 'bottom';\n const canResize = resizable && !isVerticalSide;\n const clampWidth = React.useCallback(\n (next: number) => Math.min(maxWidth, Math.max(minWidth, Math.round(next))),\n [minWidth, maxWidth]\n );\n const [resizedWidth, setResizedWidth] = React.useState<number | null>(null);\n const initialWidth = clampWidth(\n defaultWidth ?? (typeof width === 'number' ? width : sizePx[size])\n );\n const resizeWidth = resizedWidth ?? initialWidth;\n const widthRef = React.useRef(resizeWidth);\n widthRef.current = resizeWidth;\n const onWidthChangeRef = React.useRef(onWidthChange);\n onWidthChangeRef.current = onWidthChange;\n\n const commitWidth = (next: number) => {\n const clamped = clampWidth(next);\n setResizedWidth(clamped);\n onWidthChangeRef.current?.(clamped);\n };\n\n const onResizePointerDown = (event: React.PointerEvent<HTMLDivElement>) => {\n if (event.button !== 0) return;\n event.preventDefault();\n const startX = event.clientX;\n const startWidth = resizeWidth;\n const onMove = (moveEvent: PointerEvent) => {\n const delta = side === 'right' ? startX - moveEvent.clientX : moveEvent.clientX - startX;\n setResizedWidth(clampWidth(startWidth + delta));\n };\n const onUp = () => {\n window.removeEventListener('pointermove', onMove);\n window.removeEventListener('pointerup', onUp);\n onWidthChangeRef.current?.(widthRef.current);\n };\n window.addEventListener('pointermove', onMove);\n window.addEventListener('pointerup', onUp);\n };\n\n const onResizeKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {\n const step = event.shiftKey ? 64 : 16;\n const grow = side === 'right' ? 'ArrowLeft' : 'ArrowRight';\n const shrink = side === 'right' ? 'ArrowRight' : 'ArrowLeft';\n if (event.key === grow) {\n event.preventDefault();\n commitWidth(resizeWidth + step);\n } else if (event.key === shrink) {\n event.preventDefault();\n commitWidth(resizeWidth - step);\n } else if (event.key === 'Home') {\n event.preventDefault();\n commitWidth(minWidth);\n } else if (event.key === 'End') {\n event.preventDefault();\n commitWidth(maxWidth);\n }\n };\n\n // Capture the opener before the panel takes focus; restore the moment\n // open flips false — even while an exit animation keeps the DOM up.\n React.useEffect(() => {\n if (open) {\n previouslyFocused.current = document.activeElement as HTMLElement | null;\n return;\n }\n previouslyFocused.current?.focus?.();\n previouslyFocused.current = null;\n }, [open]);\n\n // Move focus in once the panel is actually mounted (present can lag\n // open by a render when the presence gate starts closed).\n React.useEffect(() => {\n if (!open || !present) return;\n const node = drawerRef.current;\n const target =\n initialFocusRef?.current ?? node?.querySelector<HTMLElement>(FOCUSABLE) ?? node;\n target?.focus();\n }, [open, present, initialFocusRef]);\n\n React.useEffect(() => {\n if (!open) return;\n const onKeyDown = (event: KeyboardEvent) => {\n if (event.key === 'Escape') {\n if (!isTopLayer()) return;\n event.stopPropagation();\n requestClose();\n return;\n }\n if (event.key !== 'Tab') return;\n const node = drawerRef.current;\n if (!node) return;\n const focusable = Array.from(node.querySelectorAll<HTMLElement>(FOCUSABLE));\n if (focusable.length === 0) {\n event.preventDefault();\n return;\n }\n const first = focusable[0];\n const last = focusable[focusable.length - 1];\n const active = document.activeElement;\n if (event.shiftKey && (active === first || !node.contains(active))) {\n event.preventDefault();\n last.focus();\n } else if (!event.shiftKey && active === last) {\n event.preventDefault();\n first.focus();\n }\n };\n document.addEventListener('keydown', onKeyDown);\n return () => document.removeEventListener('keydown', onKeyDown);\n }, [open, requestClose, isTopLayer]);\n\n if (!present || typeof document === 'undefined') return null;\n\n const customExtent = canResize\n ? `${resizeWidth}px`\n : isVerticalSide\n ? extentStyle(height)\n : extentStyle(width);\n\n const motion = animate\n ? cn(\n 'duration-200 motion-reduce:animate-none',\n exiting ? `animate-out ${slideOut[side]}` : `animate-in ${slideIn[side]}`,\n )\n : undefined;\n\n return createPortal(\n <div\n className=\"fixed inset-0 z-50\"\n onMouseDown={(event) => {\n if (closeOnBackdrop && event.target === event.currentTarget) requestClose();\n }}\n >\n <div\n ref={drawerRef}\n role=\"dialog\"\n aria-modal=\"true\"\n aria-label={ariaLabel ?? title}\n aria-labelledby={title ? titleId : undefined}\n aria-describedby={description ? descriptionId : undefined}\n tabIndex={-1}\n className={cn(\n 'fixed flex flex-col bg-background shadow-xl border-border',\n sideClasses[side],\n sizeClasses[side][size],\n motion\n )}\n style={customExtent ? { [isVerticalSide ? 'height' : 'width']: customExtent } : undefined}\n >\n {canResize && (\n <div\n role=\"separator\"\n aria-orientation=\"vertical\"\n aria-label={resizeLabel}\n aria-valuenow={resizeWidth}\n aria-valuemin={minWidth}\n aria-valuemax={maxWidth}\n tabIndex={0}\n onPointerDown={onResizePointerDown}\n onKeyDown={onResizeKeyDown}\n className={cn(\n 'absolute inset-y-0 z-10 w-2 cursor-col-resize touch-none rounded-sm bg-transparent',\n 'hover:bg-primary/20 focus-visible:bg-primary/30 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',\n side === 'right' ? '-left-1' : '-right-1'\n )}\n />\n )}\n <div className=\"flex items-start justify-between gap-4 border-b border-border px-5 py-4\">\n <div>\n <h2 id={titleId} className=\"text-base font-semibold leading-tight\">\n {title}\n </h2>\n {description && (\n <p id={descriptionId} className=\"mt-1 text-sm text-muted-foreground\">\n {description}\n </p>\n )}\n </div>\n {showClose && (\n <button\n type=\"button\"\n onClick={requestClose}\n aria-label={closeLabel}\n className=\"-me-1 rounded p-1 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring\"\n >\n ✕\n </button>\n )}\n </div>\n <div className=\"flex-1 overflow-y-auto px-5 py-4\">{children}</div>\n </div>\n </div>,\n document.body\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA4UU;AA1UV,YAAuB;AACvB,uBAA6B;AAC7B,gBAAmB;AACnB,sBAA4B;AAC5B,yBAA8B;AAkE9B,MAAM,YACJ;AAEF,MAAM,cAA0C;AAAA,EAC9C,OAAO;AAAA,EACP,MAAM;AAAA,EACN,KAAK;AAAA,EACL,QAAQ;AACV;AAEA,MAAM,aAAyC;AAAA,EAC7C,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,OAAO;AACT;AAEA,MAAM,cAA0C;AAAA,EAC9C,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,OAAO;AACT;AAEA,MAAM,cAA8D;AAAA,EAClE,OAAO;AAAA,EACP,MAAM;AAAA,EACN,KAAK;AAAA,EACL,QAAQ;AACV;AAGA,MAAM,SAAqC;AAAA,EACzC,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,OAAO;AACT;AAGA,SAAS,YAAY,OAAwD;AAC3E,MAAI,UAAU,OAAW,QAAO;AAChC,SAAO,OAAO,UAAU,WAAW,GAAG,KAAK,OAAO;AACpD;AAGA,MAAM,UAAsC;AAAA,EAC1C,OAAO;AAAA,EACP,MAAM;AAAA,EACN,KAAK;AAAA,EACL,QAAQ;AACV;AACA,MAAM,WAAuC;AAAA,EAC3C,OAAO;AAAA,EACP,MAAM;AAAA,EACN,KAAK;AAAA,EACL,QAAQ;AACV;AASO,SAAS,OAAO;AAAA,EACrB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA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