@smartsoft001/claude-plugins 2.194.0 → 2.195.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,228 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: react-components-command-palette
|
|
3
|
+
description: SmartCommandPalette React component API (@smartsoft001/react) — searchable command dialog with controlled/uncontrolled open and query, onRunCommand, eight visual variants (groups, icons, images, preview, footer), the 'command-palette' registry key, SmartCommandPalettePreset and useCommandPalette.
|
|
4
|
+
user-invocable: false
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Command Palette (`SmartCommandPalette`)
|
|
8
|
+
|
|
9
|
+
`SmartCommandPalette` is a search dialog over a list of commands: the user types, the commands are filtered by a case-insensitive substring of their `label`, and clicking one reports `onRunCommand({ commandId })` and closes the palette. Both the open state (`open` / `defaultOpen` / `onOpenChange`) and the search text (`query` / `defaultQuery` / `onQueryChange`) can be controlled or left to the component. `SmartCommandPaletteStandard` is a native `<dialog>` with a `listbox`; `SmartCommandPalettePreset` adds the visual variants of `options.variant`.
|
|
10
|
+
|
|
11
|
+
## When to Use This Skill
|
|
12
|
+
|
|
13
|
+
- A Ctrl+K / quick-search dialog listing actions or pages
|
|
14
|
+
- Running an action by id when a command is chosen (`onRunCommand`)
|
|
15
|
+
- Grouped results, icons, images, a preview pane or a footer (preset variants)
|
|
16
|
+
- Restyling every palette (the `command-palette` registry key)
|
|
17
|
+
|
|
18
|
+
## Exports
|
|
19
|
+
|
|
20
|
+
All from `@smartsoft001/react`.
|
|
21
|
+
|
|
22
|
+
| Export | Kind | What it is |
|
|
23
|
+
| ----------------------------- | --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
24
|
+
| `SmartCommandPalette` | component | Renders the implementation registered as `components['command-palette']` on `SmartProvider`, `SmartCommandPaletteStandard` by default. |
|
|
25
|
+
| `SmartCommandPalettePreset` | component | Styled command-palette variation (preset). |
|
|
26
|
+
| `SmartCommandPaletteStandard` | component | The default command palette: a native `<dialog>` with a search input and a `listbox` of the filtered commands. |
|
|
27
|
+
| `useCommandPalette` | hook | The behaviour every command-palette variant shares: the `open` and `query` models (controlled or uncontrolled), the commands filtered by a case-insensitive label substring, and `selectCommand`, which reports the command through `onRunCommand` and closes the palette. |
|
|
28
|
+
|
|
29
|
+
The preset's class helpers (`getCommandPaletteDialogClasses`, `getCommandPaletteListClasses`, `getCommandPaletteItemClasses`, `COMMAND_PALETTE_SEARCH_WRAP`, `COMMAND_PALETTE_SEARCH_ICON`, `COMMAND_PALETTE_SEARCH`, `COMMAND_PALETTE_ITEM_ICON`, `COMMAND_PALETTE_ITEM_IMAGE`, `COMMAND_PALETTE_ITEM_LABEL`, `COMMAND_PALETTE_GROUP`, `COMMAND_PALETTE_EMPTY`, `COMMAND_PALETTE_FOOTER`, `COMMAND_PALETTE_PREVIEW_LAYOUT`, `COMMAND_PALETTE_PREVIEW`) are exported too, for a custom implementation that wants the preset look.
|
|
30
|
+
|
|
31
|
+
## Props and Types
|
|
32
|
+
|
|
33
|
+
### `SmartCommandPaletteProps`
|
|
34
|
+
|
|
35
|
+
| Prop | Type | Default | Description |
|
|
36
|
+
| ---------------- | -------------------------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
37
|
+
| `commands?` | `ICommand[]` | `[]` | The commands to search. |
|
|
38
|
+
| `open?` | `boolean` | — | Whether the palette is open. Controlled when set; leave it `undefined` to let the palette keep its own state, starting from `defaultOpen`. |
|
|
39
|
+
| `defaultOpen?` | `boolean` | `false` | Initial open state when uncontrolled. |
|
|
40
|
+
| `onOpenChange?` | `(open: boolean) => void` | — | Called when the palette opens or closes (also after a command runs). |
|
|
41
|
+
| `query?` | `string` | — | The search text. Controlled when set; leave it `undefined` to let the palette keep its own state, starting from `defaultQuery`. |
|
|
42
|
+
| `defaultQuery?` | `string` | `''` | Initial search text when uncontrolled. |
|
|
43
|
+
| `onQueryChange?` | `(query: string) => void` | — | Called with the new search text. |
|
|
44
|
+
| `options?` | `ICommandPaletteOptions` | — | Variant and texts. |
|
|
45
|
+
| `className?` | `string` | — | Classes on the dialog. |
|
|
46
|
+
| `onRunCommand?` | `(event: ICommandPaletteRunCommand) => void` | — | Called with the id of the clicked command, before the palette closes. |
|
|
47
|
+
|
|
48
|
+
### `ICommandPaletteOptions`
|
|
49
|
+
|
|
50
|
+
| Field | Type | Default | Description |
|
|
51
|
+
| -------------- | ---------------------------- | -------------- | ----------------------------------------- |
|
|
52
|
+
| `variant?` | `SmartCommandPaletteVariant` | `'simple'` | The preset look; the standard ignores it. |
|
|
53
|
+
| `placeholder?` | `string` | — | Placeholder of the search input. |
|
|
54
|
+
| `emptyText?` | `string` | `'No results'` | Shown when nothing matches. |
|
|
55
|
+
| `ariaLabel?` | `string` | — | Accessible name of the dialog. |
|
|
56
|
+
|
|
57
|
+
### `ICommandPaletteRunCommand`
|
|
58
|
+
|
|
59
|
+
Passed to `onRunCommand` when a command is chosen.
|
|
60
|
+
|
|
61
|
+
| Field | Type | Default | Description |
|
|
62
|
+
| ----------- | -------- | -------- | ------------------------------- |
|
|
63
|
+
| `commandId` | `string` | required | The `id` of the chosen command. |
|
|
64
|
+
|
|
65
|
+
### `ICommand`
|
|
66
|
+
|
|
67
|
+
| Field | Type | Default | Description |
|
|
68
|
+
| -------------- | -------- | -------- | ----------------------------------------------------------------------------------- |
|
|
69
|
+
| `id` | `string` | required | Reported as `commandId`. |
|
|
70
|
+
| `label` | `string` | required | Searched and shown. |
|
|
71
|
+
| `icon?` | `string` | — | Shown by the preset's `with-icons` variant. |
|
|
72
|
+
| `group?` | `string` | — | Group header in the preset's `with-groups` variant. |
|
|
73
|
+
| `href?` | `string` | — | Carried for your own use; no variant navigates to it (handle it in `onRunCommand`). |
|
|
74
|
+
| `description?` | `string` | — | Secondary text (e.g. in the preview pane). |
|
|
75
|
+
| `imageUrl?` | `string` | — | Shown by the preset's `with-images` variant. |
|
|
76
|
+
|
|
77
|
+
### Related types
|
|
78
|
+
|
|
79
|
+
- `SmartCommandPaletteVariant`: `'simple' \| 'with-padding' \| 'with-preview' \| 'with-images' \| 'with-icons' \| 'semi-transparent' \| 'with-groups' \| 'with-footer'`
|
|
80
|
+
|
|
81
|
+
## Usage
|
|
82
|
+
|
|
83
|
+
```tsx
|
|
84
|
+
import { useEffect, useState } from 'react';
|
|
85
|
+
|
|
86
|
+
import {
|
|
87
|
+
ICommand,
|
|
88
|
+
SmartCommandPalettePreset,
|
|
89
|
+
useNavigation,
|
|
90
|
+
} from '@smartsoft001/react';
|
|
91
|
+
|
|
92
|
+
const COMMANDS: ICommand[] = [
|
|
93
|
+
{ id: 'notes', label: 'Open notes', group: 'Pages', href: '/notes' },
|
|
94
|
+
{ id: 'settings', label: 'Open settings', group: 'Pages', href: '/settings' },
|
|
95
|
+
{ id: 'new-note', label: 'Create a note', group: 'Actions' },
|
|
96
|
+
];
|
|
97
|
+
|
|
98
|
+
export function QuickSearch({ onNewNote }: { onNewNote: () => void }) {
|
|
99
|
+
const [open, setOpen] = useState(false);
|
|
100
|
+
const navigation = useNavigation();
|
|
101
|
+
|
|
102
|
+
useEffect(() => {
|
|
103
|
+
const onKey = (event: KeyboardEvent) => {
|
|
104
|
+
if ((event.metaKey || event.ctrlKey) && event.key === 'k') setOpen(true);
|
|
105
|
+
};
|
|
106
|
+
window.addEventListener('keydown', onKey);
|
|
107
|
+
return () => window.removeEventListener('keydown', onKey);
|
|
108
|
+
}, []);
|
|
109
|
+
|
|
110
|
+
return (
|
|
111
|
+
<SmartCommandPalettePreset
|
|
112
|
+
commands={COMMANDS}
|
|
113
|
+
open={open}
|
|
114
|
+
onOpenChange={setOpen}
|
|
115
|
+
options={{ variant: 'with-groups', placeholder: 'Search…' }}
|
|
116
|
+
onRunCommand={({ commandId }) => {
|
|
117
|
+
const command = COMMANDS.find((c) => c.id === commandId);
|
|
118
|
+
if (command?.href) navigation.navigate(command.href);
|
|
119
|
+
else if (commandId === 'new-note') onNewNote();
|
|
120
|
+
}}
|
|
121
|
+
/>
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Replacing the Implementation
|
|
127
|
+
|
|
128
|
+
`SmartCommandPalette` renders the component registered under the `'command-palette'` key of `SmartProvider`'s `components`, and `SmartCommandPaletteStandard` when nothing is registered there. Every `SmartCommandPalette` below the provider then renders the registered component, which receives the same props.
|
|
129
|
+
|
|
130
|
+
```tsx
|
|
131
|
+
import type { ReactNode } from 'react';
|
|
132
|
+
|
|
133
|
+
import { SmartProvider, SmartCommandPalettePreset } from '@smartsoft001/react';
|
|
134
|
+
|
|
135
|
+
// A module constant: a new object on every render would change the context.
|
|
136
|
+
const components = { 'command-palette': SmartCommandPalettePreset };
|
|
137
|
+
|
|
138
|
+
export function AppProviders({ children }: { children: ReactNode }) {
|
|
139
|
+
return <SmartProvider components={components}>{children}</SmartProvider>;
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
`SmartCommandPalettePreset` is the styled (preset) implementation: register it as above, render it directly in place of `SmartCommandPalette`, 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.
|
|
144
|
+
|
|
145
|
+
### The `useCommandPalette` hook
|
|
146
|
+
|
|
147
|
+
The behaviour every command-palette variant shares: the `open` and `query` models (controlled or uncontrolled), the commands filtered by a case-insensitive label substring, and `selectCommand`, which reports the command through `onRunCommand` and closes the palette.
|
|
148
|
+
|
|
149
|
+
```ts
|
|
150
|
+
function useCommandPalette({
|
|
151
|
+
commands = [],
|
|
152
|
+
open,
|
|
153
|
+
defaultOpen = false,
|
|
154
|
+
onOpenChange,
|
|
155
|
+
query,
|
|
156
|
+
defaultQuery = '',
|
|
157
|
+
onQueryChange,
|
|
158
|
+
onRunCommand,
|
|
159
|
+
}: SmartCommandPaletteProps);
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
| Returns | Type | Description |
|
|
163
|
+
| ------------------ | ----------------------------- | --------------------------------------------------------------- |
|
|
164
|
+
| `open` | `boolean` | The open state (controlled or internal). |
|
|
165
|
+
| `query` | `string` | The search text (controlled or internal). |
|
|
166
|
+
| `setQuery` | `(next: string) => void` | Sets the search text and calls `onQueryChange`. |
|
|
167
|
+
| `filteredCommands` | `ICommand[]` | The commands whose label contains the query (case-insensitive). |
|
|
168
|
+
| `selectCommand` | `(commandId: string) => void` | Calls `onRunCommand({ commandId })`, then closes the palette. |
|
|
169
|
+
| `close` | `() => void` | Closes the palette and calls `onOpenChange(false)`. |
|
|
170
|
+
|
|
171
|
+
```tsx
|
|
172
|
+
import {
|
|
173
|
+
SmartCommandPaletteProps,
|
|
174
|
+
useCommandPalette,
|
|
175
|
+
} from '@smartsoft001/react';
|
|
176
|
+
|
|
177
|
+
export function InlineCommandList(props: SmartCommandPaletteProps) {
|
|
178
|
+
const { open, query, setQuery, filteredCommands, selectCommand } =
|
|
179
|
+
useCommandPalette(props);
|
|
180
|
+
|
|
181
|
+
if (!open) return null;
|
|
182
|
+
|
|
183
|
+
return (
|
|
184
|
+
<div
|
|
185
|
+
role="dialog"
|
|
186
|
+
aria-label={props.options?.ariaLabel}
|
|
187
|
+
className={props.className}
|
|
188
|
+
>
|
|
189
|
+
<input
|
|
190
|
+
value={query}
|
|
191
|
+
placeholder={props.options?.placeholder}
|
|
192
|
+
onChange={(event) => setQuery(event.target.value)}
|
|
193
|
+
/>
|
|
194
|
+
<ul role="listbox">
|
|
195
|
+
{filteredCommands.map((command) => (
|
|
196
|
+
<li
|
|
197
|
+
key={command.id}
|
|
198
|
+
role="option"
|
|
199
|
+
aria-selected={false}
|
|
200
|
+
onClick={() => selectCommand(command.id)}
|
|
201
|
+
>
|
|
202
|
+
{command.label}
|
|
203
|
+
</li>
|
|
204
|
+
))}
|
|
205
|
+
</ul>
|
|
206
|
+
{filteredCommands.length === 0 && (
|
|
207
|
+
<p>{props.options?.emptyText ?? 'No results'}</p>
|
|
208
|
+
)}
|
|
209
|
+
</div>
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
## Styling
|
|
215
|
+
|
|
216
|
+
- The standard palette is a native `<dialog>`: Escape (the dialog's `close` event) closes it.
|
|
217
|
+
- `SmartCommandPalettePreset` renders the variants `simple`, `with-padding`, `with-preview`, `with-images`, `with-icons`, `semi-transparent`, `with-groups` and `with-footer`, with `smart:dark:` variants.
|
|
218
|
+
|
|
219
|
+
## File Locations
|
|
220
|
+
|
|
221
|
+
Source: `packages/shared/react/src/lib/components/command-palette/` in the smartsoft001 repository.
|
|
222
|
+
|
|
223
|
+
- `command-palette.tsx`: `SmartCommandPalette`
|
|
224
|
+
- `command-palette.types.ts`: `ICommandPaletteRunCommand`, `SmartCommandPaletteProps`
|
|
225
|
+
- `preset/command-palette-preset.tsx`: `SmartCommandPalettePreset`
|
|
226
|
+
- `standard/command-palette-standard.tsx`: `SmartCommandPaletteStandard`
|
|
227
|
+
- `use-command-palette.ts`: `useCommandPalette`
|
|
228
|
+
- `command-palette.stories.tsx`: Storybook stories
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: react-components-container
|
|
3
|
+
description: SmartContainer React component API (@smartsoft001/react) — page-width wrapper with full-width/constrained/container modes, padding and narrow options, the 'container' registry key and SmartContainerPreset (the standard is a neutral div with data attributes).
|
|
4
|
+
user-invocable: false
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Container (`SmartContainer`)
|
|
8
|
+
|
|
9
|
+
`SmartContainer` wraps page content to control its width and horizontal padding. `options.mode` (`full-width`, `constrained`, `container`), `options.padding` (`none`, `mobile`, `always`) and `options.narrow` describe the layout. `SmartContainerStandard` (the default) is a **neutral `div`** that only exposes `data-mode` / `data-padding`; `SmartContainerPreset` maps the options to real Tailwind layout utilities.
|
|
10
|
+
|
|
11
|
+
## When to Use This Skill
|
|
12
|
+
|
|
13
|
+
- Constraining page content to a readable max width, centred, with responsive padding
|
|
14
|
+
- A narrow column (`options.narrow`) for forms or articles
|
|
15
|
+
- Restyling every container (the `container` registry key)
|
|
16
|
+
|
|
17
|
+
## Exports
|
|
18
|
+
|
|
19
|
+
All from `@smartsoft001/react`.
|
|
20
|
+
|
|
21
|
+
| Export | Kind | What it is |
|
|
22
|
+
| ------------------------ | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
23
|
+
| `SmartContainer` | component | Renders the implementation registered as `components.container` on `SmartProvider`, `SmartContainerStandard` by default. |
|
|
24
|
+
| `SmartContainerPreset` | component | Styled container variation (preset). |
|
|
25
|
+
| `SmartContainerStandard` | component | The default container rendering: a neutral `div` exposing `options.mode` / `options.padding` as `data-mode` / `data-padding` for the application's own styling. |
|
|
26
|
+
|
|
27
|
+
The preset's class helpers (`getContainerClasses`) are exported too, for a custom implementation that wants the preset look.
|
|
28
|
+
|
|
29
|
+
## Props and Types
|
|
30
|
+
|
|
31
|
+
### `SmartContainerProps`
|
|
32
|
+
|
|
33
|
+
| Prop | Type | Default | Description |
|
|
34
|
+
| ------------ | ------------------- | ------- | ------------------------------------ |
|
|
35
|
+
| `options?` | `IContainerOptions` | — | Width mode, padding and narrow flag. |
|
|
36
|
+
| `className?` | `string` | — | Classes on the container `div`. |
|
|
37
|
+
| `children?` | `ReactNode` | — | The content. |
|
|
38
|
+
|
|
39
|
+
### `IContainerOptions`
|
|
40
|
+
|
|
41
|
+
| Field | Type | Default | Description |
|
|
42
|
+
| ---------- | ---------------------------------------------- | ------- | -------------------------------------------------------------------------------------------------------------------------------- |
|
|
43
|
+
| `mode?` | `'full-width' \| 'constrained' \| 'container'` | — | In the preset: `container` centres at `max-w-7xl`, `constrained` at `max-w-5xl`, `full-width` (also when unset) spans the width. |
|
|
44
|
+
| `padding?` | `'none' \| 'mobile' \| 'always'` | — | In the preset: `always` pads at every breakpoint (`px-4` / `sm:px-6` / `lg:px-8`), `mobile` only below `sm`, `none` not at all. |
|
|
45
|
+
| `narrow?` | `boolean` | — | In the preset: centres at `max-w-3xl`, whatever the mode. |
|
|
46
|
+
|
|
47
|
+
## Usage
|
|
48
|
+
|
|
49
|
+
```tsx
|
|
50
|
+
import type { ReactNode } from 'react';
|
|
51
|
+
|
|
52
|
+
import { SmartContainer, SmartContainerPreset } from '@smartsoft001/react';
|
|
53
|
+
|
|
54
|
+
export function ArticleLayout({ children }: { children: ReactNode }) {
|
|
55
|
+
return (
|
|
56
|
+
<SmartContainerPreset
|
|
57
|
+
options={{ mode: 'constrained', padding: 'always', narrow: true }}
|
|
58
|
+
>
|
|
59
|
+
{children}
|
|
60
|
+
</SmartContainerPreset>
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Through the registry: a neutral div with data-mode / data-padding unless a preset is registered.
|
|
65
|
+
export function Section({ children }: { children: ReactNode }) {
|
|
66
|
+
return (
|
|
67
|
+
<SmartContainer options={{ mode: 'container', padding: 'mobile' }}>
|
|
68
|
+
{children}
|
|
69
|
+
</SmartContainer>
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Replacing the Implementation
|
|
75
|
+
|
|
76
|
+
`SmartContainer` renders the component registered under the `'container'` key of `SmartProvider`'s `components`, and `SmartContainerStandard` when nothing is registered there. Every `SmartContainer` below the provider then renders the registered component, which receives the same props.
|
|
77
|
+
|
|
78
|
+
```tsx
|
|
79
|
+
import type { ReactNode } from 'react';
|
|
80
|
+
|
|
81
|
+
import { SmartProvider, SmartContainerPreset } from '@smartsoft001/react';
|
|
82
|
+
|
|
83
|
+
// A module constant: a new object on every render would change the context.
|
|
84
|
+
const components = { container: SmartContainerPreset };
|
|
85
|
+
|
|
86
|
+
export function AppProviders({ children }: { children: ReactNode }) {
|
|
87
|
+
return <SmartProvider components={components}>{children}</SmartProvider>;
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
`SmartContainerPreset` is the styled (preset) implementation: register it as above, render it directly in place of `SmartContainer`, 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.
|
|
92
|
+
|
|
93
|
+
```tsx
|
|
94
|
+
import { SmartContainerProps } from '@smartsoft001/react';
|
|
95
|
+
|
|
96
|
+
export function MaxWidthContainer({
|
|
97
|
+
options,
|
|
98
|
+
className,
|
|
99
|
+
children,
|
|
100
|
+
}: SmartContainerProps) {
|
|
101
|
+
// The application's own classes: the library's compiled stylesheet is not built from your sources.
|
|
102
|
+
const width = options?.narrow
|
|
103
|
+
? 'max-w-3xl'
|
|
104
|
+
: options?.mode === 'full-width'
|
|
105
|
+
? ''
|
|
106
|
+
: 'max-w-7xl';
|
|
107
|
+
const padding = options?.padding && options.padding !== 'none' ? 'px-4' : '';
|
|
108
|
+
|
|
109
|
+
return (
|
|
110
|
+
<div
|
|
111
|
+
className={['mx-auto', width, padding, className]
|
|
112
|
+
.filter(Boolean)
|
|
113
|
+
.join(' ')}
|
|
114
|
+
>
|
|
115
|
+
{children}
|
|
116
|
+
</div>
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Styling
|
|
122
|
+
|
|
123
|
+
- With the default `SmartContainerStandard`, style `[data-mode]` / `[data-padding]` yourself, or register `SmartContainerPreset`.
|
|
124
|
+
- `className` is appended to the container.
|
|
125
|
+
|
|
126
|
+
## File Locations
|
|
127
|
+
|
|
128
|
+
Source: `packages/shared/react/src/lib/components/container/` in the smartsoft001 repository.
|
|
129
|
+
|
|
130
|
+
- `container.tsx`: `SmartContainer`
|
|
131
|
+
- `container.types.ts`: `SmartContainerProps`
|
|
132
|
+
- `preset/container-preset.tsx`: `SmartContainerPreset`
|
|
133
|
+
- `standard/container-standard.tsx`: `SmartContainerStandard`
|
|
134
|
+
- `container.stories.tsx`: Storybook stories
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: react-components-date-edit
|
|
3
|
+
description: SmartDateEdit React component API (@smartsoft001/react) — YYYY-MM-DD date editor (eight digit inputs DD-MM-RRRR, or the preset calendar popover via variant="preset"), value/onValueChange or a form control, onValidChange, and the useDateEdit hook (value/setValue, digits, validity).
|
|
4
|
+
user-invocable: false
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Date Edit (`SmartDateEdit`)
|
|
8
|
+
|
|
9
|
+
`SmartDateEdit` edits one date stored as a `YYYY-MM-DD` string. Its `variant` picks the rendering: `standard` (default) is eight single-digit inputs spelling DD-MM-RRRR where every digit moves the focus on, `preset` is a read-only trigger opening a calendar popover with month navigation and month / year selects. Bind it with `value` + `onValueChange` (or `defaultValue` uncontrolled), or pass a form `control`. Every edit is emitted, even an invalid date; `onValidChange` reports whether the edited date is valid.
|
|
10
|
+
|
|
11
|
+
## When to Use This Skill
|
|
12
|
+
|
|
13
|
+
- Entering a date as digits (birth date, document date) or picking it from a calendar popover
|
|
14
|
+
- Binding a date field to a `SmartFormControl` (`control`)
|
|
15
|
+
- Knowing whether the typed date is valid (`onValidChange`)
|
|
16
|
+
- Building a date editor of your own on `useDateEdit`
|
|
17
|
+
|
|
18
|
+
## Exports
|
|
19
|
+
|
|
20
|
+
All from `@smartsoft001/react`.
|
|
21
|
+
|
|
22
|
+
| Export | Kind | What it is |
|
|
23
|
+
| ------------------------ | --------- | ---------------------------------------------------------------------------------------------------------------------------- |
|
|
24
|
+
| `SmartDateEdit` | component | The date editor in the `variant` rendering (`standard`, eight digit inputs, by default; or `preset`, a calendar popover). |
|
|
25
|
+
| `SmartDateEditPreset` | component | Styled date-edit variation (preset) — a Preline single datepicker. |
|
|
26
|
+
| `SmartDateEditStandard` | component | The default date-edit rendering: eight single-digit inputs spelling DD-MM-RRRR. |
|
|
27
|
+
| `useDateEdit` | hook | The behaviour every date-edit variant shares: the `YYYY-MM-DD` value, its single digits and the validity of the edited date. |
|
|
28
|
+
| `DATE_EDIT_DEFAULT_DATE` | const | `'2001-01-01'`, the value an uncontrolled editor without `defaultValue` starts from. |
|
|
29
|
+
|
|
30
|
+
The preset's class helpers (`getDateEditDayClasses`, `DATE_EDIT_TRIGGER_WRAPPER`, `DATE_EDIT_TRIGGER_INPUT`, `DATE_EDIT_TRIGGER_INVALID`, `DATE_EDIT_TRIGGER_ICON`, `DATE_EDIT_POPOVER`, `DATE_EDIT_NAV_BUTTON`, `DATE_EDIT_SELECT`, `DATE_EDIT_WEEKDAY`) are exported too, for a custom implementation that wants the preset look.
|
|
31
|
+
|
|
32
|
+
## Props and Types
|
|
33
|
+
|
|
34
|
+
### `SmartDateEditProps`
|
|
35
|
+
|
|
36
|
+
Props of `<SmartDateEdit>`. Extends `SmartDateEditVariantProps`.
|
|
37
|
+
|
|
38
|
+
| Prop | Type | Default | Description |
|
|
39
|
+
| ---------- | ---------------------- | ------------ | ------------------------------------------------------------------------------------------------------------------------ |
|
|
40
|
+
| `variant?` | `DateEditVariantName` | `'standard'` | `standard` (digit inputs) or `preset` (calendar popover). |
|
|
41
|
+
| `control?` | `SmartAbstractControl` | — | Binds the date to a form control: the control's value is shown, an edit sets it and marks the control dirty and touched. |
|
|
42
|
+
|
|
43
|
+
### `SmartDateEditVariantProps`
|
|
44
|
+
|
|
45
|
+
Props of the date-edit variants: the date as a controlled `value` + `onValueChange` pair, or kept internally from `defaultValue`.
|
|
46
|
+
|
|
47
|
+
| Prop | Type | Default | Description |
|
|
48
|
+
| ---------------- | -------------------------- | ----------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
49
|
+
| `value?` | `string \| null` | — | The date as `YYYY-MM-DD`. `undefined` leaves the component uncontrolled, starting from `defaultValue`; `null` is an empty controlled value. |
|
|
50
|
+
| `defaultValue?` | `string \| null` | `'2001-01-01'` (`DATE_EDIT_DEFAULT_DATE`) | The initial value when uncontrolled (`useDateEdit` falls back to `DATE_EDIT_DEFAULT_DATE`, `'2001-01-01'`). |
|
|
51
|
+
| `onValueChange?` | `(value: string) => void` | — | Emits the edited date, even an invalid one. |
|
|
52
|
+
| `onValidChange?` | `(valid: boolean) => void` | — | Emits whether the edited date is valid. |
|
|
53
|
+
| `className?` | `string` | — | Classes on the root element. |
|
|
54
|
+
|
|
55
|
+
### `DateEditDay`
|
|
56
|
+
|
|
57
|
+
A cell of the preset's calendar grid.
|
|
58
|
+
|
|
59
|
+
| Field | Type | Default | Description |
|
|
60
|
+
| ---------- | --------- | -------- | ----------------------------------- |
|
|
61
|
+
| `date` | `string` | required | The day as `YYYY-MM-DD`. |
|
|
62
|
+
| `day` | `number` | required | Day of the month. |
|
|
63
|
+
| `inMonth` | `boolean` | required | The day belongs to the shown month. |
|
|
64
|
+
| `selected` | `boolean` | required | The day is the current value. |
|
|
65
|
+
|
|
66
|
+
### Related types
|
|
67
|
+
|
|
68
|
+
- `DateEditVariantName`: `'standard' \| 'preset'` — The renderings `SmartDateEdit` can pick.
|
|
69
|
+
|
|
70
|
+
`SmartAbstractControl` is described in the `react-forms` and `react-provider` skills.
|
|
71
|
+
|
|
72
|
+
## Binding
|
|
73
|
+
|
|
74
|
+
- **Controlled**: `value` (a `YYYY-MM-DD` string, `null` for empty) and `onValueChange`. A new `value` from the parent always wins, so resetting the parent's state also resets the editor.
|
|
75
|
+
- **Uncontrolled**: leave `value` undefined; the editor starts from `defaultValue`.
|
|
76
|
+
- **Form control**: `control={someControl}` shows the control's value; every edit sets it, marks the control dirty and touched, and still calls `onValueChange`.
|
|
77
|
+
- `onValueChange` receives the edited text even when it is not a valid date; use `onValidChange` to know.
|
|
78
|
+
|
|
79
|
+
## Usage
|
|
80
|
+
|
|
81
|
+
```tsx
|
|
82
|
+
import { useState } from 'react';
|
|
83
|
+
|
|
84
|
+
import {
|
|
85
|
+
SmartDateEdit,
|
|
86
|
+
SmartFormControl,
|
|
87
|
+
SmartValidators,
|
|
88
|
+
} from '@smartsoft001/react';
|
|
89
|
+
|
|
90
|
+
const birthDate = new SmartFormControl<string | null>(
|
|
91
|
+
null,
|
|
92
|
+
SmartValidators.required,
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
export function DateFields() {
|
|
96
|
+
const [date, setDate] = useState('2026-04-07');
|
|
97
|
+
const [valid, setValid] = useState(true);
|
|
98
|
+
|
|
99
|
+
return (
|
|
100
|
+
<>
|
|
101
|
+
{/* Eight digit inputs, controlled. */}
|
|
102
|
+
<SmartDateEdit
|
|
103
|
+
value={date}
|
|
104
|
+
onValueChange={setDate}
|
|
105
|
+
onValidChange={setValid}
|
|
106
|
+
/>
|
|
107
|
+
{!valid && <p>Not a valid date.</p>}
|
|
108
|
+
|
|
109
|
+
{/* Calendar popover. */}
|
|
110
|
+
<SmartDateEdit variant="preset" value={date} onValueChange={setDate} />
|
|
111
|
+
|
|
112
|
+
{/* Bound to a form control. */}
|
|
113
|
+
<SmartDateEdit control={birthDate} />
|
|
114
|
+
</>
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Replacing the Implementation
|
|
120
|
+
|
|
121
|
+
`SmartDateEdit` has no `SmartProvider` registry key: the `variant` prop picks `SmartDateEditStandard` or `SmartDateEditPreset`, and both can be rendered directly with `SmartDateEditVariantProps`. A form's `date` / `dateWithEdit` fields render it through the input field components (see `react-components-input`). For another look, write a component on `useDateEdit` and render it in place of `SmartDateEdit`.
|
|
122
|
+
|
|
123
|
+
### The `useDateEdit` hook
|
|
124
|
+
|
|
125
|
+
The behaviour every date-edit variant shares: the `YYYY-MM-DD` value, its single digits and the validity of the edited date.
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
function useDateEdit({
|
|
129
|
+
value,
|
|
130
|
+
defaultValue = DATE_EDIT_DEFAULT_DATE,
|
|
131
|
+
onValueChange,
|
|
132
|
+
onValidChange,
|
|
133
|
+
}: SmartDateEditVariantProps);
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
| Returns | Type | Description |
|
|
137
|
+
| -------------- | -------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
|
|
138
|
+
| `value` | `string \| null` | The current `YYYY-MM-DD` value (controlled or internal), `null` when empty. |
|
|
139
|
+
| `setValue` | `(next: string) => void` | Sets the value and calls `onValueChange` (no call when unchanged). |
|
|
140
|
+
| `validDate` | `boolean` | Whether the current value is a valid date. |
|
|
141
|
+
| `setValidDate` | `Dispatch<SetStateAction<boolean>>` | Sets the validity flag (also reported through `onValidChange`). |
|
|
142
|
+
| `setValueAt` | `(val: string \| number \| null, index: number) => void` | Writes one digit at a position of the DD-MM-RRRR mask. |
|
|
143
|
+
| `moveTo` | `(event: KeyboardEvent<HTMLInputElement>, el: HTMLInputElement \| null) => void` | Keyup handler of a digit input: a digit moves the focus to the next input. |
|
|
144
|
+
| `select` | `(el: HTMLInputElement \| null) => void` | Trims an input to one character and selects it, so the next key replaces the digit. |
|
|
145
|
+
| `d1` | `string \| null` | First day digit. |
|
|
146
|
+
| `d2` | `string \| null` | Second day digit. |
|
|
147
|
+
| `m1` | `string \| null` | First month digit. |
|
|
148
|
+
| `m2` | `string \| null` | Second month digit. |
|
|
149
|
+
| `y1` | `string \| null` | First year digit. |
|
|
150
|
+
| `y2` | `string \| null` | Second year digit. |
|
|
151
|
+
| `y3` | `string \| null` | Third year digit. |
|
|
152
|
+
| `y4` | `string \| null` | Fourth year digit. |
|
|
153
|
+
|
|
154
|
+
```tsx
|
|
155
|
+
import { SmartDateEditVariantProps, useDateEdit } from '@smartsoft001/react';
|
|
156
|
+
|
|
157
|
+
export function NativeDateEdit(props: SmartDateEditVariantProps) {
|
|
158
|
+
const { value, setValue, validDate } = useDateEdit(props);
|
|
159
|
+
|
|
160
|
+
return (
|
|
161
|
+
<input
|
|
162
|
+
type="date"
|
|
163
|
+
className={props.className}
|
|
164
|
+
aria-invalid={!validDate}
|
|
165
|
+
value={value ?? ''}
|
|
166
|
+
onChange={(event) => setValue(event.target.value)}
|
|
167
|
+
/>
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
## Styling
|
|
173
|
+
|
|
174
|
+
- The standard digit inputs and the preset trigger / popover carry `smart:dark:` variants; the preset trigger shows an invalid state when the date is not valid.
|
|
175
|
+
- `className` is appended to the root element.
|
|
176
|
+
|
|
177
|
+
## File Locations
|
|
178
|
+
|
|
179
|
+
Source: `packages/shared/react/src/lib/components/date-edit/` in the smartsoft001 repository.
|
|
180
|
+
|
|
181
|
+
- `date-edit.tsx`: `SmartDateEdit`
|
|
182
|
+
- `date-edit.types.ts`: `DateEditVariantName`, `SmartDateEditVariantProps`, `SmartDateEditProps`
|
|
183
|
+
- `preset/date-edit-preset.tsx`: `SmartDateEditPreset`, `DateEditDay`
|
|
184
|
+
- `standard/date-edit-standard.tsx`: `SmartDateEditStandard`
|
|
185
|
+
- `use-date-edit.ts`: `useDateEdit`, `DATE_EDIT_DEFAULT_DATE`
|
|
186
|
+
- `date-edit.stories.tsx`: Storybook stories
|