@imperium/layout 7.3.3 → 8.3.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 +0 -349
- package/dist/client.js +535 -325
- package/dist/client.min.js +1 -1
- package/dist/client.min.js.map +1 -1
- package/dist/commonItems.d.ts +2 -1
- package/dist/content/hooks/useBuildContentData.d.ts +3 -1
- package/dist/content/types.d.ts +2 -1
- package/dist/datahooks/DataHooks.d.ts +1 -1
- package/dist/datahooks/ExecutePermissionHook.d.ts +7 -0
- package/dist/datahooks/PermissionHooks.d.ts +7 -0
- package/dist/datahooks/types.d.ts +1 -1
- package/dist/hooks/useBuildData.d.ts +3 -2
- package/dist/hooks/useSelectPermission.d.ts +2 -0
- package/dist/layout/components/LayoutItemWrapper.d.ts +2 -2
- package/dist/layout/components/PlainItem.d.ts +2 -2
- package/dist/layout/types.d.ts +2 -1
- package/dist/state.d.ts +38 -0
- package/dist/types.d.ts +4 -0
- package/package.json +7 -6
- package/dist/content/components/ActionLinkSidebarItemComponent.d.ts +0 -9
- package/dist/content/components/ContentItemWrapper.d.ts +0 -12
- package/dist/content/components/dividerSidebarItem.d.ts +0 -2
- package/dist/hooks/DataHooks.d.ts +0 -12
- package/dist/hooks/ExecuteDataHook.d.ts +0 -7
- package/dist/hooks/types.d.ts +0 -19
- package/dist/layout/components/CustomItem.d.ts +0 -7
- package/dist/layout/components/CustomItemComponent.d.ts +0 -7
- package/dist/layout/components/ItemBar.d.ts +0 -15
- package/dist/layout/components/ItemWrapper.d.ts +0 -19
- package/dist/layout/components/SidebarToggleMenuItem.d.ts +0 -7
- package/dist/layout/hooks/useBuildData.d.ts +0 -3
- package/dist/layout/hooks/useIsActiveRoute.d.ts +0 -2
- package/dist/layout/hooks/useSelectState.d.ts +0 -2
- package/dist/layout/mergeItems.d.ts +0 -2
package/README.md
CHANGED
|
@@ -15,352 +15,3 @@ The major parts of this package are:
|
|
|
15
15
|
* Imperium client module
|
|
16
16
|
* Main layout type: `LayoutData`
|
|
17
17
|
* `createPages()` function
|
|
18
|
-
|
|
19
|
-
# Getting Started
|
|
20
|
-
|
|
21
|
-
## Add to client modules
|
|
22
|
-
In your `clientModules.ts` file:
|
|
23
|
-
```typescript
|
|
24
|
-
export function clientModules(): ImperiumClientModule[] {
|
|
25
|
-
return [
|
|
26
|
-
// ...other client modules
|
|
27
|
-
layoutClientModule(),
|
|
28
|
-
];
|
|
29
|
-
}
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
## Define a layout in each feature
|
|
33
|
-
A layout defines all the various menus in your application. Usually in a `layout.tsx` file, export a `LayoutData` variable.
|
|
34
|
-
All fields are optional.
|
|
35
|
-
```typescript jsx
|
|
36
|
-
export const layout: LayoutData = {
|
|
37
|
-
dataHooks: [ /* datahooks array */ ],
|
|
38
|
-
primaryMenu: [ /* horizontal layout items */ ],
|
|
39
|
-
secondaryMenu: [ /* layout items */ ],
|
|
40
|
-
statusbar: [ /* horizontal layout items */ ],
|
|
41
|
-
footer: [ /* horizontal layout items */ ],
|
|
42
|
-
}
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
### Data Hooks
|
|
46
|
-
Data Hooks are React hooks that don't return anything. They are usually used to retrieve values from a graphql query and
|
|
47
|
-
then use the returned data to set state using @imperium/state.
|
|
48
|
-
|
|
49
|
-
### Primary Menu
|
|
50
|
-
The primary menu runs horizontally across the top of the page.
|
|
51
|
-
|
|
52
|
-
When the page shrinks to mobile size, all non-sticky menu items are removed and placed at the bottom of the secondary menu.
|
|
53
|
-
A toggle to show/hide the secondary menu is also displayed in the top left.
|
|
54
|
-
|
|
55
|
-
### Secondary Menu
|
|
56
|
-
The secondary menu runs vertically on the left side of the page.
|
|
57
|
-
|
|
58
|
-
When the page shrinks to mobile size, the secondary menu can be shown or hidden.
|
|
59
|
-
|
|
60
|
-
### Statusbar
|
|
61
|
-
The statusbar runs horizontally just below the primary menu.
|
|
62
|
-
|
|
63
|
-
### Footer
|
|
64
|
-
The footer runs horizontally at the bottom of the page.
|
|
65
|
-
|
|
66
|
-
## Define content pages in each feature
|
|
67
|
-
Pages can be defined from routes (see @imperium/router). Usually in a `pages.tsx` file, export from a `createPages()` call.
|
|
68
|
-
Each key must align with a router defined in your router.
|
|
69
|
-
|
|
70
|
-
Using `createPages()` removes the need from having to use `routes.renderRouteProps()` directly.
|
|
71
|
-
|
|
72
|
-
The `content` field is required, all others are optional.
|
|
73
|
-
|
|
74
|
-
```typescript jsx
|
|
75
|
-
import {routes} from './routes';
|
|
76
|
-
|
|
77
|
-
export const routeProps = createPages(routes, {
|
|
78
|
-
noParam: {
|
|
79
|
-
dataHooks: [ /* datahooks array */ ],
|
|
80
|
-
stateSelectorHook: hook || [ /* array of hooks */ ],
|
|
81
|
-
content: (data: Data) => JSX.Element,
|
|
82
|
-
header: /*One of: string | {title: string, icon?: string} | (data: Data) => {title: string, icon?: string} */,
|
|
83
|
-
sidebar: [ /* SidebarItem array */ ],
|
|
84
|
-
full: boolean,
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
### Data Hooks
|
|
90
|
-
Data Hooks are React hooks that don't return anything. They are usually used to retrieve values from a graphql query and
|
|
91
|
-
then use the returned data to set state using @imperium/state.
|
|
92
|
-
|
|
93
|
-
### State Selector Hook(s)
|
|
94
|
-
Pass a state select hook (or array of hooks) that return data, usually from Redux state.
|
|
95
|
-
|
|
96
|
-
This state data is added to the Data object. The data object is passed down to each Sidebar Item as well.
|
|
97
|
-
|
|
98
|
-
### Content
|
|
99
|
-
This is required and is used to render a component as content for the specified route.
|
|
100
|
-
|
|
101
|
-
### Header
|
|
102
|
-
An optional header string, object, or function that returns an object. Used to determine the header text and icon.
|
|
103
|
-
If header is not specified, there will be no header.
|
|
104
|
-
|
|
105
|
-
### Sidebar
|
|
106
|
-
Array of Sidebar Items. The sidebar is an optional vertical menu on the right side of the content area. It should usually
|
|
107
|
-
be comprised of button actions. There are different types of sidebar items that can be rendered.
|
|
108
|
-
|
|
109
|
-
### Full
|
|
110
|
-
Sets the height of the content area to 100% and has no margins.
|
|
111
|
-
|
|
112
|
-
## Add layout and pages to your feature index
|
|
113
|
-
In your feature `index.ts` file, add layout and pages (routeProps). Layout is not optional, but it can be an empty object.
|
|
114
|
-
Using `createPages()` is entirely optional.
|
|
115
|
-
```typescript
|
|
116
|
-
import {routeProps} from './pages.tsx';
|
|
117
|
-
import {layout} from './layout.tsx';
|
|
118
|
-
|
|
119
|
-
export function feature(): ImperiumLayoutClientModule & ImperiumRouterClientModule {
|
|
120
|
-
return {
|
|
121
|
-
name: 'Feature',
|
|
122
|
-
layout,
|
|
123
|
-
routeProps, // Use `routeProps` from `createPages()`
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
# Concepts
|
|
129
|
-
|
|
130
|
-
## Data
|
|
131
|
-
A specific set of data is created and used by all layout items and page content in various ways.
|
|
132
|
-
|
|
133
|
-
```typescript
|
|
134
|
-
interface Data {
|
|
135
|
-
loc: Location;
|
|
136
|
-
route: {
|
|
137
|
-
path: string[];
|
|
138
|
-
hash: string;
|
|
139
|
-
search: Record<string, any>;
|
|
140
|
-
};
|
|
141
|
-
state: State;
|
|
142
|
-
active: boolean;
|
|
143
|
-
|
|
144
|
-
// Page data has an additional field:
|
|
145
|
-
params: RouteParameters;
|
|
146
|
-
}
|
|
147
|
-
```
|
|
148
|
-
|
|
149
|
-
### `loc: Location`
|
|
150
|
-
A location object matching the current React Router location. It's defined somewhat like the following. See React Router for more information.
|
|
151
|
-
```typescript
|
|
152
|
-
interface Location {
|
|
153
|
-
state: object | null;
|
|
154
|
-
key: string;
|
|
155
|
-
pathname: string;
|
|
156
|
-
search: string;
|
|
157
|
-
hash: string;
|
|
158
|
-
}
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
### `route`
|
|
162
|
-
The route object is basically the same as the Location object, but processed for easier use in visibility queries.
|
|
163
|
-
```typescript
|
|
164
|
-
route: {
|
|
165
|
-
path: string[]; // An array of strings. The loc.pathname split by the '/' character.
|
|
166
|
-
hash: string; // A copy of the loc.hash string.
|
|
167
|
-
search: Record<string, any>; // The loc.search string, parsed by queryString.parse(). See node package 'querystring'.
|
|
168
|
-
}
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
### `state: Record<string, any>`
|
|
172
|
-
Layout and content items can use hooks that select slices of Redux state (see @imperium/state). This is the selected state merged together.
|
|
173
|
-
|
|
174
|
-
Parent items can also select state. This state is merged together with child state and passed to the child.
|
|
175
|
-
|
|
176
|
-
### `active: boolean`
|
|
177
|
-
This is only relevant in layout items that redirect to a route. Active is true when the current path matches the route `to` path, otherwise it's false.
|
|
178
|
-
|
|
179
|
-
### `params: RouteParameters`
|
|
180
|
-
This is only available to page data (aka `ContentData`). Since each page is rendered from a route, the type of the route parameters are known.
|
|
181
|
-
If the route doesn't have any parameters, this type is `never`. If the route does have parameters this is an object, typed with
|
|
182
|
-
the parameters as fields.
|
|
183
|
-
|
|
184
|
-
# Layout
|
|
185
|
-
|
|
186
|
-
## Layout Items
|
|
187
|
-
Most layout items have the following properties:
|
|
188
|
-
|
|
189
|
-
### `weight: number` (optional)
|
|
190
|
-
Larger numbers move the item farther to the left or down.
|
|
191
|
-
|
|
192
|
-
### `visible: Object | (data: Data) => boolean` (optional)
|
|
193
|
-
When this is a function, it receives the current Data. If you return true from this function the item is visible.
|
|
194
|
-
If you return false, the item is hidden.
|
|
195
|
-
|
|
196
|
-
When this is an object, it represents a mingo (see npm 'mingo' package) query that is matched against the current Data.
|
|
197
|
-
If the mingo query returns true, the item is visible, otherwise the item is hidden.
|
|
198
|
-
|
|
199
|
-
### `stateSelectorHook: () => State | (() => State)[]` (optional)
|
|
200
|
-
Pass a state select hook (or array of hooks) that return data, usually from Redux state.
|
|
201
|
-
|
|
202
|
-
This state data is added to the Data object.
|
|
203
|
-
|
|
204
|
-
### `text: string | (data: Data) => string` (required)
|
|
205
|
-
Usually required (except for custom layout items). Either a static string or a function that returns a string.
|
|
206
|
-
The text is displayed as the items main text.
|
|
207
|
-
|
|
208
|
-
### `icon: SemanticICONS | (data: Data) => SemanticICONS` (optional)
|
|
209
|
-
Similar to the `text` field. If supplied, the icon is shown on the item.
|
|
210
|
-
|
|
211
|
-
### `moveToKey: string` (optional)
|
|
212
|
-
If you would like to have this item moved to a child of a different item (dropdown or submenu), usually from a different
|
|
213
|
-
feature, enter the target item's key string here. Note, items do not have keys unless expressly defined.
|
|
214
|
-
|
|
215
|
-
The item will be removed from its current location and rendered in the target item's children.
|
|
216
|
-
|
|
217
|
-
## Routed Items
|
|
218
|
-
If the item isn't a dropdown, menu or custom the item can be used to link to a route.
|
|
219
|
-
|
|
220
|
-
### `to: string | (data: Data) => string` (optional)
|
|
221
|
-
Will render the item as a link to a route. Also used to determine if this item's route is active.
|
|
222
|
-
|
|
223
|
-
### `exact: boolean` (optional)
|
|
224
|
-
Default is false. Used to determine if the item's route is active. See React Router route props.
|
|
225
|
-
|
|
226
|
-
### `strict: boolean` (optional)
|
|
227
|
-
Used to determine if the item's route is active. See React Router route props.
|
|
228
|
-
|
|
229
|
-
### `sensitive: boolean` (optional)
|
|
230
|
-
Used to determine if the item's route is active. See React Router route props.
|
|
231
|
-
|
|
232
|
-
## Horizontal Items
|
|
233
|
-
If the item is displayed in a horizontal menu it can have additional properties.
|
|
234
|
-
|
|
235
|
-
### `position: 'left' | 'right'` (optional)
|
|
236
|
-
Default is 'left'. Determines if the item is floated to the left or the right of the menu.
|
|
237
|
-
|
|
238
|
-
### `stickOnMobile: boolean` (optional)
|
|
239
|
-
Default is false and only relevant on the primary menu. If true, the item will not be moved to the secondary menu when
|
|
240
|
-
in mobile width mode.
|
|
241
|
-
|
|
242
|
-
## Custom Layout Items
|
|
243
|
-
Custom layout items can be used to render any React component.
|
|
244
|
-
|
|
245
|
-
### `render: (data: Data) => JSX.Element | null` (required)
|
|
246
|
-
This will render whatever custom component you want.
|
|
247
|
-
|
|
248
|
-
## Dropdown Layout Items
|
|
249
|
-
Dropdown layout items will render their children as dropdown menus. You cannot include dropdown or submenu items as children.
|
|
250
|
-
|
|
251
|
-
### `dropdown: LayoutItems[]` (required)
|
|
252
|
-
These items are rendered as the children of the dropdown.
|
|
253
|
-
|
|
254
|
-
### `key: string` (optional)
|
|
255
|
-
Dropdown items can be used as a target for other items. See `moveToKey` above.
|
|
256
|
-
|
|
257
|
-
## Menu Layout Items
|
|
258
|
-
Menu layout items will create a submenu inside the normal menu. See Semantic UI as to how these work. Submenu items aren't hidden
|
|
259
|
-
behind a click, like a dropdown, but grouped together. You cannot include dropdown or submenu items as children.
|
|
260
|
-
|
|
261
|
-
### `menu: LayoutItems[]` (required)
|
|
262
|
-
These items are rendered as the children of the menu.
|
|
263
|
-
|
|
264
|
-
### `key: string` (optional)
|
|
265
|
-
Menu items can be used as a target for other items. See `moveToKey` above.
|
|
266
|
-
|
|
267
|
-
# Page Content
|
|
268
|
-
|
|
269
|
-
## Sidebar Items
|
|
270
|
-
Most sidebar items have the following properties:
|
|
271
|
-
|
|
272
|
-
### `weight: number` (optional)
|
|
273
|
-
Larger numbers move the item farther down.
|
|
274
|
-
|
|
275
|
-
### `visible: Object | (data: ContentData) => boolean` (optional)
|
|
276
|
-
When this is a function, it receives the current ContentData. If you return true from this function the item is visible.
|
|
277
|
-
If you return false, the item is hidden.
|
|
278
|
-
|
|
279
|
-
When this is an object, it represents a mingo (see npm 'mingo' package) query that is matched against the current ContentData.
|
|
280
|
-
If the mingo query returns true, the item is visible, otherwise the item is hidden.
|
|
281
|
-
|
|
282
|
-
### `stateSelectorHook: () => State | (() => State)[]` (optional)
|
|
283
|
-
Pass a state select hook (or array of hooks) that return data, usually from Redux state.
|
|
284
|
-
|
|
285
|
-
This state data is added to the ContentData object.
|
|
286
|
-
|
|
287
|
-
### `text: string | (data: ContentData) => string` (required)
|
|
288
|
-
Usually required (except for custom sidebar items). Either a static string or a function that returns a string.
|
|
289
|
-
The text is displayed as the items main text.
|
|
290
|
-
|
|
291
|
-
### `icon: SemanticICONS | (data: ContentData) => SemanticICONS` (optional)
|
|
292
|
-
Similar to the `text` field. If supplied, the icon is shown on the item.
|
|
293
|
-
|
|
294
|
-
### `color: SemanticCOLORS | (data: ContentData) => SemanticCOLORS` (optional)
|
|
295
|
-
Similar to the `text` field. If supplied, the color is applied to the item.
|
|
296
|
-
|
|
297
|
-
## Routed Items
|
|
298
|
-
If the item isn't a special item it can be used to link to a route.
|
|
299
|
-
|
|
300
|
-
### `to: string | (data: ContentData) => string` (optional)
|
|
301
|
-
Will render the item as a link to a route. Also used to determine if this item's route is active.
|
|
302
|
-
|
|
303
|
-
### `exact: boolean` (optional)
|
|
304
|
-
Default is false. Used to determine if the item's route is active. See React Router route props.
|
|
305
|
-
|
|
306
|
-
### `strict: boolean` (optional)
|
|
307
|
-
Used to determine if the item's route is active. See React Router route props.
|
|
308
|
-
|
|
309
|
-
### `sensitive: boolean` (optional)
|
|
310
|
-
Used to determine if the item's route is active. See React Router route props.
|
|
311
|
-
|
|
312
|
-
## Custom Sidebar Items
|
|
313
|
-
Custom sidebar items can be used to render any React component.
|
|
314
|
-
|
|
315
|
-
### `render: (data: ContentData) => JSX.Element | null` (required)
|
|
316
|
-
This will render whatever custom component you want.
|
|
317
|
-
|
|
318
|
-
## Action Sidebar Items
|
|
319
|
-
An action sidebar item fires an `onClick()` event instead of redirecting to a route.
|
|
320
|
-
|
|
321
|
-
### `onClick: (data: ContentData) => void` (required)
|
|
322
|
-
This handler is fired when the sidebar action is clicked.
|
|
323
|
-
|
|
324
|
-
## Action Form Sidebar Items
|
|
325
|
-
This item renders a form that can be submitted.
|
|
326
|
-
|
|
327
|
-
### `form: (formParams) => JSX.Element | null` (required)
|
|
328
|
-
Renders the form fields needed by the form. Usually you'll render a fragment with just the form fields.
|
|
329
|
-
|
|
330
|
-
`formParams` are mostly derived from TForm (see @thx/controls):
|
|
331
|
-
|
|
332
|
-
#### `values: Record<string, any>`
|
|
333
|
-
Used to set the value of your inputs.
|
|
334
|
-
|
|
335
|
-
#### `handleChange: (e: ChangeEvent<any>) => void`
|
|
336
|
-
Used to notify TForm about changed inputs.
|
|
337
|
-
|
|
338
|
-
#### `fieldError: (fieldName) => boolean`
|
|
339
|
-
Used to determine if a field contains a validation error
|
|
340
|
-
|
|
341
|
-
#### `data: ContentData`
|
|
342
|
-
The content data passed down from the sidebar item.
|
|
343
|
-
|
|
344
|
-
### `initialValues: Record<string, any> | (data: ContentData) => Record<string, any>` (optional)
|
|
345
|
-
Initial values that will be passed to TForm. If a function, can be used to calculate from content data.
|
|
346
|
-
|
|
347
|
-
### `onSubmit: (values: Record<string, any>, data: ContentData) => void` (optional)
|
|
348
|
-
Fired when the form submits.
|
|
349
|
-
|
|
350
|
-
### `validationSchema: any` (optional)
|
|
351
|
-
A yup validation schema, passed directly to TForm.
|
|
352
|
-
|
|
353
|
-
## Divider Sidebar Items
|
|
354
|
-
You can render a divider by using the exported divider item directly.
|
|
355
|
-
|
|
356
|
-
```typescript
|
|
357
|
-
import {dividerSidebarItem} from '@imperium/layout';
|
|
358
|
-
|
|
359
|
-
createPages(routes, {
|
|
360
|
-
aRoute: {
|
|
361
|
-
sidebar: [
|
|
362
|
-
dividerSidebarItem,
|
|
363
|
-
],
|
|
364
|
-
},
|
|
365
|
-
});
|
|
366
|
-
```
|