@jfdevelops/react-layout 0.20.0 → 0.22.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/create-config/create-resource-links.cjs +20 -4
- package/dist/create-config/create-resource-links.cjs.map +1 -1
- package/dist/create-config/create-resource-links.d.cts +9 -0
- package/dist/create-config/create-resource-links.d.cts.map +1 -1
- package/dist/create-config/create-resource-links.d.mts +9 -0
- package/dist/create-config/create-resource-links.d.mts.map +1 -1
- package/dist/create-config/create-resource-links.mjs +20 -4
- package/dist/create-config/create-resource-links.mjs.map +1 -1
- package/dist/create-config/define-layout.cjs +173 -1
- package/dist/create-config/define-layout.cjs.map +1 -1
- package/dist/create-config/define-layout.d.cts +174 -18
- package/dist/create-config/define-layout.d.cts.map +1 -1
- package/dist/create-config/define-layout.d.mts +174 -18
- package/dist/create-config/define-layout.d.mts.map +1 -1
- package/dist/create-config/define-layout.mjs +174 -2
- package/dist/create-config/define-layout.mjs.map +1 -1
- package/dist/create-config/for-resources/create-component.d.mts +1 -1
- package/dist/create-config/for-resources/create-for-resources.cjs +1 -1
- package/dist/create-config/for-resources/create-for-resources.mjs +1 -1
- package/dist/create-config/index.d.cts +2 -1
- package/dist/create-config/index.d.mts +2 -1
- package/dist/create-config/shell-context.cjs +22 -0
- package/dist/create-config/shell-context.cjs.map +1 -0
- package/dist/create-config/shell-context.d.cts +18 -0
- package/dist/create-config/shell-context.d.cts.map +1 -0
- package/dist/create-config/shell-context.d.mts +18 -0
- package/dist/create-config/shell-context.d.mts.map +1 -0
- package/dist/create-config/shell-context.mjs +21 -0
- package/dist/create-config/shell-context.mjs.map +1 -0
- package/dist/index.d.cts +3 -2
- package/dist/index.d.mts +3 -2
- package/dist/resource.d.mts +1 -1
- package/package.json +1 -1
- package/skills/build-react-layouts/SKILL.md +4 -0
- package/skills/build-react-layouts/references/architecture.md +92 -0
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
- Shared layout contract
|
|
7
7
|
- Semantic composables
|
|
8
8
|
- Preset composables
|
|
9
|
+
- Persistent application shell
|
|
9
10
|
- Secondary layout families
|
|
10
11
|
- Feature organization
|
|
11
12
|
|
|
@@ -125,6 +126,97 @@ Include the preset's required values in `layout.props.include`. Keep
|
|
|
125
126
|
presentation in the preset renderer and segment definitions in resource page
|
|
126
127
|
configuration.
|
|
127
128
|
|
|
129
|
+
## Persist the application shell across navigation
|
|
130
|
+
|
|
131
|
+
Plain `defineResourceLayout` wraps every page in its own `createResourceLayout`
|
|
132
|
+
component. Navigating between resources unmounts one page component and mounts
|
|
133
|
+
another, so the chrome that `render` produces — a sidebar, a header,
|
|
134
|
+
subscriptions, observers — is rebuilt on every navigation.
|
|
135
|
+
|
|
136
|
+
Use `defineResourceLayout.withLayout` when that rebuild is a problem. It returns
|
|
137
|
+
a `Shell` component in addition to the usual helpers:
|
|
138
|
+
|
|
139
|
+
```tsx
|
|
140
|
+
export const {
|
|
141
|
+
createResourceConfig,
|
|
142
|
+
createResourceLayout,
|
|
143
|
+
createResourceLinks,
|
|
144
|
+
Shell,
|
|
145
|
+
} = defineResourceLayout.withLayout({
|
|
146
|
+
resources: ['appointments', 'locations', 'services', 'settings'],
|
|
147
|
+
options: {
|
|
148
|
+
title: createProp.component({ type: 'ReactNode' }).optional(),
|
|
149
|
+
},
|
|
150
|
+
shell: {
|
|
151
|
+
composables: (create) => ({
|
|
152
|
+
Layout: create({
|
|
153
|
+
name: ({ capitalize, resource }) =>
|
|
154
|
+
resource ? `${capitalize(resource)}Shell` : 'Shell',
|
|
155
|
+
wrapWith: AppLayout,
|
|
156
|
+
}),
|
|
157
|
+
}),
|
|
158
|
+
render: (_props, { composables, children }) => (
|
|
159
|
+
<composables.Layout>
|
|
160
|
+
<AppSidebar />
|
|
161
|
+
<main>{children}</main>
|
|
162
|
+
</composables.Layout>
|
|
163
|
+
),
|
|
164
|
+
},
|
|
165
|
+
layout: {
|
|
166
|
+
// Optional under `withLayout`. Give a resource its own header or actions
|
|
167
|
+
// here, or omit `render` entirely and the page renders its children into
|
|
168
|
+
// the shell's outlet.
|
|
169
|
+
props: {
|
|
170
|
+
custom: {
|
|
171
|
+
children: createProp.component({ type: 'ReactNode' }),
|
|
172
|
+
actions: createProp.component({ type: 'ReactNode' }).optional(),
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
render: ({ children, actions }, { composables }) => (
|
|
176
|
+
<composables.ResourceLayout>
|
|
177
|
+
{actions && (
|
|
178
|
+
<composables.ResourceHeaderActions>
|
|
179
|
+
{actions}
|
|
180
|
+
</composables.ResourceHeaderActions>
|
|
181
|
+
)}
|
|
182
|
+
{children}
|
|
183
|
+
</composables.ResourceLayout>
|
|
184
|
+
),
|
|
185
|
+
},
|
|
186
|
+
});
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
Mount `Shell` once, in the parent route, wrapping the router outlet:
|
|
190
|
+
|
|
191
|
+
```tsx
|
|
192
|
+
function AdminRoute() {
|
|
193
|
+
return (
|
|
194
|
+
<Shell>
|
|
195
|
+
<Outlet />
|
|
196
|
+
</Shell>
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
The shell's `render` context matches a per-resource `render` context
|
|
202
|
+
(`composables`, `resources`, `name`) plus `children` — the outlet subtree, which
|
|
203
|
+
you place where page content belongs. `resource` and `resources.current` are
|
|
204
|
+
possibly `undefined`: the shell outlives any single page, so the current
|
|
205
|
+
resource is whatever the mounted page reports.
|
|
206
|
+
|
|
207
|
+
A page created by `createResourceLayout` reports its resource to the shell
|
|
208
|
+
automatically, so resource-scoped composable names still resolve. Pass the
|
|
209
|
+
always-optional `resource` prop to `<Shell>` for routes that render non-library
|
|
210
|
+
content, or in tests and stories:
|
|
211
|
+
|
|
212
|
+
```tsx
|
|
213
|
+
<Shell resource="appointments">{children}</Shell>
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
Keep genuinely shared, stateful chrome (sidebar, header, breadcrumb container)
|
|
217
|
+
in `shell`. Keep anything that varies per resource in `layout.render`. Anything
|
|
218
|
+
placed in `shell` cannot read per-page render props.
|
|
219
|
+
|
|
128
220
|
## Create secondary layout families
|
|
129
221
|
|
|
130
222
|
Create another `defineResourceLayout` when a surface has a distinct structural
|