jattac.libs.web.zest-button 1.2.9 → 1.4.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/dist/ZestButton.d.ts +19 -2
- package/dist/ZestDropdownMenu.d.ts +16 -0
- package/dist/ZestDropdownMenuItem.d.ts +9 -0
- package/dist/index.cjs.js +163 -8
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +19 -2
- package/dist/index.esm.js +143 -9
- package/dist/index.esm.js.map +1 -1
- package/docs/e2e/critical-paths.md +75 -0
- package/docs/features/zest-button-dropdown-options/BRS.md +213 -0
- package/docs/guidelines/AI_ARCHITECTURE.md +455 -0
- package/docs/guidelines/AI_BRS.md +435 -0
- package/docs/guidelines/AI_CODE_REVIEW.md +198 -0
- package/docs/guidelines/AI_E2E_TESTING.md +227 -0
- package/docs/guidelines/AI_GIT_WORKFLOW.md +595 -0
- package/docs/guidelines/AI_KNOWLEDGE.md +213 -0
- package/docs/guidelines/AI_PITFALLS.md +245 -0
- package/docs/guidelines/AI_STYLE_GUIDE.md +162 -0
- package/docs/guidelines/AI_TESTING.md +275 -0
- package/docs/guidelines/AI_TEST_CONFIGURATION.md +529 -0
- package/docs/guidelines/AI_WORKFLOW.md +442 -0
- package/docs/guidelines/AI_WORKFLOW_TRIGGERS.md +222 -0
- package/docs/guidelines/ai-knowledge.md +154 -0
- package/docs/guidelines/decision-log.md +149 -0
- package/package.json +78 -69
- package/dist/ZestContext.d.ts +0 -9
- package/dist/ZestProvider.d.ts +0 -8
- package/dist/semanticTypeDefaults.d.ts +0 -4
- package/docs/api.md +0 -140
- package/docs/breaking-changes.md +0 -143
- package/docs/configuration.md +0 -214
- package/docs/development.md +0 -93
- package/docs/examples.md +0 -227
- package/docs/features.md +0 -126
package/docs/breaking-changes.md
DELETED
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
[⬅️ Previous: Development Guide](./development.md)
|
|
3
|
-
|
|
4
|
-
# Breaking Changes: The Upgrade Path
|
|
5
|
-
|
|
6
|
-
This document lists significant changes between versions that might require modifications to your existing codebase.
|
|
7
|
-
|
|
8
|
-
---
|
|
9
|
-
|
|
10
|
-
## Table of Contents
|
|
11
|
-
|
|
12
|
-
- [Version 1.2.7](#version-127)
|
|
13
|
-
- [Version 1.2.6](#version-126)
|
|
14
|
-
- [Version 1.2.0](#version-120)
|
|
15
|
-
|
|
16
|
-
---
|
|
17
|
-
|
|
18
|
-
## Version 1.2.7
|
|
19
|
-
|
|
20
|
-
### Renamed `ZestProvider` to `ZestButtonConfigProvider`
|
|
21
|
-
|
|
22
|
-
To provide more explicit naming and better context within the API, the `ZestProvider` component has been renamed to `ZestButtonConfigProvider`. Additionally, its associated context is now `ZestButtonConfigContext`, and the consumption hook is `useZestButtonConfig`.
|
|
23
|
-
|
|
24
|
-
This is a breaking change that requires updating all imports and usages of the provider, context, and hook in your application.
|
|
25
|
-
|
|
26
|
-
**Before:**
|
|
27
|
-
|
|
28
|
-
```tsx
|
|
29
|
-
import { ZestProvider, useZest } from 'jattac.libs.web.zest-button';
|
|
30
|
-
|
|
31
|
-
const App = () => (
|
|
32
|
-
<ZestProvider config={myConfig}>...</ZestProvider>
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
const MyComponent = () => {
|
|
36
|
-
const config = useZest();
|
|
37
|
-
// ...
|
|
38
|
-
}
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
**After:**
|
|
42
|
-
|
|
43
|
-
```tsx
|
|
44
|
-
import { ZestButtonConfigProvider, useZestButtonConfig } from 'jattac.libs.web.zest-button';
|
|
45
|
-
|
|
46
|
-
const App = () => (
|
|
47
|
-
<ZestButtonConfigProvider config={myConfig}>...</ZestButtonConfigProvider>
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
const MyComponent = () => {
|
|
51
|
-
const config = useZestButtonConfig();
|
|
52
|
-
// ...
|
|
53
|
-
}
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
---
|
|
57
|
-
|
|
58
|
-
## Version 1.2.6
|
|
59
|
-
|
|
60
|
-
### Renamed `fullWidth` prop to `stretch`
|
|
61
|
-
|
|
62
|
-
To better reflect its behavior and avoid potential confusion with other layout properties, the `fullWidth` prop within `visualOptions` has been renamed to `stretch`. This means any usage of `fullWidth` in your `ZestButton` configurations must be updated.
|
|
63
|
-
|
|
64
|
-
**Before:**
|
|
65
|
-
|
|
66
|
-
```tsx
|
|
67
|
-
<ZestButton
|
|
68
|
-
zest={{
|
|
69
|
-
visualOptions: {
|
|
70
|
-
fullWidth: true,
|
|
71
|
-
},
|
|
72
|
-
}}
|
|
73
|
-
>
|
|
74
|
-
Stretched Button
|
|
75
|
-
</ZestButton>
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
**After:**
|
|
79
|
-
|
|
80
|
-
```tsx
|
|
81
|
-
<ZestButton
|
|
82
|
-
zest={{
|
|
83
|
-
visualOptions: {
|
|
84
|
-
stretch: true,
|
|
85
|
-
},
|
|
86
|
-
}}
|
|
87
|
-
>
|
|
88
|
-
Stretched Button
|
|
89
|
-
</ZestButton>
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
---
|
|
93
|
-
|
|
94
|
-
## Version 1.2.0
|
|
95
|
-
|
|
96
|
-
### Encapsulated Custom Props under `zest` Object
|
|
97
|
-
|
|
98
|
-
To improve maintainability, reduce prop-drilling, and provide a clearer API surface, all custom `ZestButton` properties have been consolidated under a single `zest` prop. Previously, these properties were passed directly to the `ZestButton` component.
|
|
99
|
-
|
|
100
|
-
This change allows for better organization of configuration options (e.g., `visualOptions`, `busyOptions`, `confirmOptions`) and prepares the component for future global configuration contexts.
|
|
101
|
-
|
|
102
|
-
**Before:**
|
|
103
|
-
|
|
104
|
-
```tsx
|
|
105
|
-
<ZestButton
|
|
106
|
-
variant="success"
|
|
107
|
-
size="lg"
|
|
108
|
-
fullWidth={true}
|
|
109
|
-
minBusyDurationMs={1000}
|
|
110
|
-
preventRageClick={false}
|
|
111
|
-
confirmOptions={{ displayLabel: "Delete?", timeoutSecs: 5 }}
|
|
112
|
-
>
|
|
113
|
-
My Button
|
|
114
|
-
</ZestButton>
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
**After:**
|
|
118
|
-
|
|
119
|
-
```tsx
|
|
120
|
-
<ZestButton
|
|
121
|
-
zest={{
|
|
122
|
-
visualOptions: {
|
|
123
|
-
variant: "success",
|
|
124
|
-
size: "lg",
|
|
125
|
-
fullWidth: true,
|
|
126
|
-
},
|
|
127
|
-
busyOptions: {
|
|
128
|
-
minBusyDurationMs: 1000,
|
|
129
|
-
preventRageClick: false,
|
|
130
|
-
},
|
|
131
|
-
confirmOptions: {
|
|
132
|
-
displayLabel: "Delete?",
|
|
133
|
-
timeoutSecs: 5,
|
|
134
|
-
},
|
|
135
|
-
}}
|
|
136
|
-
>
|
|
137
|
-
My Button
|
|
138
|
-
</ZestButton>
|
|
139
|
-
```
|
|
140
|
-
|
|
141
|
-
---
|
|
142
|
-
|
|
143
|
-
[⬅️ Previous: Development Guide](./development.md) | [Next: README ➡️](../README.md)
|
package/docs/configuration.md
DELETED
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
[⬅️ Previous: API Reference](./api.md)
|
|
3
|
-
|
|
4
|
-
# Configuration: The Control Panel
|
|
5
|
-
|
|
6
|
-
This document explains how to configure `ZestButton` on a component and global level.
|
|
7
|
-
|
|
8
|
-
---
|
|
9
|
-
|
|
10
|
-
## Table of Contents
|
|
11
|
-
|
|
12
|
-
- [Overview](#overview)
|
|
13
|
-
- [Theme Configuration](#theme-configuration)
|
|
14
|
-
- [Order of Precedence](#order-of-precedence)
|
|
15
|
-
- [Example: Forcing a Theme](#example-forcing-a-theme)
|
|
16
|
-
- [Global Configuration with ZestButtonConfigProvider](#global-configuration-with-zestbuttonconfigprovider)
|
|
17
|
-
- [Usage](#usage)
|
|
18
|
-
- [Precedence with the ZestButtonConfigProvider](#precedence-with-the-zestbuttonconfigprovider)
|
|
19
|
-
- [Advanced: Customizing Semantic Defaults](#advanced-customizing-semantic-defaults)
|
|
20
|
-
- [Example: Defining a Custom 'archive' Type](#example-defining-a-custom-archive-type)
|
|
21
|
-
- [Example: Overriding a Built-in 'delete' Default](#example-overriding-a-built-in-delete-default)
|
|
22
|
-
|
|
23
|
-
---
|
|
24
|
-
|
|
25
|
-
### Overview
|
|
26
|
-
|
|
27
|
-
Currently, `ZestButton` is primarily configured on a per-component basis via the `zest` prop. This provides the most explicit and direct control over each button's behavior and appearance.
|
|
28
|
-
|
|
29
|
-
However, there are ways to manage themes and a clear path for future global configuration.
|
|
30
|
-
|
|
31
|
-
---
|
|
32
|
-
|
|
33
|
-
### Theme Configuration
|
|
34
|
-
|
|
35
|
-
One of the most powerful configuration options is theme control. `ZestButton` can automatically adapt to the user's operating system preferences, or you can lock it to a specific theme.
|
|
36
|
-
|
|
37
|
-
The `theme` prop within the `zest` object accepts one of three values:
|
|
38
|
-
|
|
39
|
-
- `'system'` (Default): The button listens for the system's color scheme (`prefers-color-scheme`) and applies the `light` or `dark` theme automatically.
|
|
40
|
-
- `'light'`: Forces the button to use the light theme, regardless of system settings.
|
|
41
|
-
- `'dark'`: Forces the button to use the dark theme, regardless of system settings.
|
|
42
|
-
|
|
43
|
-
#### Order of Precedence
|
|
44
|
-
|
|
45
|
-
The `zest.theme` prop has the highest precedence.
|
|
46
|
-
|
|
47
|
-
1. **`zest.theme` Prop (`light` or `dark`)**: If set, this value is always used.
|
|
48
|
-
2. **`zest.theme` Prop (`system`)**: If set to `system` (or if undefined), the button will defer to the user's OS-level preference.
|
|
49
|
-
|
|
50
|
-
#### Example: Forcing a Theme
|
|
51
|
-
|
|
52
|
-
This is useful for sections of your UI that have a fixed background color, where you need the button's theme to match its immediate parent rather than the overall page theme.
|
|
53
|
-
|
|
54
|
-
```tsx
|
|
55
|
-
import ZestButton from 'jattac.libs.web.zest-button';
|
|
56
|
-
|
|
57
|
-
const PinnedFooter = () => (
|
|
58
|
-
<div style={{ background: '#333', padding: '1rem' }}>
|
|
59
|
-
{/* This button's text will be light, matching the dark background */}
|
|
60
|
-
<ZestButton zest={{ theme: 'dark' }}>
|
|
61
|
-
Action in Dark Footer
|
|
62
|
-
</ZestButton>
|
|
63
|
-
</div>
|
|
64
|
-
);
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
---
|
|
68
|
-
|
|
69
|
-
### Global Configuration with `ZestButtonConfigProvider`
|
|
70
|
-
|
|
71
|
-
The `ZestButtonConfigProvider` component is now implemented, allowing you to streamline `ZestButton` configuration across your entire application. You can define a set of default `zest` properties that all `ZestButton` instances within its scope will inherit.
|
|
72
|
-
|
|
73
|
-
#### Usage
|
|
74
|
-
|
|
75
|
-
Wrap your application (or specific sections) with the `ZestButtonConfigProvider` and pass a configuration object to its `config` prop. The `config` prop expects an object of type `ZestGlobalConfig`, which contains a `defaultProps` field of type `ZestCustomProps`.
|
|
76
|
-
|
|
77
|
-
```tsx
|
|
78
|
-
// In your main App.tsx file
|
|
79
|
-
|
|
80
|
-
import { ZestButtonConfigProvider } from 'jattac.libs.web.zest-button';
|
|
81
|
-
import MyRoutes from './MyRoutes';
|
|
82
|
-
|
|
83
|
-
const appZestConfig = {
|
|
84
|
-
defaultProps: {
|
|
85
|
-
visualOptions: {
|
|
86
|
-
size: 'sm', // Make all buttons small by default
|
|
87
|
-
},
|
|
88
|
-
busyOptions: {
|
|
89
|
-
minBusyDurationMs: 300, // Shorten the busy duration app-wide
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
const App = () => (
|
|
95
|
-
<ZestButtonConfigProvider config={appZestConfig}>
|
|
96
|
-
<MyRoutes />
|
|
97
|
-
</ZestButtonConfigProvider>
|
|
98
|
-
);
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
#### Precedence with the `ZestButtonConfigProvider`
|
|
102
|
-
|
|
103
|
-
Property configurations are merged in a "deep merge" fashion with the following order of precedence (where the last one wins):
|
|
104
|
-
|
|
105
|
-
1. **Global `defaultProps`**: Props defined in the `ZestButtonConfigProvider`'s `config.defaultProps` object. This is the base layer of styling.
|
|
106
|
-
2. **Built-in Semantic Defaults**: The library's own defaults for a given `semanticType` (e.g., the `success` variant for `save`).
|
|
107
|
-
3. **Custom Semantic Defaults**: **(New!)** Defaults for a `semanticType` that you provide in the `ZestButtonConfigProvider`'s `config.semanticTypeDefaults` object. This allows you to override the library's defaults or create new ones.
|
|
108
|
-
4. **Local `zest` Props**: The props passed directly to a specific `<ZestButton>` instance. This gives you the ultimate granular control.
|
|
109
|
-
|
|
110
|
-
---
|
|
111
|
-
|
|
112
|
-
### Advanced: Customizing Semantic Defaults
|
|
113
|
-
|
|
114
|
-
This is one of the most powerful features of the `ZestButtonConfigProvider`. You can define application-wide styles and behaviors for any `semanticType`. This is perfect for creating a consistent design system.
|
|
115
|
-
|
|
116
|
-
The `ZestButtonConfigProvider`'s `config` prop accepts a `semanticTypeDefaults` object. You can use this to **override** built-in defaults or **define** defaults for your own custom types.
|
|
117
|
-
|
|
118
|
-
#### Example: Defining a Custom 'archive' Type
|
|
119
|
-
|
|
120
|
-
First, let's imagine you've used module augmentation to create a new `semanticType` called `'archive'`, as explained in the [Development Guide](./development.md). Now, you want all `'archive'` buttons to have a specific look and feel across your app.
|
|
121
|
-
|
|
122
|
-
```tsx
|
|
123
|
-
// your-project/src/typings/zest-button-extensions.d.ts
|
|
124
|
-
import 'jattac.libs.web.zest-button';
|
|
125
|
-
|
|
126
|
-
declare module 'jattac.libs.web.zest-button' {
|
|
127
|
-
export interface CustomZestSemanticTypes {
|
|
128
|
-
archive: 'archive';
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
Now, configure the defaults in your `ZestButtonConfigProvider`:
|
|
134
|
-
|
|
135
|
-
```tsx
|
|
136
|
-
// In your main App.tsx file
|
|
137
|
-
import { ZestButtonConfigProvider } from 'jattac.libs.web.zest-button';
|
|
138
|
-
import { FaArchive } from 'react-icons/fa';
|
|
139
|
-
import MyRoutes from './MyRoutes';
|
|
140
|
-
|
|
141
|
-
const appZestConfig = {
|
|
142
|
-
// Define defaults for our new custom semantic type
|
|
143
|
-
semanticTypeDefaults: {
|
|
144
|
-
archive: {
|
|
145
|
-
buttonStyle: 'outline',
|
|
146
|
-
visualOptions: {
|
|
147
|
-
iconLeft: <FaArchive />,
|
|
148
|
-
variant: 'standard',
|
|
149
|
-
},
|
|
150
|
-
confirmOptions: {
|
|
151
|
-
displayLabel: 'Confirm Archive?',
|
|
152
|
-
timeoutSecs: 10,
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
const App = () => (
|
|
159
|
-
<ZestButtonConfigProvider config={appZestConfig}>
|
|
160
|
-
<MyRoutes />
|
|
161
|
-
</ZestButtonConfigProvider>
|
|
162
|
-
);
|
|
163
|
-
|
|
164
|
-
// --- Later, in some other component ---
|
|
165
|
-
|
|
166
|
-
// This button will automatically get the icon, style, and confirmation behavior!
|
|
167
|
-
<ZestButton zest={{ semanticType: 'archive' }} onClick={handleArchiveAction}>
|
|
168
|
-
Archive Record
|
|
169
|
-
</ZestButton>
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
#### Example: Overriding a Built-in 'delete' Default
|
|
173
|
-
|
|
174
|
-
Let's say you like the built-in `delete` type, but for your application, you want the button style to be `outline` instead of `solid`, and you want a shorter confirmation time.
|
|
175
|
-
|
|
176
|
-
```tsx
|
|
177
|
-
// In your main App.tsx file
|
|
178
|
-
import { ZestButtonConfigProvider } from 'jattac.libs.web.zest-button';
|
|
179
|
-
import MyRoutes from './MyRoutes';
|
|
180
|
-
|
|
181
|
-
const appZestConfig = {
|
|
182
|
-
// Override specific props for a built-in semantic type
|
|
183
|
-
semanticTypeDefaults: {
|
|
184
|
-
delete: {
|
|
185
|
-
// We only specify what we want to change.
|
|
186
|
-
// The icon and 'danger' variant will still be inherited from the built-in default.
|
|
187
|
-
buttonStyle: 'outline',
|
|
188
|
-
confirmOptions: {
|
|
189
|
-
// We must provide the full object to override, not just one property.
|
|
190
|
-
displayLabel: 'Confirm Deletion',
|
|
191
|
-
timeoutSecs: 3, // Shorter timeout
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
};
|
|
196
|
-
|
|
197
|
-
const App = () => (
|
|
198
|
-
<ZestButtonConfigProvider config={appZestConfig}>
|
|
199
|
-
<MyRoutes />
|
|
200
|
-
</ZestButtonConfigProvider>
|
|
201
|
-
);
|
|
202
|
-
|
|
203
|
-
// --- Later, in some other component ---
|
|
204
|
-
|
|
205
|
-
// This button will now be an 'outline' button with a 3-second confirmation.
|
|
206
|
-
<ZestButton zest={{ semanticType: 'delete' }} onClick={handleDeleteAction}>
|
|
207
|
-
Delete Record
|
|
208
|
-
</ZestButton>
|
|
209
|
-
```
|
|
210
|
-
|
|
211
|
-
---
|
|
212
|
-
|
|
213
|
-
[⬅️ Previous: API Reference](./api.md) | [Next: Development Guide ➡️](./development.md)
|
|
214
|
-
|
package/docs/development.md
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
[⬅️ Previous: Configuration Guide](./configuration.md)
|
|
3
|
-
|
|
4
|
-
# Development: The Contributor's Guide
|
|
5
|
-
|
|
6
|
-
This guide provides an overview of the project's internal structure and instructions for setting up your development environment.
|
|
7
|
-
|
|
8
|
-
---
|
|
9
|
-
|
|
10
|
-
## Table of Contents
|
|
11
|
-
|
|
12
|
-
- [Internal Architecture](#internal-architecture)
|
|
13
|
-
- [Setup Instructions](#setup-instructions)
|
|
14
|
-
- [Scripts](#scripts)
|
|
15
|
-
- [Extending Semantic Types](#extending-semantic-types)
|
|
16
|
-
|
|
17
|
-
---
|
|
18
|
-
|
|
19
|
-
### Internal Architecture
|
|
20
|
-
|
|
21
|
-
The `jattac.libs.web.zest-button` project is structured to be a self-contained React component library.
|
|
22
|
-
|
|
23
|
-
- **`UI/ZestButton.tsx`**: This is the heart of the component. It contains the main React functional component, state management logic, event handlers, and renders the button's UI based on its props and internal state. Auxiliary components like `AnimatedCheckmark` and `AnimatedX` are also defined here.
|
|
24
|
-
- **`UI/SpinnerIcon.tsx`**: A small, dedicated component for rendering the loading spinner, utilizing `react-icons`.
|
|
25
|
-
- **`Styles/ZestButton.module.css`**: All the CSS for the component is defined in this file. It leverages CSS Modules to ensure styles are scoped and prevent conflicts. It also includes global CSS variables for theming and animations.
|
|
26
|
-
- **`dist/`**: This directory is the output of the build process. It contains the compiled JavaScript files (CommonJS and ES Modules), the TypeScript declaration file (`index.d.ts`), and potentially source maps. This is the content that gets published to npm.
|
|
27
|
-
- **`rollup.config.mjs`**: The configuration file for Rollup, the module bundler used for this project. It defines how the TypeScript and CSS are transpiled, bundled, and how the declaration files are generated.
|
|
28
|
-
- **`tsconfig.json`**: The TypeScript compiler configuration. It specifies compiler options, such as target JavaScript version, module resolution strategy, JSX factory, and files to include/exclude from compilation.
|
|
29
|
-
|
|
30
|
-
---
|
|
31
|
-
|
|
32
|
-
### Setup Instructions
|
|
33
|
-
|
|
34
|
-
To get the development environment running on your local machine, follow these steps:
|
|
35
|
-
|
|
36
|
-
1. **Clone the repository:**
|
|
37
|
-
```bash
|
|
38
|
-
git clone https://github.com/jattac/jattac.libs.web.zest-button.git
|
|
39
|
-
cd jattac.libs.web.zest-button
|
|
40
|
-
```
|
|
41
|
-
2. **Install dependencies:**
|
|
42
|
-
```bash
|
|
43
|
-
npm install
|
|
44
|
-
```
|
|
45
|
-
This command will install all the necessary `devDependencies` listed in `package.json`.
|
|
46
|
-
|
|
47
|
-
---
|
|
48
|
-
|
|
49
|
-
### Scripts
|
|
50
|
-
|
|
51
|
-
The `package.json` includes several scripts to help with development and building the package:
|
|
52
|
-
|
|
53
|
-
- **`npm run build`**:
|
|
54
|
-
* **Purpose**: Compiles the TypeScript code, processes CSS Modules, and bundles the component into production-ready CommonJS and ES Module formats. It also generates the TypeScript declaration file (`index.d.ts`).
|
|
55
|
-
* **Output**: Creates the `dist/` directory with all the necessary files for publishing.
|
|
56
|
-
* **Command**: `rollup -c rollup.config.mjs`
|
|
57
|
-
|
|
58
|
-
- **`npm run dev`**:
|
|
59
|
-
* **Purpose**: Starts Rollup in watch mode. This command is ideal for development as it automatically recompiles the component whenever source files are changed, allowing for rapid iteration.
|
|
60
|
-
* **Output**: Similar to `build`, but also keeps the process running to watch for changes.
|
|
61
|
-
* **Command**: `rollup -c rollup.config.mjs -w`
|
|
62
|
-
|
|
63
|
-
---
|
|
64
|
-
|
|
65
|
-
### Extending Semantic Types
|
|
66
|
-
|
|
67
|
-
The `ZestButton` provides a mechanism for developers to extend the built-in `SemanticType` union with their own custom semantic types. This is achieved through TypeScript's [module augmentation](https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation) feature.
|
|
68
|
-
|
|
69
|
-
To add your own custom semantic types:
|
|
70
|
-
|
|
71
|
-
1. Create a TypeScript declaration file in your project (e.g., `your-project/src/typings/zest-button-extensions.d.ts`).
|
|
72
|
-
2. Augment the `jattac.libs.web.zest-button` module and define your custom semantic types within the `CustomZestSemanticTypes` interface. The keys of this interface will become available as new `SemanticType` values.
|
|
73
|
-
|
|
74
|
-
```typescript
|
|
75
|
-
// your-project/src/typings/zest-button-extensions.d.ts
|
|
76
|
-
import 'jattac.libs.web.zest-button'; // Important: Extend the module
|
|
77
|
-
|
|
78
|
-
declare module 'jattac.libs.web.zest-button' {
|
|
79
|
-
export interface CustomZestSemanticTypes {
|
|
80
|
-
archive: 'archive';
|
|
81
|
-
publish: 'publish';
|
|
82
|
-
// Add any other custom semantic types here
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
Once augmented, these new semantic types (`'archive'`, `'publish'`) will be available for autocompletion and type-checking when using the `semanticType` prop on your `ZestButton` instances.
|
|
88
|
-
|
|
89
|
-
*(Note: Currently, there are no dedicated test scripts defined in `package.json`. Testing is typically done manually in a consuming project during development, or through dedicated test runners that would be added in the future.)*
|
|
90
|
-
|
|
91
|
-
---
|
|
92
|
-
|
|
93
|
-
[⬅️ Previous: Configuration Guide](./configuration.md) | [Next: Breaking Changes ➡️](./breaking-changes.md)
|
package/docs/examples.md
DELETED
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
# The Cookbook: From First Button to Design System
|
|
2
|
-
|
|
3
|
-
Welcome to the ZestButton Cookbook! This is the core learning path for mastering `ZestButton`. Each recipe solves a real-world problem and builds on the concepts from the previous one. Start here to go from zero to expert.
|
|
4
|
-
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
## Table of Contents
|
|
8
|
-
|
|
9
|
-
- [Recipe 1: Your First Async Button](#recipe-1-your-first-async-button)
|
|
10
|
-
- [Recipe 2: The Safe "Delete" Button](#recipe-2-the-safe-delete-button)
|
|
11
|
-
- [Recipe 3: Standardizing Your Buttons with a Global Config](#recipe-3-standardizing-your-buttons-with-a-global-config)
|
|
12
|
-
- [Recipe 4: Creating a Custom "Archive" Button](#recipe-4-creating-a-custom-archive-button)
|
|
13
|
-
|
|
14
|
-
---
|
|
15
|
-
|
|
16
|
-
### Recipe 1: Your First Async Button
|
|
17
|
-
|
|
18
|
-
**Goal:** Create a button that automatically shows a loading spinner during an operation and gives feedback when it's done.
|
|
19
|
-
|
|
20
|
-
**Problem:** You have an API call that takes time. You need to prevent the user from clicking the button multiple times and clearly show when the action is complete.
|
|
21
|
-
|
|
22
|
-
**Solution:** Simply have your `onClick` handler return a `Promise`. `ZestButton` handles the rest. This example also shows success and failure states.
|
|
23
|
-
|
|
24
|
-
```tsx
|
|
25
|
-
import React, { useState } from 'react';
|
|
26
|
-
import ZestButton from 'jattac.libs.web.zest-button';
|
|
27
|
-
import { FaSave } from 'react-icons/fa';
|
|
28
|
-
|
|
29
|
-
const SaveButton = () => {
|
|
30
|
-
const [shouldSucceed, setShouldSucceed] = useState(true);
|
|
31
|
-
|
|
32
|
-
const handleSave = async () => {
|
|
33
|
-
console.log('Saving...');
|
|
34
|
-
// Simulate an API call
|
|
35
|
-
await new Promise((resolve, reject) => {
|
|
36
|
-
setTimeout(() => {
|
|
37
|
-
shouldSucceed ? resolve('Success!') : reject('Error!');
|
|
38
|
-
}, 1500);
|
|
39
|
-
});
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
return (
|
|
43
|
-
<div style={{ display: 'flex', flexDirection: 'column', gap: '1rem', maxWidth: '300px' }}>
|
|
44
|
-
<label>
|
|
45
|
-
<input
|
|
46
|
-
type="checkbox"
|
|
47
|
-
checked={shouldSucceed}
|
|
48
|
-
onChange={() => setShouldSucceed(e => !e)}
|
|
49
|
-
/>
|
|
50
|
-
Simulate Success
|
|
51
|
-
</label>
|
|
52
|
-
<ZestButton
|
|
53
|
-
onClick={handleSave}
|
|
54
|
-
zest={{
|
|
55
|
-
visualOptions: { iconLeft: <FaSave />, stretch: true },
|
|
56
|
-
}}
|
|
57
|
-
>
|
|
58
|
-
Save Settings
|
|
59
|
-
</ZestButton>
|
|
60
|
-
</div>
|
|
61
|
-
);
|
|
62
|
-
};
|
|
63
|
-
```
|
|
64
|
-
*For more details on all available options, see the [`BusyOptions`](./api.md#busyoptions) and [`SuccessOptions`](./api.md#successoptions) in our API reference.*
|
|
65
|
-
|
|
66
|
-
---
|
|
67
|
-
|
|
68
|
-
### Recipe 2: The Safe "Delete" Button
|
|
69
|
-
|
|
70
|
-
**Goal:** Create a button for a destructive action that requires a second click to confirm.
|
|
71
|
-
|
|
72
|
-
**Problem:** Destructive actions like deleting data are dangerous. A user might click the button by accident.
|
|
73
|
-
|
|
74
|
-
**Solution:** Use the `confirmOptions` prop. This forces the user to click once to start a countdown, and a second time to execute the action. Combining this with a `danger` variant provides a clear visual warning.
|
|
75
|
-
|
|
76
|
-
```tsx
|
|
77
|
-
import React from 'react';
|
|
78
|
-
import ZestButton from 'jattac.libs.web.zest-button';
|
|
79
|
-
import { FaTrash } from 'react-icons/fa';
|
|
80
|
-
|
|
81
|
-
const DeleteButton = () => {
|
|
82
|
-
const handleDelete = () => {
|
|
83
|
-
alert('Item has been permanently deleted.');
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
return (
|
|
87
|
-
<ZestButton
|
|
88
|
-
onClick={handleDelete}
|
|
89
|
-
zest={{
|
|
90
|
-
visualOptions: {
|
|
91
|
-
variant: 'danger',
|
|
92
|
-
iconLeft: <FaTrash />,
|
|
93
|
-
},
|
|
94
|
-
confirmOptions: {
|
|
95
|
-
displayLabel: 'Confirm Deletion',
|
|
96
|
-
timeoutSecs: 5,
|
|
97
|
-
},
|
|
98
|
-
}}
|
|
99
|
-
>
|
|
100
|
-
Delete Account
|
|
101
|
-
</ZestButton>
|
|
102
|
-
);
|
|
103
|
-
};
|
|
104
|
-
```
|
|
105
|
-
*For more details, see the [`ConfirmOptions`](./api.md#confirmoptions) in our API reference.*
|
|
106
|
-
|
|
107
|
-
---
|
|
108
|
-
|
|
109
|
-
### Recipe 3: Standardizing Your Buttons with a Global Config
|
|
110
|
-
|
|
111
|
-
**Goal:** Define a consistent look and feel for all buttons in your application without repeating props.
|
|
112
|
-
|
|
113
|
-
**Problem:** Your app has dozens of buttons. Specifying `size: 'sm'` or `buttonStyle: 'outline'` on every single one is tedious and error-prone.
|
|
114
|
-
|
|
115
|
-
**Solution:** Wrap your application in the `ZestProvider` and pass a `config` object. Any props in `defaultProps` will be applied to every `ZestButton` within the provider. Local props on a button will always override the global default.
|
|
116
|
-
|
|
117
|
-
```tsx
|
|
118
|
-
// In your main App.tsx
|
|
119
|
-
import React from 'react';
|
|
120
|
-
import { ZestButtonConfigProvider, ZestButton } from 'jattac.libs.web.zest-button';
|
|
121
|
-
|
|
122
|
-
const appZestConfig = {
|
|
123
|
-
defaultProps: {
|
|
124
|
-
visualOptions: {
|
|
125
|
-
size: 'sm', // Make all buttons small by default
|
|
126
|
-
},
|
|
127
|
-
buttonStyle: 'outline', // Make all buttons outline by default
|
|
128
|
-
},
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
const App = () => (
|
|
132
|
-
<ZestButtonConfigProvider config={appZestConfig}>
|
|
133
|
-
<div style={{ display: 'flex', gap: '1rem', alignItems: 'center' }}>
|
|
134
|
-
<ZestButton>I'm a small outline button</ZestButton>
|
|
135
|
-
<ZestButton>So am I</ZestButton>
|
|
136
|
-
<ZestButton zest={{ visualOptions: { size: 'lg' }, buttonStyle: 'solid' }}>
|
|
137
|
-
I'm a large solid button! (Local override)
|
|
138
|
-
</ZestButton>
|
|
139
|
-
</div>
|
|
140
|
-
</ZestButtonConfigProvider>
|
|
141
|
-
);
|
|
142
|
-
```
|
|
143
|
-
*For a full list of provider settings, see the [`ZestGlobalConfig`](./api.md#zestglobalconfig) documentation. To understand the precedence rules, see the [Configuration Guide](./configuration.md).*
|
|
144
|
-
|
|
145
|
-
---
|
|
146
|
-
|
|
147
|
-
### Recipe 4: Creating a Custom "Archive" Button
|
|
148
|
-
|
|
149
|
-
**Goal:** Create a new, reusable button "type" with its own specific icon, style, and behavior that can be used anywhere in the app.
|
|
150
|
-
|
|
151
|
-
**Problem:** You have a common action in your app, like "Archive," that should always look and feel the same. You want to avoid configuring it manually each time and just be able to write `zest={{ semanticType: 'archive' }}`.
|
|
152
|
-
|
|
153
|
-
**Solution:** This is a two-step process that combines **TypeScript Module Augmentation** with the **`ZestButtonConfigProvider`**.
|
|
154
|
-
|
|
155
|
-
**Step 1: Define the new type**
|
|
156
|
-
In your project's type declarations file (e.g., `src/zest.d.ts`), augment the `CustomZestSemanticTypes` interface.
|
|
157
|
-
|
|
158
|
-
```typescript
|
|
159
|
-
// src/zest.d.ts
|
|
160
|
-
import 'jattac.libs.web.zest-button';
|
|
161
|
-
import { FaArchive } from 'react-icons/fa';
|
|
162
|
-
|
|
163
|
-
// 1. Tell ZestButton that 'archive' is a valid semantic type
|
|
164
|
-
declare module 'jattac.libs.web.zest-button' {
|
|
165
|
-
export interface CustomZestSemanticTypes {
|
|
166
|
-
archive: 'archive';
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
```
|
|
170
|
-
*(For more on this, see the [Contributor's Guide](./development.md#extending-semantic-types).)*
|
|
171
|
-
|
|
172
|
-
**Step 2: Provide the default configuration**
|
|
173
|
-
In your `App.tsx`, use the `semanticTypeDefaults` property in the `ZestButtonConfigProvider` to define the default props for your new `'archive'` type.
|
|
174
|
-
|
|
175
|
-
```tsx
|
|
176
|
-
// In your main App.tsx
|
|
177
|
-
import React from 'react';
|
|
178
|
-
import { ZestButtonConfigProvider, ZestButton } from 'jattac.libs.web.zest-button';
|
|
179
|
-
import { FaArchive } from 'react-icons/fa';
|
|
180
|
-
|
|
181
|
-
const appZestConfig = {
|
|
182
|
-
semanticTypeDefaults: {
|
|
183
|
-
// 2. Define the default props for the 'archive' type
|
|
184
|
-
archive: {
|
|
185
|
-
buttonStyle: 'outline',
|
|
186
|
-
visualOptions: {
|
|
187
|
-
iconLeft: <FaArchive />,
|
|
188
|
-
variant: 'standard',
|
|
189
|
-
},
|
|
190
|
-
confirmOptions: {
|
|
191
|
-
displayLabel: 'Confirm Archive?',
|
|
192
|
-
timeoutSecs: 10,
|
|
193
|
-
},
|
|
194
|
-
},
|
|
195
|
-
// You can also override built-in types here!
|
|
196
|
-
delete: {
|
|
197
|
-
buttonStyle: 'outline', // Make all delete buttons 'outline'
|
|
198
|
-
}
|
|
199
|
-
},
|
|
200
|
-
};
|
|
201
|
-
|
|
202
|
-
const App = () => (
|
|
203
|
-
<ZestButtonConfigProvider config={appZestConfig}>
|
|
204
|
-
<div style={{ display: 'flex', gap: '1rem' }}>
|
|
205
|
-
{/* 3. Now just use it! */}
|
|
206
|
-
<ZestButton
|
|
207
|
-
zest={{ semanticType: 'archive' }}
|
|
208
|
-
onClick={() => alert('Archived!')}
|
|
209
|
-
>
|
|
210
|
-
Archive
|
|
211
|
-
</ZestButton>
|
|
212
|
-
|
|
213
|
-
<ZestButton
|
|
214
|
-
zest={{ semanticType: 'delete' }}
|
|
215
|
-
onClick={() => alert('Deleted!')}
|
|
216
|
-
>
|
|
217
|
-
Delete
|
|
218
|
-
</ZestButton>
|
|
219
|
-
</div>
|
|
220
|
-
</ZestButtonConfigProvider>
|
|
221
|
-
);
|
|
222
|
-
```
|
|
223
|
-
This powerful pattern allows you to build a complete, consistent design system for all button actions in your application. For more details on configuration, see the [Configuration Guide](./configuration.md).*
|
|
224
|
-
|
|
225
|
-
---
|
|
226
|
-
|
|
227
|
-
[⬅️ Previous: README](../README.md) | [Next: Features Showcase ➡️](./features.md)
|