@alexgorbatchev/shadcn 0.0.74 → 0.0.75
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -472,7 +472,7 @@ Embedded actions, links, menus, editable fields, and media controls retain their
|
|
|
472
472
|
|
|
473
473
|
# Split views
|
|
474
474
|
|
|
475
|
-
`SplitView` pairs a `sidebar` with its `children` in equally padded, borderless panels. Provide `sidebarLabel`, `contentLabel`, and `resizeLabel` for accessibility and a unique `storageKey` to remember the resized layout in localStorage. The desktop sidebar defaults to 325px (`defaultSidebarSize`), with a 200px minimum and a 50% maximum. Its 2px divider supports mouse, touch, and keyboard resizing. Below 1024px, the panels stack vertically while preserving the desktop preference. Storage failures leave the layout usable.
|
|
475
|
+
`SplitView` pairs a `sidebar` with its `children` in equally padded, borderless panels. Provide `sidebarLabel`, `contentLabel`, and `resizeLabel` for accessibility and a unique `storageKey` to remember the resized layout in localStorage. The desktop sidebar defaults to 325px (`defaultSidebarSize`), with a 200px minimum and a 50% maximum. Its 2px divider supports mouse, touch, and keyboard resizing. Below 1024px, the panels stack vertically while preserving the desktop preference. The sidebar and content stay mounted when the viewport crosses 1024px: they render into slots that move between the stacked and resizable layouts, so form values and component state survive resizing and rotation. Focus and scroll positions inside the panels reset when the layout changes. Server rendering places the panels in the stacked layout; after hydration they move into their slots and mount once more. Storage failures leave the layout usable.
|
|
476
476
|
|
|
477
477
|
`SplitView` defaults to `layout="content"` and `sidebarPadding="panel"` / `contentPadding="panel"`. Choose `"none"` padding for children that own their spacing. With a bounded parent, `layout="fill"` fills the available height, scrolls overflowing navigation independently, and leaves the content panel available for a scrolling child. On narrow screens the stacked navigation uses at most 35% of the split height.
|
|
478
478
|
|
|
@@ -17,5 +17,9 @@ interface ISplitViewProps {
|
|
|
17
17
|
/** Fill a bounded parent; mobile navigation scrolls within at most 35% of its height. */
|
|
18
18
|
layout?: "content" | "fill";
|
|
19
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Pairs a resizable sidebar with its content above 1024px and stacks them below it. The sidebar and content render
|
|
22
|
+
* into slots that move between the two layouts, so their state survives resizing across the breakpoint.
|
|
23
|
+
*/
|
|
20
24
|
export declare function SplitView({ sidebar, children, storageKey, sidebarPosition, sidebarOpen, storage, sidebarLabel, contentLabel, resizeLabel, defaultSidebarSize, sidebarPadding, contentPadding, layout: layoutMode, }: ISplitViewProps): ReactElement;
|
|
21
25
|
export {};
|
|
@@ -16,9 +16,10 @@ import {
|
|
|
16
16
|
} from "../../chunk-k99h6evz.js";
|
|
17
17
|
import"../../chunk-5mydsjp3.js";
|
|
18
18
|
// src/components/resizable/SplitView.tsx
|
|
19
|
-
import { useEffect } from "react";
|
|
19
|
+
import { useCallback, useEffect, useState, useSyncExternalStore } from "react";
|
|
20
|
+
import { createPortal } from "react-dom";
|
|
20
21
|
import { useDefaultLayout, usePanelRef } from "react-resizable-panels";
|
|
21
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
22
|
+
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
22
23
|
var layoutStorage = {
|
|
23
24
|
getItem(key) {
|
|
24
25
|
try {
|
|
@@ -39,6 +40,24 @@ var layoutStorage = {
|
|
|
39
40
|
} catch {}
|
|
40
41
|
}
|
|
41
42
|
};
|
|
43
|
+
function createSlot() {
|
|
44
|
+
const slot = document.createElement("div");
|
|
45
|
+
slot.className = "contents";
|
|
46
|
+
return slot;
|
|
47
|
+
}
|
|
48
|
+
function createSlots() {
|
|
49
|
+
return typeof document === "undefined" ? null : { sidebar: createSlot(), content: createSlot() };
|
|
50
|
+
}
|
|
51
|
+
function subscribeToHydration() {
|
|
52
|
+
return () => {};
|
|
53
|
+
}
|
|
54
|
+
function SlotHost({ slot }) {
|
|
55
|
+
const attach = useCallback((host) => host?.append(slot), [slot]);
|
|
56
|
+
return /* @__PURE__ */ jsx("div", {
|
|
57
|
+
className: "contents",
|
|
58
|
+
ref: attach
|
|
59
|
+
});
|
|
60
|
+
}
|
|
42
61
|
function SplitView({
|
|
43
62
|
sidebar,
|
|
44
63
|
children,
|
|
@@ -58,6 +77,9 @@ function SplitView({
|
|
|
58
77
|
const isWide = useMediaQuery("(min-width: 1024px)");
|
|
59
78
|
const layout = useDefaultLayout({ id: storageKey, storage, onlySaveAfterUserInteractions: true });
|
|
60
79
|
const sidebarRef = usePanelRef();
|
|
80
|
+
const isHydrated = useSyncExternalStore(subscribeToHydration, () => true, () => false);
|
|
81
|
+
const [slots] = useState(createSlots);
|
|
82
|
+
const portalSlots = isHydrated ? slots : null;
|
|
61
83
|
useEffect(() => {
|
|
62
84
|
if (!isWide)
|
|
63
85
|
return;
|
|
@@ -77,18 +99,12 @@ function SplitView({
|
|
|
77
99
|
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"),
|
|
78
100
|
children
|
|
79
101
|
});
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
thickness: "strong",
|
|
87
|
-
hidden: !sidebarOpen
|
|
88
|
-
}),
|
|
89
|
-
sidebarPosition === "start" ? content : sidebarContent
|
|
90
|
-
]
|
|
91
|
-
});
|
|
102
|
+
const sidebarSlot = portalSlots ? /* @__PURE__ */ jsx(SlotHost, {
|
|
103
|
+
slot: portalSlots.sidebar
|
|
104
|
+
}) : sidebarContent;
|
|
105
|
+
const contentSlot = portalSlots ? /* @__PURE__ */ jsx(SlotHost, {
|
|
106
|
+
slot: portalSlots.content
|
|
107
|
+
}) : content;
|
|
92
108
|
const sidebarPanel = /* @__PURE__ */ jsx(ResizablePanel2, {
|
|
93
109
|
id: "sidebar",
|
|
94
110
|
panelRef: sidebarRef,
|
|
@@ -97,14 +113,14 @@ function SplitView({
|
|
|
97
113
|
defaultSize: defaultSidebarSize,
|
|
98
114
|
minSize: 200,
|
|
99
115
|
maxSize: "50%",
|
|
100
|
-
children:
|
|
116
|
+
children: sidebarSlot
|
|
101
117
|
});
|
|
102
118
|
const contentPanel = /* @__PURE__ */ jsx(ResizablePanel2, {
|
|
103
119
|
id: "content",
|
|
104
120
|
minSize: "35%",
|
|
105
|
-
children:
|
|
121
|
+
children: contentSlot
|
|
106
122
|
});
|
|
107
|
-
|
|
123
|
+
const frame = isWide ? /* @__PURE__ */ jsxs(Resizable2, {
|
|
108
124
|
orientation: "horizontal",
|
|
109
125
|
defaultLayout: layout.defaultLayout,
|
|
110
126
|
onLayoutChanged: layout.onLayoutChanged,
|
|
@@ -117,6 +133,23 @@ function SplitView({
|
|
|
117
133
|
}),
|
|
118
134
|
sidebarPosition === "start" ? contentPanel : sidebarPanel
|
|
119
135
|
]
|
|
136
|
+
}) : /* @__PURE__ */ jsxs("div", {
|
|
137
|
+
className: cn2("flex min-w-0 flex-col bg-card", isFill && "h-full min-h-0 overflow-hidden"),
|
|
138
|
+
children: [
|
|
139
|
+
sidebarPosition === "start" ? sidebarSlot : contentSlot,
|
|
140
|
+
/* @__PURE__ */ jsx(Separator2, {
|
|
141
|
+
thickness: "strong",
|
|
142
|
+
hidden: !sidebarOpen
|
|
143
|
+
}),
|
|
144
|
+
sidebarPosition === "start" ? contentSlot : sidebarSlot
|
|
145
|
+
]
|
|
146
|
+
});
|
|
147
|
+
return /* @__PURE__ */ jsxs(Fragment, {
|
|
148
|
+
children: [
|
|
149
|
+
frame,
|
|
150
|
+
portalSlots && createPortal(sidebarContent, portalSlots.sidebar),
|
|
151
|
+
portalSlots && createPortal(content, portalSlots.content)
|
|
152
|
+
]
|
|
120
153
|
});
|
|
121
154
|
}
|
|
122
155
|
export {
|
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.
|
|
2054
|
+
version: "0.0.75",
|
|
2055
2055
|
description: "Sharp, monospace React components with compact and comfortable densities.",
|
|
2056
2056
|
license: "MIT",
|
|
2057
2057
|
repository: {
|
|
@@ -9,7 +9,7 @@ Source: src/components/stories/layout/SplitView.stories.tsx
|
|
|
9
9
|
|
|
10
10
|
```tsx
|
|
11
11
|
import { SplitView } from "@alexgorbatchev/shadcn/resizable";
|
|
12
|
-
import { Button } from "@alexgorbatchev/shadcn";
|
|
12
|
+
import { Button, Field, FieldGroup, FieldLabel, Input, Switch } from "@alexgorbatchev/shadcn";
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
## Supporting imports
|
|
@@ -127,3 +127,36 @@ Storybook CSF excerpts. Default args and render apply unless overridden. Local h
|
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
129
|
```
|
|
130
|
+
|
|
131
|
+
### StatefulPanels
|
|
132
|
+
|
|
133
|
+
```tsx
|
|
134
|
+
{
|
|
135
|
+
render: function Example(args) {
|
|
136
|
+
const key = useId();
|
|
137
|
+
return (<div className="w-[900px] max-w-full">
|
|
138
|
+
<SplitView {...args} storageKey={key} sidebar={<FieldGroup>
|
|
139
|
+
<Field>
|
|
140
|
+
<FieldLabel htmlFor={`${key}-filter`}>Filter pages</FieldLabel>
|
|
141
|
+
<Input id={`${key}-filter`}/>
|
|
142
|
+
</Field>
|
|
143
|
+
<Field orientation="horizontal">
|
|
144
|
+
<Switch id={`${key}-archived`}/>
|
|
145
|
+
<FieldLabel htmlFor={`${key}-archived`}>Show archived</FieldLabel>
|
|
146
|
+
</Field>
|
|
147
|
+
</FieldGroup>}>
|
|
148
|
+
<FieldGroup>
|
|
149
|
+
<Field>
|
|
150
|
+
<FieldLabel htmlFor={`${key}-answer`}>Draft answer</FieldLabel>
|
|
151
|
+
<Input id={`${key}-answer`}/>
|
|
152
|
+
</Field>
|
|
153
|
+
<Field orientation="horizontal">
|
|
154
|
+
<Switch id={`${key}-notify`}/>
|
|
155
|
+
<FieldLabel htmlFor={`${key}-notify`}>Notify me</FieldLabel>
|
|
156
|
+
</Field>
|
|
157
|
+
</FieldGroup>
|
|
158
|
+
</SplitView>
|
|
159
|
+
</div>);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
```
|
package/llms/setup.md
CHANGED
|
@@ -472,7 +472,7 @@ Embedded actions, links, menus, editable fields, and media controls retain their
|
|
|
472
472
|
|
|
473
473
|
# Split views
|
|
474
474
|
|
|
475
|
-
`SplitView` pairs a `sidebar` with its `children` in equally padded, borderless panels. Provide `sidebarLabel`, `contentLabel`, and `resizeLabel` for accessibility and a unique `storageKey` to remember the resized layout in localStorage. The desktop sidebar defaults to 325px (`defaultSidebarSize`), with a 200px minimum and a 50% maximum. Its 2px divider supports mouse, touch, and keyboard resizing. Below 1024px, the panels stack vertically while preserving the desktop preference. Storage failures leave the layout usable.
|
|
475
|
+
`SplitView` pairs a `sidebar` with its `children` in equally padded, borderless panels. Provide `sidebarLabel`, `contentLabel`, and `resizeLabel` for accessibility and a unique `storageKey` to remember the resized layout in localStorage. The desktop sidebar defaults to 325px (`defaultSidebarSize`), with a 200px minimum and a 50% maximum. Its 2px divider supports mouse, touch, and keyboard resizing. Below 1024px, the panels stack vertically while preserving the desktop preference. The sidebar and content stay mounted when the viewport crosses 1024px: they render into slots that move between the stacked and resizable layouts, so form values and component state survive resizing and rotation. Focus and scroll positions inside the panels reset when the layout changes. Server rendering places the panels in the stacked layout; after hydration they move into their slots and mount once more. Storage failures leave the layout usable.
|
|
476
476
|
|
|
477
477
|
`SplitView` defaults to `layout="content"` and `sidebarPadding="panel"` / `contentPadding="panel"`. Choose `"none"` padding for children that own their spacing. With a bounded parent, `layout="fill"` fills the available height, scrolls overflowing navigation independently, and leaves the content panel available for a scrolling child. On narrow screens the stacked navigation uses at most 35% of the split height.
|
|
478
478
|
|