@smartsoft001/claude-plugins 2.202.0 → 2.204.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/package.json +1 -1
- package/plugins/smart-angular/.claude-plugin/plugin.json +1 -1
- package/plugins/smart-angular/skills/angular-components-details/SKILL.md +32 -4
- package/plugins/smart-angular/skills/angular-components-input/SKILL.md +24 -16
- package/plugins/smart-angular/skills/angular-components-list/SKILL.md +79 -36
- package/plugins/smart-angular/skills/angular-components-modal/SKILL.md +81 -13
- package/plugins/smart-angular/skills/angular-components-notification/SKILL.md +51 -1
- package/plugins/smart-angular/skills/angular-components-page/SKILL.md +7 -5
- package/plugins/smart-angular/skills/angular-components-vertical-navigation/SKILL.md +3 -3
- package/plugins/smart-angular/skills/smart-crud/SKILL.md +5 -2
- package/plugins/smart-core/.claude-plugin/plugin.json +1 -1
- package/plugins/smart-react/.claude-plugin/plugin.json +1 -1
- package/plugins/smart-react/skills/react-components-details/SKILL.md +6 -6
- package/plugins/smart-react/skills/react-components-input/SKILL.md +10 -0
- package/plugins/smart-react/skills/react-components-list/SKILL.md +66 -33
- package/plugins/smart-react/skills/react-components-modal/SKILL.md +24 -12
- package/plugins/smart-react/skills/react-components-notification/SKILL.md +1 -1
- package/plugins/smart-react/skills/react-components-overlays/SKILL.md +15 -14
- package/plugins/smart-react/skills/react-components-page/SKILL.md +5 -5
- package/plugins/smart-react/skills/react-components-vertical-navigation/SKILL.md +3 -3
- package/plugins/smart-react/skills/react-provider/SKILL.md +1 -1
- package/plugins/smart-react/skills/smart-crud-react/SKILL.md +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smartsoft001/claude-plugins",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.204.0",
|
|
4
4
|
"description": "Installs the smartsoft Claude Code plugins into a project: smart-core (hooks and framework-neutral skills) plus smart-angular or smart-react (the component and CRUD skills and agents of one framework).",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "smart-angular",
|
|
3
3
|
"description": "Smartsoft for Angular projects - the @smartsoft001/angular component skills and their angular-components agent, the Angular CRUD skill and the Nx + Angular SSR workspace scaffold",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.203.0",
|
|
5
5
|
"dependencies": ["smart-core"]
|
|
6
6
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: angular-components-details
|
|
3
|
-
description: Details component API with InjectionToken pattern for custom implementations. Renders a list of model fields via <smart-detail
|
|
3
|
+
description: Details component API with InjectionToken pattern for custom implementations. Renders a list of model fields via <smart-detail>; DetailsPage, the [smartDetails] directive and showDetailsModal show it in a modal.
|
|
4
4
|
user-invocable: false
|
|
5
5
|
---
|
|
6
6
|
|
|
@@ -13,6 +13,7 @@ The `<smart-details>` component renders a list of model fields decorated with `@
|
|
|
13
13
|
- Developer wants to render a read-only summary of an entity using model decorators
|
|
14
14
|
- Developer asks about `<smart-details>` or `DetailsComponent`
|
|
15
15
|
- Developer wants to provide a custom layout for the standard details rendering
|
|
16
|
+
- Developer wants to show the details of a record in a modal (`[smartDetails]`, `DetailsPage`, `showDetailsModal`)
|
|
16
17
|
|
|
17
18
|
## Components
|
|
18
19
|
|
|
@@ -53,9 +54,9 @@ Abstract base directive. Extend it to build custom details implementations. It e
|
|
|
53
54
|
| `cellPipe` | `ICellPipe<T>` | - | Formats the values of the `text` and `phoneNumberPl` fields (see `angular-components-detail`). |
|
|
54
55
|
| `componentFactories` | `IDetailsComponentFactories<T>` | - | Components created above (`top`) and below (`bottom`) the fields. |
|
|
55
56
|
| `loading` | `Signal<boolean>` | - | Passed to every `<smart-detail>`; not read by the built-in implementations; available to a custom implementation. |
|
|
56
|
-
| `title` | `string` | - | Not read by `<smart-details>`; `DetailsPage` uses it as the
|
|
57
|
-
| `itemHandler` | `((id: string) => void) \| null` | - | Not read by `<smart-details>`; `DetailsPage`
|
|
58
|
-
| `removeHandler` | `((item: T) => void) \| null` | - | Not read by `<smart-details>`; `DetailsPage`
|
|
57
|
+
| `title` | `string` | - | Not read by `<smart-details>`; `DetailsPage` uses it as the title of its `pageOptions()`. |
|
|
58
|
+
| `itemHandler` | `((id: string) => void) \| null` | - | Not read by `<smart-details>`; `DetailsPage` turns it into a forward button of its `pageOptions()`. |
|
|
59
|
+
| `removeHandler` | `((item: T) => void) \| null` | - | Not read by `<smart-details>`; `DetailsPage` turns it into a remove button of its `pageOptions()`. |
|
|
59
60
|
|
|
60
61
|
`IDetailsComponentFactories<T>` has two optional fields, `top` and `bottom`, each a `Type<any>` created without inputs.
|
|
61
62
|
|
|
@@ -132,6 +133,31 @@ export class MyCustomDetailsComponent extends DetailsBaseComponent<any> {}
|
|
|
132
133
|
></smart-details>
|
|
133
134
|
```
|
|
134
135
|
|
|
136
|
+
## Details in a modal
|
|
137
|
+
|
|
138
|
+
`DetailsPage` (`SharedPagesModule`) renders `<smart-details>` of its `value` input full width, with the application style (`StyleService.init`) applied to its element; without a `value` it renders nothing. `pageOptions()` gives the page options for a page layout around it: the `title` (default `details`), a `trash` button for `removeHandler` and an `arrow-forward-outline` button for `itemHandler`; both call their handler with the current item and close the modal through `ModalService.dismiss()`. The page layout moved out of the library (FRA-121), so the page does not render these buttons itself.
|
|
139
|
+
|
|
140
|
+
The `[smartDetails]` directive (`DetailsDirective`) opens a component in a modal on click, through `ModalService` (see `angular-components-modal`), with its `params` as the `value` input. It emits `smartDetailsShowed` once the modal is open and `smartDetailsDismissed` once it is closed; the browser's back button (`HardwareService.onBackButtonClick`, the window's `popstate`) closes the modal as well. `showDetailsModal(services, options, callbacks)` does the same from code, and is what `<smart-list>` uses for its `details` option (see `angular-components-list`).
|
|
141
|
+
|
|
142
|
+
| `[smartDetails]` field | Type | Default | Description |
|
|
143
|
+
| ---------------------- | ----------------------- | ---------- | ------------------------------------------------------------------------- |
|
|
144
|
+
| `component` | `any` | required | Rendered in the modal, e.g. `DetailsPage`. |
|
|
145
|
+
| `params` | `any` | required | Its `value` input, e.g. an `IDetailsOptions`. |
|
|
146
|
+
| `mode` | `'bottom' \| 'default'` | `'bottom'` | Passed to `ModalService.show` as `mode`; `'bottom'` opens a bottom sheet. |
|
|
147
|
+
|
|
148
|
+
```html
|
|
149
|
+
<button
|
|
150
|
+
type="button"
|
|
151
|
+
[smartDetails]="{ component: DetailsPage, params: detailsOptions }"
|
|
152
|
+
(smartDetailsShowed)="load(user.id)"
|
|
153
|
+
(smartDetailsDismissed)="clear()"
|
|
154
|
+
>
|
|
155
|
+
Show
|
|
156
|
+
</button>
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
`IDetailsOptions.item` is a signal, so the page shows skeletons until the item is loaded and the fields once it is.
|
|
160
|
+
|
|
135
161
|
## Field Rendering
|
|
136
162
|
|
|
137
163
|
Each field is rendered via `<smart-detail>`. The actual rendering of a single field by `FieldType` (text, email, address, image, attachment, …) is dispatched inside `<smart-detail>` itself. See the `angular-components-detail` skill for per-field details.
|
|
@@ -143,4 +169,6 @@ Each field is rendered via `<smart-detail>`. The actual rendering of a single fi
|
|
|
143
169
|
- Base class: `packages/shared/angular/src/lib/components/details/base/base.component.ts`
|
|
144
170
|
- Token: `packages/shared/angular/src/lib/shared.inectors.ts` (`DETAILS_STANDARD_COMPONENT_TOKEN`)
|
|
145
171
|
- Interface: `packages/shared/angular/src/lib/models/interfaces.ts` (`IDetailsOptions`)
|
|
172
|
+
- Page: `packages/shared/angular/src/lib/pages/details/details.page.ts` (`DetailsPage`)
|
|
173
|
+
- Directive: `packages/shared/angular/src/lib/directives/details/details.directive.ts` (`DetailsDirective`, `[smartDetails]`) and `details-modal.ts` (`showDetailsModal`, `IDetailsModalOptions`)
|
|
146
174
|
- Stories: `packages/shared/angular/src/lib/components/details/details.component.stories.ts`
|
|
@@ -33,7 +33,15 @@ Abstract base directive for all input sub-components. Provides:
|
|
|
33
33
|
|
|
34
34
|
### InputPossibilitiesBaseComponent (abstract)
|
|
35
35
|
|
|
36
|
-
Extends `InputBaseComponent` for sub-components that need list possibilities: the radio and check components (standard and preset) and the enum preset. Its `
|
|
36
|
+
Extends `InputBaseComponent` for sub-components that need list possibilities: the radio and check components (standard and preset) and the enum preset. Its `possibilities` signal holds, in this order of precedence:
|
|
37
|
+
|
|
38
|
+
1. the list in the signal `MODEL_POSSIBILITIES_PROVIDER` returns from `get({ type, key, instance })` (the model's class, the field key and the parent form's value), while that signal's value is not `null`;
|
|
39
|
+
2. else `options.possibilities`;
|
|
40
|
+
3. else the `possibilities` of the field's `@Field()` metadata (read through the first item of an array model): an object map `{ text: id }`, such as an enum, as a list for the radio components and the enum preset, a list as it is for the check components.
|
|
41
|
+
|
|
42
|
+
The provider is asked when the options are set and again 500 ms after the parent form's value last changed, so the list can depend on other fields; a provider signal filled later (after an HTTP call, for instance) updates the field, and after a new question the former list stays until the new signal holds one. The token is optional: without a provider the field shows the input options, else the field's own possibilities. The check components keep each possibility's `checked` in line with the control value (an `id` in the value, or equal to it) whenever the list or the value changes.
|
|
43
|
+
|
|
44
|
+
A subclass that overrides `afterSetOptionsHandler()` calls `super.afterSetOptionsHandler()` first. Two more protected hooks are there to override: `afterPossibilitiesChange()`, which runs whenever the list may have changed, and `getModelPossibilities()`, the fallback read from the field's metadata.
|
|
37
45
|
|
|
38
46
|
### InputFileBaseComponent (abstract)
|
|
39
47
|
|
|
@@ -91,15 +99,15 @@ The validation messages `<smart-input>` renders under a touched field. Its only
|
|
|
91
99
|
|
|
92
100
|
`InputOptions<T>` is `IInputOptions & IInputFromFieldOptions<T>`.
|
|
93
101
|
|
|
94
|
-
| Field | Type | Default | Description
|
|
95
|
-
| --------------- | --------------------------------------------------------------- | -------- |
|
|
96
|
-
| `treeLevel` | `number` | required | Nesting depth (0 at the top; nested object / array forms go one deeper).
|
|
97
|
-
| `control` | `UntypedFormControl \| UntypedFormArray` | required | The control of the field.
|
|
98
|
-
| `possibilities` | `WritableSignal<{ id: any; text: string; checked: boolean }[]>` | — | The options of a radio, check or enum preset field
|
|
99
|
-
| `component` | `Type<InputBaseComponent<any>>` | — | A field component used instead of the one of the field type (wins over the token).
|
|
100
|
-
| `model` | `T` | required | The model instance whose `@Field()` metadata is read.
|
|
101
|
-
| `fieldKey` | `string` | required | The field's key; a `<key>Confirm` key reads the metadata of `<key>`.
|
|
102
|
-
| `mode` | `'create' \| 'update' \| string` | — | Merges the `@Field({ create })` / `@Field({ update })` overrides into the field options.
|
|
102
|
+
| Field | Type | Default | Description |
|
|
103
|
+
| --------------- | --------------------------------------------------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
104
|
+
| `treeLevel` | `number` | required | Nesting depth (0 at the top; nested object / array forms go one deeper). |
|
|
105
|
+
| `control` | `UntypedFormControl \| UntypedFormArray` | required | The control of the field. |
|
|
106
|
+
| `possibilities` | `WritableSignal<{ id: any; text: string; checked: boolean }[]>` | — | The options of a radio, check or enum preset field: the `MODEL_POSSIBILITIES_PROVIDER` list wins over them, they win over the field's own `possibilities`. The standard enum (the enum's keys) and the other field types do not read it. |
|
|
107
|
+
| `component` | `Type<InputBaseComponent<any>>` | — | A field component used instead of the one of the field type (wins over the token). |
|
|
108
|
+
| `model` | `T` | required | The model instance whose `@Field()` metadata is read. |
|
|
109
|
+
| `fieldKey` | `string` | required | The field's key; a `<key>Confirm` key reads the metadata of `<key>`. |
|
|
110
|
+
| `mode` | `'create' \| 'update' \| string` | — | Merges the `@Field({ create })` / `@Field({ update })` overrides into the field options. |
|
|
103
111
|
|
|
104
112
|
```typescript
|
|
105
113
|
type InputOptions<T> = IInputOptions & IInputFromFieldOptions<T>;
|
|
@@ -187,12 +195,12 @@ the most recently added ones:
|
|
|
187
195
|
|
|
188
196
|
Where a preset behaves differently from the standard component of its type:
|
|
189
197
|
|
|
190
|
-
| FieldType | Standard | Preset
|
|
191
|
-
| --------- | -------------------------------------------------- |
|
|
192
|
-
| `enum` | Checkboxes of the enum's keys; value: list of keys | A `<select>` of the possibilities (`options.possibilities`, else the field's); value: one possibility `id` |
|
|
193
|
-
| `file` | Keeps the picked `File` as the value (no upload) | Uploads through `FileService` (`InputFileBaseComponent`); value: the API result
|
|
194
|
-
| `logo` | Stores a base64 `data:` URL (no upload) | Uploads like `image` (`.jpg,.png,.jpeg`)
|
|
195
|
-
| `pesel` | No validator of its own | Adds an `invalidPesel` check (shown with the same message as `pesel`)
|
|
198
|
+
| FieldType | Standard | Preset |
|
|
199
|
+
| --------- | -------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------- |
|
|
200
|
+
| `enum` | Checkboxes of the enum's keys; value: list of keys | A `<select>` of the possibilities (the provider's, else `options.possibilities`, else the field's); value: one possibility `id` |
|
|
201
|
+
| `file` | Keeps the picked `File` as the value (no upload) | Uploads through `FileService` (`InputFileBaseComponent`); value: the API result |
|
|
202
|
+
| `logo` | Stores a base64 `data:` URL (no upload) | Uploads like `image` (`.jpg,.png,.jpeg`) |
|
|
203
|
+
| `pesel` | No validator of its own | Adds an `invalidPesel` check (shown with the same message as `pesel`) |
|
|
196
204
|
|
|
197
205
|
Notes:
|
|
198
206
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: angular-components-list
|
|
3
|
-
description: List component API with InjectionToken map pattern for custom implementations per mode (desktop/mobile/masonryGrid).
|
|
3
|
+
description: List component API with InjectionToken map pattern for custom implementations per mode (desktop/mobile/masonryGrid), with sortable headers, details in a modal and single-page or infinite-scroll pagination.
|
|
4
4
|
user-invocable: false
|
|
5
5
|
---
|
|
6
6
|
|
|
@@ -11,6 +11,7 @@ The `<smart-list>` component renders a list of entities. It is a wrapper that di
|
|
|
11
11
|
## When to Use This Skill
|
|
12
12
|
|
|
13
13
|
- Developer wants to display a collection of entities with row actions, multi-selection or pagination
|
|
14
|
+
- Developer wants sortable column headers, the details of an item in a modal, or infinite scroll
|
|
14
15
|
- Developer asks about `<smart-list>` or `ListComponent`
|
|
15
16
|
- Developer wants to provide a custom layout for a specific list mode (desktop, mobile, or masonryGrid)
|
|
16
17
|
|
|
@@ -22,15 +23,15 @@ Main wrapper. Resolves the list `fields` of `options.type` (the `@Field({ list }
|
|
|
22
23
|
|
|
23
24
|
### ListDesktopComponent (`<smart-list-desktop>`)
|
|
24
25
|
|
|
25
|
-
Default desktop implementation. A CDK table with a sticky header row, one column per list field, plus the multi-select checkbox column (`select: 'multi'`), the remove column (`remove`) and the item action column (`item`); the `top` component factory above it and `<smart-paging>` below it when `pagination.mode` is `PaginationMode.singlePage`.
|
|
26
|
+
Default desktop implementation. A CDK table with a sticky header row, one column per list field, plus the multi-select checkbox column (`select: 'multi'`), the details column (`details`), the remove column (`remove`) and the item action column (`item`); the `top` component factory above it and `<smart-paging>` below it when `pagination.mode` is `PaginationMode.singlePage`. With `sort` the field headers are sort buttons (see [Sorting](#sorting)).
|
|
26
27
|
|
|
27
28
|
### ListMobileComponent (`<smart-list-mobile>`)
|
|
28
29
|
|
|
29
|
-
Default mobile implementation. Renders a `<ul role="list">` with flex rows, one paragraph per cell, plus the remove and item action buttons; the `top` component factory above it and `<smart-paging>` below it (`PaginationMode.singlePage`).
|
|
30
|
+
Default mobile implementation. Renders a `<ul role="list">` with flex rows, one paragraph per cell, plus the details, remove and item action buttons; the `top` component factory above it and `<smart-paging>` below it (`PaginationMode.singlePage`).
|
|
30
31
|
|
|
31
32
|
### ListMasonryGridComponent (`<smart-list-masonry-grid>`)
|
|
32
33
|
|
|
33
|
-
Default masonry-grid implementation. Renders a grid of tiles with the item's image (the model's first `FieldType.image` field) over its other cells; the `top` component factory above it and `<smart-paging>` below it (`PaginationMode.singlePage`).
|
|
34
|
+
Default masonry-grid implementation. Renders a grid of tiles with the item's image (the model's first `FieldType.image` field) over its other cells; the `top` component factory above it and `<smart-paging>` below it (`PaginationMode.singlePage`). Its only row action is the details button (`details`).
|
|
34
35
|
|
|
35
36
|
### ListBaseComponent (abstract)
|
|
36
37
|
|
|
@@ -41,9 +42,12 @@ Abstract base directive. Extend it to build custom list implementations for any
|
|
|
41
42
|
- `loading` — `Signal<boolean>` from the provider
|
|
42
43
|
- `page`, `totalPages` — `Signal<number | null>` from the pagination options
|
|
43
44
|
- `type` — the model class, `sort`, `selectMode` (`options.sort ?? {}`, `options.select`)
|
|
45
|
+
- `sortable` — `Signal<boolean>`, `true` with `options.sort`; `activeSort` — `WritableSignal<IListSortState | null>`, the sort the headers show (`sort.default` / `sort.defaultDesc` at first, then the last header clicked; it starts over when `options.sort` changes)
|
|
44
46
|
- `itemHandler` — resolved item navigation (`Router.navigate([routingPrefix, id])`) or select handler, `null` without `item`
|
|
45
47
|
- `removeHandler` — confirms with `AlertService` (`OBJECT.confirmDelete`) and calls `remove.provider.invoke(id)`, `null` without `remove`; `checkRemoveHandler` is `remove.provider.check`
|
|
46
|
-
- `
|
|
48
|
+
- `detailsHandler` — opens the details of an item in a modal (`openDetails(item)`), `null` without `details`
|
|
49
|
+
- `detailsComponent`, `detailsComponentProps`, `select`, `unselect` — set from `details`: the custom `details.component` (else `undefined`, and `DetailsPage` opens), the `IDetailsOptions` it gets as `value`, and the provider's `getData` / `clearData`
|
|
50
|
+
- `infiniteScroll` — `Signal<boolean>`, `true` with `PaginationMode.infiniteScroll` while `page() < totalPages()`; `infiniteScrollAnchor` — the view query of the `#infiniteScrollAnchor` element the modes render after the items
|
|
47
51
|
- `loadNextPage`, `loadPrevPage` — the pagination loaders (they scroll the window), `null` without `pagination`
|
|
48
52
|
- `cellPipe` — `ICellPipe<T> | null`
|
|
49
53
|
- `cssClass` — string input (alias `class`), forwarded by `<smart-list>`
|
|
@@ -53,7 +57,9 @@ The resolved fields themselves are private; read `options().fields` in a subclas
|
|
|
53
57
|
Methods:
|
|
54
58
|
|
|
55
59
|
- `initKeys()` (protected) — populates `keys` from the resolved fields
|
|
56
|
-
- `handlePageChange(page: number)` — calls `loadNextPage()` for a later page and `loadPrevPage()` for an earlier one
|
|
60
|
+
- `handlePageChange(page: number)` — calls `loadNextPage()` for a later page and `loadPrevPage()` for an earlier one
|
|
61
|
+
- `isSortable(key)`, `sortBy(key)`, `ariaSort(key)`, `sortIndicator(key)` — whether a header sorts (every field column with `sort`, not the `__array` columns of a `dynamic` field), sort by it (calls `provider.getData({ offset: 0, sortBy, sortDesc })`), its `aria-sort` (`'ascending'` / `'descending'` on the active header, `null` otherwise) and its arrow (`↑`, `↓`, `↕`)
|
|
62
|
+
- `openDetails(item)` — clears the details provider (`unselect()`), opens `detailsComponent ?? DetailsPage` in a `'bottom'` modal (a bottom sheet) through `showDetailsModal` with `{ value: detailsComponentProps }`, then calls `select(item.id)`
|
|
57
63
|
|
|
58
64
|
## API
|
|
59
65
|
|
|
@@ -108,30 +114,30 @@ interface IListOptions<T> {
|
|
|
108
114
|
|
|
109
115
|
### IListOptions property reference
|
|
110
116
|
|
|
111
|
-
| Property | Type | Default | Description
|
|
112
|
-
| -------------------- | ---------------------------------------------------------------------------------------------------------------------------------- | ---------- |
|
|
113
|
-
| `provider` | `IListProvider<T>` | _required_ | Where the rows come from (`list`, `loading` signals) and the multi-selection callbacks.
|
|
114
|
-
| `type` | `any` | _required_ | Model class decorated with `@Model`; its `@Field({ list })` fields are the columns.
|
|
115
|
-
| `mode` | `ListMode` | - | Force a specific mode; omit to auto-detect via `HardwareService.isMobile` (mobile or desktop).
|
|
116
|
-
| `pagination` | `IListPaginationOptions` | - | Paging state and loaders
|
|
117
|
-
| `cellPipe` | `ICellPipe<T>` | - | Formats cells: `transform(item, key, translate?)` returns the cell text (rendered as HTML through Angular's sanitiser).
|
|
118
|
-
| `componentFactories` | `IListComponentFactories<T>` | - | `top`: a component created above the rows.
|
|
119
|
-
| `sort` | `boolean \| { default?: string; defaultDesc?: boolean }` | - |
|
|
120
|
-
| `details` | `boolean \| { provider?: IDetailsProvider<T>; componentFactories?: IDetailsComponentFactories<T>; component?: Type<any> }` | - |
|
|
121
|
-
| `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.
|
|
122
|
-
| `remove` | `boolean \| { provider?: IRemoveProvider<T> }` | - | Adds the remove action: an alert (`OBJECT.confirmDelete`), then `provider.invoke(id)`; `provider.check(item)` hides it per row.
|
|
123
|
-
| `select` | `'multi'` | - | Adds a checkbox column (desktop and desktop preset); changes go to `provider.onChangeMultiSelected`.
|
|
124
|
-
| `presentation` | `{ variant?: 'default' \| 'striped' \| 'bordered' \| 'borderless'; hoverable?: boolean; header?: 'default' \| 'muted' \| 'none' }` | `{}` | Desktop preset only: the table `variant` (`'default'`), `hoverable` rows and the `header` look (`'default'`). The standard components ignore it.
|
|
117
|
+
| Property | Type | Default | Description |
|
|
118
|
+
| -------------------- | ---------------------------------------------------------------------------------------------------------------------------------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
119
|
+
| `provider` | `IListProvider<T>` | _required_ | Where the rows come from (`list`, `loading` signals) and the multi-selection callbacks. |
|
|
120
|
+
| `type` | `any` | _required_ | Model class decorated with `@Model`; its `@Field({ list })` fields are the columns. |
|
|
121
|
+
| `mode` | `ListMode` | - | Force a specific mode; omit to auto-detect via `HardwareService.isMobile` (mobile or desktop). |
|
|
122
|
+
| `pagination` | `IListPaginationOptions` | - | Paging state and loaders: `<smart-paging>` for `PaginationMode.singlePage`, the next page on scroll for `PaginationMode.infiniteScroll` (see [Infinite scroll](#infinite-scroll)). |
|
|
123
|
+
| `cellPipe` | `ICellPipe<T>` | - | Formats cells: `transform(item, key, translate?)` returns the cell text (rendered as HTML through Angular's sanitiser). |
|
|
124
|
+
| `componentFactories` | `IListComponentFactories<T>` | - | `top`: a component created above the rows. |
|
|
125
|
+
| `sort` | `boolean \| { default?: string; defaultDesc?: boolean }` | - | Makes the field headers of the desktop modes sort buttons; `default` / `defaultDesc` is the sort they show at first (see [Sorting](#sorting)). |
|
|
126
|
+
| `details` | `boolean \| { provider?: IDetailsProvider<T>; componentFactories?: IDetailsComponentFactories<T>; component?: Type<any> }` | - | Adds a details action (`show`) to every item that opens `component` (`DetailsPage` by default) in a modal; requires a `provider` (else it throws). See [Details](#details). |
|
|
127
|
+
| `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. |
|
|
128
|
+
| `remove` | `boolean \| { provider?: IRemoveProvider<T> }` | - | Adds the remove action: an alert (`OBJECT.confirmDelete`), then `provider.invoke(id)`; `provider.check(item)` hides it per row. |
|
|
129
|
+
| `select` | `'multi'` | - | Adds a checkbox column (desktop and desktop preset); changes go to `provider.onChangeMultiSelected`. |
|
|
130
|
+
| `presentation` | `{ variant?: 'default' \| 'striped' \| 'bordered' \| 'borderless'; hoverable?: boolean; header?: 'default' \| 'muted' \| 'none' }` | `{}` | Desktop preset only: the table `variant` (`'default'`), `hoverable` rows and the `header` look (`'default'`). The standard components ignore it. |
|
|
125
131
|
|
|
126
132
|
### IListProvider\<T>
|
|
127
133
|
|
|
128
|
-
| Field | Type | Default | Description
|
|
129
|
-
| ------------------------ | ----------------------- | -------- |
|
|
130
|
-
| `list` | `Signal<T[]>` | required | The records to show.
|
|
131
|
-
| `loading` | `Signal<boolean>` | required | Shows the loader while `true`.
|
|
132
|
-
| `getData` | `(filter: any) => void` | required |
|
|
133
|
-
| `onChangeMultiSelected?` | `(list: T[]) => void` | - | Called with the selected records when `select: 'multi'`.
|
|
134
|
-
| `onCleanMultiSelected$?` | `Observable<void>` | - | Clears the multi-selection whenever it emits.
|
|
134
|
+
| Field | Type | Default | Description |
|
|
135
|
+
| ------------------------ | ----------------------- | -------- | ---------------------------------------------------------------------------------------------------------------- |
|
|
136
|
+
| `list` | `Signal<T[]>` | required | The records to show. |
|
|
137
|
+
| `loading` | `Signal<boolean>` | required | Shows the loader while `true`. |
|
|
138
|
+
| `getData` | `(filter: any) => void` | required | Reads the data again with `filter` merged in; a sortable header calls it with `{ offset: 0, sortBy, sortDesc }`. |
|
|
139
|
+
| `onChangeMultiSelected?` | `(list: T[]) => void` | - | Called with the selected records when `select: 'multi'`. |
|
|
140
|
+
| `onCleanMultiSelected$?` | `Observable<void>` | - | Clears the multi-selection whenever it emits. |
|
|
135
141
|
|
|
136
142
|
```typescript
|
|
137
143
|
interface IListProvider<T> {
|
|
@@ -149,14 +155,14 @@ interface IListProvider<T> {
|
|
|
149
155
|
|
|
150
156
|
### IListPaginationOptions
|
|
151
157
|
|
|
152
|
-
| Field | Type | Default | Description
|
|
153
|
-
| -------------- | ------------------------ | -------- |
|
|
154
|
-
| `mode?` | `PaginationMode` | - | `PaginationMode.singlePage` renders `<smart-paging>`; `PaginationMode.infiniteScroll`
|
|
155
|
-
| `limit` | `number` | required | Page size, for the provider's owner; the list does not read it.
|
|
156
|
-
| `loadNextPage` | `() => Promise<boolean>` | required | Loads the next page.
|
|
157
|
-
| `loadPrevPage` | `() => Promise<boolean>` | required | Loads the previous page.
|
|
158
|
-
| `page` | `Signal<number>` | required | Current page.
|
|
159
|
-
| `totalPages` | `Signal<number>` | required | Number of pages.
|
|
158
|
+
| Field | Type | Default | Description |
|
|
159
|
+
| -------------- | ------------------------ | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
160
|
+
| `mode?` | `PaginationMode` | - | `PaginationMode.singlePage` renders `<smart-paging>`; `PaginationMode.infiniteScroll` loads the next page when the end of the items scrolls into view. |
|
|
161
|
+
| `limit` | `number` | required | Page size, for the provider's owner; the list does not read it. |
|
|
162
|
+
| `loadNextPage` | `() => Promise<boolean>` | required | Loads the next page. |
|
|
163
|
+
| `loadPrevPage` | `() => Promise<boolean>` | required | Loads the previous page. |
|
|
164
|
+
| `page` | `Signal<number>` | required | Current page. |
|
|
165
|
+
| `totalPages` | `Signal<number>` | required | Number of pages. |
|
|
160
166
|
|
|
161
167
|
`PaginationMode` is an enum: `PaginationMode.infiniteScroll` (`'infiniteScroll'`), `PaginationMode.singlePage` (`'singlePage'`).
|
|
162
168
|
|
|
@@ -171,6 +177,22 @@ interface IListProvider<T> {
|
|
|
171
177
|
| `IDetailsProvider<T>` | `getData: (id: string) => void`, `clearData: () => void`, `item: Signal<T>`, `loading: Signal<boolean>` |
|
|
172
178
|
| `ICellPipe<T>` | `transform(value: T, columnName: string, translate?: (val: string) => string): string` |
|
|
173
179
|
| `IListComponentFactories<T>` | `top?: Type<any>` |
|
|
180
|
+
| `IListSortState` | `key: string`, `desc: boolean` (the sort a list shows) |
|
|
181
|
+
| `IListSortFilter` | `offset: 0`, `sortBy: string`, `sortDesc: boolean` (what a sortable header passes to `provider.getData`) |
|
|
182
|
+
|
|
183
|
+
## Sorting
|
|
184
|
+
|
|
185
|
+
With `sort` set (`true`, or `{ default?, defaultDesc? }`), every field header of the desktop table (standard and preset) is a sort button with an arrow: `↕` on the headers that do not sort the list, `↑` / `↓` on the active one, which also carries `aria-sort` (`ascending` / `descending`). A click on another column sorts by it in ascending order, a click on the active column turns the direction around. The list does not sort the rows itself: it calls `provider.getData({ offset: 0, sortBy, sortDesc })`, and the provider reads its data again in that order, from the first page. The CRUD list page (`@smartsoft001/crud-shell-angular`) merges that filter into its `ICrudFilter`, so the request carries `sort=<field>` or `sort=-<field>`. The expanded columns of a `dynamic` field do not sort. The mobile and masonry modes have no headers, so they ignore `sort`.
|
|
186
|
+
|
|
187
|
+
`sort.default` and `sort.defaultDesc` only set the header the list shows at first; the provider loads its first data in that order on its own. The clicked sort stays while other options change, and starts over from `sort.default` when the `sort` option is a new object. The helpers behind it are exported: `getListDefaultSort`, `getNextListSort`, `getListAriaSort`, `getListSortIndicator` and `isListSortableKey`.
|
|
188
|
+
|
|
189
|
+
## Details
|
|
190
|
+
|
|
191
|
+
With `details: { provider }`, every item gets a details action, labelled with the `show` translation (`data-role="details"`): a column of the desktop table and a button in the mobile rows and the masonry tiles (standard and presets). It clears the provider (`clearData()`), opens `details.component`, or `DetailsPage` by default, in a bottom sheet through `ModalService` (mode `'bottom'`, see `angular-components-modal`) with `{ value: detailsComponentProps }`, and asks the provider for the item (`getData(id)`). `detailsComponentProps` is an `IDetailsOptions`: `item` and `loading` from the provider (signals, so the modal shows the item once it is loaded), `type`, the list's `itemHandler` and `removeHandler` and `details.componentFactories`. The browser's back button closes the modal. Without a `provider`, setting `details` throws `Must set details provider`.
|
|
192
|
+
|
|
193
|
+
## Infinite scroll
|
|
194
|
+
|
|
195
|
+
With `pagination.mode` set to `PaginationMode.infiniteScroll` and `page() < totalPages()`, every mode renders an empty `<div data-role="infinite-scroll" aria-hidden="true">` after its items and watches it with an `IntersectionObserver`. When it scrolls into view, the list calls `pagination.loadNextPage()` (never twice at the same time), and it watches the element again after every page, so a short page loads the next one at once. On the last page the element is gone. Without `IntersectionObserver` (server rendering) nothing loads. The provider appends the new rows to `provider.list` (the CRUD store does for a filter whose `paginationMode` is not `singlePage`). `pagination.limit` is not read by the list.
|
|
174
196
|
|
|
175
197
|
## LIST_MODE_COMPONENTS_TOKEN
|
|
176
198
|
|
|
@@ -227,7 +249,9 @@ Notes:
|
|
|
227
249
|
primary button (label i18n key: `details`).
|
|
228
250
|
- The masonryGrid preset keeps the base masonry column algorithm and image mechanism
|
|
229
251
|
(`NgOptimizedImage` from the model's image field) and restyles items with the same card recipe as
|
|
230
|
-
the mobile preset;
|
|
252
|
+
the mobile preset; like the standard masonry child, its only action is the details button.
|
|
253
|
+
- The desktop preset styles its sort buttons with `getListDesktopSortButtonClasses()` and
|
|
254
|
+
`getListDesktopSortIndicatorClasses()`.
|
|
231
255
|
- Preline "Table with search" / "with pagination" / "selectable rows" variants are covered by the
|
|
232
256
|
existing `searchbar` feature, `smart-paging` (`PaginationMode.singlePage`), and `select: 'multi'`
|
|
233
257
|
respectively — not by `presentation`. Table caption/footer variants are not supported (no API
|
|
@@ -301,6 +325,24 @@ providers: [
|
|
|
301
325
|
}"
|
|
302
326
|
></smart-list>
|
|
303
327
|
|
|
328
|
+
<!-- Sortable headers: a click calls provider.getData({ offset: 0, sortBy, sortDesc }) -->
|
|
329
|
+
<smart-list
|
|
330
|
+
[options]="{
|
|
331
|
+
provider: myProvider,
|
|
332
|
+
type: UserModel,
|
|
333
|
+
sort: { default: 'lastName' }
|
|
334
|
+
}"
|
|
335
|
+
></smart-list>
|
|
336
|
+
|
|
337
|
+
<!-- Details in a modal (DetailsPage) -->
|
|
338
|
+
<smart-list
|
|
339
|
+
[options]="{
|
|
340
|
+
provider: myProvider,
|
|
341
|
+
type: UserModel,
|
|
342
|
+
details: { provider: myDetailsProvider }
|
|
343
|
+
}"
|
|
344
|
+
></smart-list>
|
|
345
|
+
|
|
304
346
|
<!-- With a remove action -->
|
|
305
347
|
<smart-list
|
|
306
348
|
[options]="{
|
|
@@ -318,5 +360,6 @@ providers: [
|
|
|
318
360
|
- Mobile child: `packages/shared/angular/src/lib/components/list/mobile/mobile.component.ts`
|
|
319
361
|
- Masonry grid child: `packages/shared/angular/src/lib/components/list/masonry-grid/masonry-grid.component.ts`
|
|
320
362
|
- Base class: `packages/shared/angular/src/lib/components/list/base/base.component.ts`
|
|
363
|
+
- Sort helpers: `packages/shared/angular/src/lib/components/list/list-sort.ts` (`IListSortState`, `IListSortFilter`, `getListDefaultSort`, `getNextListSort`, `getListAriaSort`, `getListSortIndicator`, `isListSortableKey`)
|
|
321
364
|
- Token: `packages/shared/angular/src/lib/shared.inectors.ts` (`LIST_MODE_COMPONENTS_TOKEN`)
|
|
322
365
|
- Interfaces: `packages/shared/angular/src/lib/models/interfaces.ts` (`IListOptions`, `IListProvider`, `IListPaginationOptions`, `ListMode`)
|
|
@@ -12,6 +12,7 @@ The `<smart-modal>` component provides a dialog overlay with title, description,
|
|
|
12
12
|
|
|
13
13
|
- Developer wants to use or customize the modal/dialog component
|
|
14
14
|
- Developer asks about `<smart-modal>`, `ModalComponent`, `ModalStandardComponent`, or `ModalBaseComponent`
|
|
15
|
+
- Developer wants to open a component in a modal from code and await its result (`ModalService`)
|
|
15
16
|
|
|
16
17
|
## Components
|
|
17
18
|
|
|
@@ -21,13 +22,13 @@ Main wrapper component. Renders `ModalStandardComponent` by default. When `MODAL
|
|
|
21
22
|
|
|
22
23
|
### ModalStandardComponent (`<smart-modal-standard>`)
|
|
23
24
|
|
|
24
|
-
Barebones placeholder concrete implementation. Renders a native `<dialog [open] role="dialog" aria-modal="true">` containing an optional `<h2 id="smart-modal-title">`, an optional `<p>` description, an `<ng-content>` slot for arbitrary body content, an optional dismiss `<button>` (when `options.withDismiss` is `true`), and a `<footer>` with one `<button data-variant>` per action. It does not include Tailwind UI styling — it exists solely as the default structural placeholder until a custom implementation is registered through the token.
|
|
25
|
+
Barebones placeholder concrete implementation. Renders a native `<dialog [open] role="dialog" aria-modal="true">` containing an optional `<h2 id="smart-modal-title">`, an optional `<p>` description, an `<ng-content>` slot for arbitrary body content, an optional dismiss `<button>` (when `options.withDismiss` is `true`), and a `<footer>` with one `<button data-variant>` per action. The dialog carries `options.variant` as `data-variant`. It does not include Tailwind UI styling — it exists solely as the default structural placeholder until a custom implementation is registered through the token — except for the `bottom-sheet` variant, which it docks to the bottom of the viewport (see the Variants table).
|
|
25
26
|
|
|
26
27
|
### ModalPresetComponent (`<smart-modal-preset>`)
|
|
27
28
|
|
|
28
|
-
Styled variation that extends `ModalBaseComponent` and is a drop-in replacement for `ModalStandardComponent`. Register it via `MODAL_STANDARD_COMPONENT_TOKEN` (or with `provideSmartPresets()`) to restyle every `<smart-modal>`, or use the `<smart-modal-preset>` selector directly. It renders a translated Preline overlay — a full-screen scrollable backdrop hosting a `rounded-xl` card with a header (`title` + optional dismiss `×`), a body (`description` + projected content), and a footer of action buttons. The look is selected through `options.variant` (default `'centered'`): `centered`/`alert` are vertically centered (`alert` is narrower), `wide` is a top-aligned large dialog,
|
|
29
|
+
Styled variation that extends `ModalBaseComponent` and is a drop-in replacement for `ModalStandardComponent`. Register it via `MODAL_STANDARD_COMPONENT_TOKEN` (or with `provideSmartPresets()`) to restyle every `<smart-modal>`, or use the `<smart-modal-preset>` selector directly. It renders a translated Preline overlay — a full-screen scrollable backdrop hosting a `rounded-xl` card with a header (`title` + optional dismiss `×`), a body (`description` + projected content), and a footer of action buttons. The look is selected through `options.variant` (default `'centered'`): `centered`/`alert` are vertically centered (`alert` is narrower), `wide` is a top-aligned large dialog, `left-aligned-buttons` left-aligns the footer, and `bottom-sheet` docks the card to the bottom of the viewport (see the Variants table). `options.footerStyle: 'gray'` tints the footer, and action buttons are styled by their `variant` (`primary`/`secondary`/`danger`). All classes are `smart:`-prefixed Tailwind with explicit `dark:` variants; the class recipes are internal to the preset (not exported).
|
|
29
30
|
|
|
30
|
-
> **Preline JS is NOT used.** Open/close is driven entirely by the existing `open` model signal + `@if` (no `HSOverlay`, no `data-hs-*`). The component binds its own dismiss UX: clicking the backdrop and pressing `Escape` both call `close()` (which sets `open` to `false` and emits `closed`). The dialog ARIA contract is preserved (`role="dialog"`, `aria-modal="true"`, `aria-labelledby` when `title` is set, else `aria-label` from `options.ariaLabel`). The header dismiss `×` button is only shown when `options.withDismiss` is `true`.
|
|
31
|
+
> **Preline JS is NOT used.** Open/close is driven entirely by the existing `open` model signal + `@if` (no `HSOverlay`, no `data-hs-*`). The component binds its own dismiss UX: clicking the backdrop and pressing `Escape` both call `close()` (which sets `open` to `false` and emits `closed`). With preset modals stacked (a modal opened from a modal), `Escape` closes only the one on top. The dialog ARIA contract is preserved (`role="dialog"`, `aria-modal="true"`, `aria-labelledby` when `title` is set, else `aria-label` from `options.ariaLabel`). The header dismiss `×` button is only shown when `options.withDismiss` is `true`.
|
|
31
32
|
>
|
|
32
33
|
> `ModalPresetComponent` declares `cssClass` without the `class` alias (applied to the centering wrapper): bind it as `[cssClass]` on the `<smart-modal-preset>` selector, or pass `class` on `<smart-modal>` (the wrapper forwards it).
|
|
33
34
|
|
|
@@ -73,23 +74,36 @@ interface IModalAction {
|
|
|
73
74
|
|
|
74
75
|
### IModalOptions
|
|
75
76
|
|
|
76
|
-
| Field | Type
|
|
77
|
-
| ------------- |
|
|
78
|
-
| `variant` | `'centered'
|
|
79
|
-
| `withDismiss` | `boolean`
|
|
80
|
-
| `footerStyle` | `'default' \| 'gray'`
|
|
81
|
-
| `ariaLabel` | `string`
|
|
77
|
+
| Field | Type | Default | Description |
|
|
78
|
+
| ------------- | --------------------- | ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
79
|
+
| `variant` | `SmartModalVariant` | `'centered'` | The layout, one of the variants in the Variants table. The preset styles each of them; the standard exposes it as `data-variant` and positions only `bottom-sheet`. |
|
|
80
|
+
| `withDismiss` | `boolean` | `false` | Renders a close (×) button that calls `close()`. |
|
|
81
|
+
| `footerStyle` | `'default' \| 'gray'` | `'default'` | Preset only: `gray` gives the footer a gray background. |
|
|
82
|
+
| `ariaLabel` | `string` | - | The `aria-label` of the dialog when there is no `title`. |
|
|
82
83
|
|
|
83
84
|
```typescript
|
|
84
85
|
interface IModalOptions {
|
|
85
|
-
variant?:
|
|
86
|
+
variant?:
|
|
87
|
+
'centered' | 'wide' | 'alert' | 'left-aligned-buttons' | 'bottom-sheet';
|
|
86
88
|
withDismiss?: boolean;
|
|
87
89
|
footerStyle?: 'default' | 'gray';
|
|
88
90
|
ariaLabel?: string;
|
|
89
91
|
}
|
|
90
92
|
```
|
|
91
93
|
|
|
92
|
-
The default `ModalStandardComponent` consumes `withDismiss` and `ariaLabel
|
|
94
|
+
The default `ModalStandardComponent` consumes `withDismiss` and `ariaLabel`, exposes `variant` as `data-variant` on the dialog and positions the `bottom-sheet` variant; `footerStyle` is read by `ModalPresetComponent` only. A custom implementation receives every field.
|
|
95
|
+
|
|
96
|
+
### Variants
|
|
97
|
+
|
|
98
|
+
`SmartModalVariant` (from `@smartsoft001/angular`) names the layouts of `options.variant`.
|
|
99
|
+
|
|
100
|
+
| Variant | `ModalPresetComponent` | `ModalStandardComponent` |
|
|
101
|
+
| ---------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
102
|
+
| `centered` (default) | A card centred vertically, `max-w-lg` from `sm`. | The browser's dialog layout. |
|
|
103
|
+
| `wide` | A top-aligned card, `max-w-4xl` from `lg`. | The browser's dialog layout. |
|
|
104
|
+
| `alert` | A narrower centred card, `max-w-md` from `sm`. | The browser's dialog layout. |
|
|
105
|
+
| `left-aligned-buttons` | Like `centered`, with the footer buttons aligned to the left. | The browser's dialog layout. |
|
|
106
|
+
| `bottom-sheet` | A sheet docked to the bottom of the viewport: full width, centred under `max-w-2xl` with rounded top corners from `sm`, at most 85% of the viewport high with the body scrolling, padded by the bottom safe area. Same backdrop, Escape and close button as the others. | The `<dialog>` fixed to the bottom of the viewport (`z-[80]`), full width, `max-w-2xl` with rounded top corners from `sm`, at most 85% of the viewport high and scrolling. |
|
|
93
107
|
|
|
94
108
|
## MODAL_STANDARD_COMPONENT_TOKEN
|
|
95
109
|
|
|
@@ -153,7 +167,8 @@ export class MyCustomModalComponent extends ModalBaseComponent {}
|
|
|
153
167
|
The inherited `cssClass` (input alias `class`) receives the class passed to `<smart-modal>`. When extending the base directly, remember to:
|
|
154
168
|
|
|
155
169
|
- call `invokeAction(id)` to emit `actionClick`, and `close()` to emit `closed` and set `open.set(false)`,
|
|
156
|
-
- implement `Escape` key handling and backdrop click yourself if you want native UX — the base does not bind any keyboard or backdrop listeners
|
|
170
|
+
- implement `Escape` key handling and backdrop click yourself if you want native UX — the base does not bind any keyboard or backdrop listeners,
|
|
171
|
+
- lay out `options()?.variant === 'bottom-sheet'` as a bottom sheet: `ModalService` opens `mode: 'bottom'` with that variant.
|
|
157
172
|
|
|
158
173
|
## Usage Examples
|
|
159
174
|
|
|
@@ -181,6 +196,58 @@ The inherited `cssClass` (input alias `class`) receives the class passed to `<sm
|
|
|
181
196
|
<smart-modal [(open)]="open" class="smart:p-4" />
|
|
182
197
|
```
|
|
183
198
|
|
|
199
|
+
## Opening a component in a modal from code
|
|
200
|
+
|
|
201
|
+
`ModalService.show(options)` (provided by `SharedServicesModule`) creates `options.component` inside a `<smart-modal>` at the end of `<body>` and resolves with an `IModal`. The modal is the implementation registered for `MODAL_STANDARD_COMPONENT_TOKEN` (the preset with `provideSmartPresets()`) and shows its close button (`withDismiss`). `props` become the component's inputs (keys it does not declare as inputs are left out), and a component that declares a `dismiss` input gets the function that closes its modal. A component can also inject `ModalService` and call `dismiss(data)`: it resolves to the service that opened it. The modals stack; `ModalService.dismiss(data)` closes the one opened last. Closing a modal restores the focus to the element focused before it opened.
|
|
202
|
+
|
|
203
|
+
| Option | Type | Default | Description |
|
|
204
|
+
| ----------------- | ----------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
205
|
+
| `component` | `any` | required | The component rendered in the modal. |
|
|
206
|
+
| `props` | `any` | - | Its inputs, by input name. |
|
|
207
|
+
| `mode` | `'default' \| 'bottom'` | `'default'` | `'bottom'` opens the modal as a bottom sheet (the `bottom-sheet` variant, see the Variants table) and adds the `smart-modal-bottom` class for an application's own styling; the modal element carries `data-mode`. |
|
|
208
|
+
| `cssClass` | `string[]` | - | Classes passed to the modal as `class`. |
|
|
209
|
+
| `backdropDismiss` | `boolean` | `true` | `false` keeps the modal open on a click on its backdrop and on Escape; its close button and `dismiss()` still close it. |
|
|
210
|
+
| `injector` | `Injector` | - | The injector the component resolves its dependencies from (e.g. the opener's `inject(Injector)`), the service's otherwise. |
|
|
211
|
+
|
|
212
|
+
| `IModal` member | Type | Description |
|
|
213
|
+
| ---------------- | ------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------- |
|
|
214
|
+
| `dismiss(data?)` | `(data?: any) => void` | Closes the modal. |
|
|
215
|
+
| `onDidDismiss()` | `() => Promise<{ data: any }>` | Resolves once the modal is closed, with the data it was closed with; `{ data: null }` for its close button, the backdrop or Escape. |
|
|
216
|
+
|
|
217
|
+
```typescript
|
|
218
|
+
import { Component, inject, input } from '@angular/core';
|
|
219
|
+
|
|
220
|
+
import { ModalService } from '@smartsoft001/angular';
|
|
221
|
+
|
|
222
|
+
@Component({
|
|
223
|
+
selector: 'app-rename-form',
|
|
224
|
+
template: `
|
|
225
|
+
<input #name [value]="name()" />
|
|
226
|
+
<button type="button" (click)="dismiss()?.(name.value)">Save</button>
|
|
227
|
+
`,
|
|
228
|
+
})
|
|
229
|
+
export class RenameFormComponent {
|
|
230
|
+
name = input('');
|
|
231
|
+
dismiss = input<(data?: unknown) => void>();
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
export class RenameAction {
|
|
235
|
+
private modalService = inject(ModalService);
|
|
236
|
+
|
|
237
|
+
async rename(name: string): Promise<string | null> {
|
|
238
|
+
const modal = await this.modalService.show({
|
|
239
|
+
component: RenameFormComponent,
|
|
240
|
+
props: { name },
|
|
241
|
+
});
|
|
242
|
+
const { data } = await modal.onDidDismiss();
|
|
243
|
+
|
|
244
|
+
return typeof data === 'string' ? data : null;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
`[smartDetails]` and `DetailsPage` (see `angular-components-details`) open details through the same service, as a bottom sheet by default; so does the `details` option of `<smart-list>`.
|
|
250
|
+
|
|
184
251
|
## File Locations
|
|
185
252
|
|
|
186
253
|
- Wrapper: `packages/shared/angular/src/lib/components/modal/modal.component.ts`
|
|
@@ -190,4 +257,5 @@ The inherited `cssClass` (input alias `class`) receives the class passed to `<sm
|
|
|
190
257
|
- Base class: `packages/shared/angular/src/lib/components/modal/base/base.component.ts`
|
|
191
258
|
- Stories: `packages/shared/angular/src/lib/components/modal/modal.component.stories.ts`
|
|
192
259
|
- Token: `packages/shared/angular/src/lib/shared.inectors.ts` (`MODAL_STANDARD_COMPONENT_TOKEN`)
|
|
193
|
-
- Interfaces: `packages/shared/angular/src/lib/models/interfaces.ts` (`IModalAction`, `IModalOptions`)
|
|
260
|
+
- Interfaces: `packages/shared/angular/src/lib/models/interfaces.ts` (`IModalAction`, `IModalOptions`, `SmartModalVariant`)
|
|
261
|
+
- Service: `packages/shared/angular/src/lib/services/modal/modal.service.ts` (`ModalService`, `IModalServiceOptions`, `IModal`)
|