@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,191 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: react-components-action-panel
|
|
3
|
+
description: SmartActionPanel React component API (@smartsoft001/react) — a titled panel with a description, a content slot and action buttons/links in eight layouts, onActionClick, the 'action-panel' registry key and SmartActionPanelPreset.
|
|
4
|
+
user-invocable: false
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Action Panel (`SmartActionPanel`)
|
|
8
|
+
|
|
9
|
+
`SmartActionPanel` renders a call-to-action panel: a title, a description (or a `descriptionTpl` node), an optional content slot (`contentTpl`, e.g. a toggle or an input) and a row of actions. Actions with `href` render as links, the others as buttons that report `onActionClick({ actionId })`. `options.layout` picks one of eight arrangements, styled by `SmartActionPanelPreset`.
|
|
10
|
+
|
|
11
|
+
## When to Use This Skill
|
|
12
|
+
|
|
13
|
+
- A settings or billing panel with a title, explanation and one or more actions
|
|
14
|
+
- A panel with an inline control (`contentTpl`) such as a toggle, an input or a payment method card
|
|
15
|
+
- Reacting to an action click by id (`onActionClick`)
|
|
16
|
+
- Restyling every action panel (the `action-panel` registry key)
|
|
17
|
+
|
|
18
|
+
## Exports
|
|
19
|
+
|
|
20
|
+
All from `@smartsoft001/react`.
|
|
21
|
+
|
|
22
|
+
| Export | Kind | What it is |
|
|
23
|
+
| -------------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
24
|
+
| `SmartActionPanel` | component | Renders the implementation registered as `components['action-panel']` on `SmartProvider`, `SmartActionPanelStandard` by default. |
|
|
25
|
+
| `SmartActionPanelPreset` | component | Styled action-panel variation (preset). |
|
|
26
|
+
| `SmartActionPanelStandard` | component | The default action panel: a `section.action-panel` with the title, the description (or `options.descriptionTpl`), `options.contentTpl` and the actions. |
|
|
27
|
+
|
|
28
|
+
The preset's class helpers (`getActionPanelCardClasses`, `getActionPanelTitleClasses`, `getActionPanelDescriptionClasses`, `getActionPanelWellClasses`, `getActionPanelActionClasses`) are exported too, for a custom implementation that wants the preset look.
|
|
29
|
+
|
|
30
|
+
## Props and Types
|
|
31
|
+
|
|
32
|
+
### `SmartActionPanelProps`
|
|
33
|
+
|
|
34
|
+
| Prop | Type | Default | Description |
|
|
35
|
+
| ---------------- | ------------------------------------------ | ------- | ------------------------------------------------ |
|
|
36
|
+
| `options?` | `IActionPanelOptions` | — | The panel's content and layout. |
|
|
37
|
+
| `className?` | `string` | — | Classes appended to the root `section`. |
|
|
38
|
+
| `onActionClick?` | `(event: IActionPanelActionClick) => void` | — | Called when an action without `href` is clicked. |
|
|
39
|
+
|
|
40
|
+
### `IActionPanelOptions`
|
|
41
|
+
|
|
42
|
+
| Field | Type | Default | Description |
|
|
43
|
+
| ----------------- | ------------------------ | ---------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
|
|
44
|
+
| `title?` | `string` | — | Heading of the panel. |
|
|
45
|
+
| `description?` | `string` | — | Text under the heading. |
|
|
46
|
+
| `layout?` | `SmartActionPanelLayout` | `'simple'` | One of the eight `SmartActionPanelLayout` arrangements; the standard implementation does not vary its markup by layout, the preset does. |
|
|
47
|
+
| `actions?` | `IActionPanelAction[]` | `[]` | The buttons / links of the panel. |
|
|
48
|
+
| `descriptionTpl?` | `ReactNode` | — | Replaces `description` with a node. |
|
|
49
|
+
| `contentTpl?` | `ReactNode` | — | Extra content placed in the panel (a toggle, an input, a card). |
|
|
50
|
+
|
|
51
|
+
### `IActionPanelActionClick`
|
|
52
|
+
|
|
53
|
+
Passed to `onActionClick` when a button action is clicked.
|
|
54
|
+
|
|
55
|
+
| Field | Type | Default | Description |
|
|
56
|
+
| ---------- | -------- | -------- | ------------------------------- |
|
|
57
|
+
| `actionId` | `string` | required | The `id` of the clicked action. |
|
|
58
|
+
|
|
59
|
+
### `IActionPanelAction`
|
|
60
|
+
|
|
61
|
+
| Field | Type | Default | Description |
|
|
62
|
+
| ---------- | ----------------------------------------------- | -------- | ---------------------------------------------------------------------------------- |
|
|
63
|
+
| `id` | `string` | required | Reported as `actionId` by `onActionClick`. |
|
|
64
|
+
| `label?` | `string` | — | Text of the button / link. |
|
|
65
|
+
| `href?` | `string` | — | Renders the action as a link instead of a button (no `onActionClick`). |
|
|
66
|
+
| `variant?` | `'primary' \| 'secondary' \| 'ghost' \| 'link'` | — | Look of the action: `primary` by default for buttons, `link` by default for links. |
|
|
67
|
+
| `iconTpl?` | `ReactNode` | — | Icon rendered with the label. |
|
|
68
|
+
|
|
69
|
+
### Related types
|
|
70
|
+
|
|
71
|
+
- `SmartActionPanelLayout`: `'simple' \| 'with-link' \| 'right-button' \| 'top-right-button' \| 'with-toggle' \| 'with-input' \| 'well' \| 'payment-method'`
|
|
72
|
+
|
|
73
|
+
## Usage
|
|
74
|
+
|
|
75
|
+
```tsx
|
|
76
|
+
import { SmartActionPanel, SmartToggle } from '@smartsoft001/react';
|
|
77
|
+
|
|
78
|
+
export function DeleteAccountPanel({ onDelete }: { onDelete: () => void }) {
|
|
79
|
+
return (
|
|
80
|
+
<SmartActionPanel
|
|
81
|
+
options={{
|
|
82
|
+
layout: 'right-button',
|
|
83
|
+
title: 'Delete your account',
|
|
84
|
+
description:
|
|
85
|
+
'Once you delete your account, you will lose all data associated with it.',
|
|
86
|
+
actions: [
|
|
87
|
+
{ id: 'delete', label: 'Delete account', variant: 'primary' },
|
|
88
|
+
{ id: 'docs', label: 'Learn more', href: '/help/delete-account' },
|
|
89
|
+
],
|
|
90
|
+
}}
|
|
91
|
+
onActionClick={({ actionId }) => {
|
|
92
|
+
if (actionId === 'delete') onDelete();
|
|
93
|
+
}}
|
|
94
|
+
/>
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function NotificationsPanel({
|
|
99
|
+
enabled,
|
|
100
|
+
onChange,
|
|
101
|
+
}: {
|
|
102
|
+
enabled: boolean;
|
|
103
|
+
onChange: (value: boolean) => void;
|
|
104
|
+
}) {
|
|
105
|
+
return (
|
|
106
|
+
<SmartActionPanel
|
|
107
|
+
options={{
|
|
108
|
+
layout: 'with-toggle',
|
|
109
|
+
title: 'Email notifications',
|
|
110
|
+
description: 'Get an email whenever someone mentions you.',
|
|
111
|
+
contentTpl: (
|
|
112
|
+
<SmartToggle
|
|
113
|
+
value={enabled}
|
|
114
|
+
onValueChange={onChange}
|
|
115
|
+
options={{ ariaLabel: 'Email notifications' }}
|
|
116
|
+
/>
|
|
117
|
+
),
|
|
118
|
+
}}
|
|
119
|
+
/>
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## Replacing the Implementation
|
|
125
|
+
|
|
126
|
+
`SmartActionPanel` renders the component registered under the `'action-panel'` key of `SmartProvider`'s `components`, and `SmartActionPanelStandard` when nothing is registered there. Every `SmartActionPanel` below the provider then renders the registered component, which receives the same props.
|
|
127
|
+
|
|
128
|
+
```tsx
|
|
129
|
+
import type { ReactNode } from 'react';
|
|
130
|
+
|
|
131
|
+
import { SmartProvider, SmartActionPanelPreset } from '@smartsoft001/react';
|
|
132
|
+
|
|
133
|
+
// A module constant: a new object on every render would change the context.
|
|
134
|
+
const components = { 'action-panel': SmartActionPanelPreset };
|
|
135
|
+
|
|
136
|
+
export function AppProviders({ children }: { children: ReactNode }) {
|
|
137
|
+
return <SmartProvider components={components}>{children}</SmartProvider>;
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
`SmartActionPanelPreset` is the styled (preset) implementation: register it as above, render it directly in place of `SmartActionPanel`, 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.
|
|
142
|
+
|
|
143
|
+
A custom implementation takes `SmartActionPanelProps` and calls `onActionClick` for its buttons:
|
|
144
|
+
|
|
145
|
+
```tsx
|
|
146
|
+
import { SmartActionPanelProps } from '@smartsoft001/react';
|
|
147
|
+
|
|
148
|
+
export function CompactActionPanel({
|
|
149
|
+
options,
|
|
150
|
+
className,
|
|
151
|
+
onActionClick,
|
|
152
|
+
}: SmartActionPanelProps) {
|
|
153
|
+
return (
|
|
154
|
+
<section className={className}>
|
|
155
|
+
<h3>{options?.title}</h3>
|
|
156
|
+
{options?.descriptionTpl ?? <p>{options?.description}</p>}
|
|
157
|
+
{options?.contentTpl}
|
|
158
|
+
{options?.actions?.map((action) =>
|
|
159
|
+
action.href ? (
|
|
160
|
+
<a key={action.id} href={action.href}>
|
|
161
|
+
{action.label}
|
|
162
|
+
</a>
|
|
163
|
+
) : (
|
|
164
|
+
<button
|
|
165
|
+
key={action.id}
|
|
166
|
+
type="button"
|
|
167
|
+
onClick={() => onActionClick?.({ actionId: action.id })}
|
|
168
|
+
>
|
|
169
|
+
{action.label}
|
|
170
|
+
</button>
|
|
171
|
+
),
|
|
172
|
+
)}
|
|
173
|
+
</section>
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## Styling
|
|
179
|
+
|
|
180
|
+
- `SmartActionPanelStandard` renders a `section.action-panel` with the title, description, content and actions in one arrangement; `SmartActionPanelPreset` renders a bordered card and re-composes the parts per `layout` (row, split, well, ...), with `smart:dark:` variants.
|
|
181
|
+
- `className` is appended to the root element.
|
|
182
|
+
|
|
183
|
+
## File Locations
|
|
184
|
+
|
|
185
|
+
Source: `packages/shared/react/src/lib/components/action-panel/` in the smartsoft001 repository.
|
|
186
|
+
|
|
187
|
+
- `action-panel.tsx`: `SmartActionPanel`
|
|
188
|
+
- `action-panel.types.ts`: `IActionPanelActionClick`, `SmartActionPanelProps`
|
|
189
|
+
- `preset/action-panel-preset.tsx`: `SmartActionPanelPreset`
|
|
190
|
+
- `standard/action-panel-standard.tsx`: `SmartActionPanelStandard`
|
|
191
|
+
- `action-panel.stories.tsx`: Storybook stories
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: react-components-alert
|
|
3
|
+
description: SmartAlert React component API (@smartsoft001/react) — modal alert dialog with header, message and buttons (IAlertOptions/IAlertButton), onDismissed, AlertService.show() for confirm dialogs from code, the 'alert' registry key and the useAlert hook.
|
|
4
|
+
user-invocable: false
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Alert (`SmartAlert`)
|
|
8
|
+
|
|
9
|
+
`SmartAlert` is a modal alert dialog (`role="alertdialog"`): a header, an optional sub-header and message, and a row of buttons. It focuses its first button, keeps Tab inside the panel, and cancels on Escape or a click on the backdrop. Most applications do not place it by hand: `useAlertService().show(options)` opens one and resolves with the button the user chose, and the alert host that `SmartProvider` renders draws it through the same `alert` registry key.
|
|
10
|
+
|
|
11
|
+
## When to Use This Skill
|
|
12
|
+
|
|
13
|
+
- Asking the user to confirm or cancel an action ("Delete this note?") from code with `AlertService.show`
|
|
14
|
+
- Rendering an alert dialog in place, with `onDismissed`
|
|
15
|
+
- Running logic in a button `handler`, or keeping the dialog open by returning `false` from it
|
|
16
|
+
- Replacing the dialog application-wide (the `alert` key), building on `useAlert`
|
|
17
|
+
|
|
18
|
+
## Exports
|
|
19
|
+
|
|
20
|
+
All from `@smartsoft001/react`.
|
|
21
|
+
|
|
22
|
+
| Export | Kind | What it is |
|
|
23
|
+
| ----------------------- | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
24
|
+
| `SmartAlert` | component | Renders the implementation registered as `components.alert` on `SmartProvider`, `SmartAlertStandard` by default. |
|
|
25
|
+
| `SmartAlertStandard` | component | The default alert dialog: a modal `alertdialog` on a full-screen backdrop, rendered where it is placed (the alert host of `SmartProvider` decides where that is). |
|
|
26
|
+
| `useAlert` | hook | The behaviour every alert variant shares: the ids linking the dialog to its header and message, the buttons, and the ways to close it, all reported through `onDismissed`: - `invoke(button)` runs `button.handler` and dismisses with the button, unless the handler of a non-cancel button returned `false`; - `cancel()` / `onEscape()` dismiss with the cancel button (or `null`), without running its handler; - `onBackdropClick(event)` cancels on a click on the backdrop itself, unless `options.backdropDismiss === false`; - `trapFocus(event, panel)` keeps Tab / Shift+Tab on the panel's buttons. |
|
|
27
|
+
| `getAlertButtonClasses` | function | Classes of an alert button by `role` (`cancel` -> secondary, `destructive` -> red, anything else -> primary), followed by its `cssClass`. |
|
|
28
|
+
|
|
29
|
+
## Props and Types
|
|
30
|
+
|
|
31
|
+
### `SmartAlertProps`
|
|
32
|
+
|
|
33
|
+
| Prop | Type | Default | Description |
|
|
34
|
+
| -------------- | ---------------------------------------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
35
|
+
| `options` | `IAlertOptions` | required | Header, message and buttons of the dialog. |
|
|
36
|
+
| `className?` | `string` | — | Classes of the dialog panel. |
|
|
37
|
+
| `onDismissed?` | `(button: IAlertButton \| null) => void` | — | Called with the button that closed the alert, after its handler ran, or the cancel button (`role: 'cancel'`, handler not run) / `null` on Escape and backdrop click. Not called when the handler of a non-cancel button returns `false`: the alert stays open. |
|
|
38
|
+
|
|
39
|
+
### `IAlertOptions`
|
|
40
|
+
|
|
41
|
+
| Field | Type | Default | Description |
|
|
42
|
+
| ------------------ | ---------------- | ------- | ------------------------------------------------------------------------ |
|
|
43
|
+
| `header?` | `string` | — | The dialog title (linked through `aria-labelledby`). |
|
|
44
|
+
| `subHeader?` | `string` | — | A smaller line under the header. |
|
|
45
|
+
| `message?` | `string` | — | The body text (linked through `aria-describedby`). |
|
|
46
|
+
| `backdropDismiss?` | `boolean` | `true` | Click on the backdrop cancels the alert. |
|
|
47
|
+
| `buttons?` | `IAlertButton[]` | `[]` | The buttons, in order. Without buttons the dialog can only be cancelled. |
|
|
48
|
+
|
|
49
|
+
### `SmartAlertKeyEvent`
|
|
50
|
+
|
|
51
|
+
The part of a keyboard event `trapFocus` reads (DOM or React).
|
|
52
|
+
|
|
53
|
+
| Field | Type | Default | Description |
|
|
54
|
+
| ---------------- | ------------ | -------- | -------------------------------------------------- |
|
|
55
|
+
| `key` | `string` | required | The pressed key. |
|
|
56
|
+
| `shiftKey` | `boolean` | required | Whether Shift is held (Shift+Tab moves backwards). |
|
|
57
|
+
| `preventDefault` | `() => void` | required | Stops the browser from moving the focus itself. |
|
|
58
|
+
|
|
59
|
+
### `SmartAlertBackdropEvent`
|
|
60
|
+
|
|
61
|
+
The part of a mouse event `onBackdropClick` reads (DOM or React).
|
|
62
|
+
|
|
63
|
+
| Field | Type | Default | Description |
|
|
64
|
+
| --------------- | --------------------- | -------- | -------------------------------------------------------------------- |
|
|
65
|
+
| `target` | `EventTarget \| null` | required | The clicked element. |
|
|
66
|
+
| `currentTarget` | `EventTarget \| null` | required | The backdrop element; the alert cancels only when both are the same. |
|
|
67
|
+
|
|
68
|
+
### `IAlertButton`
|
|
69
|
+
|
|
70
|
+
| Field | Type | Default | Description |
|
|
71
|
+
| ----------- | ----------------------------------------------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------ |
|
|
72
|
+
| `text` | `string` | required | The label. |
|
|
73
|
+
| `role?` | `'cancel' \| 'destructive' \| string` | — | `'cancel'` marks the button Escape and the backdrop use (its handler is not run then); `'destructive'` styles it as dangerous. |
|
|
74
|
+
| `cssClass?` | `string \| string[]` | — | Extra classes of the button. |
|
|
75
|
+
| `handler?` | `(value?: unknown) => boolean \| void \| Record<string, unknown>` | — | Runs on click. Returning `false` from the handler of a non-cancel button keeps the dialog open. |
|
|
76
|
+
|
|
77
|
+
## Opening an alert from code
|
|
78
|
+
|
|
79
|
+
`AlertService.show(options)` returns a promise of the chosen `IAlertButton` (or `null` on Escape / backdrop click without a cancel button), resolved after the button's handler ran. The alert host of `SmartProvider` (`SmartAlertHost`, part of `SmartOverlays`) renders the dialog at the end of `<body>` and gives the focus back to the element that had it. See the `react-components-overlays` skill for the hosts.
|
|
80
|
+
|
|
81
|
+
```tsx
|
|
82
|
+
import { SmartButton, useAlertService } from '@smartsoft001/react';
|
|
83
|
+
|
|
84
|
+
export function DeleteNoteButton({ onDelete }: { onDelete: () => void }) {
|
|
85
|
+
const alerts = useAlertService();
|
|
86
|
+
|
|
87
|
+
const confirmDelete = async () => {
|
|
88
|
+
const button = await alerts.show({
|
|
89
|
+
header: 'Delete note?',
|
|
90
|
+
message: 'This cannot be undone.',
|
|
91
|
+
buttons: [
|
|
92
|
+
{ text: 'Cancel', role: 'cancel' },
|
|
93
|
+
{ text: 'Delete', role: 'destructive' },
|
|
94
|
+
],
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
if (button?.role === 'destructive') onDelete();
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
return (
|
|
101
|
+
<SmartButton options={{ click: () => void confirmDelete(), color: 'red' }}>
|
|
102
|
+
Delete
|
|
103
|
+
</SmartButton>
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Usage
|
|
109
|
+
|
|
110
|
+
Rendered in place, the parent decides when it is shown and removes it on `onDismissed`:
|
|
111
|
+
|
|
112
|
+
```tsx
|
|
113
|
+
import { useState } from 'react';
|
|
114
|
+
|
|
115
|
+
import { SmartAlert, SmartButton } from '@smartsoft001/react';
|
|
116
|
+
|
|
117
|
+
export function PublishConfirm({ onPublish }: { onPublish: () => void }) {
|
|
118
|
+
const [open, setOpen] = useState(false);
|
|
119
|
+
|
|
120
|
+
return (
|
|
121
|
+
<>
|
|
122
|
+
<SmartButton options={{ click: () => setOpen(true) }}>
|
|
123
|
+
Publish
|
|
124
|
+
</SmartButton>
|
|
125
|
+
{open && (
|
|
126
|
+
<SmartAlert
|
|
127
|
+
options={{
|
|
128
|
+
header: 'Publish the article?',
|
|
129
|
+
message: 'Readers will see it immediately.',
|
|
130
|
+
backdropDismiss: false,
|
|
131
|
+
buttons: [
|
|
132
|
+
{ text: 'Cancel', role: 'cancel' },
|
|
133
|
+
{ text: 'Publish', handler: () => onPublish() },
|
|
134
|
+
],
|
|
135
|
+
}}
|
|
136
|
+
onDismissed={() => setOpen(false)}
|
|
137
|
+
/>
|
|
138
|
+
)}
|
|
139
|
+
</>
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## Replacing the Implementation
|
|
145
|
+
|
|
146
|
+
`SmartAlert` renders the component registered under the `'alert'` key of `SmartProvider`'s `components`, and `SmartAlertStandard` when nothing is registered there. Every `SmartAlert` below the provider then renders the registered component, which receives the same props.
|
|
147
|
+
|
|
148
|
+
There is no preset for this component: register a component of your own that takes `SmartAlertProps`, as shown below, as `components={{ alert: MyAlert }}`. Pass `components` as a stable object (a module constant or a memoised value), or the context changes on every render.
|
|
149
|
+
|
|
150
|
+
### The `useAlert` hook
|
|
151
|
+
|
|
152
|
+
The behaviour every alert variant shares: the ids linking the dialog to its header and message, the buttons, and the ways to close it, all reported through `onDismissed`:
|
|
153
|
+
|
|
154
|
+
- `invoke(button)` runs `button.handler` and dismisses with the button, unless the handler of a non-cancel button returned `false`;
|
|
155
|
+
- `cancel()` / `onEscape()` dismiss with the cancel button (or `null`), without running its handler;
|
|
156
|
+
- `onBackdropClick(event)` cancels on a click on the backdrop itself, unless `options.backdropDismiss === false`;
|
|
157
|
+
- `trapFocus(event, panel)` keeps Tab / Shift+Tab on the panel's buttons.
|
|
158
|
+
|
|
159
|
+
```ts
|
|
160
|
+
function useAlert({
|
|
161
|
+
options,
|
|
162
|
+
onDismissed,
|
|
163
|
+
}: Pick<SmartAlertProps, 'options' | 'onDismissed'>);
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
| Returns | Type | Description |
|
|
167
|
+
| ----------------- | ------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- |
|
|
168
|
+
| `headerId` | `string` | Id for the header element (`aria-labelledby`). |
|
|
169
|
+
| `messageId` | `string` | Id for the message element (`aria-describedby`). |
|
|
170
|
+
| `buttons` | `IAlertButton[]` | `options.buttons ?? []`. |
|
|
171
|
+
| `cancelButton` | `IAlertButton \| null` | The button with `role: 'cancel'`, or `null`. |
|
|
172
|
+
| `invoke` | `(button: IAlertButton) => void` | Click handler of a button: runs its handler and dismisses with it, unless a non-cancel handler returned `false`. |
|
|
173
|
+
| `cancel` | `() => void` | Dismisses with the cancel button (or `null`) without running its handler. |
|
|
174
|
+
| `onEscape` | `() => void` | Same as `cancel`, for the Escape key. |
|
|
175
|
+
| `onBackdropClick` | `(event: SmartAlertBackdropEvent) => void` | Cancels on a click on the backdrop element itself, unless `options.backdropDismiss === false`. |
|
|
176
|
+
| `trapFocus` | `(event: SmartAlertKeyEvent, container: HTMLElement) => void` | Keeps Tab / Shift+Tab on the panel's buttons; call it from the panel's `onKeyDown`. |
|
|
177
|
+
| `buttonClasses` | `(button: IAlertButton) => string` | The classes of a button (`getAlertButtonClasses`), by role and `cssClass`. |
|
|
178
|
+
|
|
179
|
+
A custom dialog builds on `useAlert`, which supplies the ids, the buttons and every way of closing:
|
|
180
|
+
|
|
181
|
+
```tsx
|
|
182
|
+
import { useRef } from 'react';
|
|
183
|
+
|
|
184
|
+
import { SmartAlertProps, useAlert } from '@smartsoft001/react';
|
|
185
|
+
|
|
186
|
+
export function BrandAlert(props: SmartAlertProps) {
|
|
187
|
+
const panel = useRef<HTMLDivElement>(null);
|
|
188
|
+
const {
|
|
189
|
+
headerId,
|
|
190
|
+
messageId,
|
|
191
|
+
buttons,
|
|
192
|
+
invoke,
|
|
193
|
+
onEscape,
|
|
194
|
+
onBackdropClick,
|
|
195
|
+
trapFocus,
|
|
196
|
+
} = useAlert(props);
|
|
197
|
+
|
|
198
|
+
return (
|
|
199
|
+
<div className="fixed inset-0 bg-black/40" onClick={onBackdropClick}>
|
|
200
|
+
<div
|
|
201
|
+
ref={panel}
|
|
202
|
+
role="alertdialog"
|
|
203
|
+
aria-modal="true"
|
|
204
|
+
aria-labelledby={headerId}
|
|
205
|
+
aria-describedby={messageId}
|
|
206
|
+
className={props.className}
|
|
207
|
+
onKeyDown={(event) => {
|
|
208
|
+
if (event.key === 'Escape') onEscape();
|
|
209
|
+
else if (panel.current) trapFocus(event, panel.current);
|
|
210
|
+
}}
|
|
211
|
+
>
|
|
212
|
+
<h2 id={headerId}>{props.options.header}</h2>
|
|
213
|
+
<p id={messageId}>{props.options.message}</p>
|
|
214
|
+
{buttons.map((button) => (
|
|
215
|
+
<button
|
|
216
|
+
key={button.text}
|
|
217
|
+
type="button"
|
|
218
|
+
onClick={() => invoke(button)}
|
|
219
|
+
>
|
|
220
|
+
{button.text}
|
|
221
|
+
</button>
|
|
222
|
+
))}
|
|
223
|
+
</div>
|
|
224
|
+
</div>
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
Registered as `components={{ alert: BrandAlert }}`, it renders both the `SmartAlert`s placed by hand and the dialogs of `AlertService.show`.
|
|
230
|
+
|
|
231
|
+
## Styling
|
|
232
|
+
|
|
233
|
+
- `className` goes on the dialog panel.
|
|
234
|
+
- The standard dialog renders a full-screen backdrop where it is placed; the alert host puts it at the end of `<body>`. Classes carry `smart:dark:` variants.
|
|
235
|
+
|
|
236
|
+
## File Locations
|
|
237
|
+
|
|
238
|
+
Source: `packages/shared/react/src/lib/components/alert/` in the smartsoft001 repository.
|
|
239
|
+
|
|
240
|
+
- `alert.tsx`: `SmartAlert`
|
|
241
|
+
- `alert.types.ts`: `SmartAlertProps`
|
|
242
|
+
- `standard/alert-standard.tsx`: `SmartAlertStandard`
|
|
243
|
+
- `use-alert.ts`: `getAlertButtonClasses`, `useAlert`, `SmartAlertKeyEvent`, `SmartAlertBackdropEvent`
|
|
244
|
+
- `alert.stories.tsx`: Storybook stories
|