@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,211 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: react-components-navbar
|
|
3
|
+
description: SmartNavbar React component API (@smartsoft001/react) — top navigation bar with logo, primary and secondary links, search/action/notification/user-menu slots and a mobile menu (controlled mobileMenuOpen or uncontrolled), onItemClick, router links through the navigation adapter, the 'navbar' registry key, SmartNavbarPreset and useNavbar.
|
|
4
|
+
user-invocable: false
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Navbar (`SmartNavbar`)
|
|
8
|
+
|
|
9
|
+
`SmartNavbar` is the top navigation bar: a logo (`logoTpl`, or `logoUrl` / `logoAlt` / `logoHref`), a row of primary links (`items`), an optional row of secondary links, slots for search, a quick action, notifications and the user menu, and a mobile menu toggle. Items with an internal `href` render through the navigation adapter's `linkComponent` (e.g. your router's `Link`) when one is set, external ones as `<a>`; items without `href` are buttons reported through `onItemClick({ itemId })`. The mobile menu state is controlled (`mobileMenuOpen` + `onMobileMenuOpenChange`) or kept inside.
|
|
10
|
+
|
|
11
|
+
## When to Use This Skill
|
|
12
|
+
|
|
13
|
+
- The top bar of an application with links, a logo and a user menu
|
|
14
|
+
- Marking the current page (`current`) and integrating with the app's router (`navigation.linkComponent`)
|
|
15
|
+
- A dark navbar or a menu button on the left (preset)
|
|
16
|
+
- Restyling every navbar (the `navbar` registry key)
|
|
17
|
+
|
|
18
|
+
## Exports
|
|
19
|
+
|
|
20
|
+
All from `@smartsoft001/react`.
|
|
21
|
+
|
|
22
|
+
| Export | Kind | What it is |
|
|
23
|
+
| --------------------- | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
24
|
+
| `SmartNavbar` | component | Renders the implementation registered as `components.navbar` on `SmartProvider`, `SmartNavbarStandard` by default. |
|
|
25
|
+
| `SmartNavbarPreset` | component | Styled navbar variation (preset). |
|
|
26
|
+
| `SmartNavbarStandard` | component | The default navbar rendering. |
|
|
27
|
+
| `useNavbar` | hook | The behaviour every navbar variant shares: the mobile menu state, controlled through `mobileMenuOpen` or kept internally when that prop is `undefined`, and the item click. |
|
|
28
|
+
|
|
29
|
+
The preset's class helpers (`getNavbarHeaderClasses`, `getNavbarBrandClasses`, `getNavbarToggleClasses`, `getNavbarCollapseClasses`, `getNavbarItemClasses`, `getNavbarSecondaryNavClasses`, `NAVBAR_NAV_CONTAINER`, `NAVBAR_BRAND_ROW`, `NAVBAR_LINKS_CONTAINER`, `NAVBAR_SECONDARY_CONTAINER`) are exported too, for a custom implementation that wants the preset look.
|
|
30
|
+
|
|
31
|
+
## Props and Types
|
|
32
|
+
|
|
33
|
+
### `SmartNavbarProps`
|
|
34
|
+
|
|
35
|
+
| Prop | Type | Default | Description |
|
|
36
|
+
| ------------------------- | ----------------------------------- | ------- | ------------------------------------------------------------------------------------------------- |
|
|
37
|
+
| `options?` | `INavbarOptions` | — | Logo, links and slots. |
|
|
38
|
+
| `className?` | `string` | — | Classes on the root element. |
|
|
39
|
+
| `mobileMenuOpen?` | `boolean` | — | Whether the mobile menu is open. Leave it `undefined` to let the component keep the state itself. |
|
|
40
|
+
| `defaultMobileMenuOpen?` | `boolean` | `false` | The initial state of an uncontrolled mobile menu. |
|
|
41
|
+
| `onMobileMenuOpenChange?` | `(mobileMenuOpen: boolean) => void` | — | Called when the mobile menu opens or closes. |
|
|
42
|
+
| `onItemClick?` | `(event: INavbarItemClick) => void` | — | A click on an item without `href`. |
|
|
43
|
+
|
|
44
|
+
### `INavbarOptions`
|
|
45
|
+
|
|
46
|
+
| Field | Type | Default | Description |
|
|
47
|
+
| ------------------- | ------------------- | ------- | --------------------------------------------------------------------------------------- |
|
|
48
|
+
| `layout?` | `SmartNavbarLayout` | — | Declared (`SmartNavbarLayout`); neither the standard nor the preset rendering reads it. |
|
|
49
|
+
| `dark?` | `boolean` | — | Preset: the solid dark colour variant. |
|
|
50
|
+
| `menuButtonOnLeft?` | `boolean` | — | Preset: places the mobile menu button on the left. |
|
|
51
|
+
| `logoTpl?` | `ReactNode` | — | The brand as a node; wins over the logo image. |
|
|
52
|
+
| `logoUrl?` | `string` | — | Logo image URL. |
|
|
53
|
+
| `logoAlt?` | `string` | `''` | Alt text of the logo image. |
|
|
54
|
+
| `logoHref?` | `string` | — | Link of the logo. |
|
|
55
|
+
| `items?` | `INavbarItem[]` | `[]` | The primary links. |
|
|
56
|
+
| `secondaryItems?` | `INavbarItem[]` | `[]` | A second row of links. |
|
|
57
|
+
| `searchTpl?` | `ReactNode` | — | Search slot. |
|
|
58
|
+
| `actionTpl?` | `ReactNode` | — | Quick-action slot (e.g. a "New" button). |
|
|
59
|
+
| `notificationTpl?` | `ReactNode` | — | Notifications slot. |
|
|
60
|
+
| `userMenuTpl?` | `ReactNode` | — | User menu slot (e.g. an avatar dropdown). |
|
|
61
|
+
|
|
62
|
+
### `INavbarItemClick`
|
|
63
|
+
|
|
64
|
+
| Field | Type | Default | Description |
|
|
65
|
+
| -------- | -------- | -------- | ----------------------------- |
|
|
66
|
+
| `itemId` | `string` | required | The `id` of the clicked item. |
|
|
67
|
+
|
|
68
|
+
### `INavbarItem`
|
|
69
|
+
|
|
70
|
+
| Field | Type | Default | Description |
|
|
71
|
+
| ---------- | ----------- | -------- | ------------------------------------------------------------------- |
|
|
72
|
+
| `id` | `string` | required | Reported as `itemId`. |
|
|
73
|
+
| `label?` | `string` | — | Link text. |
|
|
74
|
+
| `href?` | `string` | — | Renders a link (through the navigation adapter for internal paths). |
|
|
75
|
+
| `current?` | `boolean` | — | Marks the current page. |
|
|
76
|
+
| `iconTpl?` | `ReactNode` | — | Icon before the label. |
|
|
77
|
+
|
|
78
|
+
### Related types
|
|
79
|
+
|
|
80
|
+
- `SmartNavbarLayout`: `'simple' \| 'simple-with-menu-on-left' \| 'with-quick-action' \| 'with-search' \| 'with-centered-search' \| 'with-secondary-links' \| 'with-column-layout'`
|
|
81
|
+
|
|
82
|
+
## Usage
|
|
83
|
+
|
|
84
|
+
```tsx
|
|
85
|
+
import { SmartAvatarPreset, SmartNavbarPreset } from '@smartsoft001/react';
|
|
86
|
+
|
|
87
|
+
export function TopBar({ path }: { path: string }) {
|
|
88
|
+
return (
|
|
89
|
+
<SmartNavbarPreset
|
|
90
|
+
options={{
|
|
91
|
+
logoUrl: '/logo.svg',
|
|
92
|
+
logoAlt: 'Acme',
|
|
93
|
+
logoHref: '/',
|
|
94
|
+
items: [
|
|
95
|
+
{
|
|
96
|
+
id: 'dashboard',
|
|
97
|
+
label: 'Dashboard',
|
|
98
|
+
href: '/dashboard',
|
|
99
|
+
current: path.startsWith('/dashboard'),
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
id: 'notes',
|
|
103
|
+
label: 'Notes',
|
|
104
|
+
href: '/notes',
|
|
105
|
+
current: path.startsWith('/notes'),
|
|
106
|
+
},
|
|
107
|
+
],
|
|
108
|
+
userMenuTpl: <SmartAvatarPreset initials="AK" size="sm" />,
|
|
109
|
+
}}
|
|
110
|
+
/>
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
With React Router (or any router), give `SmartProvider` a navigation adapter with a `linkComponent`, and the navbar's internal links render through it (see `react-provider`).
|
|
116
|
+
|
|
117
|
+
## Replacing the Implementation
|
|
118
|
+
|
|
119
|
+
`SmartNavbar` renders the component registered under the `'navbar'` key of `SmartProvider`'s `components`, and `SmartNavbarStandard` when nothing is registered there. Every `SmartNavbar` below the provider then renders the registered component, which receives the same props.
|
|
120
|
+
|
|
121
|
+
```tsx
|
|
122
|
+
import type { ReactNode } from 'react';
|
|
123
|
+
|
|
124
|
+
import { SmartProvider, SmartNavbarPreset } from '@smartsoft001/react';
|
|
125
|
+
|
|
126
|
+
// A module constant: a new object on every render would change the context.
|
|
127
|
+
const components = { navbar: SmartNavbarPreset };
|
|
128
|
+
|
|
129
|
+
export function AppProviders({ children }: { children: ReactNode }) {
|
|
130
|
+
return <SmartProvider components={components}>{children}</SmartProvider>;
|
|
131
|
+
}
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
`SmartNavbarPreset` is the styled (preset) implementation: register it as above, render it directly in place of `SmartNavbar`, 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.
|
|
135
|
+
|
|
136
|
+
### The `useNavbar` hook
|
|
137
|
+
|
|
138
|
+
The behaviour every navbar variant shares: the mobile menu state, controlled through `mobileMenuOpen` or kept internally when that prop is `undefined`, and the item click.
|
|
139
|
+
|
|
140
|
+
```ts
|
|
141
|
+
function useNavbar({
|
|
142
|
+
mobileMenuOpen,
|
|
143
|
+
defaultMobileMenuOpen = false,
|
|
144
|
+
onMobileMenuOpenChange,
|
|
145
|
+
onItemClick,
|
|
146
|
+
}: SmartNavbarProps);
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
| Returns | Type | Description |
|
|
150
|
+
| ------------------- | --------------------------------------- | -------------------------------------------------- |
|
|
151
|
+
| `mobileMenuOpen` | `boolean` | The mobile menu state (controlled or internal). |
|
|
152
|
+
| `setMobileMenuOpen` | `(next: boolean) => void` | Sets the state and calls `onMobileMenuOpenChange`. |
|
|
153
|
+
| `toggleMobileMenu` | `() => void` | Opens or closes the mobile menu. |
|
|
154
|
+
| `itemClick` | `(itemId: string) => void \| undefined` | Reports a click on an item without `href`. |
|
|
155
|
+
|
|
156
|
+
```tsx
|
|
157
|
+
import { SmartNavbarProps, useNavbar } from '@smartsoft001/react';
|
|
158
|
+
|
|
159
|
+
export function MinimalNavbar(props: SmartNavbarProps) {
|
|
160
|
+
const { options, className } = props;
|
|
161
|
+
const { mobileMenuOpen, toggleMobileMenu, itemClick } = useNavbar(props);
|
|
162
|
+
|
|
163
|
+
return (
|
|
164
|
+
<nav className={className}>
|
|
165
|
+
{options?.logoTpl}
|
|
166
|
+
<button
|
|
167
|
+
type="button"
|
|
168
|
+
aria-expanded={mobileMenuOpen}
|
|
169
|
+
onClick={toggleMobileMenu}
|
|
170
|
+
>
|
|
171
|
+
Menu
|
|
172
|
+
</button>
|
|
173
|
+
<ul hidden={!mobileMenuOpen}>
|
|
174
|
+
{(options?.items ?? []).map((item) => (
|
|
175
|
+
<li key={item.id}>
|
|
176
|
+
{item.href ? (
|
|
177
|
+
<a
|
|
178
|
+
href={item.href}
|
|
179
|
+
aria-current={item.current ? 'page' : undefined}
|
|
180
|
+
>
|
|
181
|
+
{item.label}
|
|
182
|
+
</a>
|
|
183
|
+
) : (
|
|
184
|
+
<button type="button" onClick={() => itemClick(item.id)}>
|
|
185
|
+
{item.label}
|
|
186
|
+
</button>
|
|
187
|
+
)}
|
|
188
|
+
</li>
|
|
189
|
+
))}
|
|
190
|
+
</ul>
|
|
191
|
+
{options?.userMenuTpl}
|
|
192
|
+
</nav>
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
## Styling
|
|
198
|
+
|
|
199
|
+
- `SmartNavbarStandard` is semantic markup with class hooks (`navbar`, `mobile-menu-toggle`, `item-link`, `current`, `search`, `user-menu`, ...).
|
|
200
|
+
- `SmartNavbarPreset` is a collapsible navbar driven only by `mobileMenuOpen`; `options.dark` picks the dark colour variant, and light mode carries `smart:dark:` variants.
|
|
201
|
+
|
|
202
|
+
## File Locations
|
|
203
|
+
|
|
204
|
+
Source: `packages/shared/react/src/lib/components/navbar/` in the smartsoft001 repository.
|
|
205
|
+
|
|
206
|
+
- `navbar.tsx`: `SmartNavbar`
|
|
207
|
+
- `navbar.types.ts`: `INavbarItemClick`, `SmartNavbarProps`
|
|
208
|
+
- `preset/navbar-preset.tsx`: `SmartNavbarPreset`
|
|
209
|
+
- `standard/navbar-standard.tsx`: `SmartNavbarStandard`
|
|
210
|
+
- `use-navbar.ts`: `useNavbar`
|
|
211
|
+
- `navbar.stories.tsx`: Storybook stories
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: react-components-notification
|
|
3
|
+
description: SmartNotification React component API (@smartsoft001/react) — toast-style notification with title, description, icon or avatar, action buttons and a close button (onDismissed, onActionClick), six preset variants, ToastService for toasts from code, the 'notification' registry key, SmartNotificationPreset and useNotification.
|
|
4
|
+
user-invocable: false
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Notification (`SmartNotification`)
|
|
8
|
+
|
|
9
|
+
`SmartNotification` renders one notification panel: a `title`, an optional `description`, an icon glyph or avatar, action buttons (`actions`, reported through `onActionClick({ actionId })`) and a close button (`dismissible`, reported through `onDismissed`). It has **no open state**: render it while it should be visible and remove it on `onDismissed`. The toasts of `useToastService().info(...)` / `.error(...)` are rendered by the toast host of `SmartProvider` through this component, so registering a notification implementation restyles them too.
|
|
10
|
+
|
|
11
|
+
## When to Use This Skill
|
|
12
|
+
|
|
13
|
+
- Showing a transient message ("Saved", "Upload failed") in a corner of the screen
|
|
14
|
+
- A notification with actions (Undo, View) or an avatar (`with-avatar` preset variant)
|
|
15
|
+
- Showing toasts from code with `ToastService` (see below)
|
|
16
|
+
- Restyling every notification and toast (the `notification` registry key)
|
|
17
|
+
|
|
18
|
+
## Exports
|
|
19
|
+
|
|
20
|
+
All from `@smartsoft001/react`.
|
|
21
|
+
|
|
22
|
+
| Export | Kind | What it is |
|
|
23
|
+
| --------------------------- | --------- | ---------------------------------------------------------------------------------------------------------------------------------- |
|
|
24
|
+
| `SmartNotification` | component | Renders the implementation registered as `components.notification` on `SmartProvider`, `SmartNotificationStandard` by default. |
|
|
25
|
+
| `SmartNotificationPreset` | component | Styled notification (toast) variation (preset). |
|
|
26
|
+
| `SmartNotificationStandard` | component | The default notification rendering. |
|
|
27
|
+
| `useNotification` | hook | The behaviour every notification variant shares: `dismiss()` reports `onDismissed` and `invokeAction(id)` reports `onActionClick`. |
|
|
28
|
+
|
|
29
|
+
The preset's class helpers (`getNotificationContainerClasses`, `getNotificationTitleClasses`, `getNotificationMessageClasses`, `getNotificationDescriptionClasses`, `getNotificationIconClasses`, `getNotificationAvatarClasses`, `getNotificationCloseClasses`, `getNotificationActionsRowClasses`, `getNotificationActionClasses`) are exported too, for a custom implementation that wants the preset look.
|
|
30
|
+
|
|
31
|
+
## Props and Types
|
|
32
|
+
|
|
33
|
+
### `SmartNotificationProps`
|
|
34
|
+
|
|
35
|
+
| Prop | Type | Default | Description |
|
|
36
|
+
| ---------------- | ------------------------------------------- | -------- | ---------------------------------------------------------------------- |
|
|
37
|
+
| `title` | `string` | required | The main line. |
|
|
38
|
+
| `description?` | `string` | — | A second line. |
|
|
39
|
+
| `iconName?` | `string` | — | A glyph (text, e.g. an emoji) shown before the text by the preset. |
|
|
40
|
+
| `avatarUrl?` | `string` | — | Image shown by the preset `with-avatar` variant. |
|
|
41
|
+
| `actions?` | `INotificationAction[]` | `[]` | Action buttons (not rendered by the preset's `simple` variant). |
|
|
42
|
+
| `dismissible?` | `boolean` | `false` | Shows the close button, which reports `onDismissed`. |
|
|
43
|
+
| `options?` | `INotificationOptions` | — | Variant and live-region politeness. |
|
|
44
|
+
| `className?` | `string` | — | Classes on the root element. |
|
|
45
|
+
| `onDismissed?` | `() => void` | — | Called when the close button is clicked; remove the notification here. |
|
|
46
|
+
| `onActionClick?` | `(value: INotificationActionClick) => void` | — | Called with the id of the clicked action. |
|
|
47
|
+
|
|
48
|
+
### `INotificationOptions`
|
|
49
|
+
|
|
50
|
+
| Field | Type | Default | Description |
|
|
51
|
+
| ----------- | -------------------------- | ---------- | -------------------------------------------------------------------------------------------------------------------- |
|
|
52
|
+
| `variant?` | `SmartNotificationVariant` | `'simple'` | Preset look: `simple`, `condensed`, `with-actions-below`, `with-avatar`, `with-split-buttons`, `with-buttons-below`. |
|
|
53
|
+
| `ariaLive?` | `'polite' \| 'assertive'` | `'polite'` | `assertive` for errors. |
|
|
54
|
+
|
|
55
|
+
### `INotificationActionClick`
|
|
56
|
+
|
|
57
|
+
Payload of `onActionClick`.
|
|
58
|
+
|
|
59
|
+
| Field | Type | Default | Description |
|
|
60
|
+
| ---------- | -------- | -------- | ------------------------------- |
|
|
61
|
+
| `actionId` | `string` | required | The `id` of the clicked action. |
|
|
62
|
+
|
|
63
|
+
### `INotificationAction`
|
|
64
|
+
|
|
65
|
+
| Field | Type | Default | Description |
|
|
66
|
+
| ---------- | -------------------------- | ---------- | ------------------------------ |
|
|
67
|
+
| `id` | `string` | required | Reported as `actionId`. |
|
|
68
|
+
| `label` | `string` | required | Button text. |
|
|
69
|
+
| `variant?` | `'primary' \| 'secondary'` | `'simple'` | `primary` or `secondary` look. |
|
|
70
|
+
|
|
71
|
+
### Related types
|
|
72
|
+
|
|
73
|
+
- `SmartNotificationVariant`: `'simple' \| 'condensed' \| 'with-actions-below' \| 'with-avatar' \| 'with-split-buttons' \| 'with-buttons-below'`
|
|
74
|
+
|
|
75
|
+
## Toasts from code
|
|
76
|
+
|
|
77
|
+
`ToastService` keeps a queue of toasts that the toast host of `SmartProvider` (`SmartToastHost`, part of `SmartOverlays`) renders at the bottom of the screen through `SmartNotification`. A toast closes itself after `duration` ms (2000 by default) or on its close button.
|
|
78
|
+
|
|
79
|
+
```tsx
|
|
80
|
+
import { SmartButton, useToastService } from '@smartsoft001/react';
|
|
81
|
+
|
|
82
|
+
export function SaveButton({ save }: { save: () => Promise<void> }) {
|
|
83
|
+
const toasts = useToastService();
|
|
84
|
+
|
|
85
|
+
const run = async () => {
|
|
86
|
+
try {
|
|
87
|
+
await save();
|
|
88
|
+
await toasts.info({ message: 'Saved' });
|
|
89
|
+
} catch {
|
|
90
|
+
await toasts.error({
|
|
91
|
+
title: 'Saving failed',
|
|
92
|
+
message: 'Try again in a moment.',
|
|
93
|
+
duration: 5000,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
return <SmartButton options={{ click: () => void run() }}>Save</SmartButton>;
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
See `react-components-overlays` for the hosts and the full `IToastOptions` (buttons, durations, the error lock).
|
|
103
|
+
|
|
104
|
+
## Usage
|
|
105
|
+
|
|
106
|
+
```tsx
|
|
107
|
+
import { useState } from 'react';
|
|
108
|
+
|
|
109
|
+
import {
|
|
110
|
+
SmartNotification,
|
|
111
|
+
SmartNotificationPreset,
|
|
112
|
+
} from '@smartsoft001/react';
|
|
113
|
+
|
|
114
|
+
export function UndoNotice({ onUndo }: { onUndo: () => void }) {
|
|
115
|
+
const [visible, setVisible] = useState(true);
|
|
116
|
+
|
|
117
|
+
if (!visible) return null;
|
|
118
|
+
|
|
119
|
+
return (
|
|
120
|
+
<div className="fixed bottom-4 right-4 w-80 space-y-2">
|
|
121
|
+
<SmartNotificationPreset
|
|
122
|
+
title="Note archived"
|
|
123
|
+
description="You can restore it within 30 days."
|
|
124
|
+
iconName="📦"
|
|
125
|
+
dismissible
|
|
126
|
+
actions={[{ id: 'undo', label: 'Undo', variant: 'primary' }]}
|
|
127
|
+
options={{ variant: 'condensed' }}
|
|
128
|
+
onActionClick={({ actionId }) => {
|
|
129
|
+
if (actionId === 'undo') onUndo();
|
|
130
|
+
setVisible(false);
|
|
131
|
+
}}
|
|
132
|
+
onDismissed={() => setVisible(false)}
|
|
133
|
+
/>
|
|
134
|
+
<SmartNotification title="Synced" options={{ ariaLive: 'polite' }} />
|
|
135
|
+
</div>
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Replacing the Implementation
|
|
141
|
+
|
|
142
|
+
`SmartNotification` renders the component registered under the `'notification'` key of `SmartProvider`'s `components`, and `SmartNotificationStandard` when nothing is registered there. Every `SmartNotification` below the provider then renders the registered component, which receives the same props.
|
|
143
|
+
|
|
144
|
+
```tsx
|
|
145
|
+
import type { ReactNode } from 'react';
|
|
146
|
+
|
|
147
|
+
import { SmartProvider, SmartNotificationPreset } from '@smartsoft001/react';
|
|
148
|
+
|
|
149
|
+
// A module constant: a new object on every render would change the context.
|
|
150
|
+
const components = { notification: SmartNotificationPreset };
|
|
151
|
+
|
|
152
|
+
export function AppProviders({ children }: { children: ReactNode }) {
|
|
153
|
+
return <SmartProvider components={components}>{children}</SmartProvider>;
|
|
154
|
+
}
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
`SmartNotificationPreset` is the styled (preset) implementation: register it as above, render it directly in place of `SmartNotification`, 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.
|
|
158
|
+
|
|
159
|
+
### The `useNotification` hook
|
|
160
|
+
|
|
161
|
+
The behaviour every notification variant shares: `dismiss()` reports `onDismissed` and `invokeAction(id)` reports `onActionClick`. The notification does not hide itself; its owner removes it.
|
|
162
|
+
|
|
163
|
+
```ts
|
|
164
|
+
function useNotification({
|
|
165
|
+
onDismissed,
|
|
166
|
+
onActionClick,
|
|
167
|
+
}: SmartNotificationProps);
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
| Returns | Type | Description |
|
|
171
|
+
| -------------- | ----------------------------------------- | -------------------------------------- |
|
|
172
|
+
| `dismiss` | `() => void \| undefined` | Reports `onDismissed`. |
|
|
173
|
+
| `invokeAction` | `(actionId: string) => void \| undefined` | Reports `onActionClick({ actionId })`. |
|
|
174
|
+
|
|
175
|
+
```tsx
|
|
176
|
+
import { SmartNotificationProps, useNotification } from '@smartsoft001/react';
|
|
177
|
+
|
|
178
|
+
export function BannerNotification(props: SmartNotificationProps) {
|
|
179
|
+
const { dismiss, invokeAction } = useNotification(props);
|
|
180
|
+
|
|
181
|
+
return (
|
|
182
|
+
<div
|
|
183
|
+
role="status"
|
|
184
|
+
aria-live={props.options?.ariaLive ?? 'polite'}
|
|
185
|
+
className={props.className}
|
|
186
|
+
>
|
|
187
|
+
<strong>{props.title}</strong>
|
|
188
|
+
{props.description && <span> {props.description}</span>}
|
|
189
|
+
{props.actions?.map((action) => (
|
|
190
|
+
<button
|
|
191
|
+
key={action.id}
|
|
192
|
+
type="button"
|
|
193
|
+
onClick={() => invokeAction(action.id)}
|
|
194
|
+
>
|
|
195
|
+
{action.label}
|
|
196
|
+
</button>
|
|
197
|
+
))}
|
|
198
|
+
{props.dismissible && (
|
|
199
|
+
<button type="button" aria-label="Close" onClick={dismiss}>
|
|
200
|
+
×
|
|
201
|
+
</button>
|
|
202
|
+
)}
|
|
203
|
+
</div>
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
Registered as `components={{ notification: BannerNotification }}`, it also renders the toasts of `ToastService`.
|
|
209
|
+
|
|
210
|
+
## Styling
|
|
211
|
+
|
|
212
|
+
- Both renderings carry `smart:dark:` variants; the preset renders the six toast looks and labels itself with a `useId()`-based id.
|
|
213
|
+
|
|
214
|
+
## File Locations
|
|
215
|
+
|
|
216
|
+
Source: `packages/shared/react/src/lib/components/notification/` in the smartsoft001 repository.
|
|
217
|
+
|
|
218
|
+
- `notification.tsx`: `SmartNotification`
|
|
219
|
+
- `notification.types.ts`: `INotificationActionClick`, `SmartNotificationProps`
|
|
220
|
+
- `preset/notification-preset.tsx`: `SmartNotificationPreset`
|
|
221
|
+
- `standard/notification-standard.tsx`: `SmartNotificationStandard`
|
|
222
|
+
- `use-notification.ts`: `useNotification`
|
|
223
|
+
- `notification.stories.tsx`: Storybook stories
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: react-components-overlays
|
|
3
|
+
description: SmartOverlays React API (@smartsoft001/react) — SmartToastHost, SmartAlertHost and SmartModalHost that render what ToastService, AlertService and ModalService open (toasts, alert dialogs, modals from code), how SmartProvider mounts them (overlays prop) and how to render them yourself.
|
|
4
|
+
user-invocable: false
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Overlays (`SmartOverlays`)
|
|
8
|
+
|
|
9
|
+
Toasts, alert dialogs and modals opened from code live in services (`ToastService`, `AlertService`, `ModalService`, from `useToastService()`, `useAlertService()`, `useModalService()`). The **hosts** in this module render them: `SmartToastHost` (toasts through `SmartNotification`), `SmartAlertHost` (dialogs through `SmartAlert`) and `SmartModalHost` (components in a `SmartModal`). `SmartOverlays` renders all three, and `SmartProvider` renders `<SmartOverlays />` after its children by default. Every host renders into a portal at the end of `<body>`, once mounted in the browser, and only while it has something to show.
|
|
10
|
+
|
|
11
|
+
## When to Use This Skill
|
|
12
|
+
|
|
13
|
+
- Showing a toast, asking a confirmation or opening a component in a modal from an event handler
|
|
14
|
+
- Toasts or dialogs that do not appear (the hosts are not mounted, e.g. `overlays={null}`)
|
|
15
|
+
- Rendering the hosts at another place, or only some of them
|
|
16
|
+
- Changing how toasts, alerts or modals look (register `notification`, `alert` or `modal` components; the hosts render through them)
|
|
17
|
+
|
|
18
|
+
## Exports
|
|
19
|
+
|
|
20
|
+
All from `@smartsoft001/react`.
|
|
21
|
+
|
|
22
|
+
| Export | Kind | What it is |
|
|
23
|
+
| ---------------- | --------- | ------------------------------------------------------------------------ |
|
|
24
|
+
| `SmartOverlays` | component | The hosts of everything the services open: toasts, alerts and modals. |
|
|
25
|
+
| `SmartToastHost` | component | The toasts of `ToastService`, rendered through `<SmartNotification>`. |
|
|
26
|
+
| `SmartAlertHost` | component | The dialogs `AlertService.show` opened, rendered through `<SmartAlert>`. |
|
|
27
|
+
| `SmartModalHost` | component | The components `ModalService.show` opened, each in a `<SmartModal>`. |
|
|
28
|
+
|
|
29
|
+
## The services
|
|
30
|
+
|
|
31
|
+
### `ToastService` (`useToastService()`)
|
|
32
|
+
|
|
33
|
+
| Member | What it does |
|
|
34
|
+
| ---------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
|
|
35
|
+
| `info(options: IToastOptions): Promise<void>` | Queues an info toast. |
|
|
36
|
+
| `error(options: IToastOptions): Promise<void>` | Queues an error toast (`aria-live="assertive"`), unless an error lock is held. |
|
|
37
|
+
| `dismiss(id: number): void` | Removes a toast. |
|
|
38
|
+
| `addLockError()` / `removeLockError()` | Holds / releases the error lock: while held, error toasts are swallowed (e.g. during a sign-out that makes pending requests fail). |
|
|
39
|
+
| `toasts: SmartStore<IToast[]>` | The queue the host renders. |
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
interface IToastOptions {
|
|
43
|
+
title?: string;
|
|
44
|
+
message: string;
|
|
45
|
+
/** Milliseconds before the toast closes itself (default 2000). */
|
|
46
|
+
duration?: number;
|
|
47
|
+
// { text: string; position: 'start' | 'end'; handler: () => void }; the host renders them as actions, ignoring `position`
|
|
48
|
+
buttons?: Array<IToastButton>;
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
A toast with a title shows the title as the heading and the message under it; without one, the message is the heading. A toast with buttons renders in the `condensed` notification variant and its buttons as actions.
|
|
53
|
+
|
|
54
|
+
### `AlertService` (`useAlertService()`)
|
|
55
|
+
|
|
56
|
+
`show(options: IAlertOptions): Promise<IAlertButton | null>` opens a dialog and resolves with the chosen button, after its handler ran, or `null` on Escape / backdrop click without a cancel button. The focus goes back to the element that had it. `alerts: SmartStore<IAlertRequest[]>` is the list the host renders. `IAlertOptions` and the dialog behaviour are described in `react-components-alert`.
|
|
57
|
+
|
|
58
|
+
### `ModalService` (`useModalService()`)
|
|
59
|
+
|
|
60
|
+
| Member | What it does |
|
|
61
|
+
| ------------------------------------------------------ | -------------------------------------------- |
|
|
62
|
+
| `show(options: IModalServiceOptions): Promise<IModal>` | Opens `options.component` in a modal. |
|
|
63
|
+
| `dismiss(data?)` | Closes the modal opened last, with a result. |
|
|
64
|
+
| `modals: SmartStore<IModalRequest[]>` | The list the host renders. |
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
interface IModalServiceOptions {
|
|
68
|
+
component: ComponentType<any>; // receives `props` and a `dismiss(data)` prop
|
|
69
|
+
props?: Record<string, unknown>;
|
|
70
|
+
mode?: 'default' | 'bottom'; // not read by SmartModalHost
|
|
71
|
+
cssClass?: string[]; // joined into the SmartModal className
|
|
72
|
+
backdropDismiss?: boolean; // not read by SmartModalHost
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
interface IModal {
|
|
76
|
+
dismiss: (data?: any) => void;
|
|
77
|
+
onDidDismiss(): Promise<{ data: any }>;
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
`SmartModalHost` renders each request as `<SmartModal open className={cssClass.join(' ')} onClosed={() => dismiss()}>` around `<component {...props} dismiss={dismiss} />`, so closing the modal by its own controls resolves `onDidDismiss()` with `{ data: null }`.
|
|
82
|
+
|
|
83
|
+
## Usage
|
|
84
|
+
|
|
85
|
+
```tsx
|
|
86
|
+
import {
|
|
87
|
+
SmartButton,
|
|
88
|
+
useAlertService,
|
|
89
|
+
useModalService,
|
|
90
|
+
useToastService,
|
|
91
|
+
} from '@smartsoft001/react';
|
|
92
|
+
|
|
93
|
+
function NoteEditor({ dismiss }: { dismiss: (data?: unknown) => void }) {
|
|
94
|
+
return (
|
|
95
|
+
<SmartButton options={{ click: () => dismiss('saved') }}>
|
|
96
|
+
Save and close
|
|
97
|
+
</SmartButton>
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function NoteActions({ remove }: { remove: () => Promise<void> }) {
|
|
102
|
+
const toasts = useToastService();
|
|
103
|
+
const alerts = useAlertService();
|
|
104
|
+
const modals = useModalService();
|
|
105
|
+
|
|
106
|
+
const onDelete = async () => {
|
|
107
|
+
const button = await alerts.show({
|
|
108
|
+
header: 'Delete note?',
|
|
109
|
+
buttons: [
|
|
110
|
+
{ text: 'Cancel', role: 'cancel' },
|
|
111
|
+
{ text: 'Delete', role: 'destructive' },
|
|
112
|
+
],
|
|
113
|
+
});
|
|
114
|
+
if (button?.role !== 'destructive') return;
|
|
115
|
+
|
|
116
|
+
await remove();
|
|
117
|
+
await toasts.info({
|
|
118
|
+
message: 'Note deleted',
|
|
119
|
+
buttons: [{ text: 'OK', position: 'end', handler: () => undefined }],
|
|
120
|
+
});
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const onEdit = async () => {
|
|
124
|
+
const modal = await modals.show({
|
|
125
|
+
component: NoteEditor,
|
|
126
|
+
cssClass: ['max-w-2xl'],
|
|
127
|
+
});
|
|
128
|
+
const { data } = await modal.onDidDismiss();
|
|
129
|
+
if (data === 'saved') await toasts.info({ message: 'Saved' });
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
return (
|
|
133
|
+
<>
|
|
134
|
+
<SmartButton options={{ click: () => void onEdit() }}>Edit</SmartButton>
|
|
135
|
+
<SmartButton options={{ click: () => void onDelete(), color: 'red' }}>
|
|
136
|
+
Delete
|
|
137
|
+
</SmartButton>
|
|
138
|
+
</>
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## Replacing the Implementation
|
|
144
|
+
|
|
145
|
+
The hosts have no registry key; they render through the registered `notification`, `alert` and `modal` components, so registering those (or spreading `SMART_PRESET_COMPONENTS`) restyles toasts, dialogs and modals.
|
|
146
|
+
|
|
147
|
+
To place the hosts yourself, turn the default off with `overlays={null}` (or pass your own node) and render the hosts you want anywhere below the provider:
|
|
148
|
+
|
|
149
|
+
```tsx
|
|
150
|
+
import type { ReactNode } from 'react';
|
|
151
|
+
|
|
152
|
+
import {
|
|
153
|
+
SmartAlertHost,
|
|
154
|
+
SmartModalHost,
|
|
155
|
+
SmartProvider,
|
|
156
|
+
SmartToastHost,
|
|
157
|
+
} from '@smartsoft001/react';
|
|
158
|
+
|
|
159
|
+
export function AppProviders({ children }: { children: ReactNode }) {
|
|
160
|
+
return (
|
|
161
|
+
<SmartProvider overlays={null}>
|
|
162
|
+
{children}
|
|
163
|
+
<SmartToastHost />
|
|
164
|
+
<SmartAlertHost />
|
|
165
|
+
<SmartModalHost />
|
|
166
|
+
</SmartProvider>
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
A host renders nothing during server-side rendering and until it has mounted, then portals into `document.body`.
|
|
172
|
+
|
|
173
|
+
## Styling
|
|
174
|
+
|
|
175
|
+
- The toast stack is fixed to the bottom of the screen (centred, right-aligned from `sm`), with each toast `max-w-sm`.
|
|
176
|
+
- Looks come from the registered `notification` / `alert` / `modal` implementations, with their dark-mode variants.
|
|
177
|
+
|
|
178
|
+
## File Locations
|
|
179
|
+
|
|
180
|
+
Source: `packages/shared/react/src/lib/components/overlays/` in the smartsoft001 repository.
|
|
181
|
+
|
|
182
|
+
- `overlays.tsx`: `SmartToastHost`, `SmartAlertHost`, `SmartModalHost`, `SmartOverlays`
|