@gecko-ui-kit/react 0.0.0-stage → 0.1.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/src/forms.d.ts ADDED
@@ -0,0 +1,724 @@
1
+ import type * as React from 'react';
2
+ import type { HostProps, Mounted, DateLike } from './core.js';
3
+
4
+ type Ref<H> = React.RefAttributes<Mounted<H>>;
5
+ type MountedComponent<P, H> = React.ForwardRefExoticComponent<P & HostProps & Ref<H>>;
6
+ type InputAttrs = Omit<React.InputHTMLAttributes<HTMLInputElement>, 'onChange' | 'value' | 'defaultValue' | 'type' | 'min' | 'max' | 'list'>;
7
+
8
+ /* ---------------- MultiSelect ---------------- */
9
+ /** An option: a plain string or an object. */
10
+ export type MultiSelectOption = string | {
11
+ value?: string; label?: string; sub?: string; group?: string;
12
+ /** Show an avatar: true (from the label) or { name, ini, tone }. */
13
+ person?: true | { name: string; ini?: string; tone?: string };
14
+ /** A colour dot: a hue name ('teal') or any CSS colour. */
15
+ color?: string;
16
+ icon?: string;
17
+ disabled?: boolean;
18
+ };
19
+ export interface MultiSelectOptionObject { value: string; label: string; sub?: string; group?: string; person?: true | { name: string; ini?: string; tone?: string }; color?: string; icon?: string; disabled?: boolean; created?: boolean }
20
+ export interface MultiSelectHandle {
21
+ readonly value: string[];
22
+ readonly selected: MultiSelectOptionObject[];
23
+ readonly isOpen: boolean;
24
+ /** Replace the selection (no onChange). */
25
+ set(values: string[]): MultiSelectHandle;
26
+ add(value: string): MultiSelectHandle;
27
+ remove(value: string): MultiSelectHandle;
28
+ clear(): MultiSelectHandle;
29
+ open(): MultiSelectHandle;
30
+ close(): MultiSelectHandle;
31
+ focus(): MultiSelectHandle;
32
+ setOptions(options: MultiSelectOption[]): MultiSelectHandle;
33
+ destroy(): void;
34
+ }
35
+ export interface MultiSelectProps {
36
+ options?: MultiSelectOption[];
37
+ /** The picked values (controlled; applied in place). */
38
+ value?: string[];
39
+ /** The values picked at the start (uncontrolled). */
40
+ defaultValue?: string[];
41
+ placeholder?: string;
42
+ /** Most you can pick (0 = no limit). */
43
+ max?: number;
44
+ /** Offer to create what was typed: true, or (text) => option | Promise<option>. */
45
+ creatable?: boolean | ((text: string) => MultiSelectOption | null | Promise<MultiSelectOption | null>);
46
+ /** Close the list after each pick. */
47
+ closeOnSelect?: boolean;
48
+ /** Adds hidden inputs with this name, so a plain <form> sends the values. */
49
+ name?: string;
50
+ disabled?: boolean;
51
+ words?: { placeholder?: string; more?: string; empty?: string; create?: (text: string) => string; remove?: string; clear?: string; added?: (label: string) => string; removed?: (label: string) => string; max?: (n: number) => string; count?: (n: number) => string };
52
+ onChange?: (values: string[], options: MultiSelectOptionObject[], ms: MultiSelectHandle) => void;
53
+ onCreate?: (option: MultiSelectOptionObject, ms: MultiSelectHandle) => void;
54
+ }
55
+ /** <MultiSelect options={people} value={ids} onChange={setIds} /> */
56
+ export const MultiSelect: MountedComponent<MultiSelectProps, MultiSelectHandle>;
57
+
58
+ /* ---------------- Combobox ---------------- */
59
+ export type ComboboxOption = string | { value?: string; label?: string; sub?: string; icon?: string; group?: string; disabled?: boolean };
60
+ export interface ComboboxOptionObject { value: string; label: string; sub?: string; icon?: string; group?: string; disabled?: boolean; custom?: boolean }
61
+ export interface ComboboxHandle {
62
+ /** The picked value, or null. */
63
+ readonly value: string | null;
64
+ /** The picked option (custom text has custom: true), or null. */
65
+ readonly option: ComboboxOptionObject | null;
66
+ readonly isOpen: boolean;
67
+ /** Pick a value (or { value, label }) without calling onChange; null clears. */
68
+ set(value: string | { value: string; label?: string } | null): ComboboxHandle;
69
+ clear(): ComboboxHandle;
70
+ open(): ComboboxHandle;
71
+ close(): ComboboxHandle;
72
+ focus(): ComboboxHandle;
73
+ setOptions(options: ComboboxOption[]): ComboboxHandle;
74
+ destroy(): void;
75
+ }
76
+ export interface ComboboxProps {
77
+ options?: ComboboxOption[];
78
+ /** Ask your server instead of options. */
79
+ source?: (query: string, ctx: { signal: AbortSignal }) => Promise<ComboboxOption[]> | ComboboxOption[];
80
+ /** The pick (controlled): a value, or { value, label } with a source. */
81
+ value?: string | { value: string; label?: string } | null;
82
+ /** The pick at the start (uncontrolled). */
83
+ defaultValue?: string | { value: string; label?: string } | null;
84
+ placeholder?: string;
85
+ /** An × button; Escape on a closed list clears (default true). */
86
+ clearable?: boolean;
87
+ /** Enter (or leaving the field) keeps the typed text as the value. */
88
+ allowCustom?: boolean;
89
+ /** Letters needed before the list (or the source) is asked. */
90
+ minChars?: number;
91
+ /** ms to wait after typing before calling source (150). */
92
+ debounce?: number;
93
+ /** Rows shown at most (50; 0 = all). */
94
+ maxResults?: number;
95
+ /** A hidden input with this name, so a plain <form> sends the value. */
96
+ name?: string;
97
+ disabled?: boolean;
98
+ /** A visible label (else the placeholder names the field). */
99
+ label?: string;
100
+ words?: Record<string, string | ((...a: any[]) => string)>;
101
+ onChange?: (value: string | null, option: ComboboxOptionObject | null, cb: ComboboxHandle) => void;
102
+ onInput?: (text: string, cb: ComboboxHandle) => void;
103
+ }
104
+ /** <Combobox options={countries} value={c} onChange={setC} /> */
105
+ export const Combobox: MountedComponent<ComboboxProps, ComboboxHandle>;
106
+
107
+ /* ---------------- TagsInput ---------------- */
108
+ export interface TagsInputHandle {
109
+ readonly value: string[];
110
+ /** Add a tag (through transform, unique, max and validate); true when added. */
111
+ add(text: string): boolean;
112
+ /** Remove a tag by its text or index. */
113
+ remove(tag: string | number): boolean;
114
+ clear(): TagsInputHandle;
115
+ /** Replace every tag (no onChange). */
116
+ set(tags: string[]): TagsInputHandle;
117
+ focus(): TagsInputHandle;
118
+ destroy(): void;
119
+ }
120
+ export interface TagsInputProps {
121
+ /** The tags (controlled; applied in place). */
122
+ value?: string[];
123
+ /** The tags at the start (uncontrolled). */
124
+ defaultValue?: string[];
125
+ placeholder?: string;
126
+ /** A short list under the field, narrowed as you type. */
127
+ suggestions?: string[];
128
+ /** Most tags (0 = no limit); a counter shows n/max. */
129
+ max?: number;
130
+ /** No repeats (ignores case and accents; default true). */
131
+ unique?: boolean;
132
+ /** Characters or the keys 'Enter' / 'Tab' that make a tag (default [',', 'Enter']). */
133
+ separators?: string[];
134
+ /** true, or a message to refuse the text (false shows words.invalid). */
135
+ validate?: (text: string) => true | false | string;
136
+ /** Runs before the checks, e.g. (t) => t.toLowerCase(). */
137
+ transform?: (text: string) => string;
138
+ /** A hidden input with the tags joined by commas. */
139
+ name?: string;
140
+ disabled?: boolean;
141
+ words?: { label?: string; placeholder?: string; hint?: string; remove?: (t: string) => string; added?: (t: string) => string; removed?: (t: string) => string; duplicate?: (t: string) => string; invalid?: (t: string) => string; max?: (n: number) => string; count?: (n: number, max: number) => string; suggestions?: string };
142
+ onChange?: (tags: string[], ti: TagsInputHandle) => void;
143
+ }
144
+ /** <TagsInput value={tags} onChange={setTags} /> */
145
+ export const TagsInput: MountedComponent<TagsInputProps, TagsInputHandle>;
146
+
147
+ /* ---------------- RangeSlider ---------------- */
148
+ export interface RangeSliderHandle {
149
+ readonly value: [number, number];
150
+ /** Go to [low, high] (snapped, inside the limits); onChange runs unless { silent: true }. */
151
+ set(value: [number, number], opts?: { silent?: boolean }): RangeSliderHandle;
152
+ destroy(): void;
153
+ }
154
+ export interface RangeSliderProps {
155
+ min?: number;
156
+ max?: number;
157
+ step?: number;
158
+ /** [low, high] (controlled; the thumbs glide there). */
159
+ value?: [number, number];
160
+ /** [low, high] at the start (default: the whole range). */
161
+ defaultValue?: [number, number];
162
+ /** The least the two may be apart. */
163
+ minGap?: number;
164
+ /** Text for the bubble, aria-valuetext, marks and inputs. */
165
+ format?: (value: number) => string;
166
+ /** Reads the number inputs. */
167
+ parse?: (text: string) => number;
168
+ /** Ticks + labels under the track (a number: every n). */
169
+ marks?: number[] | number;
170
+ /** Bars behind the track, spread evenly from min to max. */
171
+ histogram?: number[];
172
+ /** Two number boxes under the track. */
173
+ inputs?: boolean;
174
+ /** Two hidden inputs: name_min and name_max. */
175
+ name?: string;
176
+ /** A heading with the range written out next to it. */
177
+ label?: string;
178
+ disabled?: boolean;
179
+ words?: { min?: string; max?: string; to?: string; range?: string };
180
+ /** Every change while dragging. */
181
+ onInput?: (value: [number, number], rs: RangeSliderHandle) => void;
182
+ /** When a drag ends, a key is pressed or a box is committed. */
183
+ onChange?: (value: [number, number], rs: RangeSliderHandle) => void;
184
+ }
185
+ /** <RangeSlider min={0} max={2000} value={price} onChange={setPrice} /> */
186
+ export const RangeSlider: MountedComponent<RangeSliderProps, RangeSliderHandle>;
187
+
188
+ /* ---------------- Stepper ---------------- */
189
+ export interface StepperHandle {
190
+ readonly value: number;
191
+ /** Go to a number (clamped and snapped); onChange runs unless { silent: true }. */
192
+ set(value: number, opts?: { silent?: boolean }): StepperHandle;
193
+ /** One step up (1) or down (-1); false at the limit. */
194
+ stepBy(dir: 1 | -1): boolean;
195
+ setRange(range: { min?: number; max?: number }): StepperHandle;
196
+ destroy(): void;
197
+ }
198
+ export interface StepperProps {
199
+ /** The number (controlled; the digits roll to it). */
200
+ value?: number;
201
+ defaultValue?: number;
202
+ min?: number;
203
+ max?: number;
204
+ /** 0.5 shows one decimal, 0.25 two. */
205
+ step?: number;
206
+ /** After the number: 'days' or (n) => (n === 1 ? 'day' : 'days'). */
207
+ unit?: string | ((n: number) => string);
208
+ /** Before the number, e.g. '฿'. */
209
+ prefix?: string;
210
+ /** Default: grouped digits for the locale (1,250). */
211
+ format?: (n: number) => string;
212
+ locale?: string;
213
+ size?: '' | 'sm' | 'lg';
214
+ /** A hidden input, so a plain <form> sends the value. */
215
+ name?: string;
216
+ disabled?: boolean;
217
+ words?: { label?: string; less?: string; more?: string; min?: (n: string) => string; max?: (n: string) => string };
218
+ onChange?: (value: number, st: StepperHandle) => void;
219
+ }
220
+ /** <Stepper value={days} onChange={setDays} min={1} max={30} /> */
221
+ export const Stepper: MountedComponent<StepperProps, StepperHandle>;
222
+
223
+ /* ---------------- Rating ---------------- */
224
+ export interface RatingHandle {
225
+ readonly value: number;
226
+ /** Go to a score; onChange runs unless { silent: true }. */
227
+ set(value: number, opts?: { silent?: boolean }): void;
228
+ setReadOnly(readOnly: boolean): void;
229
+ destroy(): void;
230
+ }
231
+ export interface RatingProps {
232
+ /** The score (controlled; applied in place without onChange). */
233
+ value?: number;
234
+ defaultValue?: number;
235
+ max?: number;
236
+ /** Pick in halves (3.5). */
237
+ half?: boolean;
238
+ /** Show a score; any number fills partly (4.3). */
239
+ readOnly?: boolean;
240
+ /** Picking the same score again clears it (default true). */
241
+ clearable?: boolean;
242
+ icon?: 'star' | 'heart' | (string & {});
243
+ size?: '' | 'sm' | 'lg';
244
+ /** A word beside the stars for each score. */
245
+ labels?: string[] | null;
246
+ /** The number beside the stars. */
247
+ showValue?: boolean;
248
+ /** A hidden input with this name, so a plain <form> sends the score. */
249
+ name?: string;
250
+ disabled?: boolean;
251
+ words?: { label?: string; of?: (value: number, max: number) => string; none?: string; cleared?: string };
252
+ onChange?: (value: number, handle: RatingHandle) => void;
253
+ }
254
+ /** <Rating value={score} onChange={setScore} /> */
255
+ export const Rating: MountedComponent<RatingProps, RatingHandle>;
256
+
257
+ /* ---------------- RadioCards ---------------- */
258
+ export interface RadioCardOption { value: string; title?: string; desc?: string; price?: string | number; icon?: string; badge?: string; disabled?: boolean }
259
+ export interface RadioCardsHandle {
260
+ readonly value: string;
261
+ /** Pick from code (no onChange unless { silent: false }); '' clears. */
262
+ set(value: string, opts?: { silent?: boolean }): RadioCardsHandle;
263
+ focus(): void;
264
+ destroy(): void;
265
+ }
266
+ export interface RadioCardsProps {
267
+ /** The group name (a <legend>). */
268
+ label?: string;
269
+ /** Keep the label for screen readers only. */
270
+ hideLabel?: boolean;
271
+ options: (RadioCardOption | string)[];
272
+ /** The picked value (controlled; '' = none). */
273
+ value?: string;
274
+ defaultValue?: string;
275
+ /** list: one card per row; grid: side by side. */
276
+ layout?: 'list' | 'grid';
277
+ /** grid only: the narrowest a card gets, in px (160). */
278
+ min?: number;
279
+ /** The radios' name (sent with a form). */
280
+ name?: string;
281
+ required?: boolean;
282
+ disabled?: boolean;
283
+ words?: { group?: string };
284
+ onChange?: (value: string, option: RadioCardOption, plan: RadioCardsHandle) => void;
285
+ }
286
+ /** <RadioCards options={[…]} value={v} onChange={setV} /> */
287
+ export const RadioCards: MountedComponent<RadioCardsProps, RadioCardsHandle>;
288
+
289
+ /* ---------------- PricingToggle ---------------- */
290
+ export interface PricingPeriod { id: string; label: string; per?: string; badge?: string }
291
+ export interface PricingPlan {
292
+ id?: string; name: string; desc?: string;
293
+ /** { month: 12, year: 9 }, one number, or a string ('Free', 'Custom'). */
294
+ price?: Record<string, number | string> | number | string;
295
+ /** A line under the price, per period or (periodId, plan) => text. */
296
+ note?: Record<string, string> | string | ((periodId: string, plan: PricingPlan) => string);
297
+ features?: string[];
298
+ /** The button's label (no action: no button). */
299
+ action?: string;
300
+ featured?: boolean;
301
+ /** A small tag beside the name ('Popular'). */
302
+ tag?: string;
303
+ }
304
+ export interface PricingToggleHandle {
305
+ readonly period: string;
306
+ /** Show another period's prices; onChange runs unless { silent: true }. */
307
+ set(periodId: string, opts?: { silent?: boolean }): boolean;
308
+ destroy(): void;
309
+ }
310
+ export interface PricingToggleProps {
311
+ periods?: PricingPeriod[];
312
+ plans: PricingPlan[];
313
+ /** The period shown (controlled). */
314
+ value?: string;
315
+ defaultValue?: string;
316
+ /** Intl.NumberFormat options, or (value, periodId, plan) => text. */
317
+ format?: Intl.NumberFormatOptions | ((value: number, periodId: string, plan: PricingPlan) => string);
318
+ locale?: string;
319
+ /** Roll digit by digit or count to the new number. */
320
+ motion?: 'roll' | 'count';
321
+ /** Show the first period's higher price crossed out (default true). */
322
+ strike?: boolean;
323
+ words?: { label?: string; showing?: (periodLabel: string) => string; was?: string; features?: (planName: string) => string };
324
+ onChange?: (periodId: string, prices: PricingToggleHandle) => void;
325
+ /** A plan's action button was pressed. */
326
+ onSelect?: (plan: PricingPlan, periodId: string, prices: PricingToggleHandle) => void;
327
+ }
328
+ /** <PricingToggle plans={plans} value={period} onChange={setPeriod} /> */
329
+ export const PricingToggle: MountedComponent<PricingToggleProps, PricingToggleHandle>;
330
+
331
+ /* ---------------- DateRange ---------------- */
332
+ export interface DateRangeValue { start: string | null; end: string | null; count: number | null }
333
+ export interface DateRangeHandle {
334
+ readonly value: DateRangeValue;
335
+ /** Pick from code (no onChange); null clears. */
336
+ set(value: { start: DateLike; end?: DateLike | null } | DateLike | null, opts?: { animate?: boolean }): DateRangeHandle;
337
+ clear(): DateRangeHandle;
338
+ /** Show another month: a date, or +1 / -1. */
339
+ go(where: DateLike | number): DateRangeHandle;
340
+ destroy(): void;
341
+ }
342
+ export interface DateRangeProps {
343
+ mode?: 'range' | 'single';
344
+ /** The pick (controlled): { start, end } (end may be null), or one date in single mode. */
345
+ value?: { start: DateLike | null; end?: DateLike | null } | DateLike | null;
346
+ defaultValue?: { start: DateLike | null; end?: DateLike | null } | DateLike | null;
347
+ /** Two months side by side (drops to one when narrow). */
348
+ months?: 1 | 2;
349
+ min?: DateLike;
350
+ max?: DateLike;
351
+ /** Days that cannot be picked: dates, { start, end } spans, or (date) => true. */
352
+ disabled?: (DateLike | { start: DateLike; end: DateLike })[] | ((date: string) => boolean);
353
+ /** 4–7 Dec = 4 days, or 3 nights. */
354
+ count?: 'days' | 'nights';
355
+ minDays?: number;
356
+ /** 0 = no limit. */
357
+ maxDays?: number;
358
+ /** A range may not run across a day that is not free (default true). */
359
+ blockSpan?: boolean;
360
+ presets?: ({ label: string; days: number } | { label: string; start: DateLike; end: DateLike })[];
361
+ locale?: string;
362
+ /** 1 = Monday, 0 = Sunday. */
363
+ weekStart?: number;
364
+ words?: Record<string, string | ((...a: any[]) => string)>;
365
+ onChange?: (value: DateRangeValue, dp: DateRangeHandle) => void;
366
+ onInvalid?: (reason: 'blocked' | 'short' | 'long' | 'off', dp: DateRangeHandle) => void;
367
+ }
368
+ /** <DateRange value={range} onChange={setRange} /> */
369
+ export const DateRange: MountedComponent<DateRangeProps, DateRangeHandle>;
370
+
371
+ /* ---------------- TimePicker ---------------- */
372
+ export interface TimePickerHandle {
373
+ /** 'HH:MM' (24-hour), or null when nothing is picked (slots). */
374
+ readonly value: string | null;
375
+ set(time: string | null, opts?: { silent?: boolean }): TimePickerHandle;
376
+ /** Change which times are taken. */
377
+ setDisabled(disabled: string[] | ((time: string) => boolean) | null): TimePickerHandle;
378
+ /** '14:30' or '2:30 PM' with hour12. */
379
+ format(time?: string): string;
380
+ destroy(): void;
381
+ }
382
+ export interface TimePickerProps {
383
+ look?: 'wheel' | 'slots';
384
+ /** 'HH:MM', 24-hour (controlled). */
385
+ value?: string | null;
386
+ defaultValue?: string | null;
387
+ /** Minutes between choices (wheel 5, slots 30). */
388
+ step?: number;
389
+ min?: string;
390
+ max?: string;
391
+ /** Times that can't be picked (applied in place when it changes). */
392
+ disabled?: string[] | ((time: string) => boolean) | null;
393
+ /** Show 2:30 PM (the value stays 24-hour). */
394
+ hour12?: boolean;
395
+ words?: Record<string, string | ((...a: any[]) => string)>;
396
+ onChange?: (value: string | null, tp: TimePickerHandle) => void;
397
+ }
398
+ /** <TimePicker look="slots" value={t} onChange={setT} /> */
399
+ export const TimePicker: MountedComponent<TimePickerProps, TimePickerHandle>;
400
+
401
+ /* ---------------- SubscribeForm ---------------- */
402
+ export interface SubscribeFormHandle {
403
+ readonly value: string;
404
+ readonly state: 'idle' | 'bad' | 'busy' | 'done';
405
+ /** Show your own message under the field (red); '' clears it. */
406
+ setError(text: string): void;
407
+ /** Back to an empty field (also after success). */
408
+ reset(): void;
409
+ destroy(): void;
410
+ }
411
+ export interface SubscribeFormProps {
412
+ /** The email in the field at the start. */
413
+ defaultValue?: string;
414
+ /** The input's name ('email'). */
415
+ name?: string;
416
+ /** An icon inside the field on the left, e.g. 'mail'. */
417
+ icon?: string;
418
+ /** Button beside the field (wraps under it when narrow) or always under it. */
419
+ layout?: 'row' | 'stack';
420
+ /** Your own extra check: return a message to refuse the address. */
421
+ validate?: (email: string) => string | null | undefined;
422
+ /** ms after success before the empty form comes back (0 = stay thanked). */
423
+ resetAfter?: number;
424
+ words?: { label?: string; button?: string; hint?: string; missing?: string; bad?: string; busy?: string; done?: string; doneText?: string; failed?: string };
425
+ /** Resolve (a string replaces doneText); reject or throw to show the error. */
426
+ onSubmit?: (email: string, sub: SubscribeFormHandle) => unknown | Promise<unknown>;
427
+ }
428
+ /** <SubscribeForm onSubmit={join} /> */
429
+ export const SubscribeForm: MountedComponent<SubscribeFormProps, SubscribeFormHandle>;
430
+
431
+ /* ---------------- AuthForm ---------------- */
432
+ export type AuthMode = 'in' | 'up';
433
+ export interface AuthValues { name?: string; email: string; password: string; remember?: boolean }
434
+ export interface PasswordRule { id?: string; test: (value: string) => boolean; label: string }
435
+ export interface PasswordMeterOptions {
436
+ /** Default: length (min), upper + lower, number, symbol. */
437
+ rules?: PasswordRule[] | null;
438
+ /** Length for the default first rule (8). */
439
+ min?: number;
440
+ /** valid needs this score (0–4; 3 = “okay”). */
441
+ minScore?: number;
442
+ /** Your own scoring 0–4; met = [true, false, …] in rule order. */
443
+ score?: ((value: string, met: boolean[]) => number) | null;
444
+ /** The rules checklist (default true). */
445
+ list?: boolean;
446
+ /** The padlock that clicks shut when strong (default true). */
447
+ lock?: boolean;
448
+ words?: Record<string, string | ((...a: any[]) => string)>;
449
+ }
450
+ export interface AuthFormHandle {
451
+ readonly mode: AuthMode;
452
+ setMode(mode: AuthMode): boolean;
453
+ readonly values: AuthValues;
454
+ readonly busy: boolean;
455
+ /** Mark a field red with a message ('' clears). */
456
+ setError(field: 'name' | 'email' | 'password' | 'confirm', message: string): void;
457
+ reset(): void;
458
+ destroy(): void;
459
+ }
460
+ export interface AuthFormProps {
461
+ /** Sign in or create account (controlled; applied in place). */
462
+ mode?: AuthMode;
463
+ defaultMode?: AuthMode;
464
+ /** forgot: true (a button → onForgot) or a URL. */
465
+ fields?: { name?: boolean; confirm?: boolean; remember?: boolean; forgot?: boolean | string };
466
+ /** Strength meter on sign-up; or passwordMeter options. */
467
+ meter?: boolean | PasswordMeterOptions;
468
+ /** Shortest password on sign-up when meter is false. */
469
+ min?: number;
470
+ /** Fill the fields in when it mounts. */
471
+ values?: { name?: string; email?: string; remember?: boolean };
472
+ /** Your own extra checks: { email: 'message' }. */
473
+ validate?: (values: AuthValues, mode: AuthMode) => Partial<Record<'name' | 'email' | 'password' | 'confirm', string>> | null | undefined;
474
+ words?: Record<string, unknown>;
475
+ /** Reject (or throw) to show an error; Error.field = 'email' marks that field. Resolve a string to show it. */
476
+ onSubmit?: (values: AuthValues, mode: AuthMode, f: AuthFormHandle) => unknown | Promise<unknown>;
477
+ onModeChange?: (mode: AuthMode, f: AuthFormHandle) => void;
478
+ onForgot?: (email: string, f: AuthFormHandle) => void;
479
+ }
480
+ /** <AuthForm onSubmit={signIn} /> */
481
+ export const AuthForm: MountedComponent<AuthFormProps, AuthFormHandle>;
482
+
483
+ /* ---------------- PasswordToggle / PasswordMeter ---------------- */
484
+ export interface PasswordToggleProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'type' | 'onToggle'> {
485
+ /** Letters visible (controlled). */
486
+ shown?: boolean;
487
+ defaultShown?: boolean;
488
+ onToggle?: (shown: boolean) => void;
489
+ words?: { show?: string; hide?: string };
490
+ }
491
+ /** <PasswordToggle name="password" autoComplete="current-password" /> — ref is the <input>. */
492
+ export const PasswordToggle: React.ForwardRefExoticComponent<PasswordToggleProps & React.RefAttributes<HTMLInputElement>>;
493
+
494
+ export interface PasswordState { score: number; level: 'empty' | 'tooWeak' | 'weak' | 'okay' | 'strong'; valid: boolean; rules: Record<string, boolean> }
495
+ export interface PasswordMeterHandle {
496
+ readonly score: number;
497
+ readonly level: PasswordState['level'];
498
+ readonly valid: boolean;
499
+ readonly rules: Record<string, boolean>;
500
+ /** Read the field again. */
501
+ check(): PasswordState;
502
+ /** Show or hide the letters (with reveal). */
503
+ reveal(on: boolean): void;
504
+ readonly input: HTMLInputElement;
505
+ readonly root: HTMLElement;
506
+ }
507
+ export interface PasswordMeterProps extends PasswordMeterOptions, Omit<InputAttrs, 'min'> {
508
+ /** A show / hide eye inside the field. */
509
+ reveal?: boolean;
510
+ /** The password (controlled). */
511
+ value?: string;
512
+ defaultValue?: string;
513
+ /** The text changed. */
514
+ onValueChange?: (value: string, event: React.ChangeEvent<HTMLInputElement>) => void;
515
+ /** The meter changed: { score, level, valid, rules }. */
516
+ onChange?: (state: PasswordState, pw: PasswordMeterHandle) => void;
517
+ }
518
+ /** <PasswordMeter value={pw} onValueChange={setPw} onChange={(s) => setOk(s.valid)} /> */
519
+ export const PasswordMeter: React.ForwardRefExoticComponent<PasswordMeterProps & React.RefAttributes<PasswordMeterHandle>>;
520
+
521
+ /* ---------------- SignaturePad ---------------- */
522
+ /** Strokes saved with toJSON(). */
523
+ export interface SignatureData { v: number; ratio: number; strokes: [number, number, number, number][][] }
524
+ export interface SignaturePadHandle {
525
+ readonly isEmpty: boolean;
526
+ undo(): SignaturePadHandle;
527
+ clear(): SignaturePadHandle;
528
+ /** Draw it again, stroke by stroke. */
529
+ replay(): Promise<SignaturePadHandle>;
530
+ toJSON(): SignatureData;
531
+ fromJSON(data: SignatureData, opts?: { animate?: boolean }): Promise<SignaturePadHandle>;
532
+ /** A data URL; trim cuts it to the ink; background '' keeps it transparent. */
533
+ toImage(opts?: { type?: string; background?: string; color?: string; trim?: boolean; scale?: number; margin?: number }): string;
534
+ toSVG(opts?: { color?: string }): string;
535
+ destroy(): void;
536
+ }
537
+ export interface SignaturePadProps {
538
+ /** 'currentColor' (follows the text colour) or any colour. */
539
+ color?: string;
540
+ /** Thinnest and thickest line in px. */
541
+ width?: [number, number];
542
+ /** Fast = thin, slow or pressed hard = thick (false: one even width). */
543
+ pressure?: boolean;
544
+ /** The line and × to sign on. */
545
+ guide?: boolean;
546
+ /** Undo and clear buttons in the corner. */
547
+ tools?: boolean;
548
+ /** Show a signature that can't be changed. */
549
+ readOnly?: boolean;
550
+ /** Strokes to show (loaded again when they change). */
551
+ defaultValue?: SignatureData | null;
552
+ words?: { label?: string; hint?: string; undo?: string; clear?: string; signed?: string; empty?: string; cleared?: string };
553
+ /** After every change. */
554
+ onChange?: (isEmpty: boolean, sig: SignaturePadHandle) => void;
555
+ /** After each stroke. */
556
+ onEnd?: (sig: SignaturePadHandle) => void;
557
+ }
558
+ /** <SignaturePad onChange={(empty) => setSigned(!empty)} /> */
559
+ export const SignaturePad: MountedComponent<SignaturePadProps, SignaturePadHandle>;
560
+
561
+ /* ---------------- PhotoUpload ---------------- */
562
+ export interface UploadItem { id: string; name: string; size: number; type: string; file: File | null; url: string; status: 'queued' | 'uploading' | 'done' | 'error'; progress: number; result: unknown; error: unknown }
563
+ export interface PhotoUploadHandle {
564
+ readonly items: UploadItem[];
565
+ /** Each photo's upload result (or the File without upload), in order. */
566
+ readonly value: unknown[];
567
+ readonly busy: boolean;
568
+ /** Resolves with value once nothing is uploading. */
569
+ settled(): Promise<unknown[]>;
570
+ add(files: FileList | File[], from?: { x: number; y: number } | null): UploadItem[];
571
+ remove(id: string): PhotoUploadHandle;
572
+ move(id: string, index: number): PhotoUploadHandle;
573
+ retry(id: string): PhotoUploadHandle;
574
+ clear(): PhotoUploadHandle;
575
+ /** Open the file picker. */
576
+ open(): PhotoUploadHandle;
577
+ /** Show photos that are already uploaded. */
578
+ setValue(list: (string | { url: string; name?: string; [k: string]: unknown })[]): PhotoUploadHandle;
579
+ destroy(): void;
580
+ }
581
+ export interface PhotoUploadProps {
582
+ /** Like <input accept> (default 'image/*'). */
583
+ accept?: string;
584
+ /** Most photos (8; 0 = no limit). */
585
+ max?: number;
586
+ /** MB per photo (10; 0 = no limit). */
587
+ maxSize?: number;
588
+ /** Photos already uploaded (controlled): [{ url, … }] or URLs. */
589
+ value?: (string | { url: string; name?: string; [k: string]: unknown })[];
590
+ defaultValue?: (string | { url: string; name?: string; [k: string]: unknown })[];
591
+ /** Your upload; call progress(0…1); resolve to anything (usually { url }). */
592
+ upload?: (file: File, ctx: { progress: (f: number) => void; signal: AbortSignal; item: UploadItem }) => Promise<unknown>;
593
+ /** Uploads at the same time (2). */
594
+ concurrent?: number;
595
+ /** Make big photos smaller first. */
596
+ resize?: boolean | { max?: number; quality?: number; type?: string } | null;
597
+ /** Label the first photo "Cover". */
598
+ cover?: boolean;
599
+ sortable?: boolean;
600
+ readOnly?: boolean;
601
+ /** 'environment' opens the camera on phones. */
602
+ capture?: string | null;
603
+ words?: Record<string, string | ((...a: any[]) => string)>;
604
+ onChange?: (items: UploadItem[], up: PhotoUploadHandle) => void;
605
+ onReject?: (file: File, reason: 'type' | 'size' | 'count', up: PhotoUploadHandle) => void;
606
+ onUploaded?: (item: UploadItem, up: PhotoUploadHandle) => void;
607
+ onError?: (item: UploadItem, error: unknown, up: PhotoUploadHandle) => void;
608
+ }
609
+ /** <PhotoUpload upload={send} /> */
610
+ export const PhotoUpload: MountedComponent<PhotoUploadProps, PhotoUploadHandle>;
611
+
612
+ /* ---------------- FileDrop ---------------- */
613
+ export interface FileDropFile { id: string; file: File; name: string; size: number; type: string; status: 'queued' | 'uploading' | 'done' | 'error'; progress: number; error: string | null; reason: 'type' | 'size' | 'count' | 'upload' | null; result: unknown }
614
+ export interface FileDropHandle {
615
+ readonly files: FileDropFile[];
616
+ /** Results of finished uploads (or the Files without upload). */
617
+ readonly value: unknown[];
618
+ readonly busy: boolean;
619
+ add(files: FileList | File[]): FileDropFile[];
620
+ remove(id: string): FileDropHandle;
621
+ retry(id: string): FileDropHandle;
622
+ cancel(id: string): FileDropHandle;
623
+ clear(): FileDropHandle;
624
+ /** Open the file picker. */
625
+ browse(): FileDropHandle;
626
+ /** Start the queued uploads (with auto: false). */
627
+ upload(): Promise<unknown[]>;
628
+ destroy(): void;
629
+ }
630
+ export interface FileDropProps {
631
+ /** Like <input accept> ('' = anything). */
632
+ accept?: string;
633
+ /** false: one file; a new one replaces it. */
634
+ multiple?: boolean;
635
+ /** Bytes per file (0 = no limit). */
636
+ maxSize?: number;
637
+ /** Most files (0 = no limit). */
638
+ maxFiles?: number;
639
+ /** Call progress(0…1); without it files are only listed. */
640
+ upload?: (file: File, ctx: { progress: (f: number) => void; signal: AbortSignal; id: string }) => Promise<unknown>;
641
+ /** Start uploading as files are added (false: call ref.upload()). */
642
+ auto?: boolean;
643
+ /** Uploads at the same time (3). */
644
+ concurrent?: number;
645
+ /** A slim one-line zone. */
646
+ compact?: boolean;
647
+ words?: Record<string, string | ((...a: any[]) => string)>;
648
+ onChange?: (files: FileDropFile[], fd: FileDropHandle) => void;
649
+ onError?: (problem: { id: string; file: File; name: string; reason: 'type' | 'size' | 'count' | 'upload'; message: string; error: unknown }, fd: FileDropHandle) => void;
650
+ }
651
+ /** <FileDrop upload={send} /> */
652
+ export const FileDrop: MountedComponent<FileDropProps, FileDropHandle>;
653
+
654
+ /* ---------------- Wizard ---------------- */
655
+ export interface WizardHandle {
656
+ /** The step on show (from 0); steps.length once finished. */
657
+ readonly index: number;
658
+ readonly finished: boolean;
659
+ /** Every named field in the panels: { name: value }. */
660
+ readonly values: Record<string, unknown>;
661
+ /** Show a step without checking the one you are on. */
662
+ go(index: number): WizardHandle;
663
+ /** Check this step and move on (or finish). */
664
+ next(): Promise<boolean>;
665
+ back(): WizardHandle;
666
+ /** Back to the first step with the fields as they started. */
667
+ reset(): WizardHandle;
668
+ setBusy(on: boolean): WizardHandle;
669
+ destroy(): void;
670
+ }
671
+ export interface WizardStep {
672
+ id?: string;
673
+ title: string;
674
+ sub?: string;
675
+ /** The panel's content: any React node. */
676
+ content?: React.ReactNode;
677
+ optional?: boolean;
678
+ /** true, a message, or a Promise of either; no validate: the browser's own checks on the fields. */
679
+ validate?: (panel: HTMLElement, wz: WizardHandle) => true | false | string | Promise<true | false | string>;
680
+ }
681
+ export interface WizardProps {
682
+ steps: WizardStep[];
683
+ /** The step shown (controlled; applied with go(), without checking). */
684
+ index?: number;
685
+ /** The step shown first. */
686
+ start?: number;
687
+ /** The header cannot jump past steps that are not finished (default true). */
688
+ linear?: boolean;
689
+ header?: 'steps' | 'bar' | 'none';
690
+ /** Heading level of the panel titles (3). */
691
+ level?: number;
692
+ /** The progress header's name for screen readers. */
693
+ label?: string;
694
+ words?: { next?: string; back?: string; finish?: string; step?: (i: number, n: number) => string; done?: string; doneText?: string; optional?: string; completed?: string; locked?: string; busy?: string; invalid?: string; label?: string };
695
+ onStep?: (index: number, wz: WizardHandle) => void;
696
+ /** May return a Promise; false (or a message) keeps the last step open. */
697
+ onFinish?: (values: Record<string, unknown>, wz: WizardHandle) => unknown | Promise<unknown>;
698
+ }
699
+ /** <Wizard steps={[{ title: 'Bike', content: <BikeStep /> }, …]} onFinish={book} /> */
700
+ export const Wizard: MountedComponent<WizardProps, WizardHandle>;
701
+
702
+ /* ---------------- useValidation ---------------- */
703
+ /** A rule: '' (or true / null) when fine, else the message to show. */
704
+ export type ValidationRule = (value: any, values: Record<string, any>) => string | boolean | null | undefined;
705
+ export interface Validation<K extends string> {
706
+ /** The message of every field that is wrong now. */
707
+ errors: Partial<Record<K, string>>;
708
+ /** Props for the field's <input>/<textarea>/<select>: name, ref, onInput, aria-invalid. */
709
+ field(name: K): { name: K; ref: (el: HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement | null) => void; onInput: () => void; 'aria-invalid': true | undefined };
710
+ /** Check every field (or these): marks and shakes the bad ones; true when all are fine. */
711
+ validate(names?: K[]): boolean;
712
+ /** Check one field. */
713
+ check(name: K): boolean;
714
+ /** Mark a field from elsewhere (a server answer); '' clears. */
715
+ setError(name: K, message: string): void;
716
+ /** Clear every message. */
717
+ reset(): void;
718
+ /** The current values of the fields. */
719
+ values(): Record<K, any>;
720
+ }
721
+ /** const v = useValidation({ email: (v) => (v ? '' : 'Enter your email.') }) */
722
+ export function useValidation<K extends string>(rules: Record<K, ValidationRule>, options?: { live?: boolean; shake?: boolean }): Validation<K>;
723
+
724
+ export {};