@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,272 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: react-components-detail
|
|
3
|
+
description: SmartDetail React component API (@smartsoft001/react) — renders the label and read-only value of one model field by its FieldType (text, email, enum, flag, address, color, image, pdf, video, attachment, object, array...), cell pipes and trustHtml, detailFieldComponents / DETAIL_PRESET_FIELD_COMPONENTS, and the useDetail hook for custom detail field components.
|
|
4
|
+
user-invocable: false
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Detail (`SmartDetail`)
|
|
8
|
+
|
|
9
|
+
`SmartDetail` shows one field of a model instance read-only: the field's label (the label provider's, or `MODEL.<key>` translated), its info tooltip, and the value rendered by the **detail component of the field's `FieldType`**, or a skeleton while there is no item yet. `SmartDetails` renders one `SmartDetail` per field marked `details`, so most applications use it indirectly; render it yourself to place single fields. Detail components are resolved from `detailFieldComponents` on `SmartProvider` over the library's own (`DETAIL_PRESET_FIELD_COMPONENTS` gives the styled set); a type without one renders `SmartDetailText`.
|
|
10
|
+
|
|
11
|
+
## When to Use This Skill
|
|
12
|
+
|
|
13
|
+
- Showing single read-only fields of a record in a layout of your own
|
|
14
|
+
- Formatting values through a cell pipe (`ICellPipe`), or rendering trusted HTML (`trustHtml`)
|
|
15
|
+
- Choosing or replacing the detail component of a field type (`detailFieldComponents`)
|
|
16
|
+
- Writing a custom detail component on `useDetail`
|
|
17
|
+
|
|
18
|
+
## Exports
|
|
19
|
+
|
|
20
|
+
All from `@smartsoft001/react`.
|
|
21
|
+
|
|
22
|
+
| Export | Kind | What it is |
|
|
23
|
+
| --------------------------------- | --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
24
|
+
| `SmartDetail` | component | The label of a field and its value, rendered by the detail component of the field type, with the field's info tooltip and a skeleton while there is no item yet. |
|
|
25
|
+
| `SmartDetailText` | component | The text detail: the value of the field, or what `options.cellPipe` makes of it, rendered as HTML. |
|
|
26
|
+
| `useDetail` | hook | What every detail field shares: the item, the key of the field and its value, unwrapped from `options`. |
|
|
27
|
+
| `useDetailCellValue` | hook | The value a text-like detail renders: the list cell of `key` in `item`, the cell pipe's result (or the raw value), translated when it is a string. |
|
|
28
|
+
| `getDefaultDetailFieldComponents` | function | The library's detail component of every `FieldType` that has one. |
|
|
29
|
+
| `DETAIL_PRESET_FIELD_COMPONENTS` | const | The preset detail components, keyed by `FieldType`. |
|
|
30
|
+
|
|
31
|
+
## Props and Types
|
|
32
|
+
|
|
33
|
+
### `SmartDetailProps<T = any>`
|
|
34
|
+
|
|
35
|
+
| Prop | Type | Default | Description |
|
|
36
|
+
| ------------ | -------------------------------- | -------- | ---------------------------------------------------------------- |
|
|
37
|
+
| `options` | `IDetailOptions<T> \| undefined` | required | The field to show: key, item, field options, cell pipe, loading. |
|
|
38
|
+
| `type` | `any` | required | The model class, for the label (`useModelLabel`). |
|
|
39
|
+
| `className?` | `string` | — | Forwarded to the field component. |
|
|
40
|
+
|
|
41
|
+
### `SmartDetailFieldProps<T = any>`
|
|
42
|
+
|
|
43
|
+
The props of every detail field component: `options` and `className`.
|
|
44
|
+
|
|
45
|
+
| Prop | Type | Default | Description |
|
|
46
|
+
| ------------ | ------------------- | ------- | ------------------------------------------ |
|
|
47
|
+
| `options?` | `IDetailOptions<T>` | — | The detail options `SmartDetail` received. |
|
|
48
|
+
| `className?` | `string` | — | The `className` of `SmartDetail`. |
|
|
49
|
+
|
|
50
|
+
### `IDetailOptions<T>`
|
|
51
|
+
|
|
52
|
+
| Field | Type | Default | Description |
|
|
53
|
+
| ----------- | --------------- | -------- | ---------------------------------------------------------------------------------------------------------------------- |
|
|
54
|
+
| `key` | `string` | required | The field key. |
|
|
55
|
+
| `item?` | `T \| null` | — | The record; `null` / `undefined` shows a skeleton. |
|
|
56
|
+
| `options` | `IFieldOptions` | required | The field's `@Field` options (`getModelFieldOptions(instance, key)`, or the `options` of `getModelFieldsWithOptions`). |
|
|
57
|
+
| `cellPipe?` | `ICellPipe<T>` | — | Formats the value of text-like details. |
|
|
58
|
+
| `loading?` | `boolean` | — | Passed to the detail component. |
|
|
59
|
+
|
|
60
|
+
### `ICellPipe<T>`
|
|
61
|
+
|
|
62
|
+
Formats a value: `transform(item, key, translate?)` returns text (sanitised before it is rendered as HTML) or `trustHtml(html)` (rendered as is).
|
|
63
|
+
|
|
64
|
+
| Field | Type | Default | Description |
|
|
65
|
+
| ----------- | --------------------------------------------------------------------------------------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------- |
|
|
66
|
+
| `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. |
|
|
67
|
+
|
|
68
|
+
### Related types
|
|
69
|
+
|
|
70
|
+
- `SmartDetailFieldComponents`: `Partial< Record<FieldTypeDef, ComponentType<SmartDetailFieldProps<any>>> >` — Detail components by `FieldType`.
|
|
71
|
+
|
|
72
|
+
## Field types
|
|
73
|
+
|
|
74
|
+
| `FieldType` | Standard | Preset |
|
|
75
|
+
| --------------------------------------- | ------------------------------------------------------------------------------------------------------------ | -------------------------------------------- |
|
|
76
|
+
| `text` (and every type without its own) | `SmartDetailText`: the value, or the cell pipe's result, translated when a string, as sanitised HTML | `SmartDetailTextPreset` (em dash when empty) |
|
|
77
|
+
| `email` | `SmartDetailEmail`: a `mailto:` link | `SmartDetailEmailPreset` |
|
|
78
|
+
| `phoneNumberPl` | `SmartDetailPhoneNumberPl`: a `tel:` link with the `48` prefix | `SmartDetailPhoneNumberPlPreset` |
|
|
79
|
+
| `enum` | `SmartDetailEnum`: the translated value(s), comma-separated | `SmartDetailEnumPreset` (a badge each) |
|
|
80
|
+
| `flag` | `SmartDetailFlag`: a check or an x-mark | `SmartDetailFlagPreset` |
|
|
81
|
+
| `color` | `SmartDetailColor`: a colour bar | `SmartDetailColorPreset` (swatch and code) |
|
|
82
|
+
| `dateRange` | `SmartDetailDateRange`: `start – end` | `SmartDetailDateRangePreset` |
|
|
83
|
+
| `address` | `SmartDetailAddress`: street and building / flat, zip code and city | `SmartDetailAddressPreset` |
|
|
84
|
+
| `image` / `logo` | `SmartDetailImage` (the uploaded file's URL) / `SmartDetailLogo` (the URL in the field) | `…Preset` |
|
|
85
|
+
| `pdf` / `video` / `attachment` | `SmartDetailPdf` (show button) / `SmartDetailVideo` (mp4 player) / `SmartDetailAttachment` (download button) | `…Preset` |
|
|
86
|
+
| `object` | `SmartDetailObject`: the nested object's own `SmartDetails` | `SmartDetailObjectPreset` (in a card) |
|
|
87
|
+
| `array` | `SmartDetailArray`: a `SmartDetails` per element | `SmartDetailArrayPreset` (a card each) |
|
|
88
|
+
|
|
89
|
+
File-based details (`image`, `pdf`, `video`, `attachment`) build their URLs with the file service: give `SmartProvider` a `fileServiceConfig`.
|
|
90
|
+
|
|
91
|
+
## Sanitised HTML
|
|
92
|
+
|
|
93
|
+
Text details render the value as HTML **sanitised with DOMPurify**. A cell pipe that returns `trustHtml(html)` opts out for markup you vouch for (`trustHtml`, `sanitizeHtml` and `toInnerHtml` are exported from `@smartsoft001/react`).
|
|
94
|
+
|
|
95
|
+
## Usage
|
|
96
|
+
|
|
97
|
+
```tsx
|
|
98
|
+
import {
|
|
99
|
+
Field,
|
|
100
|
+
FieldType,
|
|
101
|
+
getModelFieldOptions,
|
|
102
|
+
Model,
|
|
103
|
+
} from '@smartsoft001/models';
|
|
104
|
+
import { ICellPipe, SmartDetail, trustHtml } from '@smartsoft001/react';
|
|
105
|
+
|
|
106
|
+
@Model({})
|
|
107
|
+
export class Invoice {
|
|
108
|
+
id!: string;
|
|
109
|
+
|
|
110
|
+
@Field({ type: FieldType.text, details: true })
|
|
111
|
+
number!: string;
|
|
112
|
+
|
|
113
|
+
@Field({
|
|
114
|
+
type: FieldType.email,
|
|
115
|
+
details: true,
|
|
116
|
+
info: 'Where the invoice is sent.',
|
|
117
|
+
})
|
|
118
|
+
email!: string;
|
|
119
|
+
|
|
120
|
+
@Field({ type: FieldType.text, details: true })
|
|
121
|
+
total!: number;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const money: ICellPipe<Invoice> = {
|
|
125
|
+
transform: (item, key) =>
|
|
126
|
+
key === 'total'
|
|
127
|
+
? trustHtml(`<strong>${item.total.toFixed(2)} PLN</strong>`)
|
|
128
|
+
: String(item[key as keyof Invoice] ?? ''),
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
export function InvoiceSummary({ invoice }: { invoice: Invoice | null }) {
|
|
132
|
+
const probe = new Invoice();
|
|
133
|
+
|
|
134
|
+
return (
|
|
135
|
+
<div className="grid grid-cols-3 gap-4">
|
|
136
|
+
{(['number', 'email', 'total'] as const).map((key) => (
|
|
137
|
+
<SmartDetail
|
|
138
|
+
key={key}
|
|
139
|
+
type={Invoice}
|
|
140
|
+
options={{
|
|
141
|
+
key,
|
|
142
|
+
item: invoice,
|
|
143
|
+
options: getModelFieldOptions(probe, key),
|
|
144
|
+
cellPipe: money,
|
|
145
|
+
}}
|
|
146
|
+
/>
|
|
147
|
+
))}
|
|
148
|
+
</div>
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## Replacing the Implementation
|
|
154
|
+
|
|
155
|
+
`SmartDetail` has no single registry key: its field components come from `detailFieldComponents` on `SmartProvider`, merged over the library's map. Register the preset set, or a component of your own for one type:
|
|
156
|
+
|
|
157
|
+
```tsx
|
|
158
|
+
import type { ReactNode } from 'react';
|
|
159
|
+
|
|
160
|
+
import { FieldType } from '@smartsoft001/models';
|
|
161
|
+
import {
|
|
162
|
+
DETAIL_PRESET_FIELD_COMPONENTS,
|
|
163
|
+
SmartDetailFieldProps,
|
|
164
|
+
SmartProvider,
|
|
165
|
+
useDetail,
|
|
166
|
+
} from '@smartsoft001/react';
|
|
167
|
+
|
|
168
|
+
function MoneyDetail(props: SmartDetailFieldProps) {
|
|
169
|
+
const { value } = useDetail(props);
|
|
170
|
+
|
|
171
|
+
return (
|
|
172
|
+
<span className={props.className}>
|
|
173
|
+
{typeof value === 'number' ? value.toFixed(2) : '—'}
|
|
174
|
+
</span>
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const detailFieldComponents = {
|
|
179
|
+
...DETAIL_PRESET_FIELD_COMPONENTS,
|
|
180
|
+
[FieldType.currency]: MoneyDetail,
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
export function AppProviders({ children }: { children: ReactNode }) {
|
|
184
|
+
return (
|
|
185
|
+
<SmartProvider detailFieldComponents={detailFieldComponents}>
|
|
186
|
+
{children}
|
|
187
|
+
</SmartProvider>
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
`SMART_PRESET_COMPONENTS` registers `DETAIL_PRESET_FIELD_COMPONENTS` together with the other presets. The `object` and `array` details render nested objects through `SmartDetails`, so the `details` registry key applies to them too.
|
|
193
|
+
|
|
194
|
+
### Hooks
|
|
195
|
+
|
|
196
|
+
#### `useDetail`
|
|
197
|
+
|
|
198
|
+
What every detail field shares: the item, the key of the field and its value, unwrapped from `options`.
|
|
199
|
+
|
|
200
|
+
```ts
|
|
201
|
+
function useDetail<T>({ options }: SmartDetailFieldProps<T>);
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
| Returns | Type | Description |
|
|
205
|
+
| -------------- | ------------------------ | --------------------------------------- |
|
|
206
|
+
| `item` | `NonNullable<T> \| null` | `options.item`, `null` without one. |
|
|
207
|
+
| `key` | `string \| null` | `options.key`. |
|
|
208
|
+
| `value` | `any` | `item[key]`. |
|
|
209
|
+
| `cellPipe` | `ICellPipe<T> \| null` | `options.cellPipe`, `null` without one. |
|
|
210
|
+
| `fieldOptions` | `IFieldOptions \| null` | `options.options`. |
|
|
211
|
+
| `loading` | `boolean \| undefined` | `options.loading`. |
|
|
212
|
+
|
|
213
|
+
#### `useDetailCellValue`
|
|
214
|
+
|
|
215
|
+
The value a text-like detail renders: the list cell of `key` in `item`, the cell pipe's result (or the raw value), translated when it is a string.
|
|
216
|
+
|
|
217
|
+
```ts
|
|
218
|
+
function useDetailCellValue<T>(props: SmartDetailFieldProps<T>): any;
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
## Styling
|
|
222
|
+
|
|
223
|
+
- `SmartDetail` renders the label in a muted `smart:text-sm` span and a pulsing skeleton without an item, with `smart:dark:` variants; `className` reaches the field component.
|
|
224
|
+
|
|
225
|
+
## File Locations
|
|
226
|
+
|
|
227
|
+
Source: `packages/shared/react/src/lib/components/detail/` in the smartsoft001 repository.
|
|
228
|
+
|
|
229
|
+
- `address/detail-address.tsx`: `SmartDetailAddress`
|
|
230
|
+
- `address/preset/detail-address-preset.tsx`: `SmartDetailAddressPreset`
|
|
231
|
+
- `address/use-detail-address.ts`: `useDetailAddress`
|
|
232
|
+
- `array/detail-array.tsx`: `SmartDetailArray`
|
|
233
|
+
- `array/preset/detail-array-preset.tsx`: `SmartDetailArrayPreset`
|
|
234
|
+
- `array/use-detail-array.ts`: `useDetailArray`
|
|
235
|
+
- `attachment/detail-attachment.tsx`: `SmartDetailAttachment`
|
|
236
|
+
- `attachment/preset/detail-attachment-preset.tsx`: `SmartDetailAttachmentPreset`
|
|
237
|
+
- `attachment/use-detail-attachment.ts`: `useDetailAttachment`
|
|
238
|
+
- `color/detail-color.tsx`: `SmartDetailColor`
|
|
239
|
+
- `color/preset/detail-color-preset.tsx`: `SmartDetailColorPreset`
|
|
240
|
+
- `date-range/detail-date-range.tsx`: `SmartDetailDateRange`
|
|
241
|
+
- `date-range/preset/detail-date-range-preset.tsx`: `SmartDetailDateRangePreset`
|
|
242
|
+
- `default-field-components.ts`: `getDefaultDetailFieldComponents`, `SmartDetailFieldComponents`
|
|
243
|
+
- `detail.tsx`: `SmartDetail`
|
|
244
|
+
- `detail.types.ts`: `SmartDetailFieldProps`, `SmartDetailProps`
|
|
245
|
+
- `email/detail-email.tsx`: `SmartDetailEmail`
|
|
246
|
+
- `email/preset/detail-email-preset.tsx`: `SmartDetailEmailPreset`
|
|
247
|
+
- `enum/detail-enum.tsx`: `SmartDetailEnum`
|
|
248
|
+
- `enum/preset/detail-enum-preset.tsx`: `SmartDetailEnumPreset`
|
|
249
|
+
- `enum/use-detail-enum.ts`: `useDetailEnum`
|
|
250
|
+
- `flag/detail-flag.tsx`: `SmartDetailFlag`
|
|
251
|
+
- `flag/preset/detail-flag-preset.tsx`: `SmartDetailFlagPreset`
|
|
252
|
+
- `image/detail-image.tsx`: `SmartDetailImage`
|
|
253
|
+
- `image/preset/detail-image-preset.tsx`: `SmartDetailImagePreset`
|
|
254
|
+
- `image/use-detail-image.ts`: `useDetailImage`
|
|
255
|
+
- `logo/detail-logo.tsx`: `SmartDetailLogo`
|
|
256
|
+
- `logo/preset/detail-logo-preset.tsx`: `SmartDetailLogoPreset`
|
|
257
|
+
- `object/detail-object.tsx`: `SmartDetailObject`
|
|
258
|
+
- `object/preset/detail-object-preset.tsx`: `SmartDetailObjectPreset`
|
|
259
|
+
- `object/use-detail-object.ts`: `useDetailObject`
|
|
260
|
+
- `pdf/detail-pdf.tsx`: `SmartDetailPdf`
|
|
261
|
+
- `pdf/preset/detail-pdf-preset.tsx`: `SmartDetailPdfPreset`
|
|
262
|
+
- `pdf/use-detail-pdf.ts`: `useDetailPdf`
|
|
263
|
+
- `phone-number-pl/detail-phone-number-pl.tsx`: `SmartDetailPhoneNumberPl`
|
|
264
|
+
- `phone-number-pl/preset/detail-phone-number-pl-preset.tsx`: `SmartDetailPhoneNumberPlPreset`
|
|
265
|
+
- `preset-fields.ts`: `DETAIL_PRESET_FIELD_COMPONENTS`
|
|
266
|
+
- `text/detail-text.tsx`: `SmartDetailText`
|
|
267
|
+
- `text/preset/detail-text-preset.tsx`: `SmartDetailTextPreset`
|
|
268
|
+
- `use-detail.ts`: `useDetail`, `useDetailCellValue`
|
|
269
|
+
- `video/detail-video.tsx`: `SmartDetailVideo`
|
|
270
|
+
- `video/preset/detail-video-preset.tsx`: `SmartDetailVideoPreset`
|
|
271
|
+
- `video/use-detail-video.ts`: `useDetailVideo`
|
|
272
|
+
- `detail.stories.tsx`: Storybook stories
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: react-components-details
|
|
3
|
+
description: SmartDetails React component API (@smartsoft001/react) — read-only view of a model record built from @Field({ details }) metadata (IDetailsOptions with type, item, cellPipe, loading, top/bottom components), field permissions and enabled specifications, the 'details' registry key, useDetails, SmartDetailsPage and useDetailsModal for showing details in a modal.
|
|
4
|
+
user-invocable: false
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Details (`SmartDetails`)
|
|
8
|
+
|
|
9
|
+
`SmartDetails` shows a record read-only. It reads the fields of `options.type` marked `@Field({ details: ... })`, leaves out those whose `details.permissions` the user lacks and those whose `enabled` specification the item fails, converts `options.item` to an instance of the type, and renders one `SmartDetail` per field (a description list), between the optional `componentFactories.top` and `bottom` components. CRUD item pages render it in their details mode. `SmartDetailsPage` and `useDetailsModal` show the same view in a modal.
|
|
10
|
+
|
|
11
|
+
## When to Use This Skill
|
|
12
|
+
|
|
13
|
+
- A read-only view of a record whose model has `@Field({ details: true })` fields
|
|
14
|
+
- Hiding fields by permission or by a specification on the item (`details.permissions`, `details.enabled`)
|
|
15
|
+
- Adding content above or below the fields (`componentFactories`)
|
|
16
|
+
- Showing the details of a record in a modal (`useDetailsModal` + `SmartDetailsPage`)
|
|
17
|
+
- Restyling the details view (the `details` registry key) or building one on `useDetails`
|
|
18
|
+
|
|
19
|
+
## Exports
|
|
20
|
+
|
|
21
|
+
All from `@smartsoft001/react`.
|
|
22
|
+
|
|
23
|
+
| Export | Kind | What it is |
|
|
24
|
+
| ---------------------- | --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
25
|
+
| `SmartDetails` | component | Renders the implementation registered as `components.details` on `SmartProvider`, `SmartDetailsStandard` by default. |
|
|
26
|
+
| `SmartDetailsStandard` | component | The default details rendering: a description list with a `<SmartDetail>` per field, between the `componentFactories.top` and `componentFactories.bottom` components. |
|
|
27
|
+
| `useDetailsModal` | hook | Returns a handler for an element's `onClick` that opens `options.component` in a modal with `{ value: options.params }` as props (e.g. `SmartDetailsPage` with `IDetailsOptions`), and resolves once the modal is closed. |
|
|
28
|
+
| `useDetails` | hook | The logic every details variant shares: - `fields`: the fields of `options.type` marked `@Field({ details })`, without those whose `details.permissions` the user lacks and those whose `enabled` specification (`details.enabled`, else the field's `enabled`) the item fails; a specification can refer to the outermost details' item as `$root`; - `item`: `options.item` as an instance of `options.type` (a plain API object is converted); - `loading`, `cellPipe` and `componentFactories` from the options. |
|
|
29
|
+
|
|
30
|
+
## Props and Types
|
|
31
|
+
|
|
32
|
+
### `SmartDetailsProps<T extends IEntity<string> = any>`
|
|
33
|
+
|
|
34
|
+
| Prop | Type | Default | Description |
|
|
35
|
+
| ------------ | -------------------- | ------- | ------------------------------------------ |
|
|
36
|
+
| `options?` | `IDetailsOptions<T>` | — | The model type, the record and the extras. |
|
|
37
|
+
| `className?` | `string` | — | Classes on the root element. |
|
|
38
|
+
|
|
39
|
+
### `IDetailsModalOptions`
|
|
40
|
+
|
|
41
|
+
What `useDetailsModal` opens: a component and its params.
|
|
42
|
+
|
|
43
|
+
| Field | Type | Default | Description |
|
|
44
|
+
| ----------- | ----------------------- | ---------- | ---------------------------------------------------------------- |
|
|
45
|
+
| `component` | `ComponentType<any>` | required | Rendered in the modal, with `params` as its `value` prop. |
|
|
46
|
+
| `params` | `any` | required | Passed to the component as its `value` prop. |
|
|
47
|
+
| `mode?` | `'bottom' \| 'default'` | `'bottom'` | Passed to `ModalService.show` (the modal host does not read it). |
|
|
48
|
+
|
|
49
|
+
### `IDetailsOptions<T extends IEntity<string>>`
|
|
50
|
+
|
|
51
|
+
| Field | Type | Default | Description |
|
|
52
|
+
| --------------------- | -------------------------------- | -------- | ---------------------------------------------------------------------------------------------- |
|
|
53
|
+
| `title?` | `string` | — | Not rendered by `SmartDetails`; `useDetailsPageOptions` uses it as a page title. |
|
|
54
|
+
| `cellPipe?` | `ICellPipe<T>` | — | Formats the values of text-like fields (see `react-components-detail`). |
|
|
55
|
+
| `type` | `any` | required | The `@Model` class whose `details` fields are shown. |
|
|
56
|
+
| `item` | `T \| null \| undefined` | required | The record (a plain API object is converted to `type`); without one the fields show skeletons. |
|
|
57
|
+
| `loading?` | `boolean` | — | Passed to every field. |
|
|
58
|
+
| `itemHandler?` | `((id: string) => void) \| null` | — | Not rendered by `SmartDetails`; `useDetailsPageOptions` turns it into a "go to item" button. |
|
|
59
|
+
| `removeHandler?` | `((item: T) => void) \| null` | — | Not rendered by `SmartDetails`; `useDetailsPageOptions` turns it into a remove button. |
|
|
60
|
+
| `componentFactories?` | `IDetailsComponentFactories<T>` | — | Components rendered above (`top`) and below (`bottom`) the fields. |
|
|
61
|
+
|
|
62
|
+
### `UseDetailsModalCallbacks`
|
|
63
|
+
|
|
64
|
+
Callbacks of `useDetailsModal`.
|
|
65
|
+
|
|
66
|
+
| Field | Type | Default | Description |
|
|
67
|
+
| -------------- | ------------ | ------- | ------------------------- |
|
|
68
|
+
| `onShowed?` | `() => void` | — | Once the modal is open. |
|
|
69
|
+
| `onDismissed?` | `() => void` | — | Once the modal is closed. |
|
|
70
|
+
|
|
71
|
+
### `SmartDetailsField`
|
|
72
|
+
|
|
73
|
+
A field `useDetails` shows.
|
|
74
|
+
|
|
75
|
+
| Field | Type | Default | Description |
|
|
76
|
+
| --------- | --------------- | -------- | ----------------------------- |
|
|
77
|
+
| `key` | `string` | required | The field key. |
|
|
78
|
+
| `options` | `IFieldOptions` | required | The field's `@Field` options. |
|
|
79
|
+
|
|
80
|
+
### `ICellPipe<T>`
|
|
81
|
+
|
|
82
|
+
Formats a value: `transform(item, key, translate?)` returns text (sanitised) or `trustHtml(html)` (rendered as is).
|
|
83
|
+
|
|
84
|
+
| Field | Type | Default | Description |
|
|
85
|
+
| ----------- | --------------------------------------------------------------------------------------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------- |
|
|
86
|
+
| `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. |
|
|
87
|
+
|
|
88
|
+
### `IDetailsComponentFactories<T>`
|
|
89
|
+
|
|
90
|
+
| Field | Type | Default | Description |
|
|
91
|
+
| --------- | -------------------- | ------- | ------------------------------------- |
|
|
92
|
+
| `top?` | `ComponentType<any>` | — | Rendered above the fields (no props). |
|
|
93
|
+
| `bottom?` | `ComponentType<any>` | — | Rendered below the fields (no props). |
|
|
94
|
+
|
|
95
|
+
## Which fields are shown
|
|
96
|
+
|
|
97
|
+
- Fields with `details: true` or `details: { ... }` in `@Field`, in declaration order.
|
|
98
|
+
- `details.permissions`: the field is left out when the signed-in user has none of them (`AuthService.expectPermissions`).
|
|
99
|
+
- `details.enabled` (else the field's `enabled`): a specification evaluated against the item; a nested details view can refer to the outermost item as `$root`.
|
|
100
|
+
|
|
101
|
+
## In a modal
|
|
102
|
+
|
|
103
|
+
`useDetailsModal({ component, params, mode? }, { onShowed?, onDismissed? })` returns a click handler that opens `component` in a modal through `ModalService`, with `{ value: params }` as its props, and resolves once the modal closed. `SmartDetailsPage` is the component made for it: it renders `SmartDetails` of `value` full width, with the application style applied. `useDetailsPageOptions(value)` returns page options (title, a remove button for `removeHandler`, a forward button for `itemHandler`) for a page layout of your own around it.
|
|
104
|
+
|
|
105
|
+
## Usage
|
|
106
|
+
|
|
107
|
+
```tsx
|
|
108
|
+
import { Field, FieldType, Model } from '@smartsoft001/models';
|
|
109
|
+
import {
|
|
110
|
+
SmartButton,
|
|
111
|
+
SmartDetails,
|
|
112
|
+
SmartDetailsPage,
|
|
113
|
+
useDetailsModal,
|
|
114
|
+
} from '@smartsoft001/react';
|
|
115
|
+
|
|
116
|
+
@Model({ titleKey: 'name' })
|
|
117
|
+
export class Customer {
|
|
118
|
+
id!: string;
|
|
119
|
+
|
|
120
|
+
@Field({ type: FieldType.text, details: true })
|
|
121
|
+
name!: string;
|
|
122
|
+
|
|
123
|
+
@Field({ type: FieldType.email, details: true })
|
|
124
|
+
email!: string;
|
|
125
|
+
|
|
126
|
+
@Field({ type: FieldType.text, details: { permissions: ['admin'] } })
|
|
127
|
+
creditLimit!: number;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export function CustomerDetails({ customer }: { customer: Customer | null }) {
|
|
131
|
+
return (
|
|
132
|
+
<SmartDetails
|
|
133
|
+
options={{
|
|
134
|
+
type: Customer,
|
|
135
|
+
item: customer,
|
|
136
|
+
componentFactories: { top: () => <h2>Customer</h2> },
|
|
137
|
+
}}
|
|
138
|
+
/>
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function CustomerPreviewButton({ customer }: { customer: Customer }) {
|
|
143
|
+
const open = useDetailsModal({
|
|
144
|
+
component: SmartDetailsPage,
|
|
145
|
+
params: { type: Customer, item: customer },
|
|
146
|
+
mode: 'default',
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
return (
|
|
150
|
+
<SmartButton options={{ click: () => void open() }}>Preview</SmartButton>
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## Replacing the Implementation
|
|
156
|
+
|
|
157
|
+
`SmartDetails` renders the component registered under the `'details'` key of `SmartProvider`'s `components`, and `SmartDetailsStandard` when nothing is registered there. Every `SmartDetails` below the provider then renders the registered component, which receives the same props.
|
|
158
|
+
|
|
159
|
+
There is no preset for this component: register a component of your own that takes `SmartDetailsProps`, as shown below, as `components={{ details: MyDetails }}`. Pass `components` as a stable object (a module constant or a memoised value), or the context changes on every render.
|
|
160
|
+
|
|
161
|
+
### Hooks
|
|
162
|
+
|
|
163
|
+
#### `useDetailsModal`
|
|
164
|
+
|
|
165
|
+
Returns a handler for an element's `onClick` that opens `options.component` in a modal with `{ value: options.params }` as props (e.g. `SmartDetailsPage` with `IDetailsOptions`), and resolves once the modal is closed. Without `options` or `options.component` it does nothing.
|
|
166
|
+
|
|
167
|
+
```ts
|
|
168
|
+
function useDetailsModal(
|
|
169
|
+
options: IDetailsModalOptions | null | undefined,
|
|
170
|
+
{ onShowed, onDismissed }: UseDetailsModalCallbacks = {},
|
|
171
|
+
): () => Promise<void>;
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
#### `useDetails`
|
|
175
|
+
|
|
176
|
+
The logic every details variant shares:
|
|
177
|
+
|
|
178
|
+
- `fields`: the fields of `options.type` marked `@Field({ details })`, without those whose `details.permissions` the user lacks and those whose `enabled` specification (`details.enabled`, else the field's `enabled`) the item fails; a specification can refer to the outermost details' item as `$root`;
|
|
179
|
+
- `item`: `options.item` as an instance of `options.type` (a plain API object is converted);
|
|
180
|
+
- `loading`, `cellPipe` and `componentFactories` from the options. The item becomes the `DetailsService` root while rendering, before nested details evaluate their specifications (the service keeps the first root, so the outermost details win; React effects would run the innermost first).
|
|
181
|
+
|
|
182
|
+
```ts
|
|
183
|
+
function useDetails<T extends IEntity<string>>({
|
|
184
|
+
options,
|
|
185
|
+
}: SmartDetailsProps<T>);
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
| Returns | Type | Description |
|
|
189
|
+
| -------------------- | --------------------------------------- | ----------------------------------------------------- |
|
|
190
|
+
| `fields` | `SmartDetailsField[] \| null` | The fields to show (`null` before they are resolved). |
|
|
191
|
+
| `type` | `any` | `options.type`. |
|
|
192
|
+
| `item` | `T \| null \| undefined` | The record as an instance of `options.type`. |
|
|
193
|
+
| `loading` | `boolean \| undefined` | `options.loading`. |
|
|
194
|
+
| `cellPipe` | `ICellPipe<T> \| null` | `options.cellPipe`, `null` without one. |
|
|
195
|
+
| `componentFactories` | `IDetailsComponentFactories<T> \| null` | `options.componentFactories`, `null` without them. |
|
|
196
|
+
|
|
197
|
+
```tsx
|
|
198
|
+
import type { IEntity } from '@smartsoft001/domain-core';
|
|
199
|
+
import {
|
|
200
|
+
SmartDetail,
|
|
201
|
+
SmartDetailsProps,
|
|
202
|
+
useDetails,
|
|
203
|
+
} from '@smartsoft001/react';
|
|
204
|
+
|
|
205
|
+
export function CardDetails<T extends IEntity<string>>(
|
|
206
|
+
props: SmartDetailsProps<T>,
|
|
207
|
+
) {
|
|
208
|
+
const { fields, type, item, loading, cellPipe } = useDetails(props);
|
|
209
|
+
|
|
210
|
+
return (
|
|
211
|
+
<div
|
|
212
|
+
className={['grid grid-cols-2 gap-6', props.className]
|
|
213
|
+
.filter(Boolean)
|
|
214
|
+
.join(' ')}
|
|
215
|
+
>
|
|
216
|
+
{fields?.map((field) => (
|
|
217
|
+
<div key={field.key} className="rounded-lg border p-4">
|
|
218
|
+
<SmartDetail
|
|
219
|
+
type={type}
|
|
220
|
+
options={{
|
|
221
|
+
key: field.key,
|
|
222
|
+
options: field.options,
|
|
223
|
+
item,
|
|
224
|
+
cellPipe: cellPipe ?? undefined,
|
|
225
|
+
loading,
|
|
226
|
+
}}
|
|
227
|
+
/>
|
|
228
|
+
</div>
|
|
229
|
+
))}
|
|
230
|
+
</div>
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
Registered as `components={{ details: CardDetails }}`, it also renders nested `object` / `array` details and the details mode of CRUD item pages.
|
|
236
|
+
|
|
237
|
+
## Styling
|
|
238
|
+
|
|
239
|
+
- `SmartDetailsStandard` is a divided description list with a top border and `smart:dark:` variants; the field values follow the registered detail field components (`DETAIL_PRESET_FIELD_COMPONENTS` for the preset look).
|
|
240
|
+
|
|
241
|
+
## File Locations
|
|
242
|
+
|
|
243
|
+
Source: `packages/shared/react/src/lib/components/details/` in the smartsoft001 repository.
|
|
244
|
+
|
|
245
|
+
- `details.tsx`: `SmartDetails`
|
|
246
|
+
- `details.types.ts`: `SmartDetailsProps`
|
|
247
|
+
- `standard/details-standard.tsx`: `SmartDetailsStandard`
|
|
248
|
+
- `use-details-modal.ts`: `useDetailsModal`, `IDetailsModalOptions`, `UseDetailsModalCallbacks`
|
|
249
|
+
- `use-details.ts`: `useDetails`, `SmartDetailsField`
|
|
250
|
+
- `details.stories.tsx`: Storybook stories
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: react-components-divider
|
|
3
|
+
description: SmartDivider React component API (@smartsoft001/react) — horizontal separator with an optional label, icon, title or action button (onActionClick), left/center/right position, five variants, the 'divider' registry key and SmartDividerPreset.
|
|
4
|
+
user-invocable: false
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Divider (`SmartDivider`)
|
|
8
|
+
|
|
9
|
+
`SmartDivider` separates sections. Without content it is a plain `<hr />`; with `label`, `title`, `iconName` or `actionLabel` it renders that content on the line (the action as a button reporting `onActionClick`). `options.position` places the content left, centre (default) or right, and `options.variant` picks the arrangement in the preset (inferred from the given props when omitted).
|
|
10
|
+
|
|
11
|
+
## When to Use This Skill
|
|
12
|
+
|
|
13
|
+
- Separating sections of a page or a form, optionally with a label ("or continue with")
|
|
14
|
+
- A section title on a line, or a "Load more" / "Add item" button centred on the line
|
|
15
|
+
- Restyling every divider (the `divider` registry key)
|
|
16
|
+
|
|
17
|
+
## Exports
|
|
18
|
+
|
|
19
|
+
All from `@smartsoft001/react`.
|
|
20
|
+
|
|
21
|
+
| Export | Kind | What it is |
|
|
22
|
+
| ---------------------- | --------- | --------------------------------------------------------------------------------------------------------------------- |
|
|
23
|
+
| `SmartDivider` | component | Renders the implementation registered as `components.divider` on `SmartProvider`, `SmartDividerStandard` by default. |
|
|
24
|
+
| `SmartDividerPreset` | component | Styled divider variation (preset). |
|
|
25
|
+
| `SmartDividerStandard` | component | The default divider rendering: the title, the label and the action button, or an `<hr />` when there is none of them. |
|
|
26
|
+
|
|
27
|
+
The preset's class helpers (`getDividerContainerClasses`, `getDividerIconClasses`, `getDividerActionClasses`, `getDividerToolbarClasses`, `getDividerToolbarLineClasses`, `getDividerPlainClasses`, `DIVIDER_PLAIN_HR`, `DIVIDER_TOOLBAR_LINE`, `DIVIDER_TOOLBAR_CONTAINER`, `DIVIDER_ICON_CLASSES`, `DIVIDER_ACTION_BUTTON`) are exported too, for a custom implementation that wants the preset look.
|
|
28
|
+
|
|
29
|
+
## Props and Types
|
|
30
|
+
|
|
31
|
+
### `SmartDividerProps`
|
|
32
|
+
|
|
33
|
+
| Prop | Type | Default | Description |
|
|
34
|
+
| ---------------- | ----------------- | ------- | ---------------------------------------------------------------------- |
|
|
35
|
+
| `label?` | `string` | — | Short text on the line. |
|
|
36
|
+
| `iconName?` | `string` | — | An icon on the line (rendered by the preset; the standard ignores it). |
|
|
37
|
+
| `title?` | `string` | — | A heading on the line. |
|
|
38
|
+
| `actionLabel?` | `string` | — | Renders a button with this text that calls `onActionClick`. |
|
|
39
|
+
| `options?` | `IDividerOptions` | — | Variant and position. |
|
|
40
|
+
| `className?` | `string` | — | Classes on the root element. |
|
|
41
|
+
| `onActionClick?` | `() => void` | — | The action button was clicked. |
|
|
42
|
+
|
|
43
|
+
### `IDividerOptions`
|
|
44
|
+
|
|
45
|
+
| Field | Type | Default | Description |
|
|
46
|
+
| ----------- | ------------------------------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
47
|
+
| `variant?` | `SmartDividerVariant` | — | `with-label`, `with-icon`, `with-title`, `with-button` or `with-toolbar` (label + line + action). Read by the preset; inferred from the props when omitted (action, title, icon, label, in that order). |
|
|
48
|
+
| `position?` | `'left' \| 'center' \| 'right'` | `'center'` | Where the content sits on the line. |
|
|
49
|
+
|
|
50
|
+
### Related types
|
|
51
|
+
|
|
52
|
+
- `SmartDividerVariant`: `'with-label' \| 'with-icon' \| 'with-title' \| 'with-button' \| 'with-toolbar'`
|
|
53
|
+
|
|
54
|
+
## Usage
|
|
55
|
+
|
|
56
|
+
```tsx
|
|
57
|
+
import { SmartDivider, SmartDividerPreset } from '@smartsoft001/react';
|
|
58
|
+
|
|
59
|
+
export function Separators({ onLoadMore }: { onLoadMore: () => void }) {
|
|
60
|
+
return (
|
|
61
|
+
<>
|
|
62
|
+
<SmartDivider />
|
|
63
|
+
<SmartDividerPreset label="or continue with" />
|
|
64
|
+
<SmartDividerPreset title="Projects" options={{ position: 'left' }} />
|
|
65
|
+
<SmartDividerPreset actionLabel="Load more" onActionClick={onLoadMore} />
|
|
66
|
+
</>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Replacing the Implementation
|
|
72
|
+
|
|
73
|
+
`SmartDivider` renders the component registered under the `'divider'` key of `SmartProvider`'s `components`, and `SmartDividerStandard` when nothing is registered there. Every `SmartDivider` below the provider then renders the registered component, which receives the same props.
|
|
74
|
+
|
|
75
|
+
```tsx
|
|
76
|
+
import type { ReactNode } from 'react';
|
|
77
|
+
|
|
78
|
+
import { SmartProvider, SmartDividerPreset } from '@smartsoft001/react';
|
|
79
|
+
|
|
80
|
+
// A module constant: a new object on every render would change the context.
|
|
81
|
+
const components = { divider: SmartDividerPreset };
|
|
82
|
+
|
|
83
|
+
export function AppProviders({ children }: { children: ReactNode }) {
|
|
84
|
+
return <SmartProvider components={components}>{children}</SmartProvider>;
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
`SmartDividerPreset` is the styled (preset) implementation: register it as above, render it directly in place of `SmartDivider`, 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.
|
|
89
|
+
|
|
90
|
+
```tsx
|
|
91
|
+
import { SmartDividerProps } from '@smartsoft001/react';
|
|
92
|
+
|
|
93
|
+
export function TextDivider({
|
|
94
|
+
label,
|
|
95
|
+
title,
|
|
96
|
+
actionLabel,
|
|
97
|
+
className,
|
|
98
|
+
onActionClick,
|
|
99
|
+
}: SmartDividerProps) {
|
|
100
|
+
const text = title ?? label;
|
|
101
|
+
|
|
102
|
+
return (
|
|
103
|
+
<div role="separator" className={className}>
|
|
104
|
+
{text && <span>{text}</span>}
|
|
105
|
+
{actionLabel && (
|
|
106
|
+
<button type="button" onClick={onActionClick}>
|
|
107
|
+
{actionLabel}
|
|
108
|
+
</button>
|
|
109
|
+
)}
|
|
110
|
+
</div>
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Styling
|
|
116
|
+
|
|
117
|
+
- `SmartDividerStandard` renders the title, label and action button, or an `<hr />` when none is given; it does not render `iconName`.
|
|
118
|
+
- `SmartDividerPreset` draws the connecting lines around the content per `position`, with `smart:dark:` variants.
|
|
119
|
+
|
|
120
|
+
## File Locations
|
|
121
|
+
|
|
122
|
+
Source: `packages/shared/react/src/lib/components/divider/` in the smartsoft001 repository.
|
|
123
|
+
|
|
124
|
+
- `divider.tsx`: `SmartDivider`
|
|
125
|
+
- `divider.types.ts`: `SmartDividerProps`
|
|
126
|
+
- `preset/divider-preset.tsx`: `SmartDividerPreset`
|
|
127
|
+
- `standard/divider-standard.tsx`: `SmartDividerStandard`
|
|
128
|
+
- `divider.stories.tsx`: Storybook stories
|