@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,406 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: react-components-input
|
|
3
|
+
description: SmartInput React component API (@smartsoft001/react) — renders one model field of a form by its FieldType (text, email, int, enum, radio, check, date, dateRange, file, image, object, array, address, password...), the standard and preset field components, inputFieldComponents / INPUT_PRESET_FIELD_COMPONENTS, the 'input-error' registry key, validation messages and the useInput hook for custom field components.
|
|
4
|
+
user-invocable: false
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Input (`SmartInput`)
|
|
8
|
+
|
|
9
|
+
`SmartInput` renders one field of a model-driven form: it reads the field's `@Field` options for the form's mode, picks the **field component of the field's `FieldType`** (or `options.component`), and renders it with the field's info tooltip, a loader while an async validator runs, and the validation messages once the control is touched. `SmartForm` renders one `SmartInput` per control, so most applications use it indirectly; render it yourself when you lay out a form's fields by hand. Field components are resolved from `inputFieldComponents` on `SmartProvider` over the library's defaults (`INPUT_PRESET_FIELD_COMPONENTS` gives the styled set), and the messages render through `components['input-error']`.
|
|
10
|
+
|
|
11
|
+
## When to Use This Skill
|
|
12
|
+
|
|
13
|
+
- Laying out the inputs of a model-driven form yourself (one `SmartInput` per control)
|
|
14
|
+
- Choosing or replacing the editor of a field type (`inputFieldComponents`) or of one field (`IFormOptions.inputComponents`, `options.component`)
|
|
15
|
+
- Writing a custom field component on `useInput`
|
|
16
|
+
- Understanding what each `FieldType` renders, which ones upload files, and which add their own validators
|
|
17
|
+
- Restyling the validation messages (`input-error` key, `SmartInputErrorPreset`)
|
|
18
|
+
|
|
19
|
+
## Exports
|
|
20
|
+
|
|
21
|
+
All from `@smartsoft001/react`.
|
|
22
|
+
|
|
23
|
+
| Export | Kind | What it is |
|
|
24
|
+
| -------------------------------- | --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
25
|
+
| `SmartInput` | component | Renders the field component of the control's field type (or `options.component`), with the field's info tooltip, a loader while an async validator runs, and the validation messages once the control is touched. |
|
|
26
|
+
| `SmartInputError` | component | The messages of a field's validation errors. |
|
|
27
|
+
| `SmartInputErrorPreset` | component | Styled validation messages (preset), each with an alert icon and `role="alert"`. |
|
|
28
|
+
| `SmartRichTextEditor` | component | A dependency-free rich-text editor: a menu bar over a `contentEditable` element whose HTML is the value. |
|
|
29
|
+
| `useInputFile` | hook | The upload behaviour of the file fields: picking a file checks it against the input's `accept` list, uploads it through the file service with progress, and sets the attachment the API returns as the value. |
|
|
30
|
+
| `useInputPossibilities` | hook | The options of a field with possibilities: the ones the model possibilities provider returns, asked again 500 ms after the form's value last changed so they can depend on other fields, or else the ones in the input options. |
|
|
31
|
+
| `useInput` | hook | What every field component shares: the control and its live state, whether it is required, the translated label and the handlers that bind an element to the control (a change sets the value and marks the control dirty, a blur marks it touched). |
|
|
32
|
+
| `getDefaultInputFieldComponents` | function | The standard field component of every `FieldType` (the map `SmartInput` falls back to). |
|
|
33
|
+
| `getInputErrorMessages` | function | The messages a field shows for its validation errors, in a fixed order. |
|
|
34
|
+
| `resolveInputFieldOptions` | function | The options of the field an input renders, merged with the options of the form's mode: a `<key>Confirm` control takes the options of `<key>`, and an array model is read through its first item. |
|
|
35
|
+
| `INPUT_PRESET_FIELD_COMPONENTS` | const | The Preline-styled field presets, by `FieldType`. |
|
|
36
|
+
|
|
37
|
+
The preset's class helpers (`getInputEmailPresetClasses`, `getInputEmailPresetLabelClasses`, `getInputNipPresetClasses`, `getInputNipPresetLabelClasses`, `getInputPhoneNumberPlPresetClasses`, `getInputPhoneNumberPlPresetLabelClasses`, `getInputPhoneNumberPlPresetWrapperClasses`, `getInputPhoneNumberPlPresetPrefixClasses`, `getInputPhoneNumberPresetClasses`, `getInputPhoneNumberPresetLabelClasses`, `getInputTextPresetClasses`, `getInputTextPresetLabelClasses`) are exported too, for a custom implementation that wants the preset look.
|
|
38
|
+
|
|
39
|
+
## Props and Types
|
|
40
|
+
|
|
41
|
+
### `SmartInputProps<T = any>`
|
|
42
|
+
|
|
43
|
+
The props of `<SmartInput>`.
|
|
44
|
+
|
|
45
|
+
| Prop | Type | Default | Description |
|
|
46
|
+
| ------------ | ----------------- | ------- | ------------------------------------------------------------------------------------------- |
|
|
47
|
+
| `options?` | `InputOptions<T>` | — | The field to render: control, model, field key, mode, tree level, possibilities, component. |
|
|
48
|
+
| `className?` | `string` | — | Passed to the field component (usually appended to its input). |
|
|
49
|
+
|
|
50
|
+
### `SmartInputErrorProps`
|
|
51
|
+
|
|
52
|
+
| Prop | Type | Default | Description |
|
|
53
|
+
| --------- | ------------------------------- | ------- | --------------------- |
|
|
54
|
+
| `errors?` | `SmartValidationErrors \| null` | — | The control's errors. |
|
|
55
|
+
|
|
56
|
+
### `SmartInputFieldProps<T = any>`
|
|
57
|
+
|
|
58
|
+
The props every field component receives from `<SmartInput>`: the input options (control, model, field key, mode, tree level, possibilities) and the field's options for the current mode.
|
|
59
|
+
|
|
60
|
+
| Prop | Type | Default | Description |
|
|
61
|
+
| --------------- | ----------------- | ------- | ----------------------------------------------------------------- |
|
|
62
|
+
| `options?` | `InputOptions<T>` | — | The input options `SmartInput` received. |
|
|
63
|
+
| `fieldOptions?` | `IFieldOptions` | — | The field's `@Field` options merged with the options of the mode. |
|
|
64
|
+
| `className?` | `string` | — | The `className` of `SmartInput`. |
|
|
65
|
+
|
|
66
|
+
### `SmartRichTextEditorProps`
|
|
67
|
+
|
|
68
|
+
Props of the rich-text editor of `longText` fields.
|
|
69
|
+
|
|
70
|
+
| Prop | Type | Default | Description |
|
|
71
|
+
| -------------- | ------------------------ | ------------- | --------------------------------------------------------------------------------------------------------- |
|
|
72
|
+
| `value?` | `string \| null` | — | The HTML to edit; rendered sanitised when it does not come from here. |
|
|
73
|
+
| `placeholder?` | `string` | — | Placeholder of the empty editor. |
|
|
74
|
+
| `disabled?` | `boolean` | `false` | Makes the editor read-only. |
|
|
75
|
+
| `toolbar?` | `SmartRichTextToolbar` | the full menu | The menu groups; the full menu (formatting, lists, headings, link, image, colours, alignment) by default. |
|
|
76
|
+
| `labelledBy?` | `string` | — | The id of the element labelling the editor. |
|
|
77
|
+
| `onChange?` | `(html: string) => void` | — | Called with the HTML of the content after every change. |
|
|
78
|
+
| `onBlur?` | `() => void` | — | Called when the editor loses the focus. |
|
|
79
|
+
|
|
80
|
+
### `IInputOptions`
|
|
81
|
+
|
|
82
|
+
| Field | Type | Default | Description |
|
|
83
|
+
| ---------------- | ------------------------- | -------------------------------------------- | ------------------------------------------------------------------------------------------ |
|
|
84
|
+
| `treeLevel` | `number` | required | Nesting depth (0 at the top; nested object / array forms go one deeper). |
|
|
85
|
+
| `control` | `SmartAbstractControl` | required | The control of the field (`form.controls[fieldKey]`). |
|
|
86
|
+
| `possibilities?` | `SmartPossibility[]` | — | The options of an `enum`, `radio`, `check` or `strings` field (wins over the model's own). |
|
|
87
|
+
| `component?` | `InputComponentType<any>` | `(type ? fieldComponents[type] : undefined)` | A field component used instead of the type's one. |
|
|
88
|
+
|
|
89
|
+
### `IInputFromFieldOptions<T>`
|
|
90
|
+
|
|
91
|
+
| Field | Type | Default | Description |
|
|
92
|
+
| ---------- | -------------------------------- | -------- | --------------------------------------------------------------------------- |
|
|
93
|
+
| `model` | `T` | required | The model instance the form was built from (its `@Field` metadata is read). |
|
|
94
|
+
| `fieldKey` | `string` | required | The field's key (a `<key>Confirm` key reads the options of `<key>`). |
|
|
95
|
+
| `mode?` | `'create' \| 'update' \| string` | — | The form mode whose options are merged (`create`, `update`, ...). |
|
|
96
|
+
|
|
97
|
+
### Related types
|
|
98
|
+
|
|
99
|
+
- `InputOptions<T>`: `IInputOptions & IInputFromFieldOptions<T>` — What `SmartInput` takes: `IInputOptions & IInputFromFieldOptions<T>`.
|
|
100
|
+
|
|
101
|
+
`SmartPossibility`, `SmartAbstractControl` are described in the `react-forms` and `react-provider` skills.
|
|
102
|
+
|
|
103
|
+
## Field types
|
|
104
|
+
|
|
105
|
+
`SmartInput` picks the component by `fieldOptions.type` (from `@smartsoft001/models`' `FieldType`). The standard component is the default; the preset one is what `INPUT_PRESET_FIELD_COMPONENTS` registers. Where the two behave differently, it is noted.
|
|
106
|
+
|
|
107
|
+
| `FieldType` | Standard | Preset | Notes |
|
|
108
|
+
| ------------------------------ | ------------------------------------------------------------ | ------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
109
|
+
| `text` | `SmartInputText` | `SmartInputTextPreset` | Text input. |
|
|
110
|
+
| `longText` | `SmartInputLongText` | `SmartInputLongTextPreset` | Rich-text editor (`SmartRichTextEditor`); the value is HTML, shown sanitised. |
|
|
111
|
+
| `email` | `SmartInputEmail` | `SmartInputEmailPreset` | `type="email"`; the form factory adds the `email` check. |
|
|
112
|
+
| `password` | `SmartInputPassword` | `SmartInputPasswordPreset` | With `possibilities: { strength: true }` a strength meter sets the `passwordStrength` error until the password is strong. `confirm: true` adds a `<key>Confirm` field. |
|
|
113
|
+
| `int` / `float` / `currency` | `SmartInputInt` / `SmartInputFloat` / `SmartInputCurrency` | `…Preset` | Number inputs (`step` 1 / 0.01 / 0.01); empty sets `null`. |
|
|
114
|
+
| `ints` | `SmartInputInts` | `SmartInputIntsPreset` | A list of numbers, one row each plus a row to add. |
|
|
115
|
+
| `strings` | `SmartInputStrings` | `SmartInputStringsPreset` | A list of strings (the preset as chips). |
|
|
116
|
+
| `flag` | `SmartInputFlag` | `SmartInputFlagPreset` | Checkbox bound to a boolean. |
|
|
117
|
+
| `radio` | `SmartInputRadio` | `SmartInputRadioPreset` | One radio per possibility; the value is its `id`. |
|
|
118
|
+
| `check` | `SmartInputCheck` | `SmartInputCheckPreset` | One checkbox per possibility; the value is the list of checked ids. |
|
|
119
|
+
| `enum` | `SmartInputEnum` | `SmartInputEnumPreset` | **Differs**: the standard renders checkboxes of the enum's keys (value: list of keys); the preset renders a `<select>` (value: one possibility `id`). |
|
|
120
|
+
| `date` | `SmartInputDate` | `SmartInputDatePreset` | Native `type="date"`, `YYYY-MM-DD`. |
|
|
121
|
+
| `dateWithEdit` | `SmartInputDateWithEdit` | `SmartInputDateWithEditPreset` | `SmartDateEdit` (digit inputs) bound to the control. |
|
|
122
|
+
| `dateRange` | `SmartInputDateRange` | `SmartInputDateRangePreset` | `IDateRange` value; the standard uses `SmartDateRange`, the preset two native date inputs. |
|
|
123
|
+
| `nip` | `SmartInputNip` | `SmartInputNipPreset` | Adds the NIP check (`invalidNip`) to the control. |
|
|
124
|
+
| `pesel` | `SmartInputPesel` | `SmartInputPeselPreset` | **Differs**: only the preset adds the PESEL check (`invalidPesel`). |
|
|
125
|
+
| `phoneNumber` | `SmartInputPhoneNumber` | `SmartInputPhoneNumberPreset` | `type="tel"`; the form factory adds the `phoneNumber` check. |
|
|
126
|
+
| `phoneNumberPl` | `SmartInputPhoneNumberPl` | `SmartInputPhoneNumberPlPreset` | Exactly 9 characters (`minlength` / `maxlength`); the preset shows a `+48` addon. |
|
|
127
|
+
| `color` | `SmartInputColor` | `SmartInputColorPreset` | Native colour picker with a clear button. |
|
|
128
|
+
| `file` | `SmartInputFile` | `SmartInputFilePreset` | **Differs**: the standard keeps the picked `File` as the value (no upload); the preset uploads it through the file service. |
|
|
129
|
+
| `attachment` / `pdf` / `video` | `SmartInputAttachment` / `SmartInputPdf` / `SmartInputVideo` | `…Preset` (drop zones) | Upload through the file service; the value is the attachment the API returns. |
|
|
130
|
+
| `image` | `SmartInputImage` | `SmartInputImagePreset` | `.jpg,.png,.jpeg` upload with a preview. |
|
|
131
|
+
| `logo` | `SmartInputLogo` | `SmartInputLogoPreset` | **Differs**: the standard stores a base64 `data:` URL (no upload); the preset uploads like `image`. |
|
|
132
|
+
| `object` | `SmartInputObject` | `SmartInputObjectPreset` | A nested `SmartForm` for the field's group (`classType` model), one tree level deeper. |
|
|
133
|
+
| `array` | `SmartInputArray` | `SmartInputArrayPreset` | A nested `SmartForm` per item, an add button and drag-and-drop reordering (remove button in the preset only; `possibilities.static` disables changes). |
|
|
134
|
+
| `address` | `SmartInputAddress` | `SmartInputAddressPreset` | A labelled input per part (city, zip code, street, building and flat number). |
|
|
135
|
+
|
|
136
|
+
`dateTime` has no input component: a `dateTime` field renders nothing unless you register one under `inputFieldComponents[FieldType.dateTime]` or pass `component`.
|
|
137
|
+
|
|
138
|
+
Uploading fields need a file service: give `SmartProvider` a `fileServiceConfig` (`{ apiUrl }`) or a `fileService`; without one, a picked file is not uploaded. Files go to `<apiUrl>/attachments`.
|
|
139
|
+
|
|
140
|
+
## Labels, info and messages
|
|
141
|
+
|
|
142
|
+
- The label is the label provider's (`modelLabelProvider` on `SmartProvider`) or the translation of `MODEL.<key>` (see `react-provider`).
|
|
143
|
+
- A field with `info: '...'` shows a `SmartInfo` tooltip; a field with `hide: true` (for the mode) renders nothing.
|
|
144
|
+
- Messages are shown once the control is touched, from its errors, in a fixed order: `required` (which hides `confirm`), `confirm`, `invalidNip`, `invalidUnique`, `email`, `phoneNumber`, `pesel`, `minlength`, `maxlength`, `min`, `max`, and `customMessage` (its value is shown as is). The texts come from `INPUT.ERRORS.*` translations. `getInputErrorMessages(errors, t)` returns that list for a custom message component.
|
|
145
|
+
|
|
146
|
+
## Choosing the component of a field
|
|
147
|
+
|
|
148
|
+
1. `options.component` on `SmartInput` (`SmartForm` fills it from `IFormOptions.inputComponents[fieldKey]`, and CRUD screens from `CrudFullConfig.inputComponents`);
|
|
149
|
+
2. else `inputFieldComponents[type]` registered on `SmartProvider`;
|
|
150
|
+
3. else the library's standard component for the type (`getDefaultInputFieldComponents()`).
|
|
151
|
+
|
|
152
|
+
## Usage
|
|
153
|
+
|
|
154
|
+
Rendering the inputs of a form by hand (with `useModelForm` building the form from the model):
|
|
155
|
+
|
|
156
|
+
```tsx
|
|
157
|
+
import { Field, FieldType, Model } from '@smartsoft001/models';
|
|
158
|
+
import { SmartButton, SmartInput, useModelForm } from '@smartsoft001/react';
|
|
159
|
+
|
|
160
|
+
@Model({})
|
|
161
|
+
export class Address {
|
|
162
|
+
@Field({
|
|
163
|
+
type: FieldType.text,
|
|
164
|
+
create: { required: true },
|
|
165
|
+
info: 'As on the doorbell.',
|
|
166
|
+
})
|
|
167
|
+
name!: string;
|
|
168
|
+
|
|
169
|
+
@Field({ type: FieldType.phoneNumberPl, create: true })
|
|
170
|
+
phone!: string;
|
|
171
|
+
|
|
172
|
+
@Field({
|
|
173
|
+
type: FieldType.radio,
|
|
174
|
+
create: true,
|
|
175
|
+
possibilities: { home: 'home', office: 'office' },
|
|
176
|
+
})
|
|
177
|
+
kind!: string;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const model = new Address();
|
|
181
|
+
|
|
182
|
+
export function AddressFields({
|
|
183
|
+
onSave,
|
|
184
|
+
}: {
|
|
185
|
+
onSave: (value: Address) => void;
|
|
186
|
+
}) {
|
|
187
|
+
const form = useModelForm(model, { mode: 'create' });
|
|
188
|
+
|
|
189
|
+
if (!form) return null;
|
|
190
|
+
|
|
191
|
+
return (
|
|
192
|
+
<div className="grid grid-cols-2 gap-4">
|
|
193
|
+
<SmartInput
|
|
194
|
+
options={{
|
|
195
|
+
control: form.controls['name'],
|
|
196
|
+
fieldKey: 'name',
|
|
197
|
+
model,
|
|
198
|
+
mode: 'create',
|
|
199
|
+
treeLevel: 0,
|
|
200
|
+
}}
|
|
201
|
+
/>
|
|
202
|
+
<SmartInput
|
|
203
|
+
options={{
|
|
204
|
+
control: form.controls['phone'],
|
|
205
|
+
fieldKey: 'phone',
|
|
206
|
+
model,
|
|
207
|
+
mode: 'create',
|
|
208
|
+
treeLevel: 0,
|
|
209
|
+
}}
|
|
210
|
+
/>
|
|
211
|
+
<SmartInput
|
|
212
|
+
options={{
|
|
213
|
+
control: form.controls['kind'],
|
|
214
|
+
fieldKey: 'kind',
|
|
215
|
+
model,
|
|
216
|
+
mode: 'create',
|
|
217
|
+
treeLevel: 0,
|
|
218
|
+
possibilities: [
|
|
219
|
+
{ id: 'home', text: 'Home', checked: false },
|
|
220
|
+
{ id: 'office', text: 'Office', checked: false },
|
|
221
|
+
],
|
|
222
|
+
}}
|
|
223
|
+
/>
|
|
224
|
+
<SmartButton
|
|
225
|
+
options={{
|
|
226
|
+
click: () => {
|
|
227
|
+
form.markAllAsTouched();
|
|
228
|
+
if (form.valid) onSave(form.value as Address);
|
|
229
|
+
},
|
|
230
|
+
}}
|
|
231
|
+
>
|
|
232
|
+
Save
|
|
233
|
+
</SmartButton>
|
|
234
|
+
</div>
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
The styled field set, for every form of the application:
|
|
240
|
+
|
|
241
|
+
```tsx
|
|
242
|
+
import type { ReactNode } from 'react';
|
|
243
|
+
|
|
244
|
+
import {
|
|
245
|
+
INPUT_PRESET_FIELD_COMPONENTS,
|
|
246
|
+
SmartInputErrorPreset,
|
|
247
|
+
SmartProvider,
|
|
248
|
+
} from '@smartsoft001/react';
|
|
249
|
+
|
|
250
|
+
const components = { 'input-error': SmartInputErrorPreset };
|
|
251
|
+
|
|
252
|
+
export function AppProviders({ children }: { children: ReactNode }) {
|
|
253
|
+
return (
|
|
254
|
+
<SmartProvider
|
|
255
|
+
inputFieldComponents={INPUT_PRESET_FIELD_COMPONENTS}
|
|
256
|
+
components={components}
|
|
257
|
+
fileServiceConfig={{ apiUrl: '/api' }}
|
|
258
|
+
>
|
|
259
|
+
{children}
|
|
260
|
+
</SmartProvider>
|
|
261
|
+
);
|
|
262
|
+
}
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
## Replacing the Implementation
|
|
266
|
+
|
|
267
|
+
- **Per field type, application-wide**: `inputFieldComponents` on `SmartProvider` maps a `FieldType` to a component taking `SmartInputFieldProps`. Spread the preset map to override only some types: `{ ...INPUT_PRESET_FIELD_COMPONENTS, [FieldType.text]: MyText }`.
|
|
268
|
+
- **Per field of one form**: `IFormOptions.inputComponents` (`{ [fieldKey]: Component }`), or `options.component` when you render `SmartInput` yourself.
|
|
269
|
+
- **Validation messages**: the `input-error` registry key (`components={{ 'input-error': SmartInputErrorPreset }}`); the component receives `{ errors }`.
|
|
270
|
+
- `SMART_PRESET_COMPONENTS` registers the preset field map and `SmartInputErrorPreset` together with the other presets.
|
|
271
|
+
|
|
272
|
+
### Hooks
|
|
273
|
+
|
|
274
|
+
#### `useInputFile`
|
|
275
|
+
|
|
276
|
+
The upload behaviour of the file fields: picking a file checks it against the input's `accept` list, uploads it through the file service with progress, and sets the attachment the API returns as the value. Also the options of the add, show and delete buttons the file fields render.
|
|
277
|
+
|
|
278
|
+
```ts
|
|
279
|
+
function useInputFile<T = any>({ options }: SmartInputFieldProps<T>);
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
| Returns | Type | Description |
|
|
283
|
+
| --------------------- | ------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------ |
|
|
284
|
+
| `inputRef` | `RefObject<HTMLInputElement \| null>` | Attach to the hidden file input. |
|
|
285
|
+
| `loading` | `boolean` | `true` while a file uploads. |
|
|
286
|
+
| `percent` | `number \| undefined` | Upload progress (0–100), `undefined` when unknown. |
|
|
287
|
+
| `file` | `File \| null` | The picked `File`. |
|
|
288
|
+
| `onFileChange` | `(event: ChangeEvent<HTMLInputElement>) => void` | The input's `change` handler: checks `accept`, uploads through the file service and sets the returned attachment as the value. |
|
|
289
|
+
| `addButtonOptions` | `IButtonOptions` | `IButtonOptions` of the add / change button (opens the picker). |
|
|
290
|
+
| `showButtonOptions` | `IButtonOptions` | `IButtonOptions` of the download / show button. |
|
|
291
|
+
| `deleteButtonOptions` | `IButtonOptions` | `IButtonOptions` of the delete button. |
|
|
292
|
+
|
|
293
|
+
#### `useInputPossibilities`
|
|
294
|
+
|
|
295
|
+
The options of a field with possibilities: the ones the model possibilities provider returns, asked again 500 ms after the form's value last changed so they can depend on other fields, or else the ones in the input options. `null` when there are none; the field then falls back to its model's `possibilities`.
|
|
296
|
+
|
|
297
|
+
```ts
|
|
298
|
+
function useInputPossibilities<T = any>({
|
|
299
|
+
options,
|
|
300
|
+
}: SmartInputFieldProps<T>): SmartPossibility[] | null;
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
#### `useInput`
|
|
304
|
+
|
|
305
|
+
What every field component shares: the control and its live state, whether it is required, the translated label and the handlers that bind an element to the control (a change sets the value and marks the control dirty, a blur marks it touched).
|
|
306
|
+
|
|
307
|
+
```ts
|
|
308
|
+
function useInput<T = any>({ options, fieldOptions }: SmartInputFieldProps<T>);
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
| Returns | Type | Description |
|
|
312
|
+
| --------------- | ----------------------------------- | --------------------------------------------------------------------------------- |
|
|
313
|
+
| `control` | `SmartAbstractControl<any> \| null` | The field's control (`options.control`). |
|
|
314
|
+
| `state` | `SmartControlState<any> \| null` | The control's live state (`useControlState`). |
|
|
315
|
+
| `value` | `any` | The control's value. |
|
|
316
|
+
| `required` | `boolean` | Whether the control reports `required` for an empty value (show a required mark). |
|
|
317
|
+
| `disabled` | `boolean` | Whether the control is disabled. |
|
|
318
|
+
| `label` | `string` | The field label: the label provider's, or `MODEL.<key>` translated. |
|
|
319
|
+
| `fieldKey` | `string` | `options.fieldKey`. |
|
|
320
|
+
| `model` | `T \| undefined` | `options.model`. |
|
|
321
|
+
| `mode` | `string \| undefined` | `options.mode`. |
|
|
322
|
+
| `treeLevel` | `number` | `options.treeLevel` (0 by default). |
|
|
323
|
+
| `fieldOptions` | `IFieldOptions \| undefined` | The merged field options. |
|
|
324
|
+
| `setValue` | `(value: unknown) => void` | Sets the value as the user would: the control becomes dirty. |
|
|
325
|
+
| `markAsTouched` | `() => void \| undefined` | Marks the control as touched, as leaving the field does. |
|
|
326
|
+
| `autoFocus` | `boolean` | Autofocus as `fieldOptions.focused` asks. |
|
|
327
|
+
|
|
328
|
+
A custom field component takes `SmartInputFieldProps` and binds an element to the control through `useInput`:
|
|
329
|
+
|
|
330
|
+
```tsx
|
|
331
|
+
import type { ReactNode } from 'react';
|
|
332
|
+
|
|
333
|
+
import { FieldType } from '@smartsoft001/models';
|
|
334
|
+
import {
|
|
335
|
+
INPUT_PRESET_FIELD_COMPONENTS,
|
|
336
|
+
SmartInputFieldProps,
|
|
337
|
+
SmartProvider,
|
|
338
|
+
useInput,
|
|
339
|
+
} from '@smartsoft001/react';
|
|
340
|
+
|
|
341
|
+
export function SlugInput(props: SmartInputFieldProps) {
|
|
342
|
+
const {
|
|
343
|
+
value,
|
|
344
|
+
label,
|
|
345
|
+
required,
|
|
346
|
+
disabled,
|
|
347
|
+
fieldKey,
|
|
348
|
+
autoFocus,
|
|
349
|
+
setValue,
|
|
350
|
+
markAsTouched,
|
|
351
|
+
} = useInput(props);
|
|
352
|
+
|
|
353
|
+
return (
|
|
354
|
+
<label className="block">
|
|
355
|
+
<span>
|
|
356
|
+
{label}
|
|
357
|
+
{required && ' *'}
|
|
358
|
+
</span>
|
|
359
|
+
<input
|
|
360
|
+
id={fieldKey}
|
|
361
|
+
className={props.className}
|
|
362
|
+
value={value ?? ''}
|
|
363
|
+
disabled={disabled}
|
|
364
|
+
autoFocus={autoFocus}
|
|
365
|
+
onChange={(event) =>
|
|
366
|
+
setValue(
|
|
367
|
+
event.target.value.toLowerCase().replace(/[^a-z0-9-]+/g, '-'),
|
|
368
|
+
)
|
|
369
|
+
}
|
|
370
|
+
onBlur={markAsTouched}
|
|
371
|
+
/>
|
|
372
|
+
</label>
|
|
373
|
+
);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
const inputFieldComponents = {
|
|
377
|
+
...INPUT_PRESET_FIELD_COMPONENTS,
|
|
378
|
+
[FieldType.text]: SlugInput,
|
|
379
|
+
};
|
|
380
|
+
|
|
381
|
+
export function AppProviders({ children }: { children: ReactNode }) {
|
|
382
|
+
return (
|
|
383
|
+
<SmartProvider inputFieldComponents={inputFieldComponents}>
|
|
384
|
+
{children}
|
|
385
|
+
</SmartProvider>
|
|
386
|
+
);
|
|
387
|
+
}
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
`useInputPossibilities` gives a custom `radio` / `check` / `enum` component the options from the possibilities provider or the input options, and `useInputFile` the upload logic of the file fields.
|
|
391
|
+
|
|
392
|
+
## Styling
|
|
393
|
+
|
|
394
|
+
- Standard field components are lightly styled Tailwind inputs with `smart:dark:` variants; the preset set is the Preline look. `className` reaches the field component (usually its input).
|
|
395
|
+
|
|
396
|
+
## File Locations
|
|
397
|
+
|
|
398
|
+
Source: `packages/shared/react/src/lib/components/input/` in the smartsoft001 repository.
|
|
399
|
+
|
|
400
|
+
- `input.tsx`, `input.types.ts`: `SmartInput`, `SmartInputProps`, `SmartInputFieldProps`
|
|
401
|
+
- `default-field-components.ts`, `preset-fields.ts`: the standard and preset field maps
|
|
402
|
+
- `field-options.ts`: `resolveInputFieldOptions`
|
|
403
|
+
- `base/`: `useInput`, `useInputPossibilities`, `useInputFile`
|
|
404
|
+
- `<type>/`: the field components of each type (`text/`, `enum/`, `object/`, `array/`, ...), each with a `preset/` folder and, where they have one, a `use-input-<type>.ts` hook
|
|
405
|
+
- `error/`: `SmartInputError`, `SmartInputErrorPreset`, `getInputErrorMessages`
|
|
406
|
+
- `input.stories.tsx`: Storybook stories
|