@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,183 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: react-components-breadcrumbs
|
|
3
|
+
description: SmartBreadcrumbs React component API (@smartsoft001/react) — breadcrumb trail with link or button items, chevron/slash/arrow separators and four layouts, onItemClick, the 'breadcrumbs' registry key, SmartBreadcrumbsPreset and useBreadcrumbs.
|
|
4
|
+
user-invocable: false
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Breadcrumbs (`SmartBreadcrumbs`)
|
|
8
|
+
|
|
9
|
+
`SmartBreadcrumbs` renders a breadcrumb trail inside a `nav` (labelled `options.ariaLabel`, `'Breadcrumb'` by default). Items with `href` are links; items without one are buttons reported through `onItemClick({ itemId })`, so the trail also works with a router that navigates in code. The item marked `current` gets `aria-current="page"`. `options.separator` and `options.layout` choose the look, styled by `SmartBreadcrumbsPreset`.
|
|
10
|
+
|
|
11
|
+
## When to Use This Skill
|
|
12
|
+
|
|
13
|
+
- Showing where a page sits in the hierarchy (Home / Projects / Alpha)
|
|
14
|
+
- Navigating through a click handler instead of `href` (`onItemClick`)
|
|
15
|
+
- Choosing the separator glyph or a contained / full-width bar layout
|
|
16
|
+
- Restyling every breadcrumb trail (the `breadcrumbs` registry key)
|
|
17
|
+
|
|
18
|
+
## Exports
|
|
19
|
+
|
|
20
|
+
All from `@smartsoft001/react`.
|
|
21
|
+
|
|
22
|
+
| Export | Kind | What it is |
|
|
23
|
+
| -------------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
24
|
+
| `SmartBreadcrumbs` | component | Renders the implementation registered as `components.breadcrumbs` on `SmartProvider`, `SmartBreadcrumbsStandard` by default. |
|
|
25
|
+
| `SmartBreadcrumbsPreset` | component | Styled breadcrumbs variation (preset). |
|
|
26
|
+
| `SmartBreadcrumbsStandard` | component | The default breadcrumbs rendering: semantic markup with `breadcrumbs-*` class hooks; items with `href` are links, the others buttons reporting `onItemClick`. |
|
|
27
|
+
| `useBreadcrumbs` | hook | The behaviour every breadcrumbs variant shares: the items to render and the click on an item without `href`, reported as `{ itemId }`. |
|
|
28
|
+
|
|
29
|
+
The preset's class helpers (`getBreadcrumbsNavClasses`, `getBreadcrumbsListClasses`, `getBreadcrumbsItemClasses`, `getBreadcrumbsLinkClasses`, `getBreadcrumbsCurrentClasses`, `getBreadcrumbsSeparatorClasses`, `resolveBreadcrumbsSeparator`) are exported too, for a custom implementation that wants the preset look.
|
|
30
|
+
|
|
31
|
+
## Props and Types
|
|
32
|
+
|
|
33
|
+
### `SmartBreadcrumbsProps`
|
|
34
|
+
|
|
35
|
+
| Prop | Type | Default | Description |
|
|
36
|
+
| -------------- | ---------------------------------------- | ------- | ------------------------------------------------------- |
|
|
37
|
+
| `options?` | `IBreadcrumbsOptions` | — | The items and the look. |
|
|
38
|
+
| `className?` | `string` | — | Classes on the root `nav`. |
|
|
39
|
+
| `onItemClick?` | `(event: IBreadcrumbsItemClick) => void` | — | Click on an item without `href` (rendered as a button). |
|
|
40
|
+
|
|
41
|
+
### `IBreadcrumbsOptions`
|
|
42
|
+
|
|
43
|
+
| Field | Type | Default | Description |
|
|
44
|
+
| ------------ | --------------------------- | -------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
45
|
+
| `layout?` | `SmartBreadcrumbsLayout` | — | `contained` or `full-width-bar` wrap the trail in a bar; `simple-with-slashes` implies the slash separator. Read by the preset; the standard markup ignores it. |
|
|
46
|
+
| `ariaLabel?` | `string` | `'Breadcrumb'` | Accessible name of the `nav`. |
|
|
47
|
+
| `separator?` | `SmartBreadcrumbsSeparator` | `'chevron'` | Glyph between items (`data-separator` on the standard markup). |
|
|
48
|
+
| `items` | `IBreadcrumbItem[]` | required | The trail, first to last. |
|
|
49
|
+
|
|
50
|
+
### `IBreadcrumbsItemClick`
|
|
51
|
+
|
|
52
|
+
Payload of `onItemClick`.
|
|
53
|
+
|
|
54
|
+
| Field | Type | Default | Description |
|
|
55
|
+
| -------- | -------- | -------- | ----------------------------- |
|
|
56
|
+
| `itemId` | `string` | required | The `id` of the clicked item. |
|
|
57
|
+
|
|
58
|
+
### `IBreadcrumbItem`
|
|
59
|
+
|
|
60
|
+
| Field | Type | Default | Description |
|
|
61
|
+
| -------------- | ----------- | -------- | ------------------------------------------------------------ |
|
|
62
|
+
| `id` | `string` | required | Reported as `itemId` by `onItemClick`. |
|
|
63
|
+
| `label?` | `string` | — | Visible text. |
|
|
64
|
+
| `href?` | `string` | — | Renders the item as a link; without it the item is a button. |
|
|
65
|
+
| `iconTpl?` | `ReactNode` | — | Icon before the label (e.g. a home icon). |
|
|
66
|
+
| `srOnlyLabel?` | `string` | — | Text for screen readers only, for an icon-only item. |
|
|
67
|
+
| `current?` | `boolean` | — | Marks the current page (`aria-current="page"`). |
|
|
68
|
+
|
|
69
|
+
### Related types
|
|
70
|
+
|
|
71
|
+
- `SmartBreadcrumbsLayout`: `'contained' \| 'full-width-bar' \| 'simple-with-chevrons' \| 'simple-with-slashes'`
|
|
72
|
+
- `SmartBreadcrumbsSeparator`: `'chevron' \| 'slash' \| 'arrow'`
|
|
73
|
+
|
|
74
|
+
## Usage
|
|
75
|
+
|
|
76
|
+
```tsx
|
|
77
|
+
import { SmartBreadcrumbs, useNavigation } from '@smartsoft001/react';
|
|
78
|
+
|
|
79
|
+
export function ProjectBreadcrumbs({ projectName }: { projectName: string }) {
|
|
80
|
+
const navigation = useNavigation();
|
|
81
|
+
|
|
82
|
+
return (
|
|
83
|
+
<SmartBreadcrumbs
|
|
84
|
+
options={{
|
|
85
|
+
separator: 'slash',
|
|
86
|
+
items: [
|
|
87
|
+
{ id: 'home', label: 'Home', href: '/' },
|
|
88
|
+
{ id: 'projects', label: 'Projects' },
|
|
89
|
+
{ id: 'project', label: projectName, current: true },
|
|
90
|
+
],
|
|
91
|
+
}}
|
|
92
|
+
onItemClick={({ itemId }) => {
|
|
93
|
+
if (itemId === 'projects') navigation.navigate('/projects');
|
|
94
|
+
}}
|
|
95
|
+
/>
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Replacing the Implementation
|
|
101
|
+
|
|
102
|
+
`SmartBreadcrumbs` renders the component registered under the `'breadcrumbs'` key of `SmartProvider`'s `components`, and `SmartBreadcrumbsStandard` when nothing is registered there. Every `SmartBreadcrumbs` below the provider then renders the registered component, which receives the same props.
|
|
103
|
+
|
|
104
|
+
```tsx
|
|
105
|
+
import type { ReactNode } from 'react';
|
|
106
|
+
|
|
107
|
+
import { SmartProvider, SmartBreadcrumbsPreset } from '@smartsoft001/react';
|
|
108
|
+
|
|
109
|
+
// A module constant: a new object on every render would change the context.
|
|
110
|
+
const components = { breadcrumbs: SmartBreadcrumbsPreset };
|
|
111
|
+
|
|
112
|
+
export function AppProviders({ children }: { children: ReactNode }) {
|
|
113
|
+
return <SmartProvider components={components}>{children}</SmartProvider>;
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
`SmartBreadcrumbsPreset` is the styled (preset) implementation: register it as above, render it directly in place of `SmartBreadcrumbs`, 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.
|
|
118
|
+
|
|
119
|
+
### The `useBreadcrumbs` hook
|
|
120
|
+
|
|
121
|
+
The behaviour every breadcrumbs variant shares: the items to render and the click on an item without `href`, reported as `{ itemId }`.
|
|
122
|
+
|
|
123
|
+
```ts
|
|
124
|
+
function useBreadcrumbs({
|
|
125
|
+
options,
|
|
126
|
+
onItemClick,
|
|
127
|
+
}: Pick<SmartBreadcrumbsProps, 'options' | 'onItemClick'>);
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
| Returns | Type | Description |
|
|
131
|
+
| ----------- | --------------------------------------- | ---------------------------------------------------------- |
|
|
132
|
+
| `items` | `IBreadcrumbItem[]` | `options.items ?? []`. |
|
|
133
|
+
| `itemClick` | `(itemId: string) => void \| undefined` | Reports a click on an item without `href` as `{ itemId }`. |
|
|
134
|
+
|
|
135
|
+
```tsx
|
|
136
|
+
import { SmartBreadcrumbsProps, useBreadcrumbs } from '@smartsoft001/react';
|
|
137
|
+
|
|
138
|
+
export function TextBreadcrumbs({
|
|
139
|
+
options,
|
|
140
|
+
className,
|
|
141
|
+
onItemClick,
|
|
142
|
+
}: SmartBreadcrumbsProps) {
|
|
143
|
+
const { items, itemClick } = useBreadcrumbs({ options, onItemClick });
|
|
144
|
+
|
|
145
|
+
return (
|
|
146
|
+
<nav aria-label={options?.ariaLabel ?? 'Breadcrumb'} className={className}>
|
|
147
|
+
{items.map((item, index) => (
|
|
148
|
+
<span key={item.id}>
|
|
149
|
+
{index > 0 && ' › '}
|
|
150
|
+
{item.href ? (
|
|
151
|
+
<a
|
|
152
|
+
href={item.href}
|
|
153
|
+
aria-current={item.current ? 'page' : undefined}
|
|
154
|
+
>
|
|
155
|
+
{item.label}
|
|
156
|
+
</a>
|
|
157
|
+
) : (
|
|
158
|
+
<button type="button" onClick={() => itemClick(item.id)}>
|
|
159
|
+
{item.label}
|
|
160
|
+
</button>
|
|
161
|
+
)}
|
|
162
|
+
</span>
|
|
163
|
+
))}
|
|
164
|
+
</nav>
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## Styling
|
|
170
|
+
|
|
171
|
+
- `SmartBreadcrumbsStandard` renders semantic markup with `breadcrumbs-*` class hooks (`breadcrumbs-link`, `breadcrumbs-button`, `breadcrumbs-separator`, `current`) and `data-separator` for your own CSS.
|
|
172
|
+
- `SmartBreadcrumbsPreset` renders muted links, a bold current crumb and the separator glyph, with `smart:dark:` variants.
|
|
173
|
+
|
|
174
|
+
## File Locations
|
|
175
|
+
|
|
176
|
+
Source: `packages/shared/react/src/lib/components/breadcrumbs/` in the smartsoft001 repository.
|
|
177
|
+
|
|
178
|
+
- `breadcrumbs.tsx`: `SmartBreadcrumbs`
|
|
179
|
+
- `breadcrumbs.types.ts`: `IBreadcrumbsItemClick`, `SmartBreadcrumbsProps`
|
|
180
|
+
- `preset/breadcrumbs-preset.tsx`: `SmartBreadcrumbsPreset`
|
|
181
|
+
- `standard/breadcrumbs-standard.tsx`: `SmartBreadcrumbsStandard`
|
|
182
|
+
- `use-breadcrumbs.ts`: `useBreadcrumbs`
|
|
183
|
+
- `breadcrumbs.stories.tsx`: Storybook stories
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: react-components-button
|
|
3
|
+
description: SmartButton React component API (@smartsoft001/react) — IButtonOptions (click, variant, color, size, confirm, loading), the 'button' registry key, SmartButtonPreset and the useButton hook for custom implementations.
|
|
4
|
+
user-invocable: false
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Button (`SmartButton`)
|
|
8
|
+
|
|
9
|
+
`SmartButton` is the button of `@smartsoft001/react`. It is configured through an `IButtonOptions` object (`click` plus the look: `variant`, `color`, `size`, `rounded`, `circular`), renders its `children` as the label, shows a spinner while `options.loading` is `true`, and with `options.confirm` turns the first click into a Cancel / Confirm pair before `click` runs. The wrapper renders whatever is registered under the `button` key of `SmartProvider` (`SmartButtonStandard` by default), so one registration restyles every button of the application.
|
|
10
|
+
|
|
11
|
+
## When to Use This Skill
|
|
12
|
+
|
|
13
|
+
- Rendering a clickable action (save, delete, submit) in a React app built with `@smartsoft001/react`
|
|
14
|
+
- Asking for a confirmation step before an action runs (`options.confirm`)
|
|
15
|
+
- Showing a loading spinner on a button while a request runs
|
|
16
|
+
- Restyling every button (register `SmartButtonPreset` or an own component under the `button` key)
|
|
17
|
+
- Writing a custom button on top of `useButton`
|
|
18
|
+
|
|
19
|
+
## Exports
|
|
20
|
+
|
|
21
|
+
All from `@smartsoft001/react`.
|
|
22
|
+
|
|
23
|
+
| Export | Kind | What it is |
|
|
24
|
+
| --------------------- | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
25
|
+
| `SmartButton` | component | Renders the implementation registered as `components.button` on `SmartProvider`, `SmartButtonStandard` by default. |
|
|
26
|
+
| `SmartButtonPreset` | component | Styled button variation (preset). |
|
|
27
|
+
| `SmartButtonStandard` | component | The default button rendering. |
|
|
28
|
+
| `useButton` | hook | The behaviour every button variant shares: the colour classes of the variant, and the confirm mode, where a first click asks for confirmation instead of running `options.click`. |
|
|
29
|
+
|
|
30
|
+
The preset's class helpers (`toButtonPresetVariant`, `getButtonPresetClasses`) are exported too, for a custom implementation that wants the preset look.
|
|
31
|
+
|
|
32
|
+
## Props and Types
|
|
33
|
+
|
|
34
|
+
### `SmartButtonProps`
|
|
35
|
+
|
|
36
|
+
| Prop | Type | Default | Description |
|
|
37
|
+
| ------------ | ---------------- | -------- | ----------------------------------------------------------------------------- |
|
|
38
|
+
| `options` | `IButtonOptions` | required | The button configuration; `click` is required. |
|
|
39
|
+
| `disabled?` | `boolean` | `false` | Disables the button and adds `smart:opacity-50 smart:cursor-not-allowed`. |
|
|
40
|
+
| `className?` | `string` | — | Classes appended to the `<button>`. |
|
|
41
|
+
| `children?` | `ReactNode` | — | The label (any `ReactNode`). Replaced by the spinner while `options.loading`. |
|
|
42
|
+
|
|
43
|
+
### `IButtonOptions`
|
|
44
|
+
|
|
45
|
+
| Field | Type | Default | Description |
|
|
46
|
+
| --------------- | ------------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------ |
|
|
47
|
+
| `type?` | `'submit' \| 'button'` | `'button'` | The `type` attribute of the `<button>`. Use `'submit'` inside a `<form>` of your own. |
|
|
48
|
+
| `confirm?` | `boolean` | — | The first click shows Cancel / Confirm buttons (translated `cancel` / `confirm`); `click` runs only after Confirm. |
|
|
49
|
+
| `click` | `() => void` | required | Called on click (after the confirmation when `confirm` is set). |
|
|
50
|
+
| `loading?` | `boolean` | — | Shows the spinner instead of the label and disables the button. |
|
|
51
|
+
| `variant?` | `SmartVariant` | `'primary'` | `primary` (solid), `secondary` (outline) or `soft`. |
|
|
52
|
+
| `size?` | `SmartSize` | `'md'` | Padding and text size; `xs` / `sm` also use smaller rounding. |
|
|
53
|
+
| `color?` | `SmartColor` | `'indigo'` | One of the 22 Tailwind palette names. |
|
|
54
|
+
| `rounded?` | `boolean` | — | Pill shape. Read by `SmartButtonPreset` only. |
|
|
55
|
+
| `circular?` | `boolean` | — | Square padding plus pill shape, for an icon-only button. Read by `SmartButtonPreset` only. |
|
|
56
|
+
| `iconPosition?` | `'leading' \| 'trailing'` | — | Declared for implementations of your own; neither `SmartButtonStandard` nor `SmartButtonPreset` reads it. |
|
|
57
|
+
|
|
58
|
+
`SmartColor`, `SmartSize`, `SmartVariant` are described in the `react-provider` skill.
|
|
59
|
+
|
|
60
|
+
## Behaviour
|
|
61
|
+
|
|
62
|
+
- There is no `onClick` prop: the handler is `options.click`.
|
|
63
|
+
- `options.loading` and `disabled` both disable the `<button>`; while loading, the label is replaced by `<SmartIcon name="spinner" />`.
|
|
64
|
+
- With `options.confirm` the button switches to a confirm mode: it renders a Cancel and a Confirm button instead of itself. Confirm runs `click` and returns to the normal mode; Cancel only returns. The labels come from the provider's translations (`cancel`, `confirm`).
|
|
65
|
+
- `options.type` defaults to `'button'`, so a `SmartButton` inside a `<form>` does not submit it unless you pass `type: 'submit'`.
|
|
66
|
+
|
|
67
|
+
## Usage
|
|
68
|
+
|
|
69
|
+
```tsx
|
|
70
|
+
import { useState } from 'react';
|
|
71
|
+
|
|
72
|
+
import { SmartButton, SmartButtonPreset } from '@smartsoft001/react';
|
|
73
|
+
|
|
74
|
+
export function SaveActions({
|
|
75
|
+
onSave,
|
|
76
|
+
onDelete,
|
|
77
|
+
}: {
|
|
78
|
+
onSave: () => Promise<void>;
|
|
79
|
+
onDelete: () => void;
|
|
80
|
+
}) {
|
|
81
|
+
const [saving, setSaving] = useState(false);
|
|
82
|
+
|
|
83
|
+
const save = async () => {
|
|
84
|
+
setSaving(true);
|
|
85
|
+
try {
|
|
86
|
+
await onSave();
|
|
87
|
+
} finally {
|
|
88
|
+
setSaving(false);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
return (
|
|
93
|
+
<div className="flex gap-2">
|
|
94
|
+
{/* Rendered by whatever is registered under `button` (standard by default). */}
|
|
95
|
+
<SmartButton
|
|
96
|
+
options={{
|
|
97
|
+
click: () => void save(),
|
|
98
|
+
loading: saving,
|
|
99
|
+
variant: 'primary',
|
|
100
|
+
size: 'lg',
|
|
101
|
+
}}
|
|
102
|
+
>
|
|
103
|
+
Save
|
|
104
|
+
</SmartButton>
|
|
105
|
+
|
|
106
|
+
{/* The first click asks for confirmation. */}
|
|
107
|
+
<SmartButton
|
|
108
|
+
options={{
|
|
109
|
+
click: onDelete,
|
|
110
|
+
confirm: true,
|
|
111
|
+
color: 'red',
|
|
112
|
+
variant: 'secondary',
|
|
113
|
+
}}
|
|
114
|
+
>
|
|
115
|
+
Delete
|
|
116
|
+
</SmartButton>
|
|
117
|
+
|
|
118
|
+
{/* The preset rendered directly, without registering it. */}
|
|
119
|
+
<SmartButtonPreset
|
|
120
|
+
options={{ click: () => undefined, variant: 'soft', rounded: true }}
|
|
121
|
+
>
|
|
122
|
+
Pill
|
|
123
|
+
</SmartButtonPreset>
|
|
124
|
+
</div>
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Replacing the Implementation
|
|
130
|
+
|
|
131
|
+
`SmartButton` renders the component registered under the `'button'` key of `SmartProvider`'s `components`, and `SmartButtonStandard` when nothing is registered there. Every `SmartButton` below the provider then renders the registered component, which receives the same props.
|
|
132
|
+
|
|
133
|
+
```tsx
|
|
134
|
+
import type { ReactNode } from 'react';
|
|
135
|
+
|
|
136
|
+
import { SmartProvider, SmartButtonPreset } from '@smartsoft001/react';
|
|
137
|
+
|
|
138
|
+
// A module constant: a new object on every render would change the context.
|
|
139
|
+
const components = { button: SmartButtonPreset };
|
|
140
|
+
|
|
141
|
+
export function AppProviders({ children }: { children: ReactNode }) {
|
|
142
|
+
return <SmartProvider components={components}>{children}</SmartProvider>;
|
|
143
|
+
}
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
`SmartButtonPreset` is the styled (preset) implementation: register it as above, render it directly in place of `SmartButton`, 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.
|
|
147
|
+
|
|
148
|
+
### The `useButton` hook
|
|
149
|
+
|
|
150
|
+
The behaviour every button variant shares: the colour classes of the variant, and the confirm mode, where a first click asks for confirmation instead of running `options.click`.
|
|
151
|
+
|
|
152
|
+
```ts
|
|
153
|
+
function useButton({ options, disabled = false }: SmartButtonProps);
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
| Returns | Type | Description |
|
|
157
|
+
| ---------------- | ------------------------ | ------------------------------------------------------------------------------------------------------------- |
|
|
158
|
+
| `mode` | `"default" \| "confirm"` | `'confirm'` after a first click on a `confirm` button, `'default'` otherwise. |
|
|
159
|
+
| `loading` | `boolean` | `!!options.loading`. |
|
|
160
|
+
| `variantClasses` | `string[]` | The colour classes of `options.variant` / `options.color` from `COMPONENT_COLORS`, plus the disabled classes. |
|
|
161
|
+
| `invoke` | `() => void` | The click handler: runs `options.click`, or enters the confirm mode when `options.confirm`. |
|
|
162
|
+
| `confirmInvoke` | `() => void` | Runs `options.click` and leaves the confirm mode. |
|
|
163
|
+
| `confirmCancel` | `() => void` | Leaves the confirm mode without running `click`. |
|
|
164
|
+
|
|
165
|
+
A custom button builds on `useButton`, which keeps the confirm mode and computes the colour classes of `options.variant` / `options.color`:
|
|
166
|
+
|
|
167
|
+
```tsx
|
|
168
|
+
import type { ReactNode } from 'react';
|
|
169
|
+
|
|
170
|
+
import {
|
|
171
|
+
SmartButtonProps,
|
|
172
|
+
SmartProvider,
|
|
173
|
+
useButton,
|
|
174
|
+
useTranslate,
|
|
175
|
+
} from '@smartsoft001/react';
|
|
176
|
+
|
|
177
|
+
export function BrandButton(props: SmartButtonProps) {
|
|
178
|
+
const { options, disabled = false, className, children } = props;
|
|
179
|
+
const t = useTranslate();
|
|
180
|
+
const {
|
|
181
|
+
mode,
|
|
182
|
+
loading,
|
|
183
|
+
variantClasses,
|
|
184
|
+
invoke,
|
|
185
|
+
confirmInvoke,
|
|
186
|
+
confirmCancel,
|
|
187
|
+
} = useButton(props);
|
|
188
|
+
|
|
189
|
+
if (mode === 'confirm') {
|
|
190
|
+
return (
|
|
191
|
+
<span className="inline-flex gap-2">
|
|
192
|
+
<button type="button" onClick={confirmCancel}>
|
|
193
|
+
{t('cancel')}
|
|
194
|
+
</button>
|
|
195
|
+
<button type="button" onClick={confirmInvoke}>
|
|
196
|
+
{t('confirm')}
|
|
197
|
+
</button>
|
|
198
|
+
</span>
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return (
|
|
203
|
+
<button
|
|
204
|
+
type={options.type ?? 'button'}
|
|
205
|
+
className={[...variantClasses, 'rounded-full px-6 py-2', className]
|
|
206
|
+
.filter(Boolean)
|
|
207
|
+
.join(' ')}
|
|
208
|
+
disabled={disabled || loading}
|
|
209
|
+
onClick={invoke}
|
|
210
|
+
>
|
|
211
|
+
{loading ? '…' : children}
|
|
212
|
+
</button>
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// Registered once, at the root: every SmartButton now renders BrandButton.
|
|
217
|
+
const components = { button: BrandButton };
|
|
218
|
+
|
|
219
|
+
export function App({ children }: { children: ReactNode }) {
|
|
220
|
+
return <SmartProvider components={components}>{children}</SmartProvider>;
|
|
221
|
+
}
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
## Styling
|
|
225
|
+
|
|
226
|
+
- Classes are Tailwind 4 utilities with the `smart:` prefix; import `@smartsoft001/react/styles.css` once in the app.
|
|
227
|
+
- Every colour of `COMPONENT_COLORS` (used by `useButton().variantClasses`) carries `smart:dark:` variants, and the preset classes do too, so the button follows the `dark` class on `<html>`.
|
|
228
|
+
- `className` is appended last, so it can add spacing or override utilities.
|
|
229
|
+
|
|
230
|
+
## File Locations
|
|
231
|
+
|
|
232
|
+
Source: `packages/shared/react/src/lib/components/button/` in the smartsoft001 repository.
|
|
233
|
+
|
|
234
|
+
- `button.tsx`: `SmartButton`
|
|
235
|
+
- `button.types.ts`: `SmartButtonProps`
|
|
236
|
+
- `preset/button-preset.tsx`: `SmartButtonPreset`
|
|
237
|
+
- `standard/button-standard.tsx`: `SmartButtonStandard`
|
|
238
|
+
- `use-button.ts`: `useButton`
|
|
239
|
+
- `button.stories.tsx`: Storybook stories
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: react-components-button-group
|
|
3
|
+
description: SmartButtonGroup React component API (@smartsoft001/react) — segmented control of toggle buttons with labels, icons and counts, controlled selected/onSelectedChange or uncontrolled defaultSelected, onButtonClick, the 'button-group' registry key, SmartButtonGroupPreset and useButtonGroup.
|
|
4
|
+
user-invocable: false
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Button Group (`SmartButtonGroup`)
|
|
8
|
+
|
|
9
|
+
`SmartButtonGroup` renders a row of toggle buttons (a segmented control, `role="group"`) where one button is selected. Each button has an `id`, a label and optionally an icon and a count. The selection is controlled (`selected` + `onSelectedChange`) or kept inside the group (`defaultSelected`); every click is also reported through `onButtonClick({ buttonId })`. `SmartButtonGroupStandard` is unstyled; `SmartButtonGroupPreset` is the styled look.
|
|
10
|
+
|
|
11
|
+
## When to Use This Skill
|
|
12
|
+
|
|
13
|
+
- Switching between views or periods (Day / Week / Month)
|
|
14
|
+
- A compact single-choice selector with counts (`count`)
|
|
15
|
+
- Restyling every button group (the `button-group` registry key)
|
|
16
|
+
|
|
17
|
+
## Exports
|
|
18
|
+
|
|
19
|
+
All from `@smartsoft001/react`.
|
|
20
|
+
|
|
21
|
+
| Export | Kind | What it is |
|
|
22
|
+
| -------------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
23
|
+
| `SmartButtonGroup` | component | Renders the implementation registered as `components['button-group']` on `SmartProvider`, `SmartButtonGroupStandard` by default. |
|
|
24
|
+
| `SmartButtonGroupPreset` | component | Styled button group variation (preset). |
|
|
25
|
+
| `SmartButtonGroupStandard` | component | The default button group rendering: an unstyled `role="group"` of toggle buttons with their label and count. |
|
|
26
|
+
| `useButtonGroup` | hook | The behaviour every button group variant shares: the selected button id, controlled through `selected` / `onSelectedChange` or kept internally, and `select(id)`, which selects a button and emits `onButtonClick`. |
|
|
27
|
+
|
|
28
|
+
The preset's class helpers (`getButtonGroupClasses`, `getButtonGroupButtonClasses`, `getButtonGroupCountClasses`, `getButtonGroupIconClasses`, `BUTTON_GROUP_CONTAINER`) are exported too, for a custom implementation that wants the preset look.
|
|
29
|
+
|
|
30
|
+
## Props and Types
|
|
31
|
+
|
|
32
|
+
### `SmartButtonGroupProps`
|
|
33
|
+
|
|
34
|
+
| Prop | Type | Default | Description |
|
|
35
|
+
| ------------------- | ------------------------------------------ | ------- | ------------------------------------------------------------------------------------------------------- |
|
|
36
|
+
| `buttons?` | `IButtonGroupButton[]` | `[]` | The buttons, in order. |
|
|
37
|
+
| `options?` | `IButtonGroupOptions` | — | The variant. |
|
|
38
|
+
| `selected?` | `string` | — | The id of the selected button. Controlled when defined; otherwise the group keeps the selection itself. |
|
|
39
|
+
| `defaultSelected?` | `string` | — | The initial selection when `selected` is not controlled. |
|
|
40
|
+
| `onSelectedChange?` | `(selected: string) => void` | — | Called with the id of the button the user selected. |
|
|
41
|
+
| `className?` | `string` | — | Classes on the group container. |
|
|
42
|
+
| `onButtonClick?` | `(event: IButtonGroupButtonClick) => void` | — | A button was clicked. |
|
|
43
|
+
|
|
44
|
+
### `IButtonGroupOptions`
|
|
45
|
+
|
|
46
|
+
| Field | Type | Default | Description |
|
|
47
|
+
| ---------- | ------------------------- | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
48
|
+
| `variant?` | `SmartButtonGroupVariant` | `'basic'` | Read by the preset: `icon-only` hides the labels, `with-stat` styles the count as a pill; `with-dropdown` and `with-checkbox-select` render like `basic`. |
|
|
49
|
+
|
|
50
|
+
### `IButtonGroupButtonClick`
|
|
51
|
+
|
|
52
|
+
Payload of `onButtonClick`.
|
|
53
|
+
|
|
54
|
+
| Field | Type | Default | Description |
|
|
55
|
+
| ---------- | -------- | -------- | ------------------------------- |
|
|
56
|
+
| `buttonId` | `string` | required | The `id` of the clicked button. |
|
|
57
|
+
|
|
58
|
+
### `IButtonGroupButton`
|
|
59
|
+
|
|
60
|
+
| Field | Type | Default | Description |
|
|
61
|
+
| ----------- | --------- | -------- | ---------------------------------------------------------------------------- |
|
|
62
|
+
| `id` | `string` | required | Identifies the button in `selected`, `onSelectedChange` and `onButtonClick`. |
|
|
63
|
+
| `label?` | `string` | — | Visible text (moved to `aria-label` by the preset's `icon-only` variant). |
|
|
64
|
+
| `icon?` | `string` | — | Text or glyph rendered before the label by the preset. |
|
|
65
|
+
| `disabled?` | `boolean` | — | Disables the button. |
|
|
66
|
+
| `count?` | `number` | — | A number shown after the label. |
|
|
67
|
+
|
|
68
|
+
### Related types
|
|
69
|
+
|
|
70
|
+
- `SmartButtonGroupVariant`: `'basic' \| 'icon-only' \| 'with-stat' \| 'with-dropdown' \| 'with-checkbox-select'`
|
|
71
|
+
|
|
72
|
+
## Usage
|
|
73
|
+
|
|
74
|
+
```tsx
|
|
75
|
+
import { useState } from 'react';
|
|
76
|
+
|
|
77
|
+
import { SmartButtonGroup, SmartButtonGroupPreset } from '@smartsoft001/react';
|
|
78
|
+
|
|
79
|
+
const PERIODS = [
|
|
80
|
+
{ id: 'day', label: 'Day' },
|
|
81
|
+
{ id: 'week', label: 'Week' },
|
|
82
|
+
{ id: 'month', label: 'Month', count: 3 },
|
|
83
|
+
];
|
|
84
|
+
|
|
85
|
+
export function PeriodSwitch({ onPeriod }: { onPeriod: (id: string) => void }) {
|
|
86
|
+
const [period, setPeriod] = useState('week');
|
|
87
|
+
|
|
88
|
+
return (
|
|
89
|
+
<>
|
|
90
|
+
{/* Controlled. */}
|
|
91
|
+
<SmartButtonGroupPreset
|
|
92
|
+
buttons={PERIODS}
|
|
93
|
+
selected={period}
|
|
94
|
+
onSelectedChange={(id) => {
|
|
95
|
+
setPeriod(id);
|
|
96
|
+
onPeriod(id);
|
|
97
|
+
}}
|
|
98
|
+
options={{ variant: 'with-stat' }}
|
|
99
|
+
/>
|
|
100
|
+
|
|
101
|
+
{/* Uncontrolled, starting on "day". */}
|
|
102
|
+
<SmartButtonGroup
|
|
103
|
+
buttons={PERIODS}
|
|
104
|
+
defaultSelected="day"
|
|
105
|
+
onButtonClick={({ buttonId }) => onPeriod(buttonId)}
|
|
106
|
+
/>
|
|
107
|
+
</>
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Replacing the Implementation
|
|
113
|
+
|
|
114
|
+
`SmartButtonGroup` renders the component registered under the `'button-group'` key of `SmartProvider`'s `components`, and `SmartButtonGroupStandard` when nothing is registered there. Every `SmartButtonGroup` below the provider then renders the registered component, which receives the same props.
|
|
115
|
+
|
|
116
|
+
```tsx
|
|
117
|
+
import type { ReactNode } from 'react';
|
|
118
|
+
|
|
119
|
+
import { SmartProvider, SmartButtonGroupPreset } from '@smartsoft001/react';
|
|
120
|
+
|
|
121
|
+
// A module constant: a new object on every render would change the context.
|
|
122
|
+
const components = { 'button-group': SmartButtonGroupPreset };
|
|
123
|
+
|
|
124
|
+
export function AppProviders({ children }: { children: ReactNode }) {
|
|
125
|
+
return <SmartProvider components={components}>{children}</SmartProvider>;
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
`SmartButtonGroupPreset` is the styled (preset) implementation: register it as above, render it directly in place of `SmartButtonGroup`, 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.
|
|
130
|
+
|
|
131
|
+
### The `useButtonGroup` hook
|
|
132
|
+
|
|
133
|
+
The behaviour every button group variant shares: the selected button id, controlled through `selected` / `onSelectedChange` or kept internally, and `select(id)`, which selects a button and emits `onButtonClick`.
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
function useButtonGroup({
|
|
137
|
+
selected: controlledSelected,
|
|
138
|
+
defaultSelected,
|
|
139
|
+
onSelectedChange,
|
|
140
|
+
onButtonClick,
|
|
141
|
+
}: SmartButtonGroupProps);
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
| Returns | Type | Description |
|
|
145
|
+
| ---------- | ---------------------- | ------------------------------------------------------------------------------------------------------------------ |
|
|
146
|
+
| `selected` | `string \| undefined` | The selected id (the `selected` prop when controlled). |
|
|
147
|
+
| `select` | `(id: string) => void` | Selects a button: updates the internal state when uncontrolled, then calls `onSelectedChange` and `onButtonClick`. |
|
|
148
|
+
|
|
149
|
+
```tsx
|
|
150
|
+
import { SmartButtonGroupProps, useButtonGroup } from '@smartsoft001/react';
|
|
151
|
+
|
|
152
|
+
export function PillGroup(props: SmartButtonGroupProps) {
|
|
153
|
+
const { selected, select } = useButtonGroup(props);
|
|
154
|
+
|
|
155
|
+
return (
|
|
156
|
+
<div role="group" className={props.className}>
|
|
157
|
+
{(props.buttons ?? []).map((button) => (
|
|
158
|
+
<button
|
|
159
|
+
key={button.id}
|
|
160
|
+
type="button"
|
|
161
|
+
aria-pressed={button.id === selected}
|
|
162
|
+
disabled={button.disabled}
|
|
163
|
+
onClick={() => select(button.id)}
|
|
164
|
+
>
|
|
165
|
+
{button.label}
|
|
166
|
+
</button>
|
|
167
|
+
))}
|
|
168
|
+
</div>
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## Styling
|
|
174
|
+
|
|
175
|
+
- `SmartButtonGroupStandard` is an unstyled `role="group"` of buttons (`aria-pressed` on the selected one, `smart-button-group-count` on the count).
|
|
176
|
+
- `SmartButtonGroupPreset` renders the segmented look (collapsed borders, rounded ends, an emphasised active segment) in one medium size, with `smart:dark:` variants.
|
|
177
|
+
|
|
178
|
+
## File Locations
|
|
179
|
+
|
|
180
|
+
Source: `packages/shared/react/src/lib/components/button-group/` in the smartsoft001 repository.
|
|
181
|
+
|
|
182
|
+
- `button-group.tsx`: `SmartButtonGroup`
|
|
183
|
+
- `button-group.types.ts`: `IButtonGroupButtonClick`, `SmartButtonGroupProps`
|
|
184
|
+
- `preset/button-group-preset.tsx`: `SmartButtonGroupPreset`
|
|
185
|
+
- `standard/button-group-standard.tsx`: `SmartButtonGroupStandard`
|
|
186
|
+
- `use-button-group.ts`: `useButtonGroup`
|
|
187
|
+
- `button-group.stories.tsx`: Storybook stories
|