@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,120 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: react-components-export
|
|
3
|
+
description: SmartExport React component API (@smartsoft001/react) — download-icon button that hands value and fileName to a handler you write to serialise and download data, disabled while there is no value, and the useExport hook.
|
|
4
|
+
user-invocable: false
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Export (`SmartExport`)
|
|
8
|
+
|
|
9
|
+
`SmartExport` is a download-icon button. On click it calls `handler(value, fileName)`; the handler serialises the data and triggers the download, so the format is yours (JSON, CSV, ...). The button is disabled while `value` is empty. It renders through `SmartButton`, so it follows whatever is registered under the `button` key.
|
|
10
|
+
|
|
11
|
+
## When to Use This Skill
|
|
12
|
+
|
|
13
|
+
- An "export / download" button for data the page already holds
|
|
14
|
+
- Pairing with `SmartImport` for a JSON round trip
|
|
15
|
+
|
|
16
|
+
For exporting a CRUD collection from the server (CSV / XLSX of the current filter), use the CRUD export of `@smartsoft001/crud-shell-react` (`smart-crud-react` skill).
|
|
17
|
+
|
|
18
|
+
## Exports
|
|
19
|
+
|
|
20
|
+
All from `@smartsoft001/react`.
|
|
21
|
+
|
|
22
|
+
| Export | Kind | What it is |
|
|
23
|
+
| ------------- | --------- | ------------------------------------------------------------------------------------------------------------------------- |
|
|
24
|
+
| `SmartExport` | component | A download-icon `SmartButton` that calls `handler(value, fileName)`. |
|
|
25
|
+
| `useExport` | hook | The export button's logic: `onClick` hands `value` and `fileName` to `handler`, and does nothing while there is no value. |
|
|
26
|
+
|
|
27
|
+
## Props and Types
|
|
28
|
+
|
|
29
|
+
### `SmartExportProps`
|
|
30
|
+
|
|
31
|
+
| Prop | Type | Default | Description |
|
|
32
|
+
| ------------ | ----------------------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
33
|
+
| `value?` | `any` | — | The data to export; the button is disabled while it is empty. |
|
|
34
|
+
| `fileName?` | `string` | — | Name for the exported file, passed to `handler` as its second argument. |
|
|
35
|
+
| `handler` | `(value: any, fileName?: string) => void` | required | Called with `value` and `fileName` on click. Serialise and download the data here. The `fileName` argument is optional, so `(value) => void` handlers keep working. |
|
|
36
|
+
| `className?` | `string` | — | Classes on the button and on the `<span>` around it. |
|
|
37
|
+
|
|
38
|
+
## Usage
|
|
39
|
+
|
|
40
|
+
```tsx
|
|
41
|
+
import { SmartExport } from '@smartsoft001/react';
|
|
42
|
+
|
|
43
|
+
function downloadJson(value: unknown, fileName = 'export') {
|
|
44
|
+
const blob = new Blob([JSON.stringify(value, null, 2)], {
|
|
45
|
+
type: 'application/json',
|
|
46
|
+
});
|
|
47
|
+
const url = URL.createObjectURL(blob);
|
|
48
|
+
const link = document.createElement('a');
|
|
49
|
+
link.href = url;
|
|
50
|
+
link.download = `${fileName}.json`;
|
|
51
|
+
link.click();
|
|
52
|
+
URL.revokeObjectURL(url);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function ExportNotes({
|
|
56
|
+
notes,
|
|
57
|
+
}: {
|
|
58
|
+
notes: Array<{ id: string; title: string }>;
|
|
59
|
+
}) {
|
|
60
|
+
return (
|
|
61
|
+
<SmartExport
|
|
62
|
+
value={notes.length ? notes : undefined}
|
|
63
|
+
fileName="notes"
|
|
64
|
+
handler={downloadJson}
|
|
65
|
+
/>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Replacing the Implementation
|
|
71
|
+
|
|
72
|
+
`SmartExport` has no registry key of its own: it renders a `SmartButton`, so registering a component under the `button` key (or `SMART_PRESET_COMPONENTS`) restyles it too. For a different control, call `useExport` from a component of your own.
|
|
73
|
+
|
|
74
|
+
### The `useExport` hook
|
|
75
|
+
|
|
76
|
+
The export button's logic: `onClick` hands `value` and `fileName` to `handler`, and does nothing while there is no value.
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
function useExport({
|
|
80
|
+
value,
|
|
81
|
+
fileName,
|
|
82
|
+
handler,
|
|
83
|
+
}: Pick<SmartExportProps, 'value' | 'fileName' | 'handler'>);
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
| Returns | Type | Description |
|
|
87
|
+
| --------- | --------------------- | ----------------------------------------------------------------------- |
|
|
88
|
+
| `onClick` | `() => Promise<void>` | Calls `handler(value, fileName)`; does nothing while there is no value. |
|
|
89
|
+
|
|
90
|
+
```tsx
|
|
91
|
+
import { SmartExportProps, useExport } from '@smartsoft001/react';
|
|
92
|
+
|
|
93
|
+
export function ExportLink(props: SmartExportProps) {
|
|
94
|
+
const { onClick } = useExport(props);
|
|
95
|
+
|
|
96
|
+
return (
|
|
97
|
+
<button
|
|
98
|
+
type="button"
|
|
99
|
+
className={props.className}
|
|
100
|
+
disabled={!props.value}
|
|
101
|
+
onClick={() => void onClick()}
|
|
102
|
+
>
|
|
103
|
+
Download
|
|
104
|
+
</button>
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Styling
|
|
110
|
+
|
|
111
|
+
- The icon is an inline SVG with an `Export` screen-reader label; the button look comes from the registered button implementation.
|
|
112
|
+
|
|
113
|
+
## File Locations
|
|
114
|
+
|
|
115
|
+
Source: `packages/shared/react/src/lib/components/export/` in the smartsoft001 repository.
|
|
116
|
+
|
|
117
|
+
- `export.tsx`: `SmartExport`
|
|
118
|
+
- `export.types.ts`: `SmartExportProps`
|
|
119
|
+
- `use-export.ts`: `useExport`
|
|
120
|
+
- `export.stories.tsx`: Storybook stories
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: react-components-feed
|
|
3
|
+
description: SmartFeed React component API (@smartsoft001/react) — activity feed / timeline of events with icons or avatars, timestamps, links and nested comments, empty, comment-submit and footer slots, the 'feed' registry key and SmartFeedPreset.
|
|
4
|
+
user-invocable: false
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Feed (`SmartFeed`)
|
|
8
|
+
|
|
9
|
+
`SmartFeed` renders an activity feed: an ordered list of events, each with a marker (`iconTpl`, else `avatarUrl`), a timestamp, a title (a link when `href` is set), a description and nested `comments`. `emptyTpl` replaces the list when there are no events, and `commentSubmitTpl` / `footerTpl` add content below it. `SmartFeedPreset` draws the timeline rail.
|
|
10
|
+
|
|
11
|
+
## When to Use This Skill
|
|
12
|
+
|
|
13
|
+
- An activity log or history of a record ("Anna commented", "Status changed")
|
|
14
|
+
- A comment thread under an event
|
|
15
|
+
- Restyling every feed (the `feed` registry key)
|
|
16
|
+
|
|
17
|
+
## Exports
|
|
18
|
+
|
|
19
|
+
All from `@smartsoft001/react`.
|
|
20
|
+
|
|
21
|
+
| Export | Kind | What it is |
|
|
22
|
+
| ------------------- | --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
23
|
+
| `SmartFeed` | component | Renders the implementation registered as `components.feed` on `SmartProvider`, `SmartFeedStandard` by default. |
|
|
24
|
+
| `SmartFeedPreset` | component | Styled feed / timeline variation (preset). |
|
|
25
|
+
| `SmartFeedStandard` | component | The default feed rendering: an ordered list of events (icon template > avatar, timestamp, title as a link when `href` is set, description, nested comments), the `emptyTpl` when there are no events, then the `commentSubmitTpl` and `footerTpl` slots. |
|
|
26
|
+
|
|
27
|
+
The preset's class helpers (`FEED_ROOT`, `FEED_HEADING_WRAP`, `FEED_HEADING_TEXT`, `FEED_DESCRIPTION`, `FEED_ITEM`, `FEED_TIMESTAMP_SIDE`, `FEED_TIMESTAMP_TEXT`, `FEED_MARKER_RAIL`, `FEED_MARKER_INNER`, `FEED_DOT`, `FEED_AVATAR`, `FEED_BODY`, `FEED_EVENT_TITLE`, `FEED_EVENT_TITLE_LINK`, `FEED_EVENT_DESCRIPTION`, `FEED_COMMENT_BUTTON`, `FEED_COMMENT_AVATAR`, `FEED_COMMENT_INITIALS`, `FEED_COMMENT_CONTENT`, `FEED_COMMENT_TIME`, `FEED_EMPTY`, `FEED_COMMENT_SUBMIT`, `FEED_FOOTER`) are exported too, for a custom implementation that wants the preset look.
|
|
28
|
+
|
|
29
|
+
## Props and Types
|
|
30
|
+
|
|
31
|
+
### `SmartFeedProps`
|
|
32
|
+
|
|
33
|
+
| Prop | Type | Default | Description |
|
|
34
|
+
| ------------ | -------------- | ------- | ---------------------------- |
|
|
35
|
+
| `options?` | `IFeedOptions` | — | Header, events and slots. |
|
|
36
|
+
| `className?` | `string` | — | Classes on the root element. |
|
|
37
|
+
|
|
38
|
+
### `IFeedOptions`
|
|
39
|
+
|
|
40
|
+
| Field | Type | Default | Description |
|
|
41
|
+
| ------------------- | ------------------ | ------- | ------------------------------------------------------------------------------------------------------------- |
|
|
42
|
+
| `title?` | `string` | — | Heading above the feed. |
|
|
43
|
+
| `description?` | `string` | — | Text under the heading. |
|
|
44
|
+
| `events?` | `IFeedEvent[]` | `[]` | The events, in the order shown. |
|
|
45
|
+
| `variant?` | `SmartFeedVariant` | — | Declared (`simple`, `with-comments`, `multiple-types`); the standard and preset renderings do not vary by it. |
|
|
46
|
+
| `commentSubmitTpl?` | `ReactNode` | — | A slot below the feed, e.g. a comment form. |
|
|
47
|
+
| `emptyTpl?` | `ReactNode` | — | Rendered instead of the list when there are no events. |
|
|
48
|
+
| `footerTpl?` | `ReactNode` | — | A slot at the end. |
|
|
49
|
+
|
|
50
|
+
### `IFeedEvent`
|
|
51
|
+
|
|
52
|
+
| Field | Type | Default | Description |
|
|
53
|
+
| -------------- | ---------------- | -------- | ------------------------------------------------------ |
|
|
54
|
+
| `id?` | `string` | — | Key of the event. |
|
|
55
|
+
| `title` | `string` | required | Event title; a link when `href` is set. |
|
|
56
|
+
| `description?` | `string` | — | Event text. |
|
|
57
|
+
| `timestamp?` | `string` | — | Display text for the time (e.g. "2h ago"). |
|
|
58
|
+
| `iconTpl?` | `ReactNode` | — | Marker icon; wins over `avatarUrl`. |
|
|
59
|
+
| `avatarUrl?` | `string` | — | Marker avatar. |
|
|
60
|
+
| `href?` | `string` | — | Makes the title a link. |
|
|
61
|
+
| `type?` | `string` | — | Declared for your own use; not read by the renderings. |
|
|
62
|
+
| `comments?` | `IFeedComment[]` | — | Comments listed under the event. |
|
|
63
|
+
| `ariaLabel?` | `string` | — | Accessible name of the event. |
|
|
64
|
+
|
|
65
|
+
### `IFeedComment`
|
|
66
|
+
|
|
67
|
+
| Field | Type | Default | Description |
|
|
68
|
+
| ------------------ | -------- | -------- | ---------------------------------------------------------------- |
|
|
69
|
+
| `id?` | `string` | — | Key of the comment. |
|
|
70
|
+
| `authorName` | `string` | required | Author shown with the comment (initials fallback in the preset). |
|
|
71
|
+
| `authorAvatarUrl?` | `string` | — | Author avatar. |
|
|
72
|
+
| `content` | `string` | required | Comment text. |
|
|
73
|
+
| `timestamp?` | `string` | — | Display text for the time. |
|
|
74
|
+
|
|
75
|
+
### Related types
|
|
76
|
+
|
|
77
|
+
- `SmartFeedVariant`: `'simple' \| 'with-comments' \| 'multiple-types'`
|
|
78
|
+
|
|
79
|
+
## Usage
|
|
80
|
+
|
|
81
|
+
```tsx
|
|
82
|
+
import { SmartFeed } from '@smartsoft001/react';
|
|
83
|
+
|
|
84
|
+
export function TicketHistory() {
|
|
85
|
+
return (
|
|
86
|
+
<SmartFeed
|
|
87
|
+
options={{
|
|
88
|
+
title: 'Activity',
|
|
89
|
+
events: [
|
|
90
|
+
{ id: '1', title: 'Ticket created', timestamp: '3d ago' },
|
|
91
|
+
{
|
|
92
|
+
id: '2',
|
|
93
|
+
title: 'Anna commented',
|
|
94
|
+
timestamp: '2h ago',
|
|
95
|
+
avatarUrl: '/avatars/anna.jpg',
|
|
96
|
+
comments: [
|
|
97
|
+
{
|
|
98
|
+
id: 'c1',
|
|
99
|
+
authorName: 'Anna Kowalska',
|
|
100
|
+
content: 'Reproduced on staging.',
|
|
101
|
+
timestamp: '2h ago',
|
|
102
|
+
},
|
|
103
|
+
],
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
id: '3',
|
|
107
|
+
title: 'Linked to release 2.4',
|
|
108
|
+
href: '/releases/2.4',
|
|
109
|
+
timestamp: '1h ago',
|
|
110
|
+
},
|
|
111
|
+
],
|
|
112
|
+
emptyTpl: <p>No activity yet.</p>,
|
|
113
|
+
}}
|
|
114
|
+
/>
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Replacing the Implementation
|
|
120
|
+
|
|
121
|
+
`SmartFeed` renders the component registered under the `'feed'` key of `SmartProvider`'s `components`, and `SmartFeedStandard` when nothing is registered there. Every `SmartFeed` below the provider then renders the registered component, which receives the same props.
|
|
122
|
+
|
|
123
|
+
```tsx
|
|
124
|
+
import type { ReactNode } from 'react';
|
|
125
|
+
|
|
126
|
+
import { SmartProvider, SmartFeedPreset } from '@smartsoft001/react';
|
|
127
|
+
|
|
128
|
+
// A module constant: a new object on every render would change the context.
|
|
129
|
+
const components = { feed: SmartFeedPreset };
|
|
130
|
+
|
|
131
|
+
export function AppProviders({ children }: { children: ReactNode }) {
|
|
132
|
+
return <SmartProvider components={components}>{children}</SmartProvider>;
|
|
133
|
+
}
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
`SmartFeedPreset` is the styled (preset) implementation: register it as above, render it directly in place of `SmartFeed`, 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.
|
|
137
|
+
|
|
138
|
+
```tsx
|
|
139
|
+
import { SmartFeedProps } from '@smartsoft001/react';
|
|
140
|
+
|
|
141
|
+
export function CompactFeed({ options, className }: SmartFeedProps) {
|
|
142
|
+
const events = options?.events ?? [];
|
|
143
|
+
|
|
144
|
+
if (!events.length) return <>{options?.emptyTpl}</>;
|
|
145
|
+
|
|
146
|
+
return (
|
|
147
|
+
<ol className={className}>
|
|
148
|
+
{events.map((event, index) => (
|
|
149
|
+
<li key={event.id ?? index}>
|
|
150
|
+
<time>{event.timestamp}</time>{' '}
|
|
151
|
+
{event.href ? <a href={event.href}>{event.title}</a> : event.title}
|
|
152
|
+
</li>
|
|
153
|
+
))}
|
|
154
|
+
</ol>
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## Styling
|
|
160
|
+
|
|
161
|
+
- `SmartFeedStandard` is an unstyled ordered list with class hooks; `SmartFeedPreset` draws a vertical rail with markers (icon > avatar > dot), a timestamp column and author rows for comments, with `smart:dark:` variants.
|
|
162
|
+
|
|
163
|
+
## File Locations
|
|
164
|
+
|
|
165
|
+
Source: `packages/shared/react/src/lib/components/feed/` in the smartsoft001 repository.
|
|
166
|
+
|
|
167
|
+
- `feed.tsx`: `SmartFeed`
|
|
168
|
+
- `feed.types.ts`: `SmartFeedProps`
|
|
169
|
+
- `preset/feed-preset.tsx`: `SmartFeedPreset`
|
|
170
|
+
- `standard/feed-standard.tsx`: `SmartFeedStandard`
|
|
171
|
+
- `feed.stories.tsx`: Storybook stories
|
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: react-components-form
|
|
3
|
+
description: SmartForm React component API (@smartsoft001/react) — model-driven form built from @Model/@Field metadata by the form factory (IFormOptions with model, mode, control, loading, possibilities, inputComponents), onInvokeSubmit/onValueChange/onValuePartialChange/onValidChange, the 'form' registry key, SmartFormPreset and the useFormBase hook for custom form bodies.
|
|
4
|
+
user-invocable: false
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Form (`SmartForm`)
|
|
8
|
+
|
|
9
|
+
`SmartForm` turns a model instance into a form. It asks the provider's `FormFactory` for a form of `options.model` in `options.mode` (`'create'` by default): one control per `@Field` the mode includes, with the validators the field options call for (see `react-forms`). Then it renders a body (the component registered under the `form` key, `SmartFormStandard` by default) with one `SmartInput` per control, and reports the value as the user types. Submitting, or pressing Enter in a single-line input, calls `onInvokeSubmit(value)` once. Pass a form you built yourself as `options.control` to skip the factory.
|
|
10
|
+
|
|
11
|
+
## When to Use This Skill
|
|
12
|
+
|
|
13
|
+
- Rendering a create / edit form for a model decorated with `@Model` / `@Field`
|
|
14
|
+
- Reacting to submit, to every change, to the changed fields only, or to validity
|
|
15
|
+
- Disabling the form while saving (`options.loading`)
|
|
16
|
+
- Overriding the editor of one field (`options.inputComponents`) or supplying radio / check options (`options.possibilities`)
|
|
17
|
+
- Restyling the form body (the `form` registry key, `SmartFormPreset`) or writing one on `useFormBase`
|
|
18
|
+
|
|
19
|
+
## Exports
|
|
20
|
+
|
|
21
|
+
All from `@smartsoft001/react`.
|
|
22
|
+
|
|
23
|
+
| Export | Kind | What it is |
|
|
24
|
+
| ------------------- | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
25
|
+
| `SmartForm` | component | The form of `options.model`, built by the form factory for `options.mode` (`'create'` by default) with `options.uniqueProvider`, or `options.control` when given. |
|
|
26
|
+
| `SmartFormPreset` | component | Styled form variation (preset). |
|
|
27
|
+
| `SmartFormStandard` | component | The default form body: one input per control. |
|
|
28
|
+
| `useFormBase` | hook | What every form body shares: the fields to render, the options every input gets and `submit()`. |
|
|
29
|
+
|
|
30
|
+
The preset's class helpers (`getFormShellClasses`, `getFormFieldClasses`) are exported too, for a custom implementation that wants the preset look.
|
|
31
|
+
|
|
32
|
+
## Props and Types
|
|
33
|
+
|
|
34
|
+
### `SmartFormProps<T = any>`
|
|
35
|
+
|
|
36
|
+
The props of `<SmartForm>`.
|
|
37
|
+
|
|
38
|
+
| Prop | Type | Default | Description |
|
|
39
|
+
| ----------------------- | ----------------------------- | -------- | ------------------------------------------------ |
|
|
40
|
+
| `options` | `IFormOptions<T>` | required | The model, the mode and the other form options. |
|
|
41
|
+
| `className?` | `string` | — | Classes of the body container. |
|
|
42
|
+
| `onInvokeSubmit?` | `(value: any) => void` | — | The form value, on submit or Enter. |
|
|
43
|
+
| `onValueChange?` | `(value: T) => void` | — | The form value after every change. |
|
|
44
|
+
| `onValuePartialChange?` | `(value: Partial<T>) => void` | — | The dirty controls' values, `*Confirm` left out. |
|
|
45
|
+
| `onValidChange?` | `(valid: boolean) => void` | — | The form validity after every change. |
|
|
46
|
+
|
|
47
|
+
### `SmartFormBaseProps<T = any>`
|
|
48
|
+
|
|
49
|
+
The props of a form body: `SmartFormStandard`, `SmartFormPreset` or an implementation registered as `components.form`.
|
|
50
|
+
|
|
51
|
+
| Prop | Type | Default | Description |
|
|
52
|
+
| ----------------- | ---------------------- | -------- | ---------------------------------------------------------------------- |
|
|
53
|
+
| `form` | `SmartFormGroup` | required | The built form group. |
|
|
54
|
+
| `options` | `IFormOptions<T>` | required | The form options (`treeLevel` defaulted to 1). |
|
|
55
|
+
| `className?` | `string` | — | Classes of the body container. |
|
|
56
|
+
| `onInvokeSubmit?` | `(value: any) => void` | — | Call with the form value to submit (what `useFormBase().submit` does). |
|
|
57
|
+
|
|
58
|
+
### `IFormOptions<T>`
|
|
59
|
+
|
|
60
|
+
| Field | Type | Default | Description |
|
|
61
|
+
| ------------------ | ---------------------------------------------------- | ---------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
62
|
+
| `model` | `T` | required | The model instance (a `@Model` class); a new instance builds a new form. |
|
|
63
|
+
| `show` | `boolean` | required | Required by the type; `SmartForm` does not read it (pass `true`). |
|
|
64
|
+
| `treeLevel?` | `number` | — | Nesting depth; `SmartForm` defaults it to 1 and writes it as `tree-level` / `data-tree-level`. |
|
|
65
|
+
| `control?` | `SmartAbstractControl` | — | A ready form; without it the form is built from `model` by the form factory. |
|
|
66
|
+
| `mode?` | `'create' \| 'update' \| string` | `'create'` | Which fields and which mode options the factory uses: `create`, `update`, `multiUpdate` or a custom mode from `customs`. Pass it explicitly: the inputs merge the options of the mode they receive, and without `mode` they get none (the form is still built for `create`). |
|
|
67
|
+
| `loading?` | `boolean` | — | Disables the whole form while `true`. |
|
|
68
|
+
| `uniqueProvider?` | `(values: Record<keyof T, any>) => Promise<boolean>` | — | Async check of `unique` fields; resolve `false` to report `invalidUnique`. |
|
|
69
|
+
| `possibilities?` | `{ [key: string]: SmartPossibility[]; }` | `{}` | Options of `radio`, `check`, `enum` or `strings` fields, by field key. |
|
|
70
|
+
| `inputComponents?` | `{ [key: string]: InputComponentType<T>; }` | `{}` | Field components by field key, used instead of the type's component. |
|
|
71
|
+
| `fieldOptions?` | `IFieldOptions` | — | Declared; `SmartForm` does not read it. |
|
|
72
|
+
| `modelOptions?` | `IModelOptions` | — | Declared; `SmartForm` does not read it. |
|
|
73
|
+
|
|
74
|
+
### Related types
|
|
75
|
+
|
|
76
|
+
- `InputComponentType<T = any>`: `ComponentType<any>` — A field component (takes `SmartInputFieldProps`).
|
|
77
|
+
|
|
78
|
+
`SmartPossibility`, `SmartAbstractControl`, `SmartFormGroup` are described in the `react-forms` and `react-provider` skills.
|
|
79
|
+
|
|
80
|
+
## Callbacks
|
|
81
|
+
|
|
82
|
+
| Callback | When | Value |
|
|
83
|
+
| ---------------------- | ------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------ |
|
|
84
|
+
| `onInvokeSubmit` | Form submit, or Enter in a single-line input (not in a textarea, the rich-text editor, a button or a select) | `form.value` (disabled controls left out) |
|
|
85
|
+
| `onValueChange` | After every change, and once when the form is ready | `form.value` |
|
|
86
|
+
| `onValuePartialChange` | After every change, and once when the form is ready | The values of the dirty controls, `<key>Confirm` controls left out |
|
|
87
|
+
| `onValidChange` | After every change, and once when the form is ready | `form.valid` |
|
|
88
|
+
|
|
89
|
+
`SmartForm` does not block the submit of an invalid form: check validity yourself (keep `onValidChange` in state, or build the form with `useModelForm` and call `form.markAllAsTouched()` before reading `form.valid`). Only the latest callbacks are used, so inline functions are fine.
|
|
90
|
+
|
|
91
|
+
## Nested forms
|
|
92
|
+
|
|
93
|
+
`object` and `array` fields render a nested `SmartForm` one tree level deeper. A nested form renders a `<div>` instead of a `<form>` (HTML does not allow nested forms), and Enter in its inputs submits the outer form.
|
|
94
|
+
|
|
95
|
+
## Labels
|
|
96
|
+
|
|
97
|
+
Field labels come from the `modelLabelProvider` of `SmartProvider`, or from the translation of `MODEL.<fieldKey>`: add those keys to `translations` (see `react-provider`).
|
|
98
|
+
|
|
99
|
+
## Usage
|
|
100
|
+
|
|
101
|
+
The standard body renders no submit button: the form submits on Enter, and a button of your own reads the value kept from `onValueChange`.
|
|
102
|
+
|
|
103
|
+
```tsx
|
|
104
|
+
import { useState } from 'react';
|
|
105
|
+
|
|
106
|
+
import { Field, FieldType, Model } from '@smartsoft001/models';
|
|
107
|
+
import { SmartButton, SmartForm } from '@smartsoft001/react';
|
|
108
|
+
|
|
109
|
+
@Model({})
|
|
110
|
+
export class Contact {
|
|
111
|
+
@Field({
|
|
112
|
+
type: FieldType.text,
|
|
113
|
+
create: { required: true },
|
|
114
|
+
update: { required: true },
|
|
115
|
+
focused: true,
|
|
116
|
+
})
|
|
117
|
+
name!: string;
|
|
118
|
+
|
|
119
|
+
@Field({ type: FieldType.email, create: true, update: true })
|
|
120
|
+
email!: string;
|
|
121
|
+
|
|
122
|
+
@Field({
|
|
123
|
+
type: FieldType.radio,
|
|
124
|
+
create: true,
|
|
125
|
+
update: true,
|
|
126
|
+
possibilities: { phone: 'phone', email: 'email' },
|
|
127
|
+
})
|
|
128
|
+
preferred!: string;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export function ContactForm({
|
|
132
|
+
contact,
|
|
133
|
+
onSave,
|
|
134
|
+
}: {
|
|
135
|
+
contact?: Contact;
|
|
136
|
+
onSave: (value: Contact) => Promise<void>;
|
|
137
|
+
}) {
|
|
138
|
+
// One model instance per form: a new instance rebuilds the form.
|
|
139
|
+
const [model] = useState(() => contact ?? new Contact());
|
|
140
|
+
const [value, setValue] = useState<Contact | null>(null);
|
|
141
|
+
const [valid, setValid] = useState(false);
|
|
142
|
+
const [saving, setSaving] = useState(false);
|
|
143
|
+
|
|
144
|
+
const save = async (current: Contact | null) => {
|
|
145
|
+
if (!current || !valid) return;
|
|
146
|
+
setSaving(true);
|
|
147
|
+
try {
|
|
148
|
+
await onSave(current);
|
|
149
|
+
} finally {
|
|
150
|
+
setSaving(false);
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
return (
|
|
155
|
+
<>
|
|
156
|
+
<SmartForm
|
|
157
|
+
options={{
|
|
158
|
+
model,
|
|
159
|
+
mode: contact ? 'update' : 'create',
|
|
160
|
+
show: true,
|
|
161
|
+
loading: saving,
|
|
162
|
+
possibilities: {
|
|
163
|
+
preferred: [
|
|
164
|
+
{ id: 'phone', text: 'Phone', checked: false },
|
|
165
|
+
{ id: 'email', text: 'Email', checked: false },
|
|
166
|
+
],
|
|
167
|
+
},
|
|
168
|
+
}}
|
|
169
|
+
onValueChange={setValue}
|
|
170
|
+
onValidChange={setValid}
|
|
171
|
+
onInvokeSubmit={(submitted) => void save(submitted as Contact)}
|
|
172
|
+
/>
|
|
173
|
+
<SmartButton
|
|
174
|
+
options={{ click: () => void save(value), loading: saving }}
|
|
175
|
+
disabled={!valid}
|
|
176
|
+
>
|
|
177
|
+
Save
|
|
178
|
+
</SmartButton>
|
|
179
|
+
</>
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
The labels are the translations of `MODEL.name`, `MODEL.email` and `MODEL.preferred` (add them to the `translations` of `SmartProvider`, see `react-provider`).
|
|
185
|
+
|
|
186
|
+
## Replacing the Implementation
|
|
187
|
+
|
|
188
|
+
`SmartForm` renders the body registered under the `'form'` key of `SmartProvider`'s `components`, and `SmartFormStandard` when nothing is registered. The body gets `SmartFormBaseProps` (the built `form`, the options, `className`, `onInvokeSubmit`); `SmartForm` itself keeps building the form, the `<form>` element, the callbacks and `loading`.
|
|
189
|
+
|
|
190
|
+
`SmartFormPreset` restyles only the **shell** (vertical rhythm, a `data-role="field"` wrapper with `data-key` per row, `data-role="form"` on the root). The fields keep their look unless the input presets are registered too, so register both:
|
|
191
|
+
|
|
192
|
+
```tsx
|
|
193
|
+
import type { ReactNode } from 'react';
|
|
194
|
+
|
|
195
|
+
import {
|
|
196
|
+
INPUT_PRESET_FIELD_COMPONENTS,
|
|
197
|
+
SmartFormPreset,
|
|
198
|
+
SmartProvider,
|
|
199
|
+
} from '@smartsoft001/react';
|
|
200
|
+
|
|
201
|
+
const components = { form: SmartFormPreset };
|
|
202
|
+
|
|
203
|
+
export function AppProviders({ children }: { children: ReactNode }) {
|
|
204
|
+
return (
|
|
205
|
+
<SmartProvider
|
|
206
|
+
components={components}
|
|
207
|
+
inputFieldComponents={INPUT_PRESET_FIELD_COMPONENTS}
|
|
208
|
+
>
|
|
209
|
+
{children}
|
|
210
|
+
</SmartProvider>
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
`SMART_PRESET_COMPONENTS` registers both at once (see `react-provider`).
|
|
216
|
+
|
|
217
|
+
### The `useFormBase` hook
|
|
218
|
+
|
|
219
|
+
What every form body shares: the fields to render, the options every input gets and `submit()`. The body re-renders on every change of the form, so a field added or removed by an `enabled` specification shows up at once. Bodies render a field when `form.controls[field]` exists and is not `smartDisabled`.
|
|
220
|
+
|
|
221
|
+
```ts
|
|
222
|
+
function useFormBase<T>({
|
|
223
|
+
form,
|
|
224
|
+
options,
|
|
225
|
+
onInvokeSubmit,
|
|
226
|
+
}: SmartFormBaseProps<T>);
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
| Returns | Type | Description |
|
|
230
|
+
| ----------------- | ------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
231
|
+
| `fields` | `string[]` | The control keys to render, in model order (a control removed and re-added by an `enabled` specification keeps its place; `<key>Confirm` follows `<key>`). |
|
|
232
|
+
| `model` | `T` | `options.model`. |
|
|
233
|
+
| `mode` | `string` | `options.mode`, `''` when unset. |
|
|
234
|
+
| `possibilities` | `{ [key: string]: SmartPossibility[]; }` | `options.possibilities ?? {}`. |
|
|
235
|
+
| `inputComponents` | `{ [key: string]: InputComponentType<T>; }` | `options.inputComponents ?? {}`. |
|
|
236
|
+
| `treeLevel` | `number \| undefined` | `options.treeLevel`. |
|
|
237
|
+
| `submit` | `() => void \| undefined` | Emits `onInvokeSubmit` with the form value. |
|
|
238
|
+
| `getControl` | `(field: string) => SmartAbstractControl \| undefined` | The control of `field`. |
|
|
239
|
+
|
|
240
|
+
A form body receives the built `form` and the options; `useFormBase` gives the fields to render and `submit()`:
|
|
241
|
+
|
|
242
|
+
```tsx
|
|
243
|
+
import type { ReactNode } from 'react';
|
|
244
|
+
|
|
245
|
+
import {
|
|
246
|
+
SmartFormBaseProps,
|
|
247
|
+
SmartInput,
|
|
248
|
+
SmartProvider,
|
|
249
|
+
useFormBase,
|
|
250
|
+
} from '@smartsoft001/react';
|
|
251
|
+
|
|
252
|
+
export function TwoColumnFormBody<T>(props: SmartFormBaseProps<T>) {
|
|
253
|
+
const {
|
|
254
|
+
fields,
|
|
255
|
+
model,
|
|
256
|
+
mode,
|
|
257
|
+
possibilities,
|
|
258
|
+
inputComponents,
|
|
259
|
+
treeLevel,
|
|
260
|
+
getControl,
|
|
261
|
+
submit,
|
|
262
|
+
} = useFormBase(props);
|
|
263
|
+
|
|
264
|
+
return (
|
|
265
|
+
<div
|
|
266
|
+
className={['grid grid-cols-2 gap-4', props.className]
|
|
267
|
+
.filter(Boolean)
|
|
268
|
+
.join(' ')}
|
|
269
|
+
>
|
|
270
|
+
{fields.map((field) => {
|
|
271
|
+
const control = getControl(field);
|
|
272
|
+
|
|
273
|
+
if (!control || control.smartDisabled) return null;
|
|
274
|
+
|
|
275
|
+
return (
|
|
276
|
+
<SmartInput
|
|
277
|
+
key={field}
|
|
278
|
+
options={{
|
|
279
|
+
control,
|
|
280
|
+
fieldKey: field,
|
|
281
|
+
model,
|
|
282
|
+
mode,
|
|
283
|
+
treeLevel: treeLevel ?? 0,
|
|
284
|
+
possibilities: possibilities[field],
|
|
285
|
+
component: inputComponents[field],
|
|
286
|
+
}}
|
|
287
|
+
/>
|
|
288
|
+
);
|
|
289
|
+
})}
|
|
290
|
+
<button type="button" className="col-span-2" onClick={submit}>
|
|
291
|
+
Save
|
|
292
|
+
</button>
|
|
293
|
+
</div>
|
|
294
|
+
);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
const components = { form: TwoColumnFormBody };
|
|
298
|
+
|
|
299
|
+
export function AppProviders({ children }: { children: ReactNode }) {
|
|
300
|
+
return <SmartProvider components={components}>{children}</SmartProvider>;
|
|
301
|
+
}
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
A body skips controls that are missing or `smartDisabled` (fields an `enabled` specification turned off). It re-renders on every change of the form, so such fields appear and disappear at once.
|
|
305
|
+
|
|
306
|
+
## Styling
|
|
307
|
+
|
|
308
|
+
- `SmartFormStandard` stacks the fields with dividers (`smart:dark:` variants included); `className` is appended to the body container.
|
|
309
|
+
|
|
310
|
+
## File Locations
|
|
311
|
+
|
|
312
|
+
Source: `packages/shared/react/src/lib/components/form/` in the smartsoft001 repository.
|
|
313
|
+
|
|
314
|
+
- `form.tsx`: `SmartForm`
|
|
315
|
+
- `form.types.ts`: `SmartFormProps`, `SmartFormBaseProps`
|
|
316
|
+
- `preset/form-preset.tsx`: `SmartFormPreset`
|
|
317
|
+
- `standard/form-standard.tsx`: `SmartFormStandard`
|
|
318
|
+
- `use-form-base.ts`: `useFormBase`
|
|
319
|
+
- `form.stories.tsx`: Storybook stories
|