@vvedantb/ui 0.49.0 → 0.50.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/shell/src/AppShell.js +126 -104
- package/package.json +1 -1
- package/shell/src/AppShell.tsx +33 -9
- package/shell/src/index.ts +1 -0
- package/src/index.ts +1 -0
package/README.md
CHANGED
|
@@ -341,7 +341,7 @@ import {
|
|
|
341
341
|
```
|
|
342
342
|
|
|
343
343
|
- Widths: `AppShell` sets `--app-shell-rail-width` (default `3.5rem`; `4rem` before 0.49.0), `--app-shell-sidebar-width` (rail plus panel, default `19.5rem`; `20rem` before 0.49.0) and `--app-shell-mobile-header-height` (default `calc(3.5rem + env(safe-area-inset-top, 0px))`) as inline style. Change them with `railWidth`, `sidebarWidth` and `mobileHeaderHeight`. The other pieces read these variables. Outside `AppShell`, set the variables yourself or pass a width class with `className`.
|
|
344
|
-
- `AppShell`: `sidebar`, `children`, `panelHidden` (main offsets by the rail width instead of the sidebar width), `skipLinkLabel` (`"Skip to main content"`), `mainId` (`"main-content"`), `className`, `mainClassName`, `contentClassName
|
|
344
|
+
- `AppShell`: `sidebar`, `children`, `panelHidden` (main offsets by the rail width instead of the sidebar width), `skipLinkLabel` (`"Skip to main content"`), `mainId` (`"main-content"`), `className`, `mainClassName`, `contentClassName`, `scroll` (`"contained"`: the shell is one screen high and the content card scrolls; `"document"`: the page scrolls, with no card, gutter or margin animation).
|
|
345
345
|
- `AppSidebar`: legacy (still supported) `rail`, `panel` and `mobile*` props; compose `Sidebar.*` instead. `rail`, `panel` (not rendered while `panelHidden`), `collapsed`, `panelHidden`, `isDesktop`, `mobileOpen`, `onMobileOpenChange`, `id` (default from `useId`), `asideProps` (`data-*` attributes for the `<aside>`), `className`, `mobileTitle`, `mobileHeaderActions` (0.5.2; trailing actions such as icon buttons, in place of the end spacer), `mobileMenuIcon` (`(open) => node`, default a menu icon), `mobileMenuLabel` (`"Open navigation menu"`), `closeLabel` (`"Close navigation"`). Swipe left or Escape closes the drawer. The drawer is `inert` while closed on mobile, and closes when `isDesktop` becomes `true`. Close it on route change in the app. The mobile header is a three-column grid, so the title and trailing actions stay on one row and a long title truncates (0.5.4).
|
|
346
346
|
- `SidebarRail`: legacy (still supported) `top`, `footer`, `bodyAsChild`, `tabs` and `*ClassName` props; compose `Sidebar.Rail` parts instead. `top`, `children` (scroll body), `footer`, `showDivider`, `bodyAsChild` (the single child, for example a tabs list, becomes the body), `className`, `topClassName`, `bodyClassName`, `footerClassName`. Other HTML attributes (`id`, `data-*`, `aria-*`) go to the root `<div>`. The top and footer wrappers render only when their slot is set.
|
|
347
347
|
- `RailTile`: `label` (`aria-label` and tooltip), `active`, `tooltip`, `showTooltip` (default `true`), `badge` (inside the tile, after the children; style it with `railBadgeClass`), `asChild`, `app`, `className`. Without `asChild` it is a native `<button type="button">` (0.5.3), so icons keep their authored size; other props go to it. With `asChild` the child (for example a router link) gets the tile classes and `aria-current="page"` when active.
|
|
@@ -459,10 +459,10 @@ Convention: compound parts are static members of a namespace object, `<Namespace
|
|
|
459
459
|
|
|
460
460
|
| Part | Purpose |
|
|
461
461
|
| --- | --- |
|
|
462
|
-
| `Root` | Frame `<div>`. Sets the `--app-shell-*` variables (`railWidth`, `sidebarWidth`, `mobileHeaderHeight`), owns the `resizable` state, and passes `panelHidden` and `mainId` to the parts. `style` merges over the variables. |
|
|
462
|
+
| `Root` | Frame `<div>`. Sets the `--app-shell-*` variables (`railWidth`, `sidebarWidth`, `mobileHeaderHeight`), owns the `resizable` state, and passes `panelHidden`, `scroll` and `mainId` to the parts. `style` merges over the variables. |
|
|
463
463
|
| `SkipLink` | Visually hidden link to `<main>`. `label` (`"Skip to main content"`), `targetId` (default the Root `mainId`). |
|
|
464
464
|
| `Main` | The `<main>`. Offsets by the sidebar width, or the rail width while `panelHidden`. `id` defaults to the Root `mainId` (`"main-content"`). |
|
|
465
|
-
| `Content` | The content card inside `<main>`. |
|
|
465
|
+
| `Content` | The content card inside `<main>`. A plain column while the Root `scroll` is `"document"`. |
|
|
466
466
|
|
|
467
467
|
### `Sidebar.*`
|
|
468
468
|
|
|
@@ -5,11 +5,12 @@ import { SidebarResizeProvider, useSidebarResizeContext, useSidebarResizeState }
|
|
|
5
5
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
6
6
|
const AppShellContext = /*#__PURE__*/createContext({
|
|
7
7
|
mainId: "main-content",
|
|
8
|
-
panelHidden: false
|
|
8
|
+
panelHidden: false,
|
|
9
|
+
scroll: "contained"
|
|
9
10
|
});
|
|
10
11
|
/** Frame `<div>`: sets the `--app-shell-*` variables and owns the resize state. `style` merges over the variables. */
|
|
11
12
|
function Root(t0) {
|
|
12
|
-
const $ = _c(
|
|
13
|
+
const $ = _c(35);
|
|
13
14
|
let className;
|
|
14
15
|
let props;
|
|
15
16
|
let resizable;
|
|
@@ -19,14 +20,16 @@ function Root(t0) {
|
|
|
19
20
|
let t3;
|
|
20
21
|
let t4;
|
|
21
22
|
let t5;
|
|
23
|
+
let t6;
|
|
22
24
|
if ($[0] !== t0) {
|
|
23
25
|
({
|
|
24
26
|
panelHidden: t1,
|
|
25
27
|
railWidth: t2,
|
|
26
28
|
sidebarWidth: t3,
|
|
27
29
|
resizable,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
scroll: t4,
|
|
31
|
+
mobileHeaderHeight: t5,
|
|
32
|
+
mainId: t6,
|
|
30
33
|
className,
|
|
31
34
|
style,
|
|
32
35
|
...props
|
|
@@ -41,6 +44,7 @@ function Root(t0) {
|
|
|
41
44
|
$[7] = t3;
|
|
42
45
|
$[8] = t4;
|
|
43
46
|
$[9] = t5;
|
|
47
|
+
$[10] = t6;
|
|
44
48
|
} else {
|
|
45
49
|
className = $[1];
|
|
46
50
|
props = $[2];
|
|
@@ -51,100 +55,106 @@ function Root(t0) {
|
|
|
51
55
|
t3 = $[7];
|
|
52
56
|
t4 = $[8];
|
|
53
57
|
t5 = $[9];
|
|
58
|
+
t6 = $[10];
|
|
54
59
|
}
|
|
55
60
|
const panelHidden = t1 === undefined ? false : t1;
|
|
56
61
|
const railWidth = t2 === undefined ? "3.5rem" : t2;
|
|
57
62
|
const sidebarWidth = t3 === undefined ? "19.5rem" : t3;
|
|
58
|
-
const
|
|
59
|
-
const
|
|
63
|
+
const scroll = t4 === undefined ? "contained" : t4;
|
|
64
|
+
const mobileHeaderHeight = t5 === undefined ? "calc(3.5rem + env(safe-area-inset-top, 0px))" : t5;
|
|
65
|
+
const mainId = t6 === undefined ? "main-content" : t6;
|
|
60
66
|
const resize = useSidebarResizeState(resizable);
|
|
61
|
-
const
|
|
62
|
-
let
|
|
63
|
-
if ($[
|
|
64
|
-
|
|
67
|
+
const t7 = resize ? `calc(${railWidth} + ${resize.width}px)` : sidebarWidth;
|
|
68
|
+
let t8;
|
|
69
|
+
if ($[11] !== mobileHeaderHeight || $[12] !== railWidth || $[13] !== t7) {
|
|
70
|
+
t8 = {
|
|
65
71
|
"--app-shell-rail-width": railWidth,
|
|
66
|
-
"--app-shell-sidebar-width":
|
|
72
|
+
"--app-shell-sidebar-width": t7,
|
|
67
73
|
"--app-shell-mobile-header-height": mobileHeaderHeight
|
|
68
74
|
};
|
|
69
|
-
$[
|
|
70
|
-
$[
|
|
71
|
-
$[12] = t6;
|
|
75
|
+
$[11] = mobileHeaderHeight;
|
|
76
|
+
$[12] = railWidth;
|
|
72
77
|
$[13] = t7;
|
|
78
|
+
$[14] = t8;
|
|
73
79
|
} else {
|
|
74
|
-
|
|
80
|
+
t8 = $[14];
|
|
75
81
|
}
|
|
76
|
-
const vars =
|
|
77
|
-
let
|
|
78
|
-
if ($[
|
|
79
|
-
|
|
82
|
+
const vars = t8;
|
|
83
|
+
let t9;
|
|
84
|
+
if ($[15] !== mainId || $[16] !== panelHidden || $[17] !== scroll) {
|
|
85
|
+
t9 = {
|
|
80
86
|
mainId,
|
|
81
|
-
panelHidden
|
|
87
|
+
panelHidden,
|
|
88
|
+
scroll
|
|
82
89
|
};
|
|
83
|
-
$[
|
|
84
|
-
$[
|
|
85
|
-
$[
|
|
86
|
-
} else {
|
|
87
|
-
t8 = $[16];
|
|
88
|
-
}
|
|
89
|
-
let t9;
|
|
90
|
-
if ($[17] !== className) {
|
|
91
|
-
t9 = cn("relative h-dvh overflow-hidden bg-background", className);
|
|
92
|
-
$[17] = className;
|
|
90
|
+
$[15] = mainId;
|
|
91
|
+
$[16] = panelHidden;
|
|
92
|
+
$[17] = scroll;
|
|
93
93
|
$[18] = t9;
|
|
94
94
|
} else {
|
|
95
95
|
t9 = $[18];
|
|
96
96
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
97
|
+
const t10 = scroll === "document" ? "relative min-h-dvh bg-background" : "relative h-dvh overflow-hidden bg-background";
|
|
98
|
+
let t11;
|
|
99
|
+
if ($[19] !== className || $[20] !== t10) {
|
|
100
|
+
t11 = cn(t10, className);
|
|
101
|
+
$[19] = className;
|
|
102
|
+
$[20] = t10;
|
|
103
|
+
$[21] = t11;
|
|
104
|
+
} else {
|
|
105
|
+
t11 = $[21];
|
|
106
|
+
}
|
|
107
|
+
let t12;
|
|
108
|
+
if ($[22] !== style || $[23] !== vars) {
|
|
109
|
+
t12 = {
|
|
100
110
|
...vars,
|
|
101
111
|
...style
|
|
102
112
|
};
|
|
103
|
-
$[
|
|
104
|
-
$[
|
|
105
|
-
$[
|
|
113
|
+
$[22] = style;
|
|
114
|
+
$[23] = vars;
|
|
115
|
+
$[24] = t12;
|
|
106
116
|
} else {
|
|
107
|
-
|
|
117
|
+
t12 = $[24];
|
|
108
118
|
}
|
|
109
|
-
let
|
|
110
|
-
if ($[
|
|
111
|
-
|
|
119
|
+
let t13;
|
|
120
|
+
if ($[25] !== props || $[26] !== t11 || $[27] !== t12) {
|
|
121
|
+
t13 = /*#__PURE__*/_jsx("div", {
|
|
112
122
|
...props,
|
|
113
|
-
className:
|
|
114
|
-
style:
|
|
123
|
+
className: t11,
|
|
124
|
+
style: t12
|
|
115
125
|
});
|
|
116
|
-
$[
|
|
117
|
-
$[
|
|
118
|
-
$[
|
|
119
|
-
$[
|
|
126
|
+
$[25] = props;
|
|
127
|
+
$[26] = t11;
|
|
128
|
+
$[27] = t12;
|
|
129
|
+
$[28] = t13;
|
|
120
130
|
} else {
|
|
121
|
-
|
|
131
|
+
t13 = $[28];
|
|
122
132
|
}
|
|
123
|
-
let
|
|
124
|
-
if ($[
|
|
125
|
-
|
|
133
|
+
let t14;
|
|
134
|
+
if ($[29] !== resize || $[30] !== t13) {
|
|
135
|
+
t14 = /*#__PURE__*/_jsx(SidebarResizeProvider, {
|
|
126
136
|
value: resize,
|
|
127
|
-
children:
|
|
137
|
+
children: t13
|
|
128
138
|
});
|
|
129
|
-
$[
|
|
130
|
-
$[
|
|
131
|
-
$[
|
|
139
|
+
$[29] = resize;
|
|
140
|
+
$[30] = t13;
|
|
141
|
+
$[31] = t14;
|
|
132
142
|
} else {
|
|
133
|
-
|
|
143
|
+
t14 = $[31];
|
|
134
144
|
}
|
|
135
|
-
let
|
|
136
|
-
if ($[
|
|
137
|
-
|
|
138
|
-
value:
|
|
139
|
-
children:
|
|
145
|
+
let t15;
|
|
146
|
+
if ($[32] !== t14 || $[33] !== t9) {
|
|
147
|
+
t15 = /*#__PURE__*/_jsx(AppShellContext.Provider, {
|
|
148
|
+
value: t9,
|
|
149
|
+
children: t14
|
|
140
150
|
});
|
|
141
|
-
$[
|
|
142
|
-
$[
|
|
143
|
-
$[
|
|
151
|
+
$[32] = t14;
|
|
152
|
+
$[33] = t9;
|
|
153
|
+
$[34] = t15;
|
|
144
154
|
} else {
|
|
145
|
-
|
|
155
|
+
t15 = $[34];
|
|
146
156
|
}
|
|
147
|
-
return
|
|
157
|
+
return t15;
|
|
148
158
|
}
|
|
149
159
|
/** Visually hidden link to `<main>`, shown on focus. */
|
|
150
160
|
function SkipLink(t0) {
|
|
@@ -204,7 +214,7 @@ function SkipLink(t0) {
|
|
|
204
214
|
}
|
|
205
215
|
/** `<main>`, offset by the sidebar (or rail while the Root `panelHidden`). `id` defaults to the Root `mainId`. */
|
|
206
216
|
function Main(t0) {
|
|
207
|
-
const $ = _c(
|
|
217
|
+
const $ = _c(13);
|
|
208
218
|
let className;
|
|
209
219
|
let id;
|
|
210
220
|
let props;
|
|
@@ -225,42 +235,46 @@ function Main(t0) {
|
|
|
225
235
|
}
|
|
226
236
|
const {
|
|
227
237
|
mainId,
|
|
228
|
-
panelHidden
|
|
238
|
+
panelHidden,
|
|
239
|
+
scroll
|
|
229
240
|
} = useContext(AppShellContext);
|
|
241
|
+
const pageScrolls = scroll === "document";
|
|
230
242
|
const resize = useSidebarResizeContext();
|
|
231
243
|
const t1 = id ?? mainId;
|
|
232
|
-
const t2 =
|
|
233
|
-
const t3 =
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
244
|
+
const t2 = pageScrolls ? "relative z-10 flex min-h-dvh outline-none" : "relative z-10 flex h-full min-h-0 outline-none md:p-2";
|
|
245
|
+
const t3 = panelHidden ? "md:ml-[var(--app-shell-rail-width)]" : "md:ml-[var(--app-shell-sidebar-width)]";
|
|
246
|
+
const t4 = !pageScrolls && !resize?.isResizing && "md:transition-[margin-left] md:[transition-duration:280ms] md:[transition-timing-function:cubic-bezier(0.22,1,0.36,1)]";
|
|
247
|
+
let t5;
|
|
248
|
+
if ($[4] !== className || $[5] !== t2 || $[6] !== t3 || $[7] !== t4) {
|
|
249
|
+
t5 = cn(t2, t3, t4, className);
|
|
237
250
|
$[4] = className;
|
|
238
251
|
$[5] = t2;
|
|
239
252
|
$[6] = t3;
|
|
240
253
|
$[7] = t4;
|
|
254
|
+
$[8] = t5;
|
|
241
255
|
} else {
|
|
242
|
-
|
|
256
|
+
t5 = $[8];
|
|
243
257
|
}
|
|
244
|
-
let
|
|
245
|
-
if ($[
|
|
246
|
-
|
|
258
|
+
let t6;
|
|
259
|
+
if ($[9] !== props || $[10] !== t1 || $[11] !== t5) {
|
|
260
|
+
t6 = /*#__PURE__*/_jsx("main", {
|
|
247
261
|
id: t1,
|
|
248
262
|
tabIndex: -1,
|
|
249
263
|
...props,
|
|
250
|
-
className:
|
|
264
|
+
className: t5
|
|
251
265
|
});
|
|
252
|
-
$[
|
|
253
|
-
$[
|
|
254
|
-
$[10] = t4;
|
|
266
|
+
$[9] = props;
|
|
267
|
+
$[10] = t1;
|
|
255
268
|
$[11] = t5;
|
|
269
|
+
$[12] = t6;
|
|
256
270
|
} else {
|
|
257
|
-
|
|
271
|
+
t6 = $[12];
|
|
258
272
|
}
|
|
259
|
-
return
|
|
273
|
+
return t6;
|
|
260
274
|
}
|
|
261
|
-
/** Content card inside `<main
|
|
275
|
+
/** Content card inside `<main>` (a plain column while the Root `scroll` is `"document"`). Pads for the mobile header below `md`. */
|
|
262
276
|
function Content(t0) {
|
|
263
|
-
const $ = _c(
|
|
277
|
+
const $ = _c(9);
|
|
264
278
|
let className;
|
|
265
279
|
let props;
|
|
266
280
|
if ($[0] !== t0) {
|
|
@@ -275,27 +289,32 @@ function Content(t0) {
|
|
|
275
289
|
className = $[1];
|
|
276
290
|
props = $[2];
|
|
277
291
|
}
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
292
|
+
const {
|
|
293
|
+
scroll
|
|
294
|
+
} = useContext(AppShellContext);
|
|
295
|
+
const t1 = scroll === "document" ? "flex min-w-0 flex-1 flex-col pt-[var(--app-shell-mobile-header-height)] md:pt-0" : "flex min-h-0 flex-1 flex-col overflow-hidden bg-surface pt-[var(--app-shell-mobile-header-height)] md:rounded-lg md:pt-0";
|
|
296
|
+
let t2;
|
|
297
|
+
if ($[3] !== className || $[4] !== t1) {
|
|
298
|
+
t2 = cn(t1, className);
|
|
281
299
|
$[3] = className;
|
|
282
300
|
$[4] = t1;
|
|
301
|
+
$[5] = t2;
|
|
283
302
|
} else {
|
|
284
|
-
|
|
303
|
+
t2 = $[5];
|
|
285
304
|
}
|
|
286
|
-
let
|
|
287
|
-
if ($[
|
|
288
|
-
|
|
305
|
+
let t3;
|
|
306
|
+
if ($[6] !== props || $[7] !== t2) {
|
|
307
|
+
t3 = /*#__PURE__*/_jsx("div", {
|
|
289
308
|
...props,
|
|
290
|
-
className:
|
|
309
|
+
className: t2
|
|
291
310
|
});
|
|
292
|
-
$[
|
|
293
|
-
$[6] = t1;
|
|
311
|
+
$[6] = props;
|
|
294
312
|
$[7] = t2;
|
|
313
|
+
$[8] = t3;
|
|
295
314
|
} else {
|
|
296
|
-
|
|
315
|
+
t3 = $[8];
|
|
297
316
|
}
|
|
298
|
-
return
|
|
317
|
+
return t3;
|
|
299
318
|
}
|
|
300
319
|
|
|
301
320
|
/**
|
|
@@ -304,7 +323,7 @@ function Content(t0) {
|
|
|
304
323
|
* `.Main` and `.Content`.
|
|
305
324
|
*/
|
|
306
325
|
function LegacyAppShell(t0) {
|
|
307
|
-
const $ = _c(
|
|
326
|
+
const $ = _c(22);
|
|
308
327
|
const {
|
|
309
328
|
sidebar,
|
|
310
329
|
children,
|
|
@@ -312,6 +331,7 @@ function LegacyAppShell(t0) {
|
|
|
312
331
|
railWidth,
|
|
313
332
|
sidebarWidth,
|
|
314
333
|
resizable,
|
|
334
|
+
scroll,
|
|
315
335
|
mobileHeaderHeight,
|
|
316
336
|
skipLinkLabel,
|
|
317
337
|
mainId: t2,
|
|
@@ -360,12 +380,13 @@ function LegacyAppShell(t0) {
|
|
|
360
380
|
t5 = $[9];
|
|
361
381
|
}
|
|
362
382
|
let t6;
|
|
363
|
-
if ($[10] !== className || $[11] !== mainId || $[12] !== mobileHeaderHeight || $[13] !== panelHidden || $[14] !== railWidth || $[15] !== resizable || $[16] !==
|
|
383
|
+
if ($[10] !== className || $[11] !== mainId || $[12] !== mobileHeaderHeight || $[13] !== panelHidden || $[14] !== railWidth || $[15] !== resizable || $[16] !== scroll || $[17] !== sidebar || $[18] !== sidebarWidth || $[19] !== t3 || $[20] !== t5) {
|
|
364
384
|
t6 = /*#__PURE__*/_jsxs(Root, {
|
|
365
385
|
panelHidden: panelHidden,
|
|
366
386
|
railWidth: railWidth,
|
|
367
387
|
sidebarWidth: sidebarWidth,
|
|
368
388
|
resizable: resizable,
|
|
389
|
+
scroll: scroll,
|
|
369
390
|
mobileHeaderHeight: mobileHeaderHeight,
|
|
370
391
|
mainId: mainId,
|
|
371
392
|
className: className,
|
|
@@ -377,13 +398,14 @@ function LegacyAppShell(t0) {
|
|
|
377
398
|
$[13] = panelHidden;
|
|
378
399
|
$[14] = railWidth;
|
|
379
400
|
$[15] = resizable;
|
|
380
|
-
$[16] =
|
|
381
|
-
$[17] =
|
|
382
|
-
$[18] =
|
|
383
|
-
$[19] =
|
|
384
|
-
$[20] =
|
|
401
|
+
$[16] = scroll;
|
|
402
|
+
$[17] = sidebar;
|
|
403
|
+
$[18] = sidebarWidth;
|
|
404
|
+
$[19] = t3;
|
|
405
|
+
$[20] = t5;
|
|
406
|
+
$[21] = t6;
|
|
385
407
|
} else {
|
|
386
|
-
t6 = $[
|
|
408
|
+
t6 = $[21];
|
|
387
409
|
}
|
|
388
410
|
return t6;
|
|
389
411
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vvedantb/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.50.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Shared React 19 UI for web apps: one main JavaScript entry (primitives, shell pieces, app helpers including the Convex and Clerk provider, VITE env parsing and ensure-user, artifact viewers over the @vvedantb/server artifacts core, native tokens), third-party brand logos (also @vvedantb/ui/logos), motion-driven animated SVG icons (@vvedantb/ui/icons/animated), a client entry without @vvedantb/server, convex or Clerk for Chrome extensions, design-token CSS, shared Tailwind v4 CSS, a Tailwind preset and packaged Instrument Sans fonts.",
|
|
6
6
|
"type": "module",
|
package/shell/src/AppShell.tsx
CHANGED
|
@@ -27,6 +27,12 @@ export type AppShellProps = {
|
|
|
27
27
|
* the state with `AppSidebar`, `SidebarResizeHandle` and `useAppShellResize`.
|
|
28
28
|
*/
|
|
29
29
|
resizable?: SidebarResizeOptions;
|
|
30
|
+
/**
|
|
31
|
+
* `"contained"` (default): the shell is one screen high and the content card
|
|
32
|
+
* scrolls. `"document"`: the page scrolls. The frame grows with the content,
|
|
33
|
+
* and there is no card, gutter or margin animation.
|
|
34
|
+
*/
|
|
35
|
+
scroll?: AppShellScroll;
|
|
30
36
|
/** Sets `--app-shell-mobile-header-height`. Default `"calc(3.5rem + env(safe-area-inset-top, 0px))"`. */
|
|
31
37
|
mobileHeaderHeight?: string;
|
|
32
38
|
/** Default `"Skip to main content"`. */
|
|
@@ -39,17 +45,20 @@ export type AppShellProps = {
|
|
|
39
45
|
contentClassName?: string;
|
|
40
46
|
};
|
|
41
47
|
|
|
48
|
+
export type AppShellScroll = "contained" | "document";
|
|
49
|
+
|
|
42
50
|
type ShellVars = CSSProperties & Record<`--app-shell-${string}`, string>;
|
|
43
51
|
|
|
44
|
-
type AppShellContextValue = { mainId: string; panelHidden: boolean };
|
|
52
|
+
type AppShellContextValue = { mainId: string; panelHidden: boolean; scroll: AppShellScroll };
|
|
45
53
|
|
|
46
54
|
const AppShellContext = createContext<AppShellContextValue>({
|
|
47
55
|
mainId: "main-content",
|
|
48
56
|
panelHidden: false,
|
|
57
|
+
scroll: "contained",
|
|
49
58
|
});
|
|
50
59
|
|
|
51
60
|
export type AppShellRootProps = ComponentProps<"div"> &
|
|
52
|
-
Pick<AppShellProps, "panelHidden" | "railWidth" | "sidebarWidth" | "resizable" | "mobileHeaderHeight" | "mainId">;
|
|
61
|
+
Pick<AppShellProps, "panelHidden" | "railWidth" | "sidebarWidth" | "resizable" | "scroll" | "mobileHeaderHeight" | "mainId">;
|
|
53
62
|
|
|
54
63
|
/** Frame `<div>`: sets the `--app-shell-*` variables and owns the resize state. `style` merges over the variables. */
|
|
55
64
|
function Root({
|
|
@@ -57,6 +66,7 @@ function Root({
|
|
|
57
66
|
railWidth = "3.5rem",
|
|
58
67
|
sidebarWidth = "19.5rem",
|
|
59
68
|
resizable,
|
|
69
|
+
scroll = "contained",
|
|
60
70
|
mobileHeaderHeight = "calc(3.5rem + env(safe-area-inset-top, 0px))",
|
|
61
71
|
mainId = "main-content",
|
|
62
72
|
className,
|
|
@@ -70,11 +80,16 @@ function Root({
|
|
|
70
80
|
"--app-shell-mobile-header-height": mobileHeaderHeight,
|
|
71
81
|
};
|
|
72
82
|
return (
|
|
73
|
-
<AppShellContext.Provider value={{ mainId, panelHidden }}>
|
|
83
|
+
<AppShellContext.Provider value={{ mainId, panelHidden, scroll }}>
|
|
74
84
|
<SidebarResizeProvider value={resize}>
|
|
75
85
|
<div
|
|
76
86
|
{...props}
|
|
77
|
-
className={cn(
|
|
87
|
+
className={cn(
|
|
88
|
+
scroll === "document"
|
|
89
|
+
? "relative min-h-dvh bg-background"
|
|
90
|
+
: "relative h-dvh overflow-hidden bg-background",
|
|
91
|
+
className,
|
|
92
|
+
)}
|
|
78
93
|
style={{ ...vars, ...style }}
|
|
79
94
|
/>
|
|
80
95
|
</SidebarResizeProvider>
|
|
@@ -110,7 +125,8 @@ export type AppShellMainProps = ComponentProps<"main">;
|
|
|
110
125
|
|
|
111
126
|
/** `<main>`, offset by the sidebar (or rail while the Root `panelHidden`). `id` defaults to the Root `mainId`. */
|
|
112
127
|
function Main({ id, className, ...props }: AppShellMainProps) {
|
|
113
|
-
const { mainId, panelHidden } = useContext(AppShellContext);
|
|
128
|
+
const { mainId, panelHidden, scroll } = useContext(AppShellContext);
|
|
129
|
+
const pageScrolls = scroll === "document";
|
|
114
130
|
const resize = useSidebarResizeContext();
|
|
115
131
|
return (
|
|
116
132
|
<main
|
|
@@ -118,9 +134,12 @@ function Main({ id, className, ...props }: AppShellMainProps) {
|
|
|
118
134
|
tabIndex={-1}
|
|
119
135
|
{...props}
|
|
120
136
|
className={cn(
|
|
121
|
-
|
|
137
|
+
pageScrolls
|
|
138
|
+
? "relative z-10 flex min-h-dvh outline-none"
|
|
139
|
+
: "relative z-10 flex h-full min-h-0 outline-none md:p-2",
|
|
122
140
|
panelHidden ? "md:ml-[var(--app-shell-rail-width)]" : "md:ml-[var(--app-shell-sidebar-width)]",
|
|
123
|
-
!
|
|
141
|
+
!pageScrolls &&
|
|
142
|
+
!resize?.isResizing &&
|
|
124
143
|
"md:transition-[margin-left] md:[transition-duration:280ms] md:[transition-timing-function:cubic-bezier(0.22,1,0.36,1)]",
|
|
125
144
|
className,
|
|
126
145
|
)}
|
|
@@ -130,13 +149,16 @@ function Main({ id, className, ...props }: AppShellMainProps) {
|
|
|
130
149
|
|
|
131
150
|
export type AppShellContentProps = ComponentProps<"div">;
|
|
132
151
|
|
|
133
|
-
/** Content card inside `<main
|
|
152
|
+
/** Content card inside `<main>` (a plain column while the Root `scroll` is `"document"`). Pads for the mobile header below `md`. */
|
|
134
153
|
function Content({ className, ...props }: AppShellContentProps) {
|
|
154
|
+
const { scroll } = useContext(AppShellContext);
|
|
135
155
|
return (
|
|
136
156
|
<div
|
|
137
157
|
{...props}
|
|
138
158
|
className={cn(
|
|
139
|
-
|
|
159
|
+
scroll === "document"
|
|
160
|
+
? "flex min-w-0 flex-1 flex-col pt-[var(--app-shell-mobile-header-height)] md:pt-0"
|
|
161
|
+
: "flex min-h-0 flex-1 flex-col overflow-hidden bg-surface pt-[var(--app-shell-mobile-header-height)] md:rounded-lg md:pt-0",
|
|
140
162
|
className,
|
|
141
163
|
)}
|
|
142
164
|
/>
|
|
@@ -155,6 +177,7 @@ function LegacyAppShell({
|
|
|
155
177
|
railWidth,
|
|
156
178
|
sidebarWidth,
|
|
157
179
|
resizable,
|
|
180
|
+
scroll,
|
|
158
181
|
mobileHeaderHeight,
|
|
159
182
|
skipLinkLabel,
|
|
160
183
|
mainId = "main-content",
|
|
@@ -168,6 +191,7 @@ function LegacyAppShell({
|
|
|
168
191
|
railWidth={railWidth}
|
|
169
192
|
sidebarWidth={sidebarWidth}
|
|
170
193
|
resizable={resizable}
|
|
194
|
+
scroll={scroll}
|
|
171
195
|
mobileHeaderHeight={mobileHeaderHeight}
|
|
172
196
|
mainId={mainId}
|
|
173
197
|
className={className}
|
package/shell/src/index.ts
CHANGED