@smartsoft001/claude-plugins 2.194.0 → 2.196.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/.claude-plugin/marketplace.json +14 -3
- package/README.md +19 -4
- package/package.json +3 -3
- package/plugins/smart-angular/.claude-plugin/plugin.json +6 -0
- package/plugins/{smart → smart-angular}/skills/scaffold-nx-workspace/SKILL.md +1 -1
- package/plugins/{smart → smart-angular}/skills/scaffold-nx-workspace/references/base-claude-config.md +13 -9
- package/plugins/{smart → smart-angular}/skills/scaffold-nx-workspace/references/patch-delta.md +1 -1
- package/plugins/{smart → smart-core}/.claude-plugin/README.md +31 -16
- package/plugins/{smart → smart-core}/.claude-plugin/merge-permissions.js +7 -6
- package/plugins/smart-core/.claude-plugin/plugin.json +5 -0
- package/plugins/{smart → smart-core}/.claude-plugin/settings.template.json +2 -2
- package/plugins/{smart → smart-core}/hooks/README.md +1 -1
- package/plugins/{smart → smart-core}/skills/audit-log/SKILL.md +2 -2
- package/plugins/{smart → smart-core}/skills/format-code/SKILL.md +1 -1
- package/plugins/smart-react/.claude-plugin/plugin.json +6 -0
- package/plugins/smart-react/agents/react-components.md +260 -0
- package/plugins/smart-react/skills/react-components-accordion/SKILL.md +204 -0
- package/plugins/smart-react/skills/react-components-action-panel/SKILL.md +191 -0
- package/plugins/smart-react/skills/react-components-alert/SKILL.md +244 -0
- package/plugins/smart-react/skills/react-components-app/SKILL.md +236 -0
- package/plugins/smart-react/skills/react-components-avatar/SKILL.md +176 -0
- package/plugins/smart-react/skills/react-components-badge/SKILL.md +165 -0
- package/plugins/smart-react/skills/react-components-breadcrumbs/SKILL.md +183 -0
- package/plugins/smart-react/skills/react-components-button/SKILL.md +239 -0
- package/plugins/smart-react/skills/react-components-button-group/SKILL.md +187 -0
- package/plugins/smart-react/skills/react-components-calendar/SKILL.md +270 -0
- package/plugins/smart-react/skills/react-components-card/SKILL.md +201 -0
- package/plugins/smart-react/skills/react-components-card-heading/SKILL.md +133 -0
- package/plugins/smart-react/skills/react-components-command-palette/SKILL.md +228 -0
- package/plugins/smart-react/skills/react-components-container/SKILL.md +134 -0
- package/plugins/smart-react/skills/react-components-date-edit/SKILL.md +186 -0
- package/plugins/smart-react/skills/react-components-date-range/SKILL.md +259 -0
- package/plugins/smart-react/skills/react-components-description-list/SKILL.md +144 -0
- package/plugins/smart-react/skills/react-components-detail/SKILL.md +272 -0
- package/plugins/smart-react/skills/react-components-details/SKILL.md +250 -0
- package/plugins/smart-react/skills/react-components-divider/SKILL.md +128 -0
- package/plugins/smart-react/skills/react-components-drawer/SKILL.md +165 -0
- package/plugins/smart-react/skills/react-components-dropdown/SKILL.md +194 -0
- package/plugins/smart-react/skills/react-components-empty-state/SKILL.md +202 -0
- package/plugins/smart-react/skills/react-components-export/SKILL.md +120 -0
- package/plugins/smart-react/skills/react-components-feed/SKILL.md +171 -0
- package/plugins/smart-react/skills/react-components-form/SKILL.md +319 -0
- package/plugins/smart-react/skills/react-components-grid-list/SKILL.md +172 -0
- package/plugins/smart-react/skills/react-components-icon/SKILL.md +117 -0
- package/plugins/smart-react/skills/react-components-import/SKILL.md +113 -0
- package/plugins/smart-react/skills/react-components-info/SKILL.md +147 -0
- package/plugins/smart-react/skills/react-components-input/SKILL.md +406 -0
- package/plugins/smart-react/skills/react-components-list/SKILL.md +384 -0
- package/plugins/smart-react/skills/react-components-list-container/SKILL.md +105 -0
- package/plugins/smart-react/skills/react-components-loader/SKILL.md +126 -0
- package/plugins/smart-react/skills/react-components-media-object/SKILL.md +130 -0
- package/plugins/smart-react/skills/react-components-modal/SKILL.md +266 -0
- package/plugins/smart-react/skills/react-components-multi-column-layout/SKILL.md +155 -0
- package/plugins/smart-react/skills/react-components-navbar/SKILL.md +211 -0
- package/plugins/smart-react/skills/react-components-notification/SKILL.md +223 -0
- package/plugins/smart-react/skills/react-components-overlays/SKILL.md +182 -0
- package/plugins/smart-react/skills/react-components-page/SKILL.md +224 -0
- package/plugins/smart-react/skills/react-components-page-heading/SKILL.md +155 -0
- package/plugins/smart-react/skills/react-components-paging/SKILL.md +183 -0
- package/plugins/smart-react/skills/react-components-password-strength/SKILL.md +149 -0
- package/plugins/smart-react/skills/react-components-progress-bars/SKILL.md +195 -0
- package/plugins/smart-react/skills/react-components-searchbar/SKILL.md +150 -0
- package/plugins/smart-react/skills/react-components-section-heading/SKILL.md +138 -0
- package/plugins/smart-react/skills/react-components-select-menu/SKILL.md +168 -0
- package/plugins/smart-react/skills/react-components-sidebar-layout/SKILL.md +155 -0
- package/plugins/smart-react/skills/react-components-sidebar-navigation/SKILL.md +277 -0
- package/plugins/smart-react/skills/react-components-sign-in-form/SKILL.md +228 -0
- package/plugins/smart-react/skills/react-components-stacked-layout/SKILL.md +146 -0
- package/plugins/smart-react/skills/react-components-stacked-list/SKILL.md +156 -0
- package/plugins/smart-react/skills/react-components-stats/SKILL.md +149 -0
- package/plugins/smart-react/skills/react-components-table/SKILL.md +222 -0
- package/plugins/smart-react/skills/react-components-tabs/SKILL.md +189 -0
- package/plugins/smart-react/skills/react-components-textarea/SKILL.md +202 -0
- package/plugins/smart-react/skills/react-components-toggle/SKILL.md +157 -0
- package/plugins/smart-react/skills/react-components-vertical-navigation/SKILL.md +212 -0
- package/plugins/smart-react/skills/react-forms/SKILL.md +272 -0
- package/plugins/smart-react/skills/react-provider/SKILL.md +368 -0
- package/plugins/smart-react/skills/smart-crud-react/SKILL.md +410 -0
- package/plugins/smart/.claude-plugin/plugin.json +0 -5
- /package/plugins/{smart/agents/angular-components/AGENT.md → smart-angular/agents/angular-components.md} +0 -0
- /package/plugins/{smart → smart-angular}/skills/angular-components-accordion/SKILL.md +0 -0
- /package/plugins/{smart → smart-angular}/skills/angular-components-action-panel/SKILL.md +0 -0
- /package/plugins/{smart → smart-angular}/skills/angular-components-alert/SKILL.md +0 -0
- /package/plugins/{smart → smart-angular}/skills/angular-components-avatar/SKILL.md +0 -0
- /package/plugins/{smart → smart-angular}/skills/angular-components-badge/SKILL.md +0 -0
- /package/plugins/{smart → smart-angular}/skills/angular-components-breadcrumbs/SKILL.md +0 -0
- /package/plugins/{smart → smart-angular}/skills/angular-components-button/SKILL.md +0 -0
- /package/plugins/{smart → smart-angular}/skills/angular-components-button-group/SKILL.md +0 -0
- /package/plugins/{smart → smart-angular}/skills/angular-components-calendar/SKILL.md +0 -0
- /package/plugins/{smart → smart-angular}/skills/angular-components-card/SKILL.md +0 -0
- /package/plugins/{smart → smart-angular}/skills/angular-components-card-heading/SKILL.md +0 -0
- /package/plugins/{smart → smart-angular}/skills/angular-components-command-palette/SKILL.md +0 -0
- /package/plugins/{smart → smart-angular}/skills/angular-components-container/SKILL.md +0 -0
- /package/plugins/{smart → smart-angular}/skills/angular-components-date-edit/SKILL.md +0 -0
- /package/plugins/{smart → smart-angular}/skills/angular-components-date-range/SKILL.md +0 -0
- /package/plugins/{smart → smart-angular}/skills/angular-components-description-list/SKILL.md +0 -0
- /package/plugins/{smart → smart-angular}/skills/angular-components-detail/SKILL.md +0 -0
- /package/plugins/{smart → smart-angular}/skills/angular-components-details/SKILL.md +0 -0
- /package/plugins/{smart → smart-angular}/skills/angular-components-divider/SKILL.md +0 -0
- /package/plugins/{smart → smart-angular}/skills/angular-components-drawer/SKILL.md +0 -0
- /package/plugins/{smart → smart-angular}/skills/angular-components-dropdown/SKILL.md +0 -0
- /package/plugins/{smart → smart-angular}/skills/angular-components-empty-state/SKILL.md +0 -0
- /package/plugins/{smart → smart-angular}/skills/angular-components-feed/SKILL.md +0 -0
- /package/plugins/{smart → smart-angular}/skills/angular-components-form/SKILL.md +0 -0
- /package/plugins/{smart → smart-angular}/skills/angular-components-grid-list/SKILL.md +0 -0
- /package/plugins/{smart → smart-angular}/skills/angular-components-icon/SKILL.md +0 -0
- /package/plugins/{smart → smart-angular}/skills/angular-components-info/SKILL.md +0 -0
- /package/plugins/{smart → smart-angular}/skills/angular-components-input/SKILL.md +0 -0
- /package/plugins/{smart → smart-angular}/skills/angular-components-list/SKILL.md +0 -0
- /package/plugins/{smart → smart-angular}/skills/angular-components-list-container/SKILL.md +0 -0
- /package/plugins/{smart → smart-angular}/skills/angular-components-media-object/SKILL.md +0 -0
- /package/plugins/{smart → smart-angular}/skills/angular-components-modal/SKILL.md +0 -0
- /package/plugins/{smart → smart-angular}/skills/angular-components-multi-column-layout/SKILL.md +0 -0
- /package/plugins/{smart → smart-angular}/skills/angular-components-navbar/SKILL.md +0 -0
- /package/plugins/{smart → smart-angular}/skills/angular-components-notification/SKILL.md +0 -0
- /package/plugins/{smart → smart-angular}/skills/angular-components-page/SKILL.md +0 -0
- /package/plugins/{smart → smart-angular}/skills/angular-components-page-heading/SKILL.md +0 -0
- /package/plugins/{smart → smart-angular}/skills/angular-components-paging/SKILL.md +0 -0
- /package/plugins/{smart → smart-angular}/skills/angular-components-password-strength/SKILL.md +0 -0
- /package/plugins/{smart → smart-angular}/skills/angular-components-progress-bars/SKILL.md +0 -0
- /package/plugins/{smart → smart-angular}/skills/angular-components-searchbar/SKILL.md +0 -0
- /package/plugins/{smart → smart-angular}/skills/angular-components-section-heading/SKILL.md +0 -0
- /package/plugins/{smart → smart-angular}/skills/angular-components-select-menu/SKILL.md +0 -0
- /package/plugins/{smart → smart-angular}/skills/angular-components-sidebar-layout/SKILL.md +0 -0
- /package/plugins/{smart → smart-angular}/skills/angular-components-sidebar-navigation/SKILL.md +0 -0
- /package/plugins/{smart → smart-angular}/skills/angular-components-sign-in-form/SKILL.md +0 -0
- /package/plugins/{smart → smart-angular}/skills/angular-components-stacked-layout/SKILL.md +0 -0
- /package/plugins/{smart → smart-angular}/skills/angular-components-stacked-list/SKILL.md +0 -0
- /package/plugins/{smart → smart-angular}/skills/angular-components-stats/SKILL.md +0 -0
- /package/plugins/{smart → smart-angular}/skills/angular-components-table/SKILL.md +0 -0
- /package/plugins/{smart → smart-angular}/skills/angular-components-tabs/SKILL.md +0 -0
- /package/plugins/{smart → smart-angular}/skills/angular-components-textarea/SKILL.md +0 -0
- /package/plugins/{smart → smart-angular}/skills/angular-components-toggle/SKILL.md +0 -0
- /package/plugins/{smart → smart-angular}/skills/angular-components-vertical-navigation/SKILL.md +0 -0
- /package/plugins/{smart → smart-angular}/skills/scaffold-nx-workspace/references/base-app.md +0 -0
- /package/plugins/{smart → smart-angular}/skills/scaffold-nx-workspace/references/base-shared-lib.md +0 -0
- /package/plugins/{smart → smart-angular}/skills/scaffold-nx-workspace/references/version-resolution.md +0 -0
- /package/plugins/{smart → smart-angular}/skills/scaffold-nx-workspace/scripts/derive-prefix.sh +0 -0
- /package/plugins/{smart → smart-angular}/skills/scaffold-nx-workspace/scripts/verify-scaffold.sh +0 -0
- /package/plugins/{smart → smart-angular}/skills/smart-crud/SKILL.md +0 -0
- /package/plugins/{smart → smart-core}/hooks/CONFIG.md +0 -0
- /package/plugins/{smart → smart-core}/hooks/audit_logger.py +0 -0
- /package/plugins/{smart → smart-core}/hooks/auto_format.sh +0 -0
- /package/plugins/{smart → smart-core}/hooks/hooks.json +0 -0
- /package/plugins/{smart → smart-core}/hooks/safety_validator.py +0 -0
- /package/plugins/{smart → smart-core}/hooks/sensitive_file_blocker.py +0 -0
- /package/plugins/{smart → smart-core}/hooks/skill_validator.py +0 -0
- /package/plugins/{smart → smart-core}/skills/project-conventions/SKILL.md +0 -0
- /package/plugins/{smart → smart-core}/skills/safety-check/SKILL.md +0 -0
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: react-components-list
|
|
3
|
+
description: SmartList React component API (@smartsoft001/react) — list of model records whose columns come from @Field({ list }) metadata, fed by an IListProvider (list, loading), in desktop/mobile/masonryGrid modes, with item navigation, confirmed remove, multi-select, pagination (single page or infinite scroll) and cell pipes; listModeComponents / LIST_PRESET_MODE_COMPONENTS, the 'list' registry key and the useList hook.
|
|
4
|
+
user-invocable: false
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# List (`SmartList`)
|
|
8
|
+
|
|
9
|
+
`SmartList` renders records of a `@Model` class. Its columns are the model's fields marked `@Field({ list: ... })`, sorted by `list.order`; its rows come from `options.provider.list`, and `provider.loading` shows the loader (and suppresses the "no results" text). `options.mode` picks the layout: `ListMode.desktop` (a table, the default), `ListMode.mobile` (stacked rows) or `ListMode.masonryGrid` (image tiles). Row actions are opt-in: `item` adds a "go to item" action (navigate to `routingPrefix + id` through the navigation adapter, or call `select(id)`), `remove` a remove action confirmed with an alert, `select: 'multi'` a checkbox column. The list **does not fetch**: the provider's owner loads the data (CRUD screens wire all of this from a `CrudFullConfig`).
|
|
10
|
+
|
|
11
|
+
## When to Use This Skill
|
|
12
|
+
|
|
13
|
+
- Showing records of a model with columns taken from `@Field({ list })`
|
|
14
|
+
- Row actions: navigate to an item, remove with confirmation, multi-select
|
|
15
|
+
- Paging through a provider (`pagination`), single page or infinite scroll
|
|
16
|
+
- Choosing the layout per mode, or the preset table look (`presentation`)
|
|
17
|
+
- Replacing a mode's component (`listModeComponents`) or the whole list (`components.list`), building on `useList`
|
|
18
|
+
|
|
19
|
+
For data that is not a model (plain rows), use `SmartTable` or `SmartStackedList`; for complete CRUD screens, `@smartsoft001/crud-shell-react` (`smart-crud-react`).
|
|
20
|
+
|
|
21
|
+
## Exports
|
|
22
|
+
|
|
23
|
+
All from `@smartsoft001/react`.
|
|
24
|
+
|
|
25
|
+
| Export | Kind | What it is |
|
|
26
|
+
| ----------------------------- | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
27
|
+
| `SmartList` | component | Resolves the list `fields` of `options.type` (the fields with `list` options, sorted by `list.order`) and renders the implementation of `options.mode` (desktop by default): the one registered in `listModeComponents` on `SmartProvider` (e.g. `LIST_PRESET_MODE_COMPONENTS`), else `SmartListDesktop` / `SmartListMobile` / `SmartListMasonryGrid`. |
|
|
28
|
+
| `SmartListDesktop` | component | The desktop list: a table with one column per list field, plus the multi-select, remove and item columns, the `top` component factory above it and the paging below it (`PaginationMode.singlePage`). |
|
|
29
|
+
| `SmartListDesktopPreset` | component | Preline-styled desktop list variation. |
|
|
30
|
+
| `SmartListMasonryGrid` | component | The masonry-grid list: a grid of tiles with the item's image (the model's first image field, lazy loaded) over its non-image cells, the `top` component factory above it and the paging below it (`PaginationMode.singlePage`). |
|
|
31
|
+
| `SmartListMasonryGridPreset` | component | Preline-styled masonry-grid list variation: keeps the masonry column layout and renders every item as a Preline card, the image on a rounded top, the first non-image column as the title and the others as text. |
|
|
32
|
+
| `SmartListMobile` | component | The mobile list: a stacked list with one paragraph per cell and the remove / item buttons, the `top` component factory above it and the paging below it (`PaginationMode.singlePage`). |
|
|
33
|
+
| `SmartListMobilePreset` | component | Preline-styled mobile list variation: a responsive grid of cards. |
|
|
34
|
+
| `useListFileUrl` | hook | The download URL of an image cell's attachment (`''` without a file service). |
|
|
35
|
+
| `useList` | hook | The behaviour every list mode shares: the column `keys` (permissions via `useAuthService()`, dynamic `__array` columns), the provider `list` and `loading`, the `sort` options, the remove flow (a confirm alert, then `remove.provider.invoke(id)`), item navigation (`useNavigation().navigate(routingPrefix + id)` or `item.options.select`), the details provider (`select` / `unselect`, `detailsComponent` and its props) and the pagination (`loadNextPage` / `loadPrevPage`, `handlePageChange`). |
|
|
36
|
+
| `isListImageKey` | function | Whether a column is an image field of the model. |
|
|
37
|
+
| `getListTitleKey` | function | The first non-image column (the card title of the mobile and masonry presets). |
|
|
38
|
+
| `LIST_PRESET_MODE_COMPONENTS` | const | Preline-styled list mode presets, keyed by `ListMode`. |
|
|
39
|
+
|
|
40
|
+
The preset's class helpers (`getListDesktopContainerClasses`, `getListDesktopTableClasses`, `getListDesktopHeaderRowClasses`, `getListDesktopHeaderCellClasses`, `getListDesktopRowClasses`, `getListDesktopCellClasses`) are exported too, for a custom implementation that wants the preset look.
|
|
41
|
+
|
|
42
|
+
## Props and Types
|
|
43
|
+
|
|
44
|
+
### `SmartListProps<T extends IEntity<string>>`
|
|
45
|
+
|
|
46
|
+
Props of `<SmartList>`.
|
|
47
|
+
|
|
48
|
+
| Prop | Type | Default | Description |
|
|
49
|
+
| ------------ | ----------------- | -------- | ------------------------------------------------------- |
|
|
50
|
+
| `options` | `IListOptions<T>` | required | The provider, the model type, the mode and the actions. |
|
|
51
|
+
| `className?` | `string` | `''` | Passed to the mode component (its container). |
|
|
52
|
+
|
|
53
|
+
### `SmartListModeProps<T extends IEntity<string>>`
|
|
54
|
+
|
|
55
|
+
Props of a list mode implementation (`SmartListDesktop`, `SmartListMobile`, `SmartListMasonryGrid`, their presets, or one registered through `listModeComponents` / `components.list` on `SmartProvider`). `SmartList` passes the options with the list `fields` of the model already resolved.
|
|
56
|
+
|
|
57
|
+
| Prop | Type | Default | Description |
|
|
58
|
+
| ------------ | ------------------------- | -------- | -------------------------------------------- |
|
|
59
|
+
| `options` | `IListInternalOptions<T>` | required | The list options with the resolved `fields`. |
|
|
60
|
+
| `className?` | `string` | — | The `className` of `SmartList`. |
|
|
61
|
+
|
|
62
|
+
### `IListOptions<T>`
|
|
63
|
+
|
|
64
|
+
| Field | Type | Default | Description |
|
|
65
|
+
| --------------------- | --------------------------------------------------------------------------------------------------------------------------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
66
|
+
| `provider` | `IListProvider<T>` | required | Where the rows come from (`list`, `loading`), and the multi-selection callbacks. |
|
|
67
|
+
| `type` | `any` | required | The `@Model` class whose `list` fields are the columns. |
|
|
68
|
+
| `mode?` | `ListMode` | — | `ListMode.desktop` (default), `ListMode.mobile` or `ListMode.masonryGrid`. |
|
|
69
|
+
| `pagination?` | `IListPaginationOptions` | — | Paging state and loaders; the desktop, mobile and masonry modes render the pager below the rows. |
|
|
70
|
+
| `cellPipe?` | `ICellPipe<T>` | — | Formats cells: `transform(item, key, translate?)` returns text (sanitised) or `trustHtml(html)`. |
|
|
71
|
+
| `componentFactories?` | `IListComponentFactories<T>` | — | `top`: a component rendered above the rows. |
|
|
72
|
+
| `sort?` | `\| boolean \| { default?: string; defaultDesc?: boolean; }` | `{}` | Passed to the mode components (`useList().sort`); the library's modes render no sort controls. |
|
|
73
|
+
| `details?` | `\| boolean \| { provider?: IDetailsProvider<T>; componentFactories?: IDetailsComponentFactories<T>; component?: ComponentType<any>; }` | — | Requires a `provider` (`IDetailsProvider`) when set; `useList` exposes `select` / `unselect`, `detailsComponent` and its props for a mode that shows details. The library's modes do not render them. |
|
|
74
|
+
| `item?` | `\| boolean \| { options?: ItemOptions; }` | — | Adds the item action: `{ options: { routingPrefix, edit } }` navigates to `routingPrefix + id`, `{ options: { select, edit } }` calls `select(id)`. Setting `item` without `options` throws. |
|
|
75
|
+
| `remove?` | `\| boolean \| { provider?: IRemoveProvider<T>; }` | — | Adds the remove action: an alert (`OBJECT.confirmDelete`) then `provider.invoke(id)`; `provider.check(item)` hides it per row. |
|
|
76
|
+
| `select?` | `'multi'` | — | `'multi'` adds a checkbox column (desktop); changes go to `provider.onChangeMultiSelected`. |
|
|
77
|
+
| `presentation?` | `{ variant?: 'default' \| 'striped' \| 'bordered' \| 'borderless'; hoverable?: boolean; header?: 'default' \| 'muted' \| 'none'; }` | `{}` | Desktop preset look: `variant` (`default`, `striped`, `bordered`, `borderless`), `hoverable`, `header` (`default`, `muted`, `none`). |
|
|
78
|
+
|
|
79
|
+
### `IListInternalOptions<T>`
|
|
80
|
+
|
|
81
|
+
What mode components receive: `IListOptions` plus the resolved `fields`. Extends `IListOptions<T>`.
|
|
82
|
+
|
|
83
|
+
| Field | Type | Default | Description |
|
|
84
|
+
| --------- | ------------------------------------------------ | ------- | ------------------------------------------------------- |
|
|
85
|
+
| `fields?` | `Array<{ key: string; options: IFieldOptions }>` | — | The `list` fields of the model, sorted by `list.order`. |
|
|
86
|
+
|
|
87
|
+
### `IListPaginationOptions`
|
|
88
|
+
|
|
89
|
+
| Field | Type | Default | Description |
|
|
90
|
+
| -------------- | ------------------------ | -------- | ----------------------------------------------------------------------- |
|
|
91
|
+
| `mode?` | `PaginationMode` | — | `PaginationMode.singlePage` (pager) or `PaginationMode.infiniteScroll`. |
|
|
92
|
+
| `limit` | `number` | required | Page size. |
|
|
93
|
+
| `loadNextPage` | `() => Promise<boolean>` | required | Loads the next page; resolves whether there is a further one. |
|
|
94
|
+
| `loadPrevPage` | `() => Promise<boolean>` | required | Loads the previous page; resolves whether there is a further one. |
|
|
95
|
+
| `page` | `number` | required | Current page. |
|
|
96
|
+
| `totalPages` | `number` | required | Number of pages. |
|
|
97
|
+
|
|
98
|
+
### `IListProvider<T>`
|
|
99
|
+
|
|
100
|
+
| Field | Type | Default | Description |
|
|
101
|
+
| ------------------------ | -------------------------- | -------- | ----------------------------------------------------------------------------------------- |
|
|
102
|
+
| `getData` | `(filter: any) => void` | required | Declared for the provider's owner (CRUD providers read with it); the list never calls it. |
|
|
103
|
+
| `onChangeMultiSelected?` | `(list: Array<T>) => void` | — | Called with the selected records when `select: 'multi'`. |
|
|
104
|
+
| `onCleanMultiSelected$?` | `SmartSubscribable<void>` | — | Clears the multi-selection whenever it emits. |
|
|
105
|
+
| `list` | `T[]` | required | The records to show. |
|
|
106
|
+
| `loading` | `boolean` | required | Shows the loader while `true`. |
|
|
107
|
+
|
|
108
|
+
### `ICellPipe<T>`
|
|
109
|
+
|
|
110
|
+
Formats a cell value.
|
|
111
|
+
|
|
112
|
+
| Field | Type | Default | Description |
|
|
113
|
+
| ----------- | --------------------------------------------------------------------------------------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------- |
|
|
114
|
+
| `transform` | `(value: T, columnName: string, translate?: (val: string) => string) => string \| SmartTrustedHtml` | required | The text of a cell. Markup in it is sanitised before it is rendered; return `trustHtml(html)` to render markup you vouch for as is. |
|
|
115
|
+
|
|
116
|
+
### `IListComponentFactories<T>`
|
|
117
|
+
|
|
118
|
+
| Field | Type | Default | Description |
|
|
119
|
+
| ------ | -------------------- | ------- | ----------------------------------- |
|
|
120
|
+
| `top?` | `ComponentType<any>` | — | Rendered above the rows (no props). |
|
|
121
|
+
|
|
122
|
+
### `IDetailsProvider<T>`
|
|
123
|
+
|
|
124
|
+
The record shown in a details view of the list.
|
|
125
|
+
|
|
126
|
+
| Field | Type | Default | Description |
|
|
127
|
+
| ----------- | ------------------------ | -------- | ----------------------------------------------- |
|
|
128
|
+
| `getData` | `(id: string) => void` | required | Loads the record of an id (`useList().select`). |
|
|
129
|
+
| `clearData` | `() => void` | required | Clears it (`useList().unselect`). |
|
|
130
|
+
| `item` | `T \| null \| undefined` | required | The loaded record. |
|
|
131
|
+
| `loading` | `boolean` | required | Whether it is loading. |
|
|
132
|
+
|
|
133
|
+
### `IDetailsComponentFactories<T>`
|
|
134
|
+
|
|
135
|
+
| Field | Type | Default | Description |
|
|
136
|
+
| --------- | -------------------- | ------- | --------------------------- |
|
|
137
|
+
| `top?` | `ComponentType<any>` | — | Rendered above the details. |
|
|
138
|
+
| `bottom?` | `ComponentType<any>` | — | Rendered below the details. |
|
|
139
|
+
|
|
140
|
+
### `IRemoveProvider<T>`
|
|
141
|
+
|
|
142
|
+
| Field | Type | Default | Description |
|
|
143
|
+
| -------- | ---------------------- | -------- | ----------------------------------------------------------- |
|
|
144
|
+
| `invoke` | `(id: string) => void` | required | Removes the record of an id (after the confirmation). |
|
|
145
|
+
| `check?` | `(item: T) => boolean` | — | Whether a record can be removed (hides the action per row). |
|
|
146
|
+
|
|
147
|
+
### `SmartSubscribable<T>`
|
|
148
|
+
|
|
149
|
+
Anything with a `subscribe(listener)` that returns an `unsubscribe()` handle, e.g. a `SmartEmitter` or an observable.
|
|
150
|
+
|
|
151
|
+
| Field | Type | Default | Description |
|
|
152
|
+
| ----------- | ----------------------------------------------------------- | -------- | ---------------------------------------- |
|
|
153
|
+
| `subscribe` | `(listener: (value: T) => void) => { unsubscribe(): void }` | required | Subscribes; returns `{ unsubscribe() }`. |
|
|
154
|
+
|
|
155
|
+
### `IItemOptionsForPage`
|
|
156
|
+
|
|
157
|
+
| Field | Type | Default | Description |
|
|
158
|
+
| --------------- | --------- | -------- | ------------------------------------------------------------ |
|
|
159
|
+
| `routingPrefix` | `string` | required | The item URL is `routingPrefix + id` (one `/` between them). |
|
|
160
|
+
| `edit` | `boolean` | required | Whether the target opens for editing (passed along). |
|
|
161
|
+
|
|
162
|
+
### `IItemOptionsForCustom`
|
|
163
|
+
|
|
164
|
+
| Field | Type | Default | Description |
|
|
165
|
+
| -------- | ---------------------- | -------- | ---------------------------------------------------- |
|
|
166
|
+
| `select` | `(id: string) => void` | required | Called with the id instead of navigating. |
|
|
167
|
+
| `edit` | `boolean` | required | Whether the target opens for editing (passed along). |
|
|
168
|
+
|
|
169
|
+
### Related types
|
|
170
|
+
|
|
171
|
+
- `ListMode` (enum): `mobile = 'mobile', desktop = 'desktop', masonryGrid = 'masonryGrid'` — The list layouts.
|
|
172
|
+
- `ItemOptions`: `IItemOptionsForPage \| IItemOptionsForCustom` — Navigate by URL, or call `select(id)`.
|
|
173
|
+
- `PaginationMode` (enum): `infiniteScroll = 'infiniteScroll', singlePage = 'singlePage'` — Pager or infinite scroll.
|
|
174
|
+
|
|
175
|
+
## Columns from the model
|
|
176
|
+
|
|
177
|
+
```ts
|
|
178
|
+
@Field({ type: FieldType.text, list: { order: 1, permissions: ['admin'] } })
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
- `list: true` or `list: { order?, permissions?, filter?, dynamic? }` puts the field in the list; `order` sorts the columns.
|
|
182
|
+
- `list.permissions`: the column is left out when the user has none of them.
|
|
183
|
+
- Header labels come from the label provider, or `MODEL.<key>` translated; cell values from the cell pipe, or the value, translated and sanitised.
|
|
184
|
+
- `image` / `logo` fields render as images (the first image field is the masonry tile image).
|
|
185
|
+
|
|
186
|
+
## Usage
|
|
187
|
+
|
|
188
|
+
```tsx
|
|
189
|
+
import { useMemo } from 'react';
|
|
190
|
+
|
|
191
|
+
import { Field, FieldType, Model } from '@smartsoft001/models';
|
|
192
|
+
import { IListOptions, ListMode, SmartList } from '@smartsoft001/react';
|
|
193
|
+
|
|
194
|
+
@Model({})
|
|
195
|
+
export class Note {
|
|
196
|
+
id!: string;
|
|
197
|
+
|
|
198
|
+
@Field({ type: FieldType.text, list: { order: 1 } })
|
|
199
|
+
title!: string;
|
|
200
|
+
|
|
201
|
+
@Field({ type: FieldType.flag, list: { order: 2 } })
|
|
202
|
+
archived!: boolean;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export function NoteList({
|
|
206
|
+
notes,
|
|
207
|
+
loading,
|
|
208
|
+
onRemove,
|
|
209
|
+
}: {
|
|
210
|
+
notes: Note[];
|
|
211
|
+
loading: boolean;
|
|
212
|
+
onRemove: (id: string) => void;
|
|
213
|
+
}) {
|
|
214
|
+
const options = useMemo<IListOptions<Note>>(
|
|
215
|
+
() => ({
|
|
216
|
+
type: Note,
|
|
217
|
+
mode: ListMode.desktop,
|
|
218
|
+
provider: { list: notes, loading, getData: () => undefined },
|
|
219
|
+
item: { options: { routingPrefix: '/notes/', edit: false } },
|
|
220
|
+
remove: {
|
|
221
|
+
provider: { invoke: onRemove, check: (note) => !note.archived },
|
|
222
|
+
},
|
|
223
|
+
cellPipe: {
|
|
224
|
+
transform: (note, key) =>
|
|
225
|
+
key === 'archived'
|
|
226
|
+
? note.archived
|
|
227
|
+
? 'Yes'
|
|
228
|
+
: 'No'
|
|
229
|
+
: String(note[key as keyof Note] ?? ''),
|
|
230
|
+
},
|
|
231
|
+
}),
|
|
232
|
+
[notes, loading, onRemove],
|
|
233
|
+
);
|
|
234
|
+
|
|
235
|
+
return <SmartList options={options} />;
|
|
236
|
+
}
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
Memoise `options`: `SmartList` recomputes its internal options whenever the object changes.
|
|
240
|
+
|
|
241
|
+
## Replacing the Implementation
|
|
242
|
+
|
|
243
|
+
- **Per mode**: `listModeComponents` on `SmartProvider` maps a `ListMode` to a component taking `SmartListModeProps` (merged over `SmartListDesktop` / `SmartListMobile` / `SmartListMasonryGrid`). `LIST_PRESET_MODE_COMPONENTS` registers the Preline-styled `SmartListDesktopPreset`, `SmartListMobilePreset` and `SmartListMasonryGridPreset`.
|
|
244
|
+
- **Every mode at once**: a component registered under the `'list'` key of `components` replaces the list for every mode.
|
|
245
|
+
|
|
246
|
+
```tsx
|
|
247
|
+
import type { ReactNode } from 'react';
|
|
248
|
+
|
|
249
|
+
import {
|
|
250
|
+
LIST_PRESET_MODE_COMPONENTS,
|
|
251
|
+
SmartProvider,
|
|
252
|
+
} from '@smartsoft001/react';
|
|
253
|
+
|
|
254
|
+
export function AppProviders({ children }: { children: ReactNode }) {
|
|
255
|
+
return (
|
|
256
|
+
<SmartProvider listModeComponents={LIST_PRESET_MODE_COMPONENTS}>
|
|
257
|
+
{children}
|
|
258
|
+
</SmartProvider>
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
`SMART_PRESET_COMPONENTS` registers the mode presets with every other preset. `SmartList` keeps rendering the loader and the "no results" text (`noResults` translation) below whatever mode component is used.
|
|
264
|
+
|
|
265
|
+
### Hooks
|
|
266
|
+
|
|
267
|
+
#### `useListFileUrl`
|
|
268
|
+
|
|
269
|
+
The URL of an image cell: the download URL of an attachment (`{ id }`), `''` without a file service.
|
|
270
|
+
|
|
271
|
+
```ts
|
|
272
|
+
function useListFileUrl(): (file: { id: any } | null | undefined) => string;
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
#### `useList`
|
|
276
|
+
|
|
277
|
+
The behaviour every list mode shares: the column `keys` (permissions via `useAuthService()`, dynamic `__array` columns), the provider `list` and `loading`, the `sort` options, the remove flow (a confirm alert, then `remove.provider.invoke(id)`), item navigation (`useNavigation().navigate(routingPrefix + id)` or `item.options.select`), the details provider (`select` / `unselect`, `detailsComponent` and its props) and the pagination (`loadNextPage` / `loadPrevPage`, `handlePageChange`). With `pagination.mode === PaginationMode.infiniteScroll` and a next page, `infiniteScroll` is `true`: render an element with `infiniteScrollRef` after the items, and the next page loads when it scrolls into view.
|
|
278
|
+
|
|
279
|
+
```ts
|
|
280
|
+
function useList<T extends IEntity<string>>({ options }: SmartListModeProps<T>);
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
| Returns | Type | Description |
|
|
284
|
+
| ----------------------- | --------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- |
|
|
285
|
+
| `fields` | `{ key: string; options: IFieldOptions; }[]` | `options.fields`. |
|
|
286
|
+
| `provider` | `IListProvider<T>` | `options.provider`. |
|
|
287
|
+
| `sort` | `boolean \| { default?: string; defaultDesc?: boolean; }` | `options.sort ?? {}`. |
|
|
288
|
+
| `cellPipe` | `ICellPipe<T> \| null` | `options.cellPipe`, `null` without one. |
|
|
289
|
+
| `selectMode` | `"multi" \| undefined` | `options.select`. |
|
|
290
|
+
| `type` | `any` | `options.type`. |
|
|
291
|
+
| `keys` | `string[]` | The column keys: the list fields the user may see (`list.permissions`), with `dynamic` columns expanded. |
|
|
292
|
+
| `list` | `T[] \| null` | `provider.list` without the rows removed in this list. |
|
|
293
|
+
| `loading` | `boolean` | `provider.loading`. |
|
|
294
|
+
| `removed` | `Set<string>` | Ids hidden after a remove. |
|
|
295
|
+
| `removeHandler` | `((item: T) => void) \| null` | Confirms and removes a record (`null` without `remove`). |
|
|
296
|
+
| `checkRemoveHandler` | `((item: T) => boolean) \| undefined` | `remove.provider.check`. |
|
|
297
|
+
| `itemHandler` | `((id: string) => void) \| null` | Navigates to / selects an id (`null` without `item`). |
|
|
298
|
+
| `detailsComponent` | `ComponentType<any> \| null` | `details.component`, `null` without it. |
|
|
299
|
+
| `detailsComponentProps` | `IDetailsOptions<T> \| null` | The `IDetailsOptions` for `detailsComponent`. |
|
|
300
|
+
| `select` | `((id: string) => void) \| undefined` | `details.provider.getData`. |
|
|
301
|
+
| `unselect` | `(() => void) \| undefined` | `details.provider.clearData`. |
|
|
302
|
+
| `detailsButtonOptions` | `IButtonOptions` | `IButtonOptions` that close the details (`unselect`). |
|
|
303
|
+
| `loadNextPage` | `(() => Promise<void>) \| null` | Loads the next page and scrolls to the top (`null` without `pagination`). |
|
|
304
|
+
| `loadPrevPage` | `(() => Promise<void>) \| null` | Loads the previous page and scrolls to the top. |
|
|
305
|
+
| `page` | `number \| null` | `pagination.page`. |
|
|
306
|
+
| `totalPages` | `number \| null` | `pagination.totalPages`. |
|
|
307
|
+
| `handlePageChange` | `(nextPage: number) => void` | Moves to a page through the loaders (for `SmartPaging`'s `onPageChange`). |
|
|
308
|
+
| `infiniteScroll` | `boolean` | `true` with `PaginationMode.infiniteScroll` and a next page. |
|
|
309
|
+
| `infiniteScrollRef` | `RefObject<HTMLDivElement \| null>` | Attach to an element after the rows; the next page loads when it scrolls into view. |
|
|
310
|
+
|
|
311
|
+
```tsx
|
|
312
|
+
import type { IEntity } from '@smartsoft001/domain-core';
|
|
313
|
+
import { SmartListModeProps, SmartPaging, useList } from '@smartsoft001/react';
|
|
314
|
+
|
|
315
|
+
export function CardList<T extends IEntity<string>>(
|
|
316
|
+
props: SmartListModeProps<T>,
|
|
317
|
+
) {
|
|
318
|
+
const {
|
|
319
|
+
list,
|
|
320
|
+
keys,
|
|
321
|
+
itemHandler,
|
|
322
|
+
removeHandler,
|
|
323
|
+
page,
|
|
324
|
+
totalPages,
|
|
325
|
+
handlePageChange,
|
|
326
|
+
} = useList(props);
|
|
327
|
+
|
|
328
|
+
return (
|
|
329
|
+
<div className={props.className}>
|
|
330
|
+
{list?.map((item) => (
|
|
331
|
+
<article key={item.id}>
|
|
332
|
+
{keys.map((key) => (
|
|
333
|
+
<p key={key}>
|
|
334
|
+
{String((item as Record<string, unknown>)[key] ?? '')}
|
|
335
|
+
</p>
|
|
336
|
+
))}
|
|
337
|
+
{itemHandler && (
|
|
338
|
+
<button type="button" onClick={() => itemHandler(item.id)}>
|
|
339
|
+
Open
|
|
340
|
+
</button>
|
|
341
|
+
)}
|
|
342
|
+
{removeHandler && (
|
|
343
|
+
<button type="button" onClick={() => removeHandler(item)}>
|
|
344
|
+
Remove
|
|
345
|
+
</button>
|
|
346
|
+
)}
|
|
347
|
+
</article>
|
|
348
|
+
))}
|
|
349
|
+
{page !== null && totalPages !== null && (
|
|
350
|
+
<SmartPaging
|
|
351
|
+
currentPage={page}
|
|
352
|
+
totalPages={totalPages}
|
|
353
|
+
onPageChange={handlePageChange}
|
|
354
|
+
/>
|
|
355
|
+
)}
|
|
356
|
+
</div>
|
|
357
|
+
);
|
|
358
|
+
}
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
Register it for one mode with `listModeComponents={{ [ListMode.mobile]: CardList }}`, or for all with `components={{ list: CardList }}`.
|
|
362
|
+
|
|
363
|
+
## Styling
|
|
364
|
+
|
|
365
|
+
- `SmartListDesktop` is a table with a sticky header (`LIST_DESKTOP_STICKY_HEADER_STYLE`); the presets carry the Preline looks with `smart:dark:` variants, the desktop one driven by `options.presentation`.
|
|
366
|
+
|
|
367
|
+
## File Locations
|
|
368
|
+
|
|
369
|
+
Source: `packages/shared/react/src/lib/components/list/` in the smartsoft001 repository.
|
|
370
|
+
|
|
371
|
+
- `desktop/list-desktop.tsx`: `SmartListDesktop`
|
|
372
|
+
- `desktop/preset/list-desktop-preset.tsx`: `SmartListDesktopPreset`
|
|
373
|
+
- `desktop/use-list-desktop.ts`: `useListDesktop`, `LIST_DESKTOP_STICKY_HEADER_STYLE`
|
|
374
|
+
- `list-title-key.ts`: `isListImageKey`, `getListTitleKey`
|
|
375
|
+
- `list.tsx`: `SmartList`
|
|
376
|
+
- `list.types.ts`: `SmartListProps`, `SmartListModeProps`
|
|
377
|
+
- `masonry-grid/list-masonry-grid.tsx`: `SmartListMasonryGrid`
|
|
378
|
+
- `masonry-grid/preset/list-masonry-grid-preset.tsx`: `SmartListMasonryGridPreset`
|
|
379
|
+
- `masonry-grid/use-list-masonry-grid.ts`: `useListMasonryGrid`
|
|
380
|
+
- `mobile/list-mobile.tsx`: `SmartListMobile`
|
|
381
|
+
- `mobile/preset/list-mobile-preset.tsx`: `SmartListMobilePreset`
|
|
382
|
+
- `preset-modes.ts`: `LIST_PRESET_MODE_COMPONENTS`
|
|
383
|
+
- `use-list.ts`: `useListFileUrl`, `useList`
|
|
384
|
+
- `list.stories.tsx`: Storybook stories
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: react-components-list-container
|
|
3
|
+
description: SmartListContainer React component API (@smartsoft001/react) — role="list" wrapper around list entries with simple-dividers/card-dividers/separate-cards/flat-card-dividers variants exposed as data attributes, and the 'list-container' registry key (no preset).
|
|
4
|
+
user-invocable: false
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# List Container (`SmartListContainer`)
|
|
8
|
+
|
|
9
|
+
`SmartListContainer` wraps list entries (`children`) in a `role="list"` element and exposes `options.variant` as `data-variant` so your CSS (or an implementation of your own) can draw dividers or cards. There is no preset for it: register a component of your own under the `list-container` key for a styled container.
|
|
10
|
+
|
|
11
|
+
## When to Use This Skill
|
|
12
|
+
|
|
13
|
+
- Wrapping a set of `role="listitem"` rows with a consistent container
|
|
14
|
+
- Switching between divider and card looks through one option
|
|
15
|
+
- Providing the application's own list container (the `list-container` registry key)
|
|
16
|
+
|
|
17
|
+
For a list of records with avatars and meta, see `react-components-stacked-list`; for model-driven lists, `react-components-list`.
|
|
18
|
+
|
|
19
|
+
## Exports
|
|
20
|
+
|
|
21
|
+
All from `@smartsoft001/react`.
|
|
22
|
+
|
|
23
|
+
| Export | Kind | What it is |
|
|
24
|
+
| ---------------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
25
|
+
| `SmartListContainer` | component | Renders the implementation registered as `components['list-container']` on `SmartProvider`, `SmartListContainerStandard` by default. |
|
|
26
|
+
| `SmartListContainerStandard` | component | The default list-container rendering: a `role="list"` element around `children`, exposing `options.variant` as `data-variant` for styling. |
|
|
27
|
+
|
|
28
|
+
## Props and Types
|
|
29
|
+
|
|
30
|
+
### `SmartListContainerProps`
|
|
31
|
+
|
|
32
|
+
| Prop | Type | Default | Description |
|
|
33
|
+
| ------------ | ----------------------- | ------- | ------------------------------------- |
|
|
34
|
+
| `options?` | `IListContainerOptions` | — | Variant and mobile behaviour. |
|
|
35
|
+
| `className?` | `string` | — | Classes on the `role="list"` element. |
|
|
36
|
+
| `children?` | `ReactNode` | — | The list entries. |
|
|
37
|
+
|
|
38
|
+
### `IListContainerOptions`
|
|
39
|
+
|
|
40
|
+
| Field | Type | Default | Description |
|
|
41
|
+
| -------------------- | --------------------------- | ------- | --------------------------------------------------------------------------------------------------------- |
|
|
42
|
+
| `variant?` | `SmartListContainerVariant` | — | Exposed as `data-variant`. |
|
|
43
|
+
| `fullWidthOnMobile?` | `boolean` | — | For implementations of your own (edge-to-edge on small screens); the standard rendering does not read it. |
|
|
44
|
+
|
|
45
|
+
### Related types
|
|
46
|
+
|
|
47
|
+
- `SmartListContainerVariant`: `'simple-dividers' \| 'card-dividers' \| 'separate-cards' \| 'flat-card-dividers'`
|
|
48
|
+
|
|
49
|
+
## Usage
|
|
50
|
+
|
|
51
|
+
```tsx
|
|
52
|
+
import { SmartListContainer } from '@smartsoft001/react';
|
|
53
|
+
|
|
54
|
+
export function Team() {
|
|
55
|
+
return (
|
|
56
|
+
<SmartListContainer options={{ variant: 'card-dividers' }}>
|
|
57
|
+
<div role="listitem">Lindsay Walton — Front-end Developer</div>
|
|
58
|
+
<div role="listitem">Courtney Henry — Designer</div>
|
|
59
|
+
</SmartListContainer>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Replacing the Implementation
|
|
65
|
+
|
|
66
|
+
`SmartListContainer` renders the component registered under the `'list-container'` key of `SmartProvider`'s `components`, and `SmartListContainerStandard` when nothing is registered there. Every `SmartListContainer` below the provider then renders the registered component, which receives the same props.
|
|
67
|
+
|
|
68
|
+
There is no preset for this component: register a component of your own that takes `SmartListContainerProps`, as shown below, as `components={{ 'list-container': MyListContainer }}`. Pass `components` as a stable object (a module constant or a memoised value), or the context changes on every render.
|
|
69
|
+
|
|
70
|
+
```tsx
|
|
71
|
+
import { SmartListContainerProps } from '@smartsoft001/react';
|
|
72
|
+
|
|
73
|
+
export function CardListContainer({
|
|
74
|
+
options,
|
|
75
|
+
className,
|
|
76
|
+
children,
|
|
77
|
+
}: SmartListContainerProps) {
|
|
78
|
+
const cards = options?.variant === 'separate-cards';
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<div
|
|
82
|
+
role="list"
|
|
83
|
+
data-variant={options?.variant}
|
|
84
|
+
className={[cards ? 'space-y-3' : 'divide-y rounded-md border', className]
|
|
85
|
+
.filter(Boolean)
|
|
86
|
+
.join(' ')}
|
|
87
|
+
>
|
|
88
|
+
{children}
|
|
89
|
+
</div>
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Styling
|
|
95
|
+
|
|
96
|
+
- The standard rendering is unstyled: style `[data-variant]` with your own CSS or register your own component.
|
|
97
|
+
|
|
98
|
+
## File Locations
|
|
99
|
+
|
|
100
|
+
Source: `packages/shared/react/src/lib/components/list-container/` in the smartsoft001 repository.
|
|
101
|
+
|
|
102
|
+
- `list-container.tsx`: `SmartListContainer`
|
|
103
|
+
- `list-container.types.ts`: `SmartListContainerProps`
|
|
104
|
+
- `standard/list-container-standard.tsx`: `SmartListContainerStandard`
|
|
105
|
+
- `list-container.stories.tsx`: Storybook stories
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: react-components-loader
|
|
3
|
+
description: SmartLoader React component API (@smartsoft001/react) — spinner shown while show is true, with size and colour, the 'loader' registry key, SmartLoaderPreset and useLoader.
|
|
4
|
+
user-invocable: false
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Loader (`SmartLoader`)
|
|
8
|
+
|
|
9
|
+
`SmartLoader` renders a spinner while `show` is `true` and nothing otherwise. `size` and `color` use the shared `SmartSize` / `SmartColor` scales. Form inputs render it while an async validator runs, and lists while they load, so registering a loader under the `loader` key changes all of them.
|
|
10
|
+
|
|
11
|
+
## When to Use This Skill
|
|
12
|
+
|
|
13
|
+
- Showing that something is loading in place of, or next to, content
|
|
14
|
+
- Changing the spinner used across the library (the `loader` registry key)
|
|
15
|
+
|
|
16
|
+
## Exports
|
|
17
|
+
|
|
18
|
+
All from `@smartsoft001/react`.
|
|
19
|
+
|
|
20
|
+
| Export | Kind | What it is |
|
|
21
|
+
| --------------------- | --------- | ------------------------------------------------------------------------------------------------------------------ |
|
|
22
|
+
| `SmartLoader` | component | Renders the implementation registered as `components.loader` on `SmartProvider`, `SmartLoaderStandard` by default. |
|
|
23
|
+
| `SmartLoaderPreset` | component | Styled loader variation (preset). |
|
|
24
|
+
| `SmartLoaderStandard` | component | The default loader rendering: an SVG spinner. |
|
|
25
|
+
| `useLoader` | hook | The behaviour every loader variant shares: the spinner classes for `size` and `color`, with `className` appended. |
|
|
26
|
+
|
|
27
|
+
The preset's class helpers (`getLoaderSpinnerClasses`) are exported too, for a custom implementation that wants the preset look.
|
|
28
|
+
|
|
29
|
+
## Props and Types
|
|
30
|
+
|
|
31
|
+
### `SmartLoaderProps`
|
|
32
|
+
|
|
33
|
+
| Prop | Type | Default | Description |
|
|
34
|
+
| ------------ | ------------ | ---------- | --------------------------------- |
|
|
35
|
+
| `show?` | `boolean` | `false` | Renders the spinner while `true`. |
|
|
36
|
+
| `size?` | `SmartSize` | `'md'` | Spinner size. |
|
|
37
|
+
| `color?` | `SmartColor` | `'indigo'` | Spinner colour. |
|
|
38
|
+
| `className?` | `string` | — | Classes appended to the spinner. |
|
|
39
|
+
|
|
40
|
+
`SmartColor`, `SmartSize` are described in the `react-provider` skill.
|
|
41
|
+
|
|
42
|
+
## Usage
|
|
43
|
+
|
|
44
|
+
```tsx
|
|
45
|
+
import { SmartLoader, SmartLoaderPreset } from '@smartsoft001/react';
|
|
46
|
+
|
|
47
|
+
export function Saving({ saving }: { saving: boolean }) {
|
|
48
|
+
return (
|
|
49
|
+
<div className="flex items-center gap-2">
|
|
50
|
+
<SmartLoader show={saving} size="sm" color="blue" />
|
|
51
|
+
<SmartLoaderPreset show={saving} size="lg" />
|
|
52
|
+
{saving && <span>Saving…</span>}
|
|
53
|
+
</div>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Replacing the Implementation
|
|
59
|
+
|
|
60
|
+
`SmartLoader` renders the component registered under the `'loader'` key of `SmartProvider`'s `components`, and `SmartLoaderStandard` when nothing is registered there. Every `SmartLoader` below the provider then renders the registered component, which receives the same props.
|
|
61
|
+
|
|
62
|
+
```tsx
|
|
63
|
+
import type { ReactNode } from 'react';
|
|
64
|
+
|
|
65
|
+
import { SmartProvider, SmartLoaderPreset } from '@smartsoft001/react';
|
|
66
|
+
|
|
67
|
+
// A module constant: a new object on every render would change the context.
|
|
68
|
+
const components = { loader: SmartLoaderPreset };
|
|
69
|
+
|
|
70
|
+
export function AppProviders({ children }: { children: ReactNode }) {
|
|
71
|
+
return <SmartProvider components={components}>{children}</SmartProvider>;
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
`SmartLoaderPreset` is the styled (preset) implementation: register it as above, render it directly in place of `SmartLoader`, or spread `SMART_PRESET_COMPONENTS` on the provider to register every preset at once (see the `react-provider` skill). Pass `components` as a stable object (a module constant or a memoised value), or the context changes on every render.
|
|
76
|
+
|
|
77
|
+
### The `useLoader` hook
|
|
78
|
+
|
|
79
|
+
The behaviour every loader variant shares: the spinner classes for `size` and `color`, with `className` appended.
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
function useLoader({
|
|
83
|
+
size = 'md',
|
|
84
|
+
color = 'indigo',
|
|
85
|
+
className = '',
|
|
86
|
+
}: SmartLoaderProps);
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
| Returns | Type | Description |
|
|
90
|
+
| ---------------- | ---------- | -------------------------------------------------------------- |
|
|
91
|
+
| `spinnerClasses` | `string[]` | The classes for `size` and `color`, with `className` appended. |
|
|
92
|
+
|
|
93
|
+
```tsx
|
|
94
|
+
import { SmartLoaderProps, useLoader } from '@smartsoft001/react';
|
|
95
|
+
|
|
96
|
+
export function DotsLoader(props: SmartLoaderProps) {
|
|
97
|
+
const { spinnerClasses } = useLoader(props);
|
|
98
|
+
|
|
99
|
+
if (!props.show) return null;
|
|
100
|
+
|
|
101
|
+
return (
|
|
102
|
+
<span
|
|
103
|
+
role="status"
|
|
104
|
+
aria-label="Loading"
|
|
105
|
+
className={spinnerClasses.join(' ')}
|
|
106
|
+
>
|
|
107
|
+
…
|
|
108
|
+
</span>
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Styling
|
|
114
|
+
|
|
115
|
+
- `SmartLoaderStandard` is an SVG spinner; `SmartLoaderPreset` is a bordered spinning ring with explicit `smart:dark:` variants for every colour.
|
|
116
|
+
|
|
117
|
+
## File Locations
|
|
118
|
+
|
|
119
|
+
Source: `packages/shared/react/src/lib/components/loader/` in the smartsoft001 repository.
|
|
120
|
+
|
|
121
|
+
- `loader.tsx`: `SmartLoader`
|
|
122
|
+
- `loader.types.ts`: `SmartLoaderProps`
|
|
123
|
+
- `preset/loader-preset.tsx`: `SmartLoaderPreset`
|
|
124
|
+
- `standard/loader-standard.tsx`: `SmartLoaderStandard`
|
|
125
|
+
- `use-loader.ts`: `useLoader`
|
|
126
|
+
- `loader.stories.tsx`: Storybook stories
|