jattac.libs.web.zest-textbox 0.2.0 → 0.2.1
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/README.md +325 -47
- package/dist/components/CharacterCounter.d.ts +9 -0
- package/dist/components/HelperTextDisplay.d.ts +7 -0
- package/dist/components/PasswordToggleButton.d.ts +8 -0
- package/dist/components/ProgressBar.d.ts +9 -0
- package/dist/contexts/ZestTextboxConfigContext.d.ts +12 -0
- package/dist/hooks/useCharacterCounter.d.ts +6 -0
- package/dist/hooks/useHelperText.d.ts +3 -0
- package/dist/hooks/usePasswordVisibility.d.ts +4 -0
- package/dist/hooks/useThemeDetector.d.ts +2 -0
- package/dist/hooks/useZestTextboxConfig.d.ts +2 -0
- package/dist/index.d.ts +143 -1
- package/dist/index.esm.js +269 -57
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +273 -56
- package/dist/index.js.map +1 -1
- package/dist/{ZestTextbox.d.ts → types.d.ts} +18 -39
- package/dist/utils/numericInputFilter.d.ts +1 -0
- package/package.json +1 -1
- package/dist/IconEyeOpen.d.ts +0 -2
- package/dist/IconEyeSlashed.d.ts +0 -2
package/README.md
CHANGED
|
@@ -10,28 +10,38 @@ A delightful, feature-rich, and highly customizable React textbox component. Bui
|
|
|
10
10
|
- [Installation](#installation)
|
|
11
11
|
- [Basic Usage](#basic-usage)
|
|
12
12
|
- [Props API](#props-api)
|
|
13
|
+
- [ZestProps Interface Details](#zestprops-interface-details)
|
|
13
14
|
- [Feature Examples](#feature-examples)
|
|
14
|
-
- [Password Input](#password-input)
|
|
15
|
+
- [Password Input with Visibility Toggle](#password-input-with-visibility-toggle)
|
|
15
16
|
- [Character Counter & Progress Bar](#character-counter--progress-bar)
|
|
17
|
+
- [Enhanced Numeric Input](#enhanced-numeric-input)
|
|
16
18
|
- [Sizing](#sizing)
|
|
17
|
-
- [Theming](#theming)
|
|
19
|
+
- [Theming (Light/Dark/System)](#theming-lightdarksystem)
|
|
20
|
+
- [Multiline Textarea](#multiline-textarea)
|
|
21
|
+
- [Helper Text with Formatting](#helper-text-with-formatting)
|
|
22
|
+
- [Full Width Stretching](#full-width-stretching)
|
|
23
|
+
- [Centralized Configuration](#centralized-configuration)
|
|
24
|
+
- [Internal Architecture](#internal-architecture)
|
|
25
|
+
- [Breaking Changes](#breaking-changes)
|
|
18
26
|
- [Contributing](#contributing)
|
|
19
27
|
- [License](#license)
|
|
20
28
|
|
|
21
29
|
## Features
|
|
22
30
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
`ZestTextbox` isn't just another input field; it's crafted to bring a smile to your users' faces while providing robust functionality and a seamless developer experience.
|
|
32
|
+
|
|
33
|
+
* **Responsive and Mobile-First:** Adapts beautifully to any screen size, ensuring a consistent UX.
|
|
34
|
+
* **Light & Dark Mode:** Automatically respects user system preferences or can be explicitly set.
|
|
35
|
+
* **Password Visibility Toggle:** A crucial accessibility and usability feature for password fields.
|
|
36
|
+
* **Character Counter & Progress Bar:** Visual feedback on input length, with engaging animations as limits are approached.
|
|
37
|
+
* **Enhanced Numeric Input:** Intelligent filtering for numbers, decimals, and negative values.
|
|
38
|
+
* **Engaging Animations:** Subtle, delightful micro-interactions on focus and input.
|
|
39
|
+
* **Accessible:** Built with `rem` units and best practices for inclusivity.
|
|
40
|
+
* **Centralized Configuration:** Easily manage default behaviors and styles across your application using React Context.
|
|
31
41
|
|
|
32
42
|
## Installation
|
|
33
43
|
|
|
34
|
-
To install
|
|
44
|
+
To install `jattac.libs.web.zest-textbox` in your project, run:
|
|
35
45
|
|
|
36
46
|
```bash
|
|
37
47
|
npm install jattac.libs.web.zest-textbox
|
|
@@ -39,15 +49,16 @@ npm install jattac.libs.web.zest-textbox
|
|
|
39
49
|
|
|
40
50
|
## Basic Usage
|
|
41
51
|
|
|
42
|
-
|
|
52
|
+
Get started with `ZestTextbox` in seconds. It behaves just like a standard HTML `<input>` or `<textarea>`, but with added zest!
|
|
43
53
|
|
|
44
54
|
```jsx
|
|
45
55
|
import React from 'react';
|
|
46
|
-
import ZestTextbox from 'jattac.libs.web.zest-textbox';
|
|
56
|
+
import { ZestTextbox } from 'jattac.libs.web.zest-textbox';
|
|
47
57
|
|
|
48
58
|
const App = () => {
|
|
49
59
|
return (
|
|
50
|
-
<div style={{ padding: '2rem' }}>
|
|
60
|
+
<div style={{ padding: '2rem', maxWidth: '400px', margin: '0 auto' }}>
|
|
61
|
+
<h1>Basic ZestTextbox</h1>
|
|
51
62
|
<ZestTextbox placeholder="Enter your name" />
|
|
52
63
|
</div>
|
|
53
64
|
);
|
|
@@ -58,76 +69,342 @@ export default App;
|
|
|
58
69
|
|
|
59
70
|
## Props API
|
|
60
71
|
|
|
61
|
-
|
|
72
|
+
`ZestTextbox` accepts all standard HTML `<input>` and `<textarea>` props. Additionally, it introduces a powerful `zest` prop for all its custom enhancements.
|
|
62
73
|
|
|
63
74
|
| Prop | Type | Default | Description |
|
|
64
75
|
| ----------- | ---------------------------------- | ----------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
|
|
65
|
-
| `zest` | `ZestProps` | `undefined` | An object containing all custom configurations and behaviors specific to the ZestTextbox component. See `ZestProps` interface for details. |
|
|
76
|
+
| `zest` | `ZestProps` | `undefined` | An object containing all custom configurations and behaviors specific to the ZestTextbox component. See `ZestProps` interface for details below. |
|
|
66
77
|
| `className` | `string` | `""` | A custom CSS class to apply to the main textbox element. |
|
|
67
|
-
| `maxLength` | `number` | `undefined` | The maximum number of characters allowed. Enables the character counter. |
|
|
78
|
+
| `maxLength` | `number` | `undefined` | The maximum number of characters allowed. Enables the character counter and progress bar. |
|
|
68
79
|
| `type` | `string` | `'text'` | The type of the input element. All standard HTML input types are supported. Special handling is applied for `password` and `number`. |
|
|
69
80
|
|
|
81
|
+
### `ZestProps` Interface Details
|
|
82
|
+
|
|
83
|
+
The `zest` prop is an object that encapsulates all the unique features of `ZestTextbox`. Its properties can accept primitive values, functions, or asynchronous functions (`ZestConfigValue<T>`) for dynamic configuration, especially useful with [Centralized Configuration](#centralized-configuration).
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
import { ZestTextboxSize, ZestConfigValue, HelperTextConfig } from 'jattac.libs.web.zest-textbox';
|
|
87
|
+
|
|
88
|
+
interface ZestProps {
|
|
89
|
+
helperTextConfig?: ZestConfigValue<HelperTextConfig>;
|
|
90
|
+
onTextChanged?: (value: string) => void; // Callback for text changes
|
|
91
|
+
zSize?: ZestConfigValue<ZestTextboxSize>; // "sm" | "md" | "lg"
|
|
92
|
+
stretch?: ZestConfigValue<boolean>; // Full width
|
|
93
|
+
showProgressBar?: ZestConfigValue<boolean>; // Display character progress bar
|
|
94
|
+
animatedCounter?: ZestConfigValue<boolean>; // Counter color changes
|
|
95
|
+
theme?: ZestConfigValue<"light" | "dark" | "system">; // Color scheme
|
|
96
|
+
isMultiline?: ZestConfigValue<boolean>; // Render as <textarea>
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
| Property | Type (`ZestConfigValue<T>`) | Default | Description |
|
|
101
|
+
| ----------------- | --------------------------------------------------------- | ----------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
|
|
102
|
+
| `helperTextConfig`| `ZestConfigValue<HelperTextConfig>` | `undefined` | Configuration for dynamic helper text displayed below the input. Can be an object, a function returning an object, or a promise of an object. |
|
|
103
|
+
| `onTextChanged` | `(value: string) => void` | `undefined` | A callback function that is invoked whenever the textbox's value changes. Provides the raw string value. |
|
|
104
|
+
| `zSize` | `ZestConfigValue<"sm" | "md" | "lg">` | `'md'` | Sets the size of the textbox, affecting padding and font size. |
|
|
105
|
+
| `stretch` | `ZestConfigValue<boolean>` | `false` | If `true`, the component will stretch to the full width of its container. |
|
|
106
|
+
| `showProgressBar` | `ZestConfigValue<boolean>` | `false` | If `true`, a progress bar indicating character count vs. `maxLength` will be displayed. Requires `maxLength` to be set. |
|
|
107
|
+
| `animatedCounter` | `ZestConfigValue<boolean>` | `false` | If `true`, the character counter will change color as it approaches the `maxLength`. Requires `maxLength` to be set. |
|
|
108
|
+
| `theme` | `ZestConfigValue<"light" | "dark" | "system">` | `'system'` | Controls the component's color scheme. `'system'` automatically detects the OS/browser preference. |
|
|
109
|
+
| `isMultiline` | `ZestConfigValue<boolean>` | `false` | If `true`, the component will render as a `<textarea>`. If `false` or undefined, it renders as an `<input>`. |
|
|
110
|
+
|
|
70
111
|
## Feature Examples
|
|
71
112
|
|
|
72
|
-
|
|
113
|
+
Dive into practical examples demonstrating the power and flexibility of `ZestTextbox`.
|
|
73
114
|
|
|
74
|
-
|
|
115
|
+
### Password Input with Visibility Toggle
|
|
116
|
+
|
|
117
|
+
Simply set the `type` prop to `"password"` to enable the built-in visibility toggle.
|
|
75
118
|
|
|
76
119
|
```jsx
|
|
77
|
-
|
|
120
|
+
import React from 'react';
|
|
121
|
+
import { ZestTextbox } from 'jattac.libs.web.zest-textbox';
|
|
122
|
+
|
|
123
|
+
const PasswordExample = () => {
|
|
124
|
+
return (
|
|
125
|
+
<div style={{ padding: '2rem', maxWidth: '400px', margin: '0 auto' }}>
|
|
126
|
+
<h2>Password Input</h2>
|
|
127
|
+
<ZestTextbox type="password" placeholder="Enter your password" />
|
|
128
|
+
</div>
|
|
129
|
+
);
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
export default PasswordExample;
|
|
78
133
|
```
|
|
79
134
|
|
|
80
135
|
### Character Counter & Progress Bar
|
|
81
136
|
|
|
82
|
-
Enable the character counter
|
|
137
|
+
Enable the character counter with `maxLength` and add a visual progress bar and animated counter via `zest` props.
|
|
83
138
|
|
|
84
139
|
```jsx
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
140
|
+
import React from 'react';
|
|
141
|
+
import { ZestTextbox } from 'jattac.libs.web.zest-textbox';
|
|
142
|
+
|
|
143
|
+
const CounterExample = () => {
|
|
144
|
+
const [text, setText] = React.useState('');
|
|
145
|
+
return (
|
|
146
|
+
<div style={{ padding: '2rem', maxWidth: '400px', margin: '0 auto' }}>
|
|
147
|
+
<h2>Character Counter & Progress Bar</h2>
|
|
148
|
+
<ZestTextbox
|
|
149
|
+
maxLength={100}
|
|
150
|
+
placeholder="What's on your mind? (max 100 chars)"
|
|
151
|
+
value={text}
|
|
152
|
+
onTextChanged={setText}
|
|
153
|
+
zest={{
|
|
154
|
+
showProgressBar: true,
|
|
155
|
+
animatedCounter: true,
|
|
156
|
+
}}
|
|
157
|
+
/>
|
|
158
|
+
</div>
|
|
159
|
+
);
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
export default CounterExample;
|
|
94
163
|
```
|
|
95
164
|
|
|
96
|
-
### Numeric Input
|
|
165
|
+
### Enhanced Numeric Input
|
|
97
166
|
|
|
98
|
-
|
|
167
|
+
Set `type="number"` for intelligent filtering that allows only digits, a single decimal point, and a single leading negative sign.
|
|
99
168
|
|
|
100
169
|
```jsx
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
170
|
+
import React from 'react';
|
|
171
|
+
import { ZestTextbox } from 'jattac.libs.web.zest-textbox';
|
|
172
|
+
|
|
173
|
+
const NumericExample = () => {
|
|
174
|
+
return (
|
|
175
|
+
<div style={{ padding: '2rem', maxWidth: '400px', margin: '0 auto' }}>
|
|
176
|
+
<h2>Numeric Input</h2>
|
|
177
|
+
<ZestTextbox type="number" placeholder="Enter a number" />
|
|
178
|
+
<br /><br />
|
|
179
|
+
<ZestTextbox type="number" placeholder="Enter a decimal" defaultValue="3.14" />
|
|
180
|
+
<br /><br />
|
|
181
|
+
<ZestTextbox type="number" placeholder="Enter a negative number" defaultValue="-100" />
|
|
182
|
+
</div>
|
|
183
|
+
);
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
export default NumericExample;
|
|
104
187
|
```
|
|
105
188
|
|
|
106
189
|
### Sizing
|
|
107
190
|
|
|
108
|
-
|
|
191
|
+
Control the size of the textbox with the `zSize` property within the `zest` prop. Options are `"sm"`, `"md"` (default), and `"lg"`.
|
|
192
|
+
|
|
193
|
+
```jsx
|
|
194
|
+
import React from 'react';
|
|
195
|
+
import { ZestTextbox } from 'jattac.libs.web.zest-textbox';
|
|
196
|
+
|
|
197
|
+
const SizingExample = () => {
|
|
198
|
+
return (
|
|
199
|
+
<div style={{ padding: '2rem', maxWidth: '400px', margin: '0 auto' }}>
|
|
200
|
+
<h2>Sizing</h2>
|
|
201
|
+
<ZestTextbox zest={{ zSize: "sm" }} placeholder="Small" />
|
|
202
|
+
<br /><br />
|
|
203
|
+
<ZestTextbox zest={{ zSize: "md" }} placeholder="Medium (default)" />
|
|
204
|
+
<br /><br />
|
|
205
|
+
<ZestTextbox zest={{ zSize: "lg" }} placeholder="Large" />
|
|
206
|
+
</div>
|
|
207
|
+
);
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
export default SizingExample;
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
### Theming (Light/Dark/System)
|
|
214
|
+
|
|
215
|
+
Force the component into a specific theme or let it adapt to the user's system preference using the `theme` property.
|
|
216
|
+
|
|
217
|
+
```jsx
|
|
218
|
+
import React from 'react';
|
|
219
|
+
import { ZestTextbox } from 'jattac.libs.web.zest-textbox';
|
|
220
|
+
|
|
221
|
+
const ThemingExample = () => {
|
|
222
|
+
return (
|
|
223
|
+
<div style={{ padding: '2rem', maxWidth: '400px', margin: '0 auto' }}>
|
|
224
|
+
<h2>Theming</h2>
|
|
225
|
+
<ZestTextbox zest={{ theme: "light" }} placeholder="Light Mode" />
|
|
226
|
+
<br /><br />
|
|
227
|
+
<ZestTextbox zest={{ theme: "dark" }} placeholder="Dark Mode" />
|
|
228
|
+
<br /><br />
|
|
229
|
+
<ZestTextbox zest={{ theme: "system" }} placeholder="System Theme (default)" />
|
|
230
|
+
</div>
|
|
231
|
+
);
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
export default ThemingExample;
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
### Multiline Textarea
|
|
238
|
+
|
|
239
|
+
Render `ZestTextbox` as a `<textarea>` by setting `isMultiline` to `true` in the `zest` prop.
|
|
240
|
+
|
|
241
|
+
```jsx
|
|
242
|
+
import React from 'react';
|
|
243
|
+
import { ZestTextbox } from 'jattac.libs.web.zest-textbox';
|
|
244
|
+
|
|
245
|
+
const MultilineExample = () => {
|
|
246
|
+
return (
|
|
247
|
+
<div style={{ padding: '2rem', maxWidth: '400px', margin: '0 auto' }}>
|
|
248
|
+
<h2>Multiline Textarea</h2>
|
|
249
|
+
<ZestTextbox
|
|
250
|
+
zest={{ isMultiline: true }}
|
|
251
|
+
placeholder="Type a longer message here..."
|
|
252
|
+
rows={4}
|
|
253
|
+
/>
|
|
254
|
+
</div>
|
|
255
|
+
);
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
export default MultilineExample;
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
### Helper Text with Formatting
|
|
262
|
+
|
|
263
|
+
Provide dynamic helper text below the input using `helperTextConfig`. You can format the input value and even provide a custom templater for rich rendering.
|
|
264
|
+
|
|
265
|
+
```jsx
|
|
266
|
+
import React from 'react';
|
|
267
|
+
import { ZestTextbox } from 'jattac.libs.web.zest-textbox';
|
|
268
|
+
|
|
269
|
+
const HelperTextExample = () => {
|
|
270
|
+
const [value, setValue] = React.useState('');
|
|
271
|
+
|
|
272
|
+
const currencyFormatter = (val) => {
|
|
273
|
+
const num = parseFloat(val);
|
|
274
|
+
return isNaN(num) ? '' : `$${num.toFixed(2)}`;
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
const customTemplater = (formattedValue) => (
|
|
278
|
+
<span>
|
|
279
|
+
Formatted: <strong>{formattedValue || 'N/A'}</strong>
|
|
280
|
+
</span>
|
|
281
|
+
);
|
|
282
|
+
|
|
283
|
+
return (
|
|
284
|
+
<div style={{ padding: '2rem', maxWidth: '400px', margin: '0 auto' }}>
|
|
285
|
+
<h2>Helper Text</h2>
|
|
286
|
+
<ZestTextbox
|
|
287
|
+
type="number"
|
|
288
|
+
placeholder="Enter amount"
|
|
289
|
+
onTextChanged={setValue}
|
|
290
|
+
zest={{
|
|
291
|
+
helperTextConfig: {
|
|
292
|
+
formatter: currencyFormatter,
|
|
293
|
+
templater: customTemplater,
|
|
294
|
+
},
|
|
295
|
+
}}
|
|
296
|
+
/>
|
|
297
|
+
<br /><br />
|
|
298
|
+
<ZestTextbox
|
|
299
|
+
placeholder="Type something..."
|
|
300
|
+
onTextChanged={setValue}
|
|
301
|
+
zest={{
|
|
302
|
+
helperTextConfig: {
|
|
303
|
+
templater: (val) => (
|
|
304
|
+
<span style={{ color: val.length > 10 ? 'red' : 'green' }}>
|
|
305
|
+
Length: {val.length}
|
|
306
|
+
</span>
|
|
307
|
+
),
|
|
308
|
+
},
|
|
309
|
+
}}
|
|
310
|
+
/>
|
|
311
|
+
</div>
|
|
312
|
+
);
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
export default HelperTextExample;
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
### Full Width Stretching
|
|
319
|
+
|
|
320
|
+
Make the textbox take up the full width of its parent container by setting `stretch` to `true` in the `zest` prop.
|
|
109
321
|
|
|
110
322
|
```jsx
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
323
|
+
import React from 'react';
|
|
324
|
+
import { ZestTextbox } from 'jattac.libs.web.zest-textbox';
|
|
325
|
+
|
|
326
|
+
const StretchExample = () => {
|
|
327
|
+
return (
|
|
328
|
+
<div style={{ padding: '2rem', maxWidth: '400px', margin: '0 auto', border: '1px dashed #ccc' }}>
|
|
329
|
+
<h2>Full Width Stretching</h2>
|
|
330
|
+
<ZestTextbox zest={{ stretch: true }} placeholder="I stretch to full width!" />
|
|
331
|
+
</div>
|
|
332
|
+
);
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
export default StretchExample;
|
|
114
336
|
```
|
|
115
337
|
|
|
116
|
-
|
|
338
|
+
## Centralized Configuration
|
|
339
|
+
|
|
340
|
+
To maintain consistency and reduce boilerplate, `ZestTextbox` supports centralized configuration using React Context. This allows you to define default `ZestProps` for all `ZestTextbox` instances within a provider's scope. Component-level `zest` props will always override these global defaults.
|
|
341
|
+
|
|
342
|
+
### How it Works
|
|
117
343
|
|
|
118
|
-
|
|
344
|
+
1. **`ZestTextboxConfigProvider`:** Wrap your application or a part of it with this provider. Pass a `value` prop containing the default `ZestProps` you want to apply.
|
|
345
|
+
2. **`ZestConfigValue<T>`:** Properties within `ZestProps` can be a primitive value (`T`), a function returning `T` (`() => T`), or an asynchronous function returning a Promise of `T` (`() => Promise<T>`). This provides immense flexibility for dynamic or async defaults.
|
|
346
|
+
|
|
347
|
+
### Usage Example
|
|
348
|
+
|
|
349
|
+
Here's how you can set up a global theme and size, and then override it for a specific component:
|
|
119
350
|
|
|
120
351
|
```jsx
|
|
121
|
-
|
|
122
|
-
|
|
352
|
+
import React from 'react';
|
|
353
|
+
import { ZestTextbox, ZestTextboxConfigProvider } from 'jattac.libs.web.zest-textbox';
|
|
354
|
+
|
|
355
|
+
const AppWithCentralConfig = () => {
|
|
356
|
+
// Define your global default ZestProps
|
|
357
|
+
const globalDefaultZestProps = {
|
|
358
|
+
theme: "dark", // All textboxes will be dark by default
|
|
359
|
+
zSize: () => "lg", // All textboxes will be large by default (function example)
|
|
360
|
+
animatedCounter: Promise.resolve(true), // Async example
|
|
361
|
+
};
|
|
123
362
|
|
|
124
|
-
|
|
125
|
-
<
|
|
363
|
+
return (
|
|
364
|
+
<ZestTextboxConfigProvider value={globalDefaultZestProps}>
|
|
365
|
+
<div style={{ padding: '2rem', maxWidth: '600px', margin: '0 auto' }}>
|
|
366
|
+
<h1>Centralized Configuration Example</h1>
|
|
367
|
+
|
|
368
|
+
<h3>Default ZestTextbox (inherits global defaults)</h3>
|
|
369
|
+
<ZestTextbox placeholder="I'm large, dark, and animated!" />
|
|
370
|
+
<br /><br />
|
|
371
|
+
|
|
372
|
+
<h3>Overridden ZestTextbox (component props take precedence)</h3>
|
|
373
|
+
<ZestTextbox
|
|
374
|
+
placeholder="I'm light, overriding the global dark theme"
|
|
375
|
+
zest={{ theme: "light" }} // Overrides the global dark theme
|
|
376
|
+
/>
|
|
377
|
+
<br /><br />
|
|
378
|
+
|
|
379
|
+
<h3>Another Default ZestTextbox</h3>
|
|
380
|
+
<ZestTextbox placeholder="I'm also large, dark, and animated!" />
|
|
381
|
+
</div>
|
|
382
|
+
</ZestTextboxConfigProvider>
|
|
383
|
+
);
|
|
384
|
+
};
|
|
126
385
|
|
|
127
|
-
|
|
128
|
-
<ZestTextbox zest={{ theme: "system" }} placeholder="System Theme" />
|
|
386
|
+
export default AppWithCentralConfig;
|
|
129
387
|
```
|
|
130
388
|
|
|
389
|
+
### Prioritization Rules
|
|
390
|
+
|
|
391
|
+
The resolution order for `ZestProps` is as follows:
|
|
392
|
+
|
|
393
|
+
1. **Component-level `zest` prop:** Explicit props passed directly to a `ZestTextbox` instance have the highest priority.
|
|
394
|
+
2. **`ZestTextboxConfigProvider` `value` prop:** Defaults provided by the nearest `ZestTextboxConfigProvider` come next.
|
|
395
|
+
3. **Hardcoded internal defaults:** If no `zest` prop is provided on the component and no provider is found (or a specific property isn't defined in the provider), internal hardcoded defaults are used.
|
|
396
|
+
|
|
397
|
+
## Internal Architecture
|
|
398
|
+
|
|
399
|
+
The `ZestTextbox` component has been refactored internally for improved maintainability, readability, and reusability. Its core logic is now distributed across several custom React hooks and smaller, focused sub-components. This internal restructuring does **not** introduce any breaking changes to the public API.
|
|
400
|
+
|
|
401
|
+
The internal structure now includes:
|
|
402
|
+
* `UI/hooks/`: Contains custom React hooks (e.g., `useThemeDetector`, `usePasswordVisibility`, `useCharacterCounter`, `useHelperText`, `useZestTextboxConfig`).
|
|
403
|
+
* `UI/components/`: Contains smaller, focused UI components (e.g., `PasswordToggleButton`, `CharacterCounter`, `ProgressBar`, `HelperTextDisplay`).
|
|
404
|
+
* `UI/utils/`: Contains utility functions (e.g., `numericInputFilter`).
|
|
405
|
+
* `UI/types.ts`: Defines shared TypeScript interfaces and types.
|
|
406
|
+
* `UI/contexts/`: Contains React Contexts and Providers (e.g., `ZestTextboxConfigContext`, `ZestTextboxConfigProvider`).
|
|
407
|
+
|
|
131
408
|
## Breaking Changes
|
|
132
409
|
|
|
133
410
|
### 0.1.7 - Encapsulation of Custom Props into `zest` Object
|
|
@@ -169,6 +446,7 @@ Contributions are welcome! If you have a feature request, bug report, or pull re
|
|
|
169
446
|
1. Clone the repository.
|
|
170
447
|
2. Install dependencies with `npm install`.
|
|
171
448
|
3. Run the build with `npm run build`.
|
|
449
|
+
4. The internal architecture now includes `UI/hooks`, `UI/components`, `UI/utils`, and `UI/contexts` directories for better organization and separation of concerns.
|
|
172
450
|
|
|
173
451
|
## License
|
|
174
452
|
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
interface CharacterCounterProps {
|
|
3
|
+
showCounter: boolean;
|
|
4
|
+
currentLength: number;
|
|
5
|
+
maxLength: number | undefined;
|
|
6
|
+
counterColorClass: string;
|
|
7
|
+
}
|
|
8
|
+
export declare const CharacterCounter: React.FC<CharacterCounterProps>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React, { ReactNode } from "react";
|
|
2
|
+
import { ZestProps } from "../types";
|
|
3
|
+
interface ZestTextboxConfigContextType {
|
|
4
|
+
defaultZestProps: ZestProps;
|
|
5
|
+
}
|
|
6
|
+
interface ZestTextboxConfigProviderProps {
|
|
7
|
+
children: ReactNode;
|
|
8
|
+
value?: ZestProps;
|
|
9
|
+
}
|
|
10
|
+
export declare const ZestTextboxConfigProvider: React.FC<ZestTextboxConfigProviderProps>;
|
|
11
|
+
export declare const useZestTextboxConfig: () => ZestTextboxConfigContextType;
|
|
12
|
+
export {};
|