@alexgorbatchev/shadcn 0.0.93 → 0.0.94

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.
@@ -25,13 +25,8 @@ import {
25
25
  PaginationLink2,
26
26
  PaginationPrevious2,
27
27
  PaginationNext2,
28
- PaginationEllipsis2,
29
- Drawer2,
30
- DrawerContent2,
31
- DrawerHeader2,
32
- DrawerTitle2,
33
- DrawerDescription2
34
- } from "../../chunk-kr38ww4n.js";
28
+ PaginationEllipsis2
29
+ } from "../../chunk-fg1h007n.js";
35
30
  import {
36
31
  MenuPopup,
37
32
  MenuItem2,
@@ -116,7 +111,13 @@ import {
116
111
  SelectItem2
117
112
  } from "../../chunk-p6z2m3zp.js";
118
113
  import"../../chunk-1j2hz3w9.js";
119
- import"../../chunk-k99h6evz.js";
114
+ import {
115
+ Drawer2,
116
+ DrawerContent2,
117
+ DrawerHeader2,
118
+ DrawerTitle2,
119
+ DrawerDescription2
120
+ } from "../../chunk-cc35g6sr.js";
120
121
  import {
121
122
  Toggle2,
122
123
  ToggleGroup2,
@@ -1,4 +1,5 @@
1
1
  import { type ReactElement, type ReactNode } from "react";
2
+ import type { Dialog as DialogPrimitive } from "@base-ui/react/dialog";
2
3
  import { type LayoutStorage } from "react-resizable-panels";
3
4
  interface ISplitViewProps {
4
5
  sidebar: ReactNode;
@@ -26,16 +27,30 @@ interface ISplitViewProps {
26
27
  * Below `wideQuery`: "stack" places the panes one above the other; "takeover" shows an open sidebar in the content's
27
28
  * place, with the content hidden but still mounted, as a narrow window's inspector or review does; "strip" places an
28
29
  * open sidebar above the content as a strip whose height the divider resizes, so both stay in view and usable, as a
29
- * persistent tool panel under a player does.
30
+ * persistent tool panel under a player does. "sheet" opens the sidebar as a modal, full-height panel from its own
31
+ * edge, titled `sidebarLabel` with a Close button, as a phone's navigation does; "drawer" opens it as a modal bottom
32
+ * drawer at 85% of the viewport height, full height while `sidebarExpanded`, as a phone's comments do. Both close on
33
+ * Escape, an outside press or a swipe toward their edge, report it through `onSidebarOpenChange`, and leave the
34
+ * content in the document's flow so the page scrolls as one document.
35
+ */
36
+ narrowLayout?: "stack" | "takeover" | "strip" | "sheet" | "drawer";
37
+ /**
38
+ * Widens the sidebar to `maxSidebarSize`; turning it off restores the width it had before. With the "drawer" narrow
39
+ * layout it raises the drawer to the full viewport height.
30
40
  */
31
- narrowLayout?: "stack" | "takeover" | "strip";
32
- /** Widens the sidebar to `maxSidebarSize`; turning it off restores the width it had before. */
33
41
  sidebarExpanded?: boolean;
42
+ /** Called when a "sheet" or "drawer" narrow layout asks to open or close the sidebar, such as on Escape or a swipe. */
43
+ onSidebarOpenChange?: (open: boolean) => void;
44
+ /**
45
+ * Where focus goes when a "sheet" or "drawer" narrow layout closes, as Base UI's `finalFocus`: by default the element
46
+ * that had focus before it opened; return `false` from a function to leave focus where the consumer put it.
47
+ */
48
+ sidebarFinalFocus?: DialogPrimitive.Popup.Props["finalFocus"];
34
49
  }
35
50
  /**
36
51
  * Pairs a resizable sidebar with its content above `wideQuery` (1024px by default) and stacks them below it, or lets an
37
52
  * open sidebar take over the content's place. The sidebar and content render into slots that move between the
38
53
  * layouts, so their state survives resizing across the breakpoint and opening or closing the sidebar.
39
54
  */
40
- export declare function SplitView({ sidebar, children, storageKey, sidebarPosition, sidebarOpen, storage, sidebarLabel, contentLabel, resizeLabel, defaultSidebarSize, sidebarPadding, contentPadding, layout: layoutMode, minSidebarSize, maxSidebarSize, wideQuery, narrowLayout, sidebarExpanded, }: ISplitViewProps): ReactElement;
55
+ export declare function SplitView({ sidebar, children, storageKey, sidebarPosition, sidebarOpen, storage, sidebarLabel, contentLabel, resizeLabel, defaultSidebarSize, sidebarPadding, contentPadding, layout: layoutMode, minSidebarSize, maxSidebarSize, wideQuery, narrowLayout, sidebarExpanded, onSidebarOpenChange, sidebarFinalFocus, }: ISplitViewProps): ReactElement;
41
56
  export {};
@@ -12,8 +12,20 @@ import {
12
12
  Separator2
13
13
  } from "../../chunk-52aadmkc.js";
14
14
  import {
15
- useMediaQuery
16
- } from "../../chunk-k99h6evz.js";
15
+ useMediaQuery,
16
+ Drawer2,
17
+ DrawerClose2,
18
+ DrawerContent2,
19
+ DrawerTitle2
20
+ } from "../../chunk-cc35g6sr.js";
21
+ import"../../chunk-e6hk39ev.js";
22
+ import"../../chunk-x90xmrba.js";
23
+ import {
24
+ useDirection2
25
+ } from "../../chunk-jpvw9xqy.js";
26
+ import {
27
+ Button2
28
+ } from "../../chunk-32t5kc0y.js";
17
29
  import"../../chunk-5mydsjp3.js";
18
30
  // src/components/resizable/SplitView.tsx
19
31
  import {
@@ -24,6 +36,7 @@ import {
24
36
  useSyncExternalStore
25
37
  } from "react";
26
38
  import { createPortal } from "react-dom";
39
+ import { XIcon } from "lucide-react";
27
40
  import { useDefaultLayout, usePanelRef } from "react-resizable-panels";
28
41
  import { jsx, jsxs, Fragment } from "react/jsx-runtime";
29
42
  var layoutStorage = {
@@ -33,6 +46,8 @@ var layoutStorage = {
33
46
  if (!raw)
34
47
  return null;
35
48
  const value = JSON.parse(raw);
49
+ if (typeof value === "number")
50
+ return Number.isFinite(value) && value > 0 ? raw : null;
36
51
  if (typeof value !== "object" || value === null || Array.isArray(value))
37
52
  return null;
38
53
  return Object.values(value).every((size) => typeof size === "number" && Number.isFinite(size) && size >= 0 && size <= 100) ? raw : null;
@@ -46,6 +61,23 @@ var layoutStorage = {
46
61
  } catch {}
47
62
  }
48
63
  };
64
+ function getSidebarWidthKey(storageKey) {
65
+ return `split-view:${storageKey}:sidebar-px`;
66
+ }
67
+ function readSidebarWidth(storage, storageKey) {
68
+ try {
69
+ const raw = storage.getItem(getSidebarWidthKey(storageKey));
70
+ const value = raw === null ? null : JSON.parse(raw);
71
+ return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : null;
72
+ } catch {
73
+ return null;
74
+ }
75
+ }
76
+ function writeSidebarWidth(storage, storageKey, width) {
77
+ try {
78
+ storage.setItem(getSidebarWidthKey(storageKey), JSON.stringify(width));
79
+ } catch {}
80
+ }
49
81
  function createSlot() {
50
82
  const slot = document.createElement("div");
51
83
  slot.className = "contents";
@@ -82,22 +114,25 @@ function SplitView({
82
114
  maxSidebarSize = "50%",
83
115
  wideQuery = "(min-width: 1024px)",
84
116
  narrowLayout = "stack",
85
- sidebarExpanded = false
117
+ sidebarExpanded = false,
118
+ onSidebarOpenChange,
119
+ sidebarFinalFocus
86
120
  }) {
87
121
  const isFill = layoutMode === "fill";
88
122
  const isWide = useMediaQuery(wideQuery);
123
+ const direction = useDirection2();
89
124
  const isTakeover = !isWide && narrowLayout === "takeover" && sidebarOpen;
90
125
  const isStrip = !isWide && narrowLayout === "strip" && sidebarOpen;
91
- const layout = useDefaultLayout({ id: storageKey, storage, onlySaveAfterUserInteractions: true });
126
+ const isOverlay = !isWide && (narrowLayout === "sheet" || narrowLayout === "drawer");
92
127
  const stripLayout = useDefaultLayout({ id: `${storageKey}:strip`, storage, onlySaveAfterUserInteractions: true });
93
128
  const sidebarRef = usePanelRef();
94
129
  const isHydrated = useSyncExternalStore(subscribeToHydration, () => true, () => false);
95
130
  const [slots] = useState(createSlots);
96
131
  const portalSlots = isHydrated ? slots : null;
97
- const storedSize = layout.defaultLayout?.sidebar;
98
- const openSize = useRef(storedSize !== undefined && storedSize > 0 ? `${storedSize}%` : defaultSidebarSize);
99
- const wasShownOpen = useRef(false);
132
+ const [storedWidth] = useState(() => readSidebarWidth(storage, storageKey));
133
+ const openSize = useRef(storedWidth ?? defaultSidebarSize);
100
134
  const pendingOpenSize = useRef(null);
135
+ const groupRef = useRef(null);
101
136
  useEffect(() => {
102
137
  const panel = sidebarRef.current;
103
138
  if (!isWide || !panel)
@@ -107,12 +142,8 @@ function SplitView({
107
142
  pendingOpenSize.current = openSize.current;
108
143
  panel.expand();
109
144
  }
110
- wasShownOpen.current = true;
111
145
  return;
112
146
  }
113
- if (wasShownOpen.current && !panel.isCollapsed())
114
- openSize.current = `${panel.getSize().asPercentage}%`;
115
- wasShownOpen.current = false;
116
147
  panel.collapse();
117
148
  }, [isWide, sidebarOpen, sidebarRef]);
118
149
  const unexpandedSize = useRef(null);
@@ -129,15 +160,15 @@ function SplitView({
129
160
  }
130
161
  }, [isWide, sidebarOpen, sidebarExpanded, maxSidebarSize, sidebarRef]);
131
162
  const sidebarContent = /* @__PURE__ */ jsx("aside", {
132
- hidden: !sidebarOpen,
163
+ hidden: !sidebarOpen && !isOverlay,
133
164
  "aria-label": sidebarLabel,
134
- className: cn2("min-w-0 bg-card", isWide && "h-full", sidebarPadding === "panel" && "p-4", isFill && "min-h-0 overflow-y-auto", !isWide && isFill && !isTakeover && !isStrip && "max-h-[35%] shrink-0", isStrip && "h-full", isTakeover && isFill && "flex-1"),
165
+ className: cn2("min-w-0 bg-card", isWide && "h-full", sidebarPadding === "panel" && "p-4", (isFill || isOverlay) && "min-h-0 overflow-y-auto", isOverlay && "flex-1", !isWide && isFill && !isTakeover && !isStrip && !isOverlay && "max-h-[35%] shrink-0", isStrip && "h-full", isTakeover && isFill && "flex-1"),
135
166
  children: sidebar
136
167
  });
137
168
  const content = /* @__PURE__ */ jsx("section", {
138
169
  "aria-label": contentLabel,
139
170
  hidden: isTakeover,
140
- className: cn2("min-w-0 bg-card", isWide && "h-full", contentPadding === "panel" && "p-4", isFill && "flex min-h-0 flex-1 flex-col overflow-hidden"),
171
+ className: cn2("min-w-0 bg-card", isWide && "h-full", contentPadding === "panel" && "p-4", isFill && (isOverlay ? "flex flex-1 flex-col" : "flex min-h-0 flex-1 flex-col overflow-hidden")),
141
172
  children
142
173
  });
143
174
  const sidebarSlot = portalSlots ? /* @__PURE__ */ jsx(SlotHost, {
@@ -160,8 +191,11 @@ function SplitView({
160
191
  sidebarRef.current?.resize(pending);
161
192
  } else if (pending === null && size.inPixels === 0)
162
193
  sidebarRef.current?.resize(minSidebarSize);
194
+ else if (pending === null)
195
+ openSize.current = size.inPixels;
163
196
  },
164
- defaultSize: defaultSidebarSize,
197
+ defaultSize: openSize.current,
198
+ groupResizeBehavior: "preserve-pixel-size",
165
199
  minSize: minSidebarSize,
166
200
  maxSize: maxSidebarSize,
167
201
  children: sidebarSlot
@@ -173,8 +207,17 @@ function SplitView({
173
207
  });
174
208
  const frame = isWide ? /* @__PURE__ */ jsxs(Resizable2, {
175
209
  orientation: "horizontal",
176
- defaultLayout: layout.defaultLayout,
177
- onLayoutChanged: layout.onLayoutChanged,
210
+ elementRef: groupRef,
211
+ onLayoutChanged: (layout, meta) => {
212
+ const share = layout.sidebar;
213
+ const group = groupRef.current;
214
+ if (!meta.isUserInteraction || !sidebarOpen || share === undefined || share <= 0 || !group)
215
+ return;
216
+ const dividers = Array.from(group.querySelectorAll(":scope > [role='separator']"));
217
+ const width = dividers.reduce((total, divider) => total - divider.getBoundingClientRect().width, group.getBoundingClientRect().width);
218
+ openSize.current = width * share / 100;
219
+ writeSidebarWidth(storage, storageKey, openSize.current);
220
+ },
178
221
  children: [
179
222
  sidebarPosition === "start" ? sidebarPanel : contentPanel,
180
223
  /* @__PURE__ */ jsx(ResizableHandle2, {
@@ -208,6 +251,47 @@ function SplitView({
208
251
  children: contentSlot
209
252
  })
210
253
  ]
254
+ }) : isOverlay ? /* @__PURE__ */ jsxs(Fragment, {
255
+ children: [
256
+ /* @__PURE__ */ jsx("div", {
257
+ className: cn2("flex min-w-0 flex-col bg-card", isFill && "flex-1"),
258
+ children: contentSlot
259
+ }),
260
+ /* @__PURE__ */ jsx(Drawer2, {
261
+ open: sidebarOpen,
262
+ onOpenChange: (open) => onSidebarOpenChange?.(open),
263
+ showSwipeHandle: true,
264
+ swipeDirection: narrowLayout === "drawer" ? "down" : sidebarPosition === "start" === (direction === "rtl") ? "right" : "left",
265
+ children: /* @__PURE__ */ jsxs(DrawerContent2, {
266
+ "aria-label": sidebarLabel,
267
+ finalFocus: sidebarFinalFocus,
268
+ className: cn2(narrowLayout === "drawer" && "data-[swipe-axis=y]:[--drawer-content-max-height:100dvh] data-[swipe-axis=y]:rounded-t-none", narrowLayout === "drawer" && (sidebarExpanded ? "h-dvh" : "h-[85dvh]")),
269
+ children: [
270
+ narrowLayout === "sheet" && /* @__PURE__ */ jsxs("div", {
271
+ className: "flex shrink-0 items-center justify-between gap-2 p-panel pb-0",
272
+ children: [
273
+ /* @__PURE__ */ jsx(DrawerTitle2, {
274
+ children: sidebarLabel
275
+ }),
276
+ /* @__PURE__ */ jsxs(DrawerClose2, {
277
+ render: /* @__PURE__ */ jsx(Button2, {
278
+ variant: "ghost",
279
+ size: "sm"
280
+ }),
281
+ children: [
282
+ /* @__PURE__ */ jsx(XIcon, {
283
+ "aria-hidden": "true"
284
+ }),
285
+ "Close"
286
+ ]
287
+ })
288
+ ]
289
+ }),
290
+ sidebarSlot
291
+ ]
292
+ })
293
+ })
294
+ ]
211
295
  }) : /* @__PURE__ */ jsxs("div", {
212
296
  className: cn2("flex min-w-0 flex-col bg-card", isFill && "h-full min-h-0 overflow-hidden"),
213
297
  children: [
package/dist/index.js CHANGED
@@ -66,17 +66,6 @@ import {
66
66
  PaginationPrevious2,
67
67
  PaginationNext2,
68
68
  PaginationEllipsis2,
69
- Drawer2,
70
- DrawerTrigger2,
71
- DrawerPortal2,
72
- DrawerClose2,
73
- DrawerOverlay2,
74
- DrawerSwipeHandle2,
75
- DrawerContent2,
76
- DrawerHeader2,
77
- DrawerFooter2,
78
- DrawerTitle2,
79
- DrawerDescription2,
80
69
  Menubar2,
81
70
  MenubarMenu2,
82
71
  MenubarGroup2,
@@ -176,7 +165,7 @@ import {
176
165
  StatusTracker2,
177
166
  DashboardLayout2,
178
167
  BillingUsage2
179
- } from "./chunk-kr38ww4n.js";
168
+ } from "./chunk-fg1h007n.js";
180
169
  import {
181
170
  Combobox2,
182
171
  ComboboxValue2,
@@ -443,7 +432,19 @@ import {
443
432
  Input2
444
433
  } from "./chunk-7vg045gd.js";
445
434
  import"./chunk-7jpsybag.js";
446
- import"./chunk-k99h6evz.js";
435
+ import {
436
+ Drawer2,
437
+ DrawerTrigger2,
438
+ DrawerPortal2,
439
+ DrawerClose2,
440
+ DrawerOverlay2,
441
+ DrawerSwipeHandle2,
442
+ DrawerContent2,
443
+ DrawerHeader2,
444
+ DrawerFooter2,
445
+ DrawerTitle2,
446
+ DrawerDescription2
447
+ } from "./chunk-cc35g6sr.js";
447
448
  import {
448
449
  Separator2
449
450
  } from "./chunk-52aadmkc.js";
package/dist/prototype.js CHANGED
@@ -2051,7 +2051,7 @@ var program = new Command;
2051
2051
  // package.json
2052
2052
  var package_default = {
2053
2053
  name: "@alexgorbatchev/shadcn",
2054
- version: "0.0.93",
2054
+ version: "0.0.94",
2055
2055
  description: "Sharp, monospace React components with compact and comfortable densities.",
2056
2056
  license: "MIT",
2057
2057
  repository: {
@@ -82,7 +82,7 @@ Storybook CSF excerpts. Default args and render apply unless overridden. Local h
82
82
  {isVisible && (<SplitView {...args} storageKey="external-layout" storage={storage} sidebar={<h2>Navigation</h2>}>
83
83
  <h2>Content</h2>
84
84
  </SplitView>)}
85
- <Button onClick={() => setVisible(values.has("react-resizable-panels:external-layout"))}>
85
+ <Button onClick={() => setVisible(values.has("split-view:external-layout:sidebar-px"))}>
86
86
  Restore saved panels
87
87
  </Button>
88
88
  <p role="status">{isSaved ? "Layout saved" : "No saved layout"}</p>
@@ -236,3 +236,47 @@ Storybook CSF excerpts. Default args and render apply unless overridden. Local h
236
236
  }
237
237
  }
238
238
  ```
239
+
240
+ ### NarrowSheet
241
+
242
+ ```tsx
243
+ {
244
+ render: function Example(args) {
245
+ const [open, setOpen] = useState(false);
246
+ return (<div className="flex w-[600px] flex-col gap-2">
247
+ <Button onClick={() => setOpen(true)}>Pages</Button>
248
+ <SplitView {...args} sidebarLabel="Pages" sidebarOpen={open} onSidebarOpenChange={setOpen} wideQuery="(min-width: 100000px)" narrowLayout="sheet" layout="fill" sidebar={<nav aria-label="Projects and pages">
249
+ <button type="button" onClick={() => setOpen(false)}>
250
+ Brand questionnaire
251
+ </button>
252
+ </nav>}>
253
+ <h2>Incident review</h2>
254
+ </SplitView>
255
+ </div>);
256
+ }
257
+ }
258
+ ```
259
+
260
+ ### NarrowDrawer
261
+
262
+ ```tsx
263
+ {
264
+ render: function Example(args) {
265
+ const [open, setOpen] = useState(false);
266
+ const [expanded, setExpanded] = useState(false);
267
+ return (<div className="flex w-[600px] flex-col gap-2">
268
+ <Button onClick={() => setOpen(true)}>Comments</Button>
269
+ <SplitView {...args} sidebarLabel="Comments" sidebarPosition="end" sidebarOpen={open} sidebarExpanded={expanded} onSidebarOpenChange={setOpen} wideQuery="(min-width: 100000px)" narrowLayout="drawer" layout="fill" sidebar={<div className="flex gap-2 p-panel">
270
+ <Button variant="outline" onClick={() => setExpanded(!expanded)}>
271
+ {expanded ? "Collapse" : "Full height"}
272
+ </Button>
273
+ <Button variant="outline" onClick={() => setOpen(false)}>
274
+ Close comments
275
+ </Button>
276
+ </div>}>
277
+ <h2>Incident review</h2>
278
+ </SplitView>
279
+ </div>);
280
+ }
281
+ }
282
+ ```
@@ -595,3 +595,23 @@ Storybook CSF excerpts. Default args and render apply unless overridden. Local h
595
595
  </Drawer>)
596
596
  }
597
597
  ```
598
+
599
+ ### MotionPreference
600
+
601
+ ```tsx
602
+ {
603
+ render: (args) => (<Drawer {...args}>
604
+ <DrawerTrigger render={<Button variant="outline"/>}>Open details</DrawerTrigger>
605
+ <DrawerContent>
606
+ <DrawerHeader>
607
+ <DrawerTitle>Project details</DrawerTitle>
608
+ <DrawerDescription>Review the project before continuing.</DrawerDescription>
609
+ </DrawerHeader>
610
+ <div className="p-panel">Three tasks are ready.</div>
611
+ <DrawerFooter>
612
+ <DrawerClose render={<Button />}>Done</DrawerClose>
613
+ </DrawerFooter>
614
+ </DrawerContent>
615
+ </Drawer>)
616
+ }
617
+ ```
@@ -431,3 +431,23 @@ Storybook CSF excerpts. Default args and render apply unless overridden. Local h
431
431
  </Sheet>)
432
432
  }
433
433
  ```
434
+
435
+ ### MotionPreference
436
+
437
+ ```tsx
438
+ {
439
+ render: (args) => (<Sheet>
440
+ <SheetTrigger render={<Button variant="outline"/>}>Open preferences</SheetTrigger>
441
+ <SheetContent {...args}>
442
+ <SheetHeader>
443
+ <SheetTitle>Preferences</SheetTitle>
444
+ <SheetDescription>Adjust your workspace preferences.</SheetDescription>
445
+ </SheetHeader>
446
+ <SheetFooter>
447
+ <SheetClose render={<Button />}>Done</SheetClose>
448
+ </SheetFooter>
449
+ </SheetContent>
450
+ </Sheet>),
451
+ args: { side: "left" }
452
+ }
453
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alexgorbatchev/shadcn",
3
- "version": "0.0.93",
3
+ "version": "0.0.94",
4
4
  "description": "Sharp, monospace React components with compact and comfortable densities.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -1,11 +0,0 @@
1
- // src/hooks/useMediaQuery.ts
2
- import { useMemo, useSyncExternalStore } from "react";
3
- function useMediaQuery(query) {
4
- const media = useMemo(() => typeof window === "undefined" ? undefined : window.matchMedia(query), [query]);
5
- return useSyncExternalStore((listener) => {
6
- media?.addEventListener("change", listener);
7
- return () => media?.removeEventListener("change", listener);
8
- }, () => media?.matches ?? false, () => false);
9
- }
10
-
11
- export { useMediaQuery };