@gridkitjs/forms 0.0.0-dev-20261206092422
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/LICENSE +21 -0
- package/README.md +43 -0
- package/dist/index.d.ts +1211 -0
- package/dist/index.js +7621 -0
- package/dist/index.js.map +1 -0
- package/package.json +63 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,1211 @@
|
|
|
1
|
+
import * as core from '@gridkitjs/forms-core';
|
|
2
|
+
import { NoDetails, Parser, Formatter, Validator, FieldMessageInput, FormsMessages, FieldState, FieldMessage, Severity, ChangeCause, ParseContext, ParseResult, FormatContext, InputFilter, PlainDate, Weekday, WeekNumbering, DateDetails, CalendarMonth, DateRange, RangeDetails, NoFlags, RelativeDateRule, RangeBounds, PopupOpenChange, Instant, PlainDateTime, DateTimeDetails, PlainTime, TimeZoneDisambiguation, TimeDetails, StepDirection, StepSize, NumberValueType, NumberValue, NumberDetails, RoundingMode, NegativeStyle, NumberOptions, DecimalString, DurationDetails, DurationUnit, DurationNotation, MaskDetails, MaskOptions, MaskSource, MaskPreset, MaskValueFormat, Range, PercentScale, PeriodGranularity, Period, PeriodDetails } from '@gridkitjs/forms-core';
|
|
3
|
+
export { CalendarMonth, ChangeSource, CommitTrigger, DateDetails, DateRange, DateReadingInfo, DateSegmentType, DateTimeDetails, DecimalString, DurationDetails, DurationNotation, DurationUnit, FieldDraft, FieldMessage, FieldMessageInput, FieldPhase, FieldState, FiscalYear, FormatContext, Formatter, FormsMessages, Instant, MaskDetails, MaskOptions, MaskPreset, MaskPresets, MaskSource, MaskTokenDefinition, MaskTokens, MaskValueFormat, NegativeStyle, NoDetails, NoFlags, NumberDetails, NumberReadingInfo, NumberValue, NumberValueType, ParseContext, ParseResult, Parser, PercentScale, Period, PeriodDetails, PeriodGranularity, PlainDate, PlainDateTime, PlainTime, PopupCloseReason, PopupOpenChange, PopupOpenReason, Range, RangeBounds, RangeDetails, RangeEnd, RoundingMode, Severity, StepDirection, StepSize, TextInputDetails, TextParseOptions, TextReading, TimeDetails, TimeZoneDisambiguation, ValidationResult, Validator, ValidatorContext, WeekNumbering, Weekday, formatText, maskPresets, parsed, textParser, unreadable } from '@gridkitjs/forms-core';
|
|
4
|
+
import * as react from 'react';
|
|
5
|
+
import { Ref, RefCallback, ReactElement, ReactNode, CSSProperties, HTMLAttributes, InputHTMLAttributes, SubmitEvent } from 'react';
|
|
6
|
+
import { TextControl, TextInputOptions, ToggleOptions } from '@gridkitjs/forms-dom';
|
|
7
|
+
|
|
8
|
+
/** What every forms event carries. */
|
|
9
|
+
type FieldEventBase<V> = core.FieldEventBase<V, Event>;
|
|
10
|
+
/** The text changed: every keystroke, paste, drop or deletion. */
|
|
11
|
+
type FieldInputEvent<V, D extends object = NoDetails> = core.FieldInputEvent<V, D, Event>;
|
|
12
|
+
/** The value changed. */
|
|
13
|
+
type FieldChangeEvent<V, D extends object = NoDetails> = core.FieldChangeEvent<V, D, Event>;
|
|
14
|
+
/** The field's messages were worked out again. */
|
|
15
|
+
type FieldValidateEvent<V, D extends object = NoDetails> = core.FieldValidateEvent<V, D, Event>;
|
|
16
|
+
/** The user is done: the value is committed. */
|
|
17
|
+
type FieldCommitEvent<V, D extends object = NoDetails> = core.FieldCommitEvent<V, D, Event>;
|
|
18
|
+
/** A text edit is about to happen, and may be prevented or rewritten. */
|
|
19
|
+
type FieldBeforeInputEvent<V, D extends object = NoDetails> = core.FieldBeforeInputEvent<V, D, Event>;
|
|
20
|
+
/** The value is about to change, and may be prevented or replaced. */
|
|
21
|
+
type FieldBeforeChangeEvent<V, D extends object = NoDetails> = core.FieldBeforeChangeEvent<V, D, Event>;
|
|
22
|
+
/** The value is about to be committed, and may be refused, after a wait. */
|
|
23
|
+
type FieldBeforeCommitEvent<V, D extends object = NoDetails> = core.FieldBeforeCommitEvent<V, D, Event>;
|
|
24
|
+
/** The field gained or lost focus. */
|
|
25
|
+
type FieldFocusEvent<V> = core.FieldFocusEvent<V, Event>;
|
|
26
|
+
/**
|
|
27
|
+
* The clear button was pressed, or Escape pressed in a search box: called
|
|
28
|
+
* before the field empties, with what it held.
|
|
29
|
+
*/
|
|
30
|
+
interface FieldClearEvent<V> {
|
|
31
|
+
readonly previousValue: V | null;
|
|
32
|
+
readonly previousText: string;
|
|
33
|
+
readonly nativeEvent: Event | null;
|
|
34
|
+
}
|
|
35
|
+
/** Every handler a field calls, each optional. */
|
|
36
|
+
type FieldHandlers<V, D extends object = NoDetails> = core.FieldHandlers<V, D, Event>;
|
|
37
|
+
|
|
38
|
+
/** How tightly fields are drawn. */
|
|
39
|
+
type Density = "compact" | "standard" | "comfortable";
|
|
40
|
+
/** `"display"` shows a field's value as text, with no control to operate. */
|
|
41
|
+
type FieldMode = "edit" | "display";
|
|
42
|
+
/**
|
|
43
|
+
* Where a field's label sits: above the control (`"top"`), inside it until
|
|
44
|
+
* the field is focused or filled (`"floating"`), beside it (`"start"`), or
|
|
45
|
+
* nowhere visible while still naming the control (`"hidden"`).
|
|
46
|
+
*/
|
|
47
|
+
type LabelPosition = "top" | "floating" | "start" | "hidden";
|
|
48
|
+
/**
|
|
49
|
+
* Which fields a label marks: required ones with an asterisk
|
|
50
|
+
* (`"required"`), the others with "(optional)" (`"optional"`), or none.
|
|
51
|
+
*/
|
|
52
|
+
type NecessityIndicator = "required" | "optional" | "none";
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* What an input tells the `Field` around it about its control, so a
|
|
56
|
+
* floating label knows whether to rest inside the control or rise above.
|
|
57
|
+
*/
|
|
58
|
+
interface FieldControlState {
|
|
59
|
+
readonly focused: boolean;
|
|
60
|
+
/** No text in the control. */
|
|
61
|
+
readonly empty: boolean;
|
|
62
|
+
/** Something sits at the control's start, such as a prefix, where a resting label would cover it. */
|
|
63
|
+
readonly startAdornment?: boolean | undefined;
|
|
64
|
+
/** The input needs a value by a `required` of its own, so the field marks its label. */
|
|
65
|
+
readonly required?: boolean | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* The control carries its own label beside it (a checkbox, a switch), so
|
|
68
|
+
* nothing can rest inside it: a floating label sits above, as `top`.
|
|
69
|
+
*/
|
|
70
|
+
readonly labelBeside?: boolean | undefined;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** What an input does from code: focus it, read it, change it. */
|
|
74
|
+
interface InputHandle<V> {
|
|
75
|
+
/** The focusable element, while it is in the page. */
|
|
76
|
+
readonly element: HTMLElement | null;
|
|
77
|
+
focus(options?: FocusOptions): void;
|
|
78
|
+
blur(): void;
|
|
79
|
+
getValue(): V | null;
|
|
80
|
+
getText(): string;
|
|
81
|
+
/** `onBeforeChange`, `onChange` and `onValidate`, with `source: "api"`; no commit. */
|
|
82
|
+
setValue(value: V | null): void;
|
|
83
|
+
/** Back to `defaultValue`, or `null`, as `setValue` changes it. */
|
|
84
|
+
reset(): void;
|
|
85
|
+
/** Shows the field's messages from now on, as a commit attempt would. */
|
|
86
|
+
revealMessages(): void;
|
|
87
|
+
}
|
|
88
|
+
/** How an input reads, writes and submits its value. */
|
|
89
|
+
interface FieldInputKind<V, D extends object = NoDetails> {
|
|
90
|
+
/** The input's own reading of text, which a `parse` prop can wrap. */
|
|
91
|
+
readonly defaultParse: (text: string, context: ParseContext<V>) => ParseResult<V>;
|
|
92
|
+
/** The input's own writing of the value, which a `format` prop can wrap. */
|
|
93
|
+
readonly defaultFormat: (value: V | null, context: FormatContext<V>) => string;
|
|
94
|
+
/**
|
|
95
|
+
* The value as its hidden input submits it, the same in every locale.
|
|
96
|
+
* Never called with `null`, which submits `""`.
|
|
97
|
+
*/
|
|
98
|
+
readonly serialize: (value: V) => string;
|
|
99
|
+
/** Whether two values are one; `Object.is` by default. Never called with `null`. */
|
|
100
|
+
readonly equals?: ((a: V, b: V) => boolean) | undefined;
|
|
101
|
+
/** The input's own details, added to every event it fires. */
|
|
102
|
+
readonly details?: ((current: FieldState<V>, previous: FieldState<V>) => D) | undefined;
|
|
103
|
+
/**
|
|
104
|
+
* The input's own judgement of each edit the app's `onBeforeInput` lets
|
|
105
|
+
* through: a number input refusing letters and typing its decimals.
|
|
106
|
+
*/
|
|
107
|
+
readonly filterInput?: InputFilter<Event> | undefined;
|
|
108
|
+
}
|
|
109
|
+
/** The props `useFieldInput` reads; an input passes on its own. */
|
|
110
|
+
interface FieldInputProps<V, E extends TextControl = HTMLInputElement, D extends object = NoDetails> extends FieldHandlers<V, D> {
|
|
111
|
+
/** Present, `null` included, means controlled. */
|
|
112
|
+
readonly value?: V | null | undefined;
|
|
113
|
+
/** The value of an uncontrolled field at first, and what `reset` returns to. */
|
|
114
|
+
readonly defaultValue?: V | null | undefined;
|
|
115
|
+
/** The app's reading of typed text; `context.defaultParse` is the input's own. */
|
|
116
|
+
readonly parse?: Parser<V> | undefined;
|
|
117
|
+
/** The app's writing of the value; `context.defaultFormat` is the input's own. */
|
|
118
|
+
readonly format?: Formatter<V> | undefined;
|
|
119
|
+
readonly validate?: Validator<V> | readonly Validator<V>[] | undefined;
|
|
120
|
+
/**
|
|
121
|
+
* The control needs a value: it sets `aria-required` and marks the label
|
|
122
|
+
* of the `Field` around it. The input adds the check to `validate`.
|
|
123
|
+
*/
|
|
124
|
+
readonly required?: boolean | undefined;
|
|
125
|
+
/** The app's messages, always shown with the field's own; a string is an error. */
|
|
126
|
+
readonly message?: FieldMessageInput | readonly FieldMessageInput[] | undefined;
|
|
127
|
+
/** Shows the error state with no message, for a form library that shows its errors elsewhere. */
|
|
128
|
+
readonly invalid?: boolean | undefined;
|
|
129
|
+
/** Called first when the field is cleared, before its change and commit. */
|
|
130
|
+
readonly onClear?: ((event: FieldClearEvent<V>) => void) | undefined;
|
|
131
|
+
/** Submits the value under this name, through a hidden input. */
|
|
132
|
+
readonly name?: string | undefined;
|
|
133
|
+
/** The `id` of a `<form>` elsewhere in the page that the value belongs to. */
|
|
134
|
+
readonly form?: string | undefined;
|
|
135
|
+
readonly readOnly?: boolean | undefined;
|
|
136
|
+
/** Disabled, and not submitted. */
|
|
137
|
+
readonly disabled?: boolean | undefined;
|
|
138
|
+
/** `"display"` shows the value as text; the `Field` or form around it sets it otherwise. */
|
|
139
|
+
readonly mode?: FieldMode | undefined;
|
|
140
|
+
/** The control's `id` outside a `Field`; inside one, the field's is used. */
|
|
141
|
+
readonly id?: string | undefined;
|
|
142
|
+
readonly locale?: Intl.LocalesArgument;
|
|
143
|
+
/** Strings laid over the default English ones. */
|
|
144
|
+
readonly messages?: Partial<FormsMessages> | undefined;
|
|
145
|
+
/** The native control. */
|
|
146
|
+
readonly ref?: Ref<E> | undefined;
|
|
147
|
+
readonly handleRef?: Ref<InputHandle<V>> | undefined;
|
|
148
|
+
}
|
|
149
|
+
/** How the input that calls `useFieldInput` behaves, which its own props decide. */
|
|
150
|
+
interface FieldInputOptions extends TextInputOptions {
|
|
151
|
+
/**
|
|
152
|
+
* Something sits at the control's start (a prefix, an icon), where a
|
|
153
|
+
* resting floating label would cover it, so the label stays raised.
|
|
154
|
+
*/
|
|
155
|
+
readonly startAdornment?: boolean | undefined;
|
|
156
|
+
/**
|
|
157
|
+
* Milliseconds typing must pause before the text is read (`onChange`),
|
|
158
|
+
* for a search box; `onInput` fires at once and a commit reads at once.
|
|
159
|
+
*/
|
|
160
|
+
readonly changeDelay?: number | undefined;
|
|
161
|
+
/**
|
|
162
|
+
* The control is a checkbox, flipped whole, rather than text: forms-dom's
|
|
163
|
+
* toggle behaviour drives it, every flip commits, leaving commits nothing
|
|
164
|
+
* more, and its label sits beside it, so a `Field`'s floating label stays
|
|
165
|
+
* above. `readOnly` is passed on by the hook.
|
|
166
|
+
*/
|
|
167
|
+
readonly toggle?: Omit<ToggleOptions, "readOnly"> | undefined;
|
|
168
|
+
}
|
|
169
|
+
/** The props `useFieldInput` gives the native control. */
|
|
170
|
+
interface FieldControlBinding<E extends TextControl> {
|
|
171
|
+
readonly ref: RefCallback<E>;
|
|
172
|
+
readonly id: string;
|
|
173
|
+
/**
|
|
174
|
+
* The text on screen, for a text control. The control's live text is
|
|
175
|
+
* forms-dom's, so it is never a controlled `value`.
|
|
176
|
+
*/
|
|
177
|
+
readonly defaultValue: string | undefined;
|
|
178
|
+
/** Whether a toggle is checked when it is first drawn; forms-dom keeps it after. */
|
|
179
|
+
readonly defaultChecked: boolean | undefined;
|
|
180
|
+
/** A text control's native `readOnly`; a toggle, which ignores it, has `aria-readonly`. */
|
|
181
|
+
readonly readOnly: boolean | undefined;
|
|
182
|
+
readonly "aria-readonly": true | undefined;
|
|
183
|
+
readonly disabled: boolean | undefined;
|
|
184
|
+
readonly "aria-invalid": true | undefined;
|
|
185
|
+
/** The description and messages of the `Field` around it. */
|
|
186
|
+
readonly "aria-describedby": string | undefined;
|
|
187
|
+
readonly "aria-required": true | undefined;
|
|
188
|
+
}
|
|
189
|
+
/** What `useFieldInput` gives the input that calls it, to draw. */
|
|
190
|
+
interface FieldInput<V, E extends TextControl = HTMLInputElement> {
|
|
191
|
+
readonly state: FieldState<V>;
|
|
192
|
+
/** The text on screen. */
|
|
193
|
+
readonly text: string;
|
|
194
|
+
/**
|
|
195
|
+
* The messages to show: the app's `message`, and the field's own from
|
|
196
|
+
* the first commit attempt or `revealMessages` on, except while
|
|
197
|
+
* disabled. A `Field` around the input lists them itself.
|
|
198
|
+
*/
|
|
199
|
+
readonly messages: readonly FieldMessage[];
|
|
200
|
+
/**
|
|
201
|
+
* The most serious message shown, under the input or anywhere in the
|
|
202
|
+
* `Field` around it, or `"error"` for `invalid`: the control box's
|
|
203
|
+
* border colour.
|
|
204
|
+
*/
|
|
205
|
+
readonly severity: Severity | null;
|
|
206
|
+
/** Fires `onClear`, then empties the field and commits it (`source` and `trigger` `"clear"`). */
|
|
207
|
+
readonly clear: (nativeEvent: Event | null) => void;
|
|
208
|
+
/** The value now, read at the moment of the call rather than at render. */
|
|
209
|
+
readonly getValue: () => V | null;
|
|
210
|
+
/**
|
|
211
|
+
* The change chain to `value`, with `cause`'s source and native event,
|
|
212
|
+
* and no commit: a step, a part of a composite input.
|
|
213
|
+
*/
|
|
214
|
+
readonly change: (value: V | null, cause: ChangeCause<Event>) => void;
|
|
215
|
+
/** The props', the `Field`'s or the form's. */
|
|
216
|
+
readonly mode: FieldMode;
|
|
217
|
+
/** The value as text, to draw in place of the control in display mode. */
|
|
218
|
+
readonly displayValue: ReactElement;
|
|
219
|
+
/** Spread onto the native control. */
|
|
220
|
+
readonly controlProps: FieldControlBinding<E>;
|
|
221
|
+
/** The hidden input carrying `name`, to draw beside the control; `null` without one. */
|
|
222
|
+
readonly hiddenInput: ReactElement | null;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Binds a native text control, or with `options.toggle` a checkbox, to a
|
|
226
|
+
* field: the value and draft model, the
|
|
227
|
+
* events in their order, controlled and imperative changes, validation and
|
|
228
|
+
* the hidden input that submits the value. The input that calls it draws
|
|
229
|
+
* the control with `controlProps` spread on it, and `hiddenInput` beside
|
|
230
|
+
* it; it renders nothing itself.
|
|
231
|
+
*
|
|
232
|
+
* It only wires: forms-core's controller decides every event, and forms-dom
|
|
233
|
+
* connects it to the control once the control is in the page. The latest
|
|
234
|
+
* props reach the controller on every render. A controlled `value` is
|
|
235
|
+
* passed on after every render and adopted whenever the user is not
|
|
236
|
+
* typing, with no event; `handleRef`'s `setValue` and `reset` fire the
|
|
237
|
+
* change events with `source: "api"`.
|
|
238
|
+
*
|
|
239
|
+
* Inside a `Field` the control takes the field's `id`, description,
|
|
240
|
+
* required and invalid states, and `readOnly`, `disabled` and `mode` from
|
|
241
|
+
* the field and the form, and the hook tells the field its shown messages
|
|
242
|
+
* and whether the control is focused, empty and required. `options` are
|
|
243
|
+
* the calling input's own behaviour; the latest reach forms-dom after
|
|
244
|
+
* every render.
|
|
245
|
+
*/
|
|
246
|
+
declare function useFieldInput<V, E extends TextControl = HTMLInputElement, D extends object = NoDetails>(props: FieldInputProps<V, E, D>, kind: FieldInputKind<V, D>, options?: FieldInputOptions): FieldInput<V, E>;
|
|
247
|
+
|
|
248
|
+
/** Every input's props: the value, the events, validation and the shared states. */
|
|
249
|
+
interface InputBaseProps<V, E extends HTMLInputElement | HTMLTextAreaElement = HTMLInputElement, D extends object = NoDetails> extends Omit<FieldInputProps<V, E, D>, "parse" | "format" | "onBeforeInput"> {
|
|
250
|
+
/** Shows a spinner in the box and marks the control busy. */
|
|
251
|
+
readonly loading?: boolean | undefined;
|
|
252
|
+
/** The `Field`'s or the form's otherwise. */
|
|
253
|
+
readonly density?: Density | undefined;
|
|
254
|
+
readonly autoFocus?: boolean | undefined;
|
|
255
|
+
/**
|
|
256
|
+
* Outside a `Field`, draws one around the input with this label, as a
|
|
257
|
+
* `Field` would. Inside one, the `Field`'s label is used.
|
|
258
|
+
*/
|
|
259
|
+
readonly label?: ReactNode;
|
|
260
|
+
/** Outside a `Field`, the help text under the control, as a `Field`'s `description`. */
|
|
261
|
+
readonly description?: ReactNode;
|
|
262
|
+
readonly "aria-label"?: string | undefined;
|
|
263
|
+
readonly "aria-labelledby"?: string | undefined;
|
|
264
|
+
/** More descriptions for the control, after the input's own. */
|
|
265
|
+
readonly "aria-describedby"?: string | undefined;
|
|
266
|
+
/** On the input's root. */
|
|
267
|
+
readonly className?: string | undefined;
|
|
268
|
+
readonly style?: CSSProperties | undefined;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* The attributes a text input sets on its native control itself, which
|
|
272
|
+
* `controlProps` cannot override.
|
|
273
|
+
*/
|
|
274
|
+
type ManagedControlProps = "value" | "defaultValue" | "name" | "id" | "type" | "disabled" | "readOnly" | "required" | "form" | "placeholder" | "inputMode" | "enterKeyHint" | "autoComplete" | "autoFocus" | "maxLength" | "minLength" | "pattern" | "children" | "dangerouslySetInnerHTML" | `aria-${string}` | `on${string}`;
|
|
275
|
+
/** Every text input's props: `InputBaseProps` plus the text, the box and its buttons. */
|
|
276
|
+
interface TextInputBaseProps<V, E extends HTMLInputElement | HTMLTextAreaElement = HTMLInputElement, D extends object = NoDetails> extends InputBaseProps<V, E, D>, Pick<FieldInputProps<V, E, D>, "parse" | "format" | "onBeforeInput"> {
|
|
277
|
+
/** Shown while the field is empty; with a floating label, only while the label is raised. Never a label. */
|
|
278
|
+
readonly placeholder?: string | undefined;
|
|
279
|
+
/** Inside the box, at the inline start: a unit, a currency, an icon. Read with the control. */
|
|
280
|
+
readonly prefix?: ReactNode;
|
|
281
|
+
/** Inside the box, at the inline end. Read with the control. */
|
|
282
|
+
readonly suffix?: ReactNode;
|
|
283
|
+
/** A button in the box that empties the field, shown while it has text and can be edited. */
|
|
284
|
+
readonly clearable?: boolean | undefined;
|
|
285
|
+
/** Selects all the text on focus from the keyboard or from code, not from a click. */
|
|
286
|
+
readonly selectOnFocus?: boolean | undefined;
|
|
287
|
+
readonly inputMode?: HTMLAttributes<HTMLInputElement>["inputMode"];
|
|
288
|
+
readonly enterKeyHint?: HTMLAttributes<HTMLInputElement>["enterKeyHint"];
|
|
289
|
+
/** What the browser's autofill and password managers offer. */
|
|
290
|
+
readonly autoComplete?: InputHTMLAttributes<HTMLInputElement>["autoComplete"];
|
|
291
|
+
/**
|
|
292
|
+
* Attributes for the native control the input does not manage, such as
|
|
293
|
+
* `spellCheck` or `autoCapitalize`: those an `<input>` and a `<textarea>`
|
|
294
|
+
* share.
|
|
295
|
+
*/
|
|
296
|
+
readonly controlProps?: Omit<HTMLAttributes<HTMLElement>, ManagedControlProps> | undefined;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* The props every segmented input shares, beyond the shared input props.
|
|
301
|
+
* There is no `placeholder` (each segment shows its own) and no
|
|
302
|
+
* `controlProps` (there are several controls).
|
|
303
|
+
*/
|
|
304
|
+
interface SegmentedInputProps<V, D extends object> extends InputBaseProps<V, HTMLInputElement, D>, Pick<FieldInputProps<V, HTMLInputElement, D>, "parse" | "format" | "onBeforeInput">, Pick<TextInputBaseProps<V, HTMLInputElement, D>, "prefix" | "suffix" | "clearable" | "autoComplete" | "enterKeyHint"> {
|
|
305
|
+
/** How display mode writes the value: `dateStyle: "medium"`, `timeStyle: "short"` or both by default. */
|
|
306
|
+
readonly displayFormat?: Intl.DateTimeFormatOptions | undefined;
|
|
307
|
+
/** The digits segments show; the locale's by default (`"latn"` shows 0 to 9 everywhere). */
|
|
308
|
+
readonly numberingSystem?: string | undefined;
|
|
309
|
+
/** Escape puts back the last committed value; on by default. */
|
|
310
|
+
readonly revertOnEscape?: boolean | undefined;
|
|
311
|
+
/** The first segment's native control. */
|
|
312
|
+
readonly ref?: Ref<HTMLInputElement> | undefined;
|
|
313
|
+
}
|
|
314
|
+
/** The days a date input takes, and where its "today" is. */
|
|
315
|
+
interface DayLimits {
|
|
316
|
+
/** The first day allowed, inclusive. */
|
|
317
|
+
readonly min?: PlainDate | undefined;
|
|
318
|
+
/** The last day allowed, inclusive. */
|
|
319
|
+
readonly max?: PlainDate | undefined;
|
|
320
|
+
/** Marks days that cannot be chosen: "This date isn't available". */
|
|
321
|
+
readonly isDateDisabled?: ((date: PlainDate) => boolean) | undefined;
|
|
322
|
+
/** Typing `t`, `+3`, `-1w`, `s`, `e`; on by default. */
|
|
323
|
+
readonly shortcuts?: boolean | undefined;
|
|
324
|
+
/** The zone "today" is in, for shortcuts and the two-digit year: the runtime's by default. */
|
|
325
|
+
readonly timeZone?: string | undefined;
|
|
326
|
+
}
|
|
327
|
+
/** How a time is typed. */
|
|
328
|
+
interface TimeSettings {
|
|
329
|
+
/** The locale's by default. */
|
|
330
|
+
readonly hourCycle?: "h12" | "h23" | undefined;
|
|
331
|
+
/** `"second"` adds a seconds segment; `"minute"` by default. */
|
|
332
|
+
readonly precision?: "minute" | "second" | undefined;
|
|
333
|
+
/** What ArrowUp and ArrowDown add to the minutes, snapping to it; 1 by default. */
|
|
334
|
+
readonly minuteStep?: number | undefined;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/** How a calendar lays out its weeks. */
|
|
338
|
+
interface CalendarSettings {
|
|
339
|
+
/** The day weeks start on, 1 for Monday to 7 for Sunday; the locale's by default. */
|
|
340
|
+
readonly firstDayOfWeek?: Weekday | undefined;
|
|
341
|
+
/** Shows each week's number before its days. */
|
|
342
|
+
readonly weekNumbers?: boolean | undefined;
|
|
343
|
+
/** `"iso"` where weeks start on Monday, `"simple"` otherwise, by default. */
|
|
344
|
+
readonly weekNumbering?: WeekNumbering | undefined;
|
|
345
|
+
}
|
|
346
|
+
/** The days a calendar lets a user choose, and where its "today" is. */
|
|
347
|
+
type CalendarLimitProps = Omit<DayLimits, "shortcuts">;
|
|
348
|
+
/**
|
|
349
|
+
* The shared input props a calendar takes: nothing is typed into it, so
|
|
350
|
+
* it has no `onInput`, and it draws no `Field` of its own, so it has no
|
|
351
|
+
* `label` or `description`; its months' titles name it.
|
|
352
|
+
*/
|
|
353
|
+
type CalendarBaseProps<V, D extends object> = Omit<InputBaseProps<V, HTMLInputElement, D>, "onInput" | "label" | "description" | "autoFocus" | "loading" | "ref" | "density">;
|
|
354
|
+
|
|
355
|
+
interface CalendarProps extends CalendarBaseProps<PlainDate, DateDetails>, CalendarLimitProps, CalendarSettings {
|
|
356
|
+
/** The month shown, `"2026-03"`; present means controlled. The value's month, else today's, by default. */
|
|
357
|
+
readonly month?: CalendarMonth | undefined;
|
|
358
|
+
/** The month shown first, uncontrolled. */
|
|
359
|
+
readonly defaultMonth?: CalendarMonth | undefined;
|
|
360
|
+
/** The month shown changed: the month buttons, the keys, the month view. */
|
|
361
|
+
readonly onMonthChange?: ((month: CalendarMonth) => void) | undefined;
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* A month grid to choose one day from, following the APG date picker:
|
|
365
|
+
* the arrows move by day and week, Home and End to the week's ends,
|
|
366
|
+
* PageUp and PageDown by month (with Shift, by year), Enter or Space
|
|
367
|
+
* chooses, and the month buttons and the title's month and year view jump
|
|
368
|
+
* further. Weeks start on the locale's first day and may show their
|
|
369
|
+
* numbers; days outside `min` and `max` and those `isDateDisabled` marks
|
|
370
|
+
* take focus but cannot be chosen.
|
|
371
|
+
*
|
|
372
|
+
* Its value is a `PlainDate`, `null` when nothing is chosen. Choosing a
|
|
373
|
+
* day fires the change and commit events with `source` and `trigger`
|
|
374
|
+
* `"picker"` and `DateDetails`; moving between days fires only
|
|
375
|
+
* `onMonthChange` when the month changes. It takes the shared input props:
|
|
376
|
+
* display mode, `readOnly` (days take focus, none can be chosen),
|
|
377
|
+
* `disabled`, messages, `name` and the events of `@gridkitjs/forms`.
|
|
378
|
+
*/
|
|
379
|
+
declare function Calendar({ min, max, isDateDisabled, timeZone, firstDayOfWeek, weekNumbers, weekNumbering, month, defaultMonth, onMonthChange, required, validate, className, style, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, ...props }: CalendarProps): react.JSX.Element;
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* What a range calendar adds to every event: the range's details, with
|
|
383
|
+
* `changedEnd` always `"both"` and `rule` always `null` (a calendar holds
|
|
384
|
+
* fixed days).
|
|
385
|
+
*/
|
|
386
|
+
type RangeCalendarDetails = RangeDetails<PlainDate, NoFlags, number, RelativeDateRule>;
|
|
387
|
+
interface RangeCalendarProps extends CalendarBaseProps<DateRange, RangeCalendarDetails>, CalendarLimitProps, CalendarSettings {
|
|
388
|
+
/** Months side by side; by default 2 where two fit beside each other, else 1. */
|
|
389
|
+
readonly visibleMonths?: 1 | 2 | 3 | undefined;
|
|
390
|
+
/** `"[)"` by default: the value's `end` is the day after the last day picked. `"[]"` stores the last day. */
|
|
391
|
+
readonly bounds?: RangeBounds | undefined;
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Months side by side to pick a range of days from: a first day chosen
|
|
395
|
+
* (click, tap, Enter or Space) anchors the range, moving the pointer or
|
|
396
|
+
* focus previews it, and a second choice finishes it; an end before the
|
|
397
|
+
* start swaps them. With a mouse or pen, a press dragged across days
|
|
398
|
+
* picks the range in one gesture. Escape drops a range in progress. Keys,
|
|
399
|
+
* limits, week numbers and the month view are `Calendar`'s.
|
|
400
|
+
*
|
|
401
|
+
* Its value is a `DateRange`, stored half-open: picking 1 to 14 March
|
|
402
|
+
* gives `{ start: "2026-03-01", end: "2026-03-15" }`, and the days shown
|
|
403
|
+
* are the 1st to the 14th. The range commits once, when its end is
|
|
404
|
+
* chosen, with `source` and `trigger` `"picker"`.
|
|
405
|
+
*/
|
|
406
|
+
declare function RangeCalendar({ min, max, isDateDisabled, timeZone, firstDayOfWeek, weekNumbers, weekNumbering, visibleMonths, bounds, required, validate, className, style, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, ...props }: RangeCalendarProps): react.JSX.Element;
|
|
407
|
+
|
|
408
|
+
interface DateInputProps extends SegmentedInputProps<PlainDate, DateDetails>, DayLimits, CalendarSettings {
|
|
409
|
+
/** The calendar button and its popup; on by default. */
|
|
410
|
+
readonly calendar?: boolean | undefined;
|
|
411
|
+
/** The calendar popup opened or closed, with why. */
|
|
412
|
+
readonly onOpenChange?: ((change: PopupOpenChange) => void) | undefined;
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* A date typed in segments in the locale's order (`03/14/2026` in en-US,
|
|
416
|
+
* `14.03.2026` in de-DE, `2026/03/14` in ja-JP): typing moves on by
|
|
417
|
+
* itself, the arrow keys move between segments and step them, separators
|
|
418
|
+
* are optional, and the whole field is one Tab stop. A letter or a sign
|
|
419
|
+
* opens a box for shortcuts (`t` today, `+3`, `-1w`, `s` and `e` for the
|
|
420
|
+
* month's start and end), and a pasted date in any common form is read
|
|
421
|
+
* whole. Its value is a `PlainDate`, an ISO string (`"2026-03-14"`),
|
|
422
|
+
* `null` when empty; text that is incomplete or no date keeps the last
|
|
423
|
+
* value and says why. `min`, `max` and `isDateDisabled` add their
|
|
424
|
+
* messages. It takes every shared input prop: display mode, `readOnly`,
|
|
425
|
+
* `disabled`, messages with their severity, density, prefix and suffix,
|
|
426
|
+
* and the events of `@gridkitjs/forms` with `DateDetails`.
|
|
427
|
+
*
|
|
428
|
+
* Inside a `Field` it takes the field's label, description and messages;
|
|
429
|
+
* outside one, `label` and `description` draw a `Field` around it.
|
|
430
|
+
*/
|
|
431
|
+
declare function DateInput(props: DateInputProps): react.JSX.Element;
|
|
432
|
+
|
|
433
|
+
/** What a date-time input holds: a wall clock (`"local"`) or an exact moment (`"instant"`). */
|
|
434
|
+
type DateTimeValueType = "local" | "instant";
|
|
435
|
+
/** The value of a date-time input of `T`. */
|
|
436
|
+
type DateTimeValue<T extends DateTimeValueType> = T extends "instant" ? Instant : PlainDateTime;
|
|
437
|
+
interface DateTimeOwnProps<T extends DateTimeValueType> extends SegmentedInputProps<DateTimeValue<T>, DateTimeDetails>, Omit<DayLimits, "min" | "max" | "timeZone">, CalendarSettings, TimeSettings {
|
|
438
|
+
/** The calendar button and its popup of a calendar and time columns; on by default. */
|
|
439
|
+
readonly calendar?: boolean | undefined;
|
|
440
|
+
/** The popup opened or closed, with why. */
|
|
441
|
+
readonly onOpenChange?: ((change: PopupOpenChange) => void) | undefined;
|
|
442
|
+
/** The earliest moment allowed, inclusive. */
|
|
443
|
+
readonly min?: DateTimeValue<T> | undefined;
|
|
444
|
+
/** The latest moment allowed, inclusive. */
|
|
445
|
+
readonly max?: DateTimeValue<T> | undefined;
|
|
446
|
+
/** The time a date gets when its time is left empty; `"00:00"` by default. */
|
|
447
|
+
readonly defaultTime?: PlainTime | undefined;
|
|
448
|
+
/** Which moment a wall clock in a skipped or repeated hour means; `"compatible"` by default, as Temporal's. */
|
|
449
|
+
readonly disambiguation?: TimeZoneDisambiguation | undefined;
|
|
450
|
+
/** `"local"` (default): a wall clock, `PlainDateTime`. `"instant"`: an exact moment, typed in `timeZone`. */
|
|
451
|
+
readonly valueType?: T | undefined;
|
|
452
|
+
}
|
|
453
|
+
/** The zone a value is typed and shown in: required for an instant, where "today" is for a wall clock. */
|
|
454
|
+
type DateTimeZoneProps<T extends DateTimeValueType> = T extends "instant" ? {
|
|
455
|
+
readonly timeZone: string;
|
|
456
|
+
} : {
|
|
457
|
+
readonly timeZone?: string | undefined;
|
|
458
|
+
};
|
|
459
|
+
type DateTimeInputProps<T extends DateTimeValueType = "local"> = DateTimeOwnProps<T> & DateTimeZoneProps<T>;
|
|
460
|
+
/**
|
|
461
|
+
* A date and a time typed in segments in the locale's order
|
|
462
|
+
* (`03/14/2026, 3:05 PM` in en-US): `DateInput`'s keys and shortcuts for
|
|
463
|
+
* the date, `TimeInput`'s for the time, one Tab stop for both. A shortcut
|
|
464
|
+
* or a pasted date sets the date and keeps a time already typed; a date
|
|
465
|
+
* whose time is left empty takes `defaultTime`. The calendar button, F4 or
|
|
466
|
+
* Alt+ArrowDown opens a calendar with time columns beside it, to choose
|
|
467
|
+
* both with the mouse alone. Its value is a wall clock,
|
|
468
|
+
* a `PlainDateTime` (`"2026-03-14T15:05"`), or with `valueType="instant"`
|
|
469
|
+
* an exact moment, an `Instant` (`"2026-03-14T14:05:00.000Z"`) typed and
|
|
470
|
+
* shown in the `timeZone` it requires. A wall clock in an hour the zone
|
|
471
|
+
* skips or repeats is read as `disambiguation` says, with an info message
|
|
472
|
+
* until the value changes. It takes every shared input prop and the
|
|
473
|
+
* events of `@gridkitjs/forms` with `DateTimeDetails`.
|
|
474
|
+
*
|
|
475
|
+
* Inside a `Field` it takes the field's label, description and messages;
|
|
476
|
+
* outside one, `label` and `description` draw a `Field` around it.
|
|
477
|
+
*/
|
|
478
|
+
declare function DateTimeInput<T extends DateTimeValueType = "local">(props: DateTimeInputProps<T>): react.JSX.Element;
|
|
479
|
+
|
|
480
|
+
interface TimeInputProps extends SegmentedInputProps<PlainTime, TimeDetails>, TimeSettings {
|
|
481
|
+
/** The earliest time allowed, inclusive. */
|
|
482
|
+
readonly min?: PlainTime | undefined;
|
|
483
|
+
/** The latest time allowed, inclusive. */
|
|
484
|
+
readonly max?: PlainTime | undefined;
|
|
485
|
+
/** The clock button and its popup of time columns; on by default. */
|
|
486
|
+
readonly picker?: boolean | undefined;
|
|
487
|
+
/** The time columns' popup opened or closed, with why. */
|
|
488
|
+
readonly onOpenChange?: ((change: PopupOpenChange) => void) | undefined;
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* A time of day typed in segments, in the locale's hour cycle (`3:05 PM`
|
|
492
|
+
* in en-US, `15:05` in de-DE) unless `hourCycle` sets one: typing moves on
|
|
493
|
+
* by itself, the arrow keys move between segments and step them (minutes
|
|
494
|
+
* by `minuteStep`), `a` and `p` set the day period, and a pasted time in
|
|
495
|
+
* any common form is read whole. The clock button, F4 or Alt+ArrowDown
|
|
496
|
+
* opens columns of hours, minutes, seconds and day periods to choose from,
|
|
497
|
+
* each choice set at once. Its value is a `PlainTime`, an ISO string
|
|
498
|
+
* (`"15:05"`, with seconds under `precision="second"`), `null` when empty.
|
|
499
|
+
* `min` and `max` add their messages. It takes every shared input prop and
|
|
500
|
+
* the events of `@gridkitjs/forms` with `TimeDetails`.
|
|
501
|
+
*
|
|
502
|
+
* Inside a `Field` it takes the field's label, description and messages;
|
|
503
|
+
* outside one, `label` and `description` draw a `Field` around it.
|
|
504
|
+
*/
|
|
505
|
+
declare function TimeInput(props: TimeInputProps): react.JSX.Element;
|
|
506
|
+
|
|
507
|
+
/** Columns a field, a group or a fieldset takes in a `FormLayout`. */
|
|
508
|
+
type FieldSpan = 1 | 2 | 3 | 4 | "full";
|
|
509
|
+
|
|
510
|
+
interface FieldProps {
|
|
511
|
+
/**
|
|
512
|
+
* Names the input. Leave it out only when the input has an `aria-label`;
|
|
513
|
+
* `labelPosition="hidden"` keeps a label out of sight.
|
|
514
|
+
*/
|
|
515
|
+
readonly label?: ReactNode;
|
|
516
|
+
/** Help text under the control, read as part of its description. */
|
|
517
|
+
readonly description?: ReactNode;
|
|
518
|
+
/**
|
|
519
|
+
* Longer help behind a button after the label, shown in a small panel
|
|
520
|
+
* beside it and read out as it opens.
|
|
521
|
+
*/
|
|
522
|
+
readonly help?: ReactNode;
|
|
523
|
+
/** The app's messages, always shown; a string is an error. */
|
|
524
|
+
readonly message?: FieldMessageInput | readonly FieldMessageInput[] | undefined;
|
|
525
|
+
/** Marks the label, and tells the input a value is required. */
|
|
526
|
+
readonly required?: boolean | undefined;
|
|
527
|
+
readonly labelPosition?: LabelPosition | undefined;
|
|
528
|
+
/** The label column's width for `labelPosition="start"`, as a CSS length. */
|
|
529
|
+
readonly labelWidth?: string | undefined;
|
|
530
|
+
readonly necessityIndicator?: NecessityIndicator | undefined;
|
|
531
|
+
readonly density?: Density | undefined;
|
|
532
|
+
readonly mode?: FieldMode | undefined;
|
|
533
|
+
readonly readOnly?: boolean | undefined;
|
|
534
|
+
readonly disabled?: boolean | undefined;
|
|
535
|
+
/** Columns taken in a `FormLayout`. */
|
|
536
|
+
readonly span?: FieldSpan | undefined;
|
|
537
|
+
/** The control's `id`; one is generated without it. */
|
|
538
|
+
readonly id?: string | undefined;
|
|
539
|
+
/** On the field's root. */
|
|
540
|
+
readonly className?: string | undefined;
|
|
541
|
+
readonly style?: CSSProperties | undefined;
|
|
542
|
+
/** One input: a forms input, or the app's own through `useField`. */
|
|
543
|
+
readonly children?: ReactNode;
|
|
544
|
+
}
|
|
545
|
+
/**
|
|
546
|
+
* One input with its label, required or optional marker, help button,
|
|
547
|
+
* description and messages, wired to it for assistive technology: the label
|
|
548
|
+
* names the control, the description and messages describe it, and
|
|
549
|
+
* `aria-invalid` and `aria-required` follow the field. The input reads all of it from
|
|
550
|
+
* context, so an app's own input gets the same through `useField`.
|
|
551
|
+
*
|
|
552
|
+
* The messages shown are the app's (`message`) and the input's own shown
|
|
553
|
+
* ones, most serious first; the most serious sets the field's severity
|
|
554
|
+
* class. A disabled field shows only the app's. Inside a `Form` they are
|
|
555
|
+
* listed in its `MessageSummary`.
|
|
556
|
+
*/
|
|
557
|
+
declare function Field({ label, description, help, message, required, labelPosition, labelWidth, necessityIndicator, density, mode, readOnly, disabled, span, id, className, style, children, }: FieldProps): react.JSX.Element;
|
|
558
|
+
|
|
559
|
+
interface FieldGroupProps {
|
|
560
|
+
/** Names the group; each input in it needs an `aria-label` of its own. */
|
|
561
|
+
readonly label: ReactNode;
|
|
562
|
+
/** Help text under the inputs, read as part of each one's description. */
|
|
563
|
+
readonly description?: ReactNode;
|
|
564
|
+
/** The app's messages, always shown; a string is an error. */
|
|
565
|
+
readonly message?: FieldMessageInput | readonly FieldMessageInput[] | undefined;
|
|
566
|
+
/** Marks the label, and tells every input a value is required. */
|
|
567
|
+
readonly required?: boolean | undefined;
|
|
568
|
+
/** `"floating"` is drawn as `"top"`: the label names no one control. */
|
|
569
|
+
readonly labelPosition?: LabelPosition | undefined;
|
|
570
|
+
/** The label column's width for `labelPosition="start"`, as a CSS length. */
|
|
571
|
+
readonly labelWidth?: string | undefined;
|
|
572
|
+
readonly necessityIndicator?: NecessityIndicator | undefined;
|
|
573
|
+
/** Columns taken in a `FormLayout`. */
|
|
574
|
+
readonly span?: FieldSpan | undefined;
|
|
575
|
+
/** The group's `id`, which a summary link points at; generated without it. */
|
|
576
|
+
readonly id?: string | undefined;
|
|
577
|
+
readonly className?: string | undefined;
|
|
578
|
+
readonly style?: CSSProperties | undefined;
|
|
579
|
+
/** Several inputs, each with its own `aria-label`. */
|
|
580
|
+
readonly children?: ReactNode;
|
|
581
|
+
}
|
|
582
|
+
/**
|
|
583
|
+
* Several inputs under one label and one message area, such as a postal
|
|
584
|
+
* code and a city: a group the label names, laid out as a field is. Every
|
|
585
|
+
* input is described by the group's description and messages, and lists
|
|
586
|
+
* its own messages in the group's message area.
|
|
587
|
+
*/
|
|
588
|
+
declare function FieldGroup({ label, description, message, required, labelPosition, labelWidth, necessityIndicator, span, id, className, style, children, }: FieldGroupProps): react.JSX.Element;
|
|
589
|
+
|
|
590
|
+
/** The attributes `useField` gives an app's own control, to spread on it. */
|
|
591
|
+
interface FieldControlProps {
|
|
592
|
+
readonly id: string;
|
|
593
|
+
readonly "aria-describedby": string | undefined;
|
|
594
|
+
readonly "aria-invalid": true | undefined;
|
|
595
|
+
readonly "aria-required": true | undefined;
|
|
596
|
+
readonly disabled: boolean;
|
|
597
|
+
readonly readOnly: boolean;
|
|
598
|
+
}
|
|
599
|
+
/** What an app's own input tells `useField`. */
|
|
600
|
+
interface UseFieldOptions {
|
|
601
|
+
/**
|
|
602
|
+
* Called when the `Form` around the input reveals every field's
|
|
603
|
+
* messages, on a submit attempt, so the input shows its own messages as
|
|
604
|
+
* a commit would. The form looks for an invalid control right after, so
|
|
605
|
+
* a native constraint or `setCustomValidity` set here refuses the submit.
|
|
606
|
+
*/
|
|
607
|
+
readonly onReveal?: (() => void) | undefined;
|
|
608
|
+
}
|
|
609
|
+
/** What `useField` gives an app's own input. */
|
|
610
|
+
interface UseFieldResult {
|
|
611
|
+
/** Spread onto the control. */
|
|
612
|
+
readonly controlProps: FieldControlProps;
|
|
613
|
+
readonly mode: FieldMode;
|
|
614
|
+
readonly density: Density;
|
|
615
|
+
/** The field is marked required: the input checks for a value itself. */
|
|
616
|
+
readonly required: boolean;
|
|
617
|
+
/**
|
|
618
|
+
* Lists the input's own messages under the field, with the field's. Call
|
|
619
|
+
* it from an effect, with `null` once there are none.
|
|
620
|
+
*/
|
|
621
|
+
readonly reportMessages: (messages: FieldMessageInput | readonly FieldMessageInput[] | null) => void;
|
|
622
|
+
/**
|
|
623
|
+
* Tells the field whether the control is focused and empty, which a
|
|
624
|
+
* floating label follows, and whether the input needs a value by a
|
|
625
|
+
* `required` of its own, which marks the label. Call it from an effect
|
|
626
|
+
* whenever any of them changes.
|
|
627
|
+
*/
|
|
628
|
+
readonly reportControlState: (state: FieldControlState) => void;
|
|
629
|
+
}
|
|
630
|
+
/**
|
|
631
|
+
* Wires an app's own input into the `Field` around it: the control's `id`
|
|
632
|
+
* that the label names, its description, the invalid and required states,
|
|
633
|
+
* and `readOnly` and `disabled` from the field and the form. Outside a
|
|
634
|
+
* `Field` it gives the form's settings and an `id` of its own, and the
|
|
635
|
+
* reports go nowhere.
|
|
636
|
+
*/
|
|
637
|
+
declare function useField(options?: UseFieldOptions): UseFieldResult;
|
|
638
|
+
|
|
639
|
+
interface FormProps {
|
|
640
|
+
/** `"display"` shows every field as text. */
|
|
641
|
+
readonly mode?: FieldMode | undefined;
|
|
642
|
+
readonly density?: Density | undefined;
|
|
643
|
+
readonly labelPosition?: LabelPosition | undefined;
|
|
644
|
+
/** The label column's width for `labelPosition="start"`, as a CSS length. */
|
|
645
|
+
readonly labelWidth?: string | undefined;
|
|
646
|
+
readonly necessityIndicator?: NecessityIndicator | undefined;
|
|
647
|
+
/**
|
|
648
|
+
* Enter in a single-line field, a checkbox or a switch moves to the next
|
|
649
|
+
* field rather than submitting; from the last one it submits.
|
|
650
|
+
*/
|
|
651
|
+
readonly enterMovesToNextField?: boolean | undefined;
|
|
652
|
+
readonly readOnly?: boolean | undefined;
|
|
653
|
+
readonly disabled?: boolean | undefined;
|
|
654
|
+
readonly locale?: Intl.LocalesArgument;
|
|
655
|
+
/** Strings laid over the default English ones. */
|
|
656
|
+
readonly messages?: Partial<FormsMessages> | undefined;
|
|
657
|
+
/**
|
|
658
|
+
* Lets every submit through without checking the fields, for a form
|
|
659
|
+
* library that validates itself.
|
|
660
|
+
*/
|
|
661
|
+
readonly noValidate?: boolean | undefined;
|
|
662
|
+
/** Called only for a submit the form lets through. */
|
|
663
|
+
readonly onSubmit?: ((event: SubmitEvent<HTMLFormElement>) => void) | undefined;
|
|
664
|
+
/**
|
|
665
|
+
* The form's `action`: a URL, or a React form action, which runs only
|
|
666
|
+
* for a submit the form lets through.
|
|
667
|
+
*/
|
|
668
|
+
readonly action?: string | ((formData: FormData) => void | Promise<void>) | undefined;
|
|
669
|
+
readonly ref?: Ref<HTMLFormElement> | undefined;
|
|
670
|
+
readonly id?: string | undefined;
|
|
671
|
+
readonly className?: string | undefined;
|
|
672
|
+
readonly style?: CSSProperties | undefined;
|
|
673
|
+
readonly "aria-label"?: string | undefined;
|
|
674
|
+
readonly "aria-labelledby"?: string | undefined;
|
|
675
|
+
readonly children?: ReactNode;
|
|
676
|
+
}
|
|
677
|
+
/**
|
|
678
|
+
* A `<form>` whose fields share its mode, density, label position and
|
|
679
|
+
* width, necessity indicator, `readOnly` and `disabled`, and which refuses
|
|
680
|
+
* a submit while a field holds an error.
|
|
681
|
+
*
|
|
682
|
+
* On a submit it reveals every field's messages, then looks for the first
|
|
683
|
+
* invalid control in document order: a field showing an error, or a native
|
|
684
|
+
* constraint of an app's own control. If there is one it cancels the
|
|
685
|
+
* submit, so neither `onSubmit` nor a React form action runs, and moves
|
|
686
|
+
* focus to the form's `MessageSummary` if it shows, or else to that
|
|
687
|
+
* control, opening a collapsed section around it first. The browser's own
|
|
688
|
+
* validation bubbles never show: the fields show their messages instead.
|
|
689
|
+
*/
|
|
690
|
+
declare function Form({ mode, density, labelPosition, labelWidth, necessityIndicator, enterMovesToNextField, readOnly, disabled, locale, messages, noValidate, onSubmit, action, ref, id, className, style, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, children, }: FormProps): react.JSX.Element;
|
|
691
|
+
|
|
692
|
+
interface FormsProviderProps {
|
|
693
|
+
/** Formats counts, for every forms component under it. */
|
|
694
|
+
readonly locale?: Intl.LocalesArgument;
|
|
695
|
+
/** Strings laid over the default English ones. */
|
|
696
|
+
readonly messages?: Partial<FormsMessages> | undefined;
|
|
697
|
+
readonly density?: Density | undefined;
|
|
698
|
+
readonly children?: ReactNode;
|
|
699
|
+
}
|
|
700
|
+
/**
|
|
701
|
+
* Sets the locale, strings and density of every forms component under it,
|
|
702
|
+
* inside a `Form` or not. A `Form`, a layout level, a field or an input
|
|
703
|
+
* that sets one of them itself wins over the provider.
|
|
704
|
+
*/
|
|
705
|
+
declare function FormsProvider({ locale, messages, density, children, }: FormsProviderProps): react.JSX.Element;
|
|
706
|
+
|
|
707
|
+
interface MessageSummaryProps {
|
|
708
|
+
/** In place of "There are 2 problems with this form". */
|
|
709
|
+
readonly title?: ReactNode;
|
|
710
|
+
/** The heading element the title is. */
|
|
711
|
+
readonly headingLevel?: 2 | 3 | 4 | 5 | 6 | undefined;
|
|
712
|
+
/** Which messages it lists. */
|
|
713
|
+
readonly severities?: readonly Severity[] | undefined;
|
|
714
|
+
readonly className?: string | undefined;
|
|
715
|
+
}
|
|
716
|
+
/**
|
|
717
|
+
* Every message the fields of its `Form` show, of the chosen severities,
|
|
718
|
+
* field by field in document order, each a link that focuses its field
|
|
719
|
+
* (opening a collapsed section around it), under a title with the count
|
|
720
|
+
* and a count per severity. It renders nothing while there is nothing to
|
|
721
|
+
* list. A refused submit moves focus to it, so the count is read first.
|
|
722
|
+
*/
|
|
723
|
+
declare function MessageSummary({ title, headingLevel, severities, className, }: MessageSummaryProps): react.JSX.Element | null;
|
|
724
|
+
|
|
725
|
+
interface FieldsetProps {
|
|
726
|
+
/** Names the fields inside, as a native `<legend>`. */
|
|
727
|
+
readonly legend: ReactNode;
|
|
728
|
+
/** Under the legend, describing the fieldset. */
|
|
729
|
+
readonly description?: ReactNode;
|
|
730
|
+
readonly mode?: FieldMode | undefined;
|
|
731
|
+
readonly density?: Density | undefined;
|
|
732
|
+
readonly labelPosition?: LabelPosition | undefined;
|
|
733
|
+
/** The label column's width for `labelPosition="start"`, as a CSS length. */
|
|
734
|
+
readonly labelWidth?: string | undefined;
|
|
735
|
+
readonly readOnly?: boolean | undefined;
|
|
736
|
+
/** Disables every control inside, natively as well. */
|
|
737
|
+
readonly disabled?: boolean | undefined;
|
|
738
|
+
/** Columns taken in a `FormLayout`. */
|
|
739
|
+
readonly span?: FieldSpan | undefined;
|
|
740
|
+
readonly className?: string | undefined;
|
|
741
|
+
readonly style?: CSSProperties | undefined;
|
|
742
|
+
readonly children?: ReactNode;
|
|
743
|
+
}
|
|
744
|
+
/**
|
|
745
|
+
* Several fields under a legend, such as a delivery address, with
|
|
746
|
+
* settings for the fields inside. Usually holds a `FormLayout`.
|
|
747
|
+
*/
|
|
748
|
+
declare function Fieldset({ legend, description, mode, density, labelPosition, labelWidth, readOnly, disabled, span, className, style, children, }: FieldsetProps): react.JSX.Element;
|
|
749
|
+
|
|
750
|
+
interface FormLayoutProps {
|
|
751
|
+
/** The most columns it lays fields out in; fewer as it narrows. */
|
|
752
|
+
readonly columns?: 1 | 2 | 3 | 4 | undefined;
|
|
753
|
+
readonly labelPosition?: LabelPosition | undefined;
|
|
754
|
+
/** The label column's width for `labelPosition="start"`, as a CSS length. */
|
|
755
|
+
readonly labelWidth?: string | undefined;
|
|
756
|
+
readonly density?: Density | undefined;
|
|
757
|
+
readonly className?: string | undefined;
|
|
758
|
+
readonly style?: CSSProperties | undefined;
|
|
759
|
+
/** Fields, groups and fieldsets, each taking its `span` of columns. */
|
|
760
|
+
readonly children?: ReactNode;
|
|
761
|
+
}
|
|
762
|
+
/**
|
|
763
|
+
* Lays fields out in up to four columns, which drop to fewer as the layout
|
|
764
|
+
* itself narrows: one below 32rem, at most two below 48rem, at most three
|
|
765
|
+
* below 64rem. A field's `span` never takes more columns than the layout
|
|
766
|
+
* has at its width, and start labels stack on top below 30rem. The columns
|
|
767
|
+
* follow the writing direction.
|
|
768
|
+
*/
|
|
769
|
+
declare function FormLayout({ columns, labelPosition, labelWidth, density, className, style, children, }: FormLayoutProps): react.JSX.Element;
|
|
770
|
+
|
|
771
|
+
interface FormSectionProps {
|
|
772
|
+
readonly title: ReactNode;
|
|
773
|
+
/** The heading element the title is. */
|
|
774
|
+
readonly headingLevel?: 2 | 3 | 4 | 5 | 6 | undefined;
|
|
775
|
+
/** Under the title. */
|
|
776
|
+
readonly description?: ReactNode;
|
|
777
|
+
/** The title becomes a button that shows and hides the section's body. */
|
|
778
|
+
readonly collapsible?: boolean | undefined;
|
|
779
|
+
/** Whether a collapsible section is open; present means controlled. */
|
|
780
|
+
readonly expanded?: boolean | undefined;
|
|
781
|
+
/** Whether an uncontrolled collapsible section starts open. */
|
|
782
|
+
readonly defaultExpanded?: boolean | undefined;
|
|
783
|
+
readonly onExpandedChange?: ((expanded: boolean) => void) | undefined;
|
|
784
|
+
readonly mode?: FieldMode | undefined;
|
|
785
|
+
readonly density?: Density | undefined;
|
|
786
|
+
readonly labelPosition?: LabelPosition | undefined;
|
|
787
|
+
readonly readOnly?: boolean | undefined;
|
|
788
|
+
readonly disabled?: boolean | undefined;
|
|
789
|
+
/** The section's `id`; the title's and the body's are made from it. */
|
|
790
|
+
readonly id?: string | undefined;
|
|
791
|
+
readonly className?: string | undefined;
|
|
792
|
+
readonly children?: ReactNode;
|
|
793
|
+
}
|
|
794
|
+
/**
|
|
795
|
+
* A titled part of a long form, with settings for the fields in it. A
|
|
796
|
+
* collapsible one follows the disclosure pattern: its title is a button
|
|
797
|
+
* that shows and hides the body, which stays mounted while hidden, so its
|
|
798
|
+
* fields keep their values. Focus moving to a field inside a collapsed
|
|
799
|
+
* section of a `Form` (a summary link, a refused submit) opens it first.
|
|
800
|
+
*/
|
|
801
|
+
declare function FormSection({ title, headingLevel, description, collapsible, expanded, defaultExpanded, onExpandedChange, mode, density, labelPosition, readOnly, disabled, id, className, children, }: FormSectionProps): react.JSX.Element;
|
|
802
|
+
|
|
803
|
+
/** A limit or step: a number, or in decimal mode also an exact decimal string. */
|
|
804
|
+
type NumberLimit<T extends NumberValueType> = T extends "decimal" ? number | DecimalString : number;
|
|
805
|
+
/** onStep: a step is about to be taken. The change events follow, and may still refuse it. */
|
|
806
|
+
interface NumberStepEvent<V> {
|
|
807
|
+
readonly direction: StepDirection;
|
|
808
|
+
readonly size: StepSize;
|
|
809
|
+
readonly via: "key" | "button" | "wheel";
|
|
810
|
+
/** The value the step goes to. */
|
|
811
|
+
readonly value: V | null;
|
|
812
|
+
readonly previousValue: V | null;
|
|
813
|
+
readonly nativeEvent: Event | null;
|
|
814
|
+
}
|
|
815
|
+
interface NumberInputProps<T extends NumberValueType = "number"> extends TextInputBaseProps<NumberValue<T>, HTMLInputElement, NumberDetails> {
|
|
816
|
+
/** `"number"` (default): a JS number. `"decimal"`: an exact decimal string (`"1234.50"`). */
|
|
817
|
+
readonly valueType?: T | undefined;
|
|
818
|
+
/** Fixed decimals: shown and kept, and typed in place. Sets both the minimum and the maximum. */
|
|
819
|
+
readonly fractionDigits?: number | undefined;
|
|
820
|
+
/** Fraction digits always written; 0 by default (a currency: its minor units). */
|
|
821
|
+
readonly minimumFractionDigits?: number | undefined;
|
|
822
|
+
/** Fraction digits kept; more are rounded. Unset: every digit typed is kept. */
|
|
823
|
+
readonly maximumFractionDigits?: number | undefined;
|
|
824
|
+
/** Whole numbers only: no decimal separator, a numeric keyboard. */
|
|
825
|
+
readonly integer?: boolean | undefined;
|
|
826
|
+
/** `"halfExpand"` (ties away from zero) by default; Intl's names. */
|
|
827
|
+
readonly roundingMode?: RoundingMode | undefined;
|
|
828
|
+
/** Refuses a keystroke that would type more fraction digits than allowed, instead of rounding. */
|
|
829
|
+
readonly limitFractionDigits?: boolean | undefined;
|
|
830
|
+
/**
|
|
831
|
+
* With fixed decimals, `"fixed"` (default) shows them while typing, the
|
|
832
|
+
* decimal separator jumps into them and they are typed over; `"free"`
|
|
833
|
+
* types them as any other field does.
|
|
834
|
+
*/
|
|
835
|
+
readonly decimalEntry?: "fixed" | "free" | undefined;
|
|
836
|
+
/** Group the integer digits when the field does not have focus. On by default. */
|
|
837
|
+
readonly useGrouping?: boolean | undefined;
|
|
838
|
+
/** How a negative number is shown without focus: `"minus"` (default), `"parentheses"`, `"trailingMinus"`. */
|
|
839
|
+
readonly negative?: NegativeStyle | undefined;
|
|
840
|
+
readonly decimalSeparator?: string | undefined;
|
|
841
|
+
readonly groupSeparator?: string | undefined;
|
|
842
|
+
readonly groupSizes?: readonly [primary: number, secondary: number] | undefined;
|
|
843
|
+
/** The digits the field writes: `"latn"` keeps Latin digits in `ar-EG`. */
|
|
844
|
+
readonly numberingSystem?: string | undefined;
|
|
845
|
+
/** ISO 4217 code; its sign is drawn beside the number, where the locale puts it. */
|
|
846
|
+
readonly currency?: string | undefined;
|
|
847
|
+
readonly currencyDisplay?: NumberOptions["currencyDisplay"];
|
|
848
|
+
/** An Intl unit (`"kilogram"`), drawn beside the number. */
|
|
849
|
+
readonly unit?: string | undefined;
|
|
850
|
+
readonly unitDisplay?: NumberOptions["unitDisplay"];
|
|
851
|
+
readonly min?: NumberLimit<T> | undefined;
|
|
852
|
+
readonly max?: NumberLimit<T> | undefined;
|
|
853
|
+
/** What the arrow keys and the stepper add; 1 by default. */
|
|
854
|
+
readonly step?: NumberLimit<T> | undefined;
|
|
855
|
+
/** What PageUp and PageDown add; ten steps by default. */
|
|
856
|
+
readonly largeStep?: NumberLimit<T> | undefined;
|
|
857
|
+
/** `"keys"` (default): a spinbutton the arrow keys step. `"none"`: a plain text box. */
|
|
858
|
+
readonly stepping?: "keys" | "none" | undefined;
|
|
859
|
+
/** Stepper buttons: none (default), stacked at the end, or one at each end. */
|
|
860
|
+
readonly stepper?: "none" | "end" | "split" | undefined;
|
|
861
|
+
/** The mouse wheel steps while the field has focus. Off by default. */
|
|
862
|
+
readonly wheel?: boolean | undefined;
|
|
863
|
+
/** Refuses keys that cannot be part of a number and cleans pastes. On by default. */
|
|
864
|
+
readonly cleanInput?: boolean | undefined;
|
|
865
|
+
/** Where the number sits in the box: the end (default) or the start. */
|
|
866
|
+
readonly align?: "start" | "end" | undefined;
|
|
867
|
+
/** Escape puts back the last committed value; on by default. */
|
|
868
|
+
readonly revertOnEscape?: boolean | undefined;
|
|
869
|
+
readonly onStep?: ((event: NumberStepEvent<NumberValue<T>>) => void) | undefined;
|
|
870
|
+
readonly ref?: Ref<HTMLInputElement> | undefined;
|
|
871
|
+
}
|
|
872
|
+
/**
|
|
873
|
+
* A number field: locale-aware entry with the shared events, a JS number
|
|
874
|
+
* or (with `valueType="decimal"`) an exact decimal string as its value,
|
|
875
|
+
* `null` when empty. While it has focus it shows plain digits, and with
|
|
876
|
+
* fixed decimals every decimal, typed in place; without focus, the number
|
|
877
|
+
* grouped and padded, with a currency or unit drawn beside it. It is a
|
|
878
|
+
* spinbutton the arrow keys step, with optional stepper buttons that
|
|
879
|
+
* repeat while held, and takes every shared input prop: display mode,
|
|
880
|
+
* `readOnly`, `disabled`, messages with their severity, density, prefix
|
|
881
|
+
* and suffix, and the events of `@gridkitjs/forms` with `NumberDetails`.
|
|
882
|
+
*
|
|
883
|
+
* Inside a `Field` it takes the field's label, description and messages;
|
|
884
|
+
* outside one, `label` and `description` draw a `Field` around it.
|
|
885
|
+
*/
|
|
886
|
+
declare function NumberInput<T extends NumberValueType = "number">(props: NumberInputProps<T>): react.JSX.Element;
|
|
887
|
+
|
|
888
|
+
interface DurationInputProps extends TextInputBaseProps<number, HTMLInputElement, DurationDetails> {
|
|
889
|
+
/** The unit the value is held in; `"minute"` by default, so timesheet values stay whole. */
|
|
890
|
+
readonly valueUnit?: DurationUnit | undefined;
|
|
891
|
+
/** What a bare number means: `"hour"` by default, so "1.5" is an hour and a half. */
|
|
892
|
+
readonly inputUnit?: "minute" | "hour" | undefined;
|
|
893
|
+
/** The smallest part that can be typed; finer parts round half up to it. `"minute"` by default. */
|
|
894
|
+
readonly precision?: "minute" | "second" | undefined;
|
|
895
|
+
/** How the value is written: `"units"` ("1h 30m", default), `"clock"` ("1:30") or `"decimal"` hours ("1.5"). */
|
|
896
|
+
readonly notation?: DurationNotation | undefined;
|
|
897
|
+
/** How many hours `d` is: 24 by default, 8 for a working day. */
|
|
898
|
+
readonly hoursPerDay?: number | undefined;
|
|
899
|
+
/** Whether a duration may be negative; off by default. */
|
|
900
|
+
readonly allowNegative?: boolean | undefined;
|
|
901
|
+
/** The shortest duration allowed, in `valueUnit`, inclusive. */
|
|
902
|
+
readonly min?: number | undefined;
|
|
903
|
+
/** The longest duration allowed, in `valueUnit`, inclusive. */
|
|
904
|
+
readonly max?: number | undefined;
|
|
905
|
+
/** What ArrowUp and ArrowDown add, in `valueUnit`: 15 minutes by default. */
|
|
906
|
+
readonly step?: number | undefined;
|
|
907
|
+
/** What PageUp and PageDown add, in `valueUnit`: an hour by default. */
|
|
908
|
+
readonly largeStep?: number | undefined;
|
|
909
|
+
/** Escape puts back the last committed value; on by default. */
|
|
910
|
+
readonly revertOnEscape?: boolean | undefined;
|
|
911
|
+
readonly onStep?: ((event: NumberStepEvent<number>) => void) | undefined;
|
|
912
|
+
readonly ref?: Ref<HTMLInputElement> | undefined;
|
|
913
|
+
}
|
|
914
|
+
/**
|
|
915
|
+
* An amount of time typed freely, for timesheets and estimates: `1h 30m`,
|
|
916
|
+
* `1h30`, `90m`, `1:30` or a bare `1.5` (hours, unless `inputUnit` says
|
|
917
|
+
* minutes) all read as 90 minutes, unit words in the locale or English,
|
|
918
|
+
* and a commit rewrites the text in `notation` ("1h 30m", "1:30" or
|
|
919
|
+
* "1.5"). Its value is a number in `valueUnit` (minutes by default),
|
|
920
|
+
* `null` when empty; text that is no duration keeps the last value and
|
|
921
|
+
* says why. It is a spinbutton the arrow keys step by `step` (15
|
|
922
|
+
* minutes) and PageUp and PageDown by `largeStep` (an hour), reporting
|
|
923
|
+
* `onStep` as `NumberInput` does. `min` and `max` add their messages and
|
|
924
|
+
* bound the steps. It takes every shared input prop: display mode,
|
|
925
|
+
* `readOnly`, `disabled`, messages with their severity, density, prefix
|
|
926
|
+
* and suffix, and the events of `@gridkitjs/forms` with `DurationDetails`.
|
|
927
|
+
*
|
|
928
|
+
* Inside a `Field` it takes the field's label, description and messages;
|
|
929
|
+
* outside one, `label` and `description` draw a `Field` around it.
|
|
930
|
+
*/
|
|
931
|
+
declare function DurationInput(props: DurationInputProps): react.JSX.Element;
|
|
932
|
+
|
|
933
|
+
interface MaskedInputProps extends TextInputBaseProps<string, HTMLInputElement, MaskDetails>, Partial<Pick<MaskOptions, "tokens" | "promptCharacter">> {
|
|
934
|
+
/**
|
|
935
|
+
* A pattern (`"(000) 000-0000"`), several tried in order as the text
|
|
936
|
+
* grows, a function choosing one from the raw text, or a preset from
|
|
937
|
+
* `maskPresets`.
|
|
938
|
+
*/
|
|
939
|
+
readonly mask: MaskSource | MaskPreset;
|
|
940
|
+
/**
|
|
941
|
+
* `"raw"` (default): only the characters typed. `"formatted"`: with the
|
|
942
|
+
* literals. A preset sets its own, which this overrides.
|
|
943
|
+
*/
|
|
944
|
+
readonly valueFormat?: MaskValueFormat | undefined;
|
|
945
|
+
/** A fixed-width font, so the slots line up down a column of fields. */
|
|
946
|
+
readonly monospace?: boolean | undefined;
|
|
947
|
+
/** Escape puts back the last committed value; on by default. */
|
|
948
|
+
readonly revertOnEscape?: boolean | undefined;
|
|
949
|
+
readonly ref?: Ref<HTMLInputElement> | undefined;
|
|
950
|
+
}
|
|
951
|
+
/**
|
|
952
|
+
* A text field laid into a mask: postal codes, IBANs, card numbers, part
|
|
953
|
+
* numbers. Typing fills the mask's slots and skips its literals, a paste
|
|
954
|
+
* keeps what fits, and text an input method composed is laid in once it
|
|
955
|
+
* ends. While focused the empty slots show the prompt character; without
|
|
956
|
+
* focus, the text typed with its literals. The value is a string, the raw
|
|
957
|
+
* characters or (`valueFormat="formatted"`) the text with its literals,
|
|
958
|
+
* only once the mask is complete, and `null` when empty: incomplete text
|
|
959
|
+
* is unreadable and keeps the last complete value. Presets bring their
|
|
960
|
+
* pattern, check, keyboard and value format. It takes every shared input
|
|
961
|
+
* prop: display mode, `readOnly`, `disabled`, messages with their
|
|
962
|
+
* severity, density, prefix and suffix, and the events of
|
|
963
|
+
* `@gridkitjs/forms` with `MaskDetails`.
|
|
964
|
+
*
|
|
965
|
+
* Inside a `Field` it takes the field's label, description and messages;
|
|
966
|
+
* outside one, `label` and `description` draw a `Field` around it.
|
|
967
|
+
*/
|
|
968
|
+
declare function MaskedInput(props: MaskedInputProps): react.JSX.Element;
|
|
969
|
+
|
|
970
|
+
/** The props that decide how a number field reads and writes its text. */
|
|
971
|
+
type NumberFormatProps<T extends NumberValueType> = Pick<NumberInputProps<T>, "valueType" | "fractionDigits" | "minimumFractionDigits" | "maximumFractionDigits" | "integer" | "roundingMode" | "useGrouping" | "negative" | "decimalSeparator" | "groupSeparator" | "groupSizes" | "numberingSystem" | "currency" | "currencyDisplay" | "unit" | "unitDisplay">;
|
|
972
|
+
|
|
973
|
+
/** A number range: either end `null` when open. */
|
|
974
|
+
type NumberRange<T extends NumberValueType = "number"> = Range<NumberValue<T>>;
|
|
975
|
+
/** What `NumberRangeInput` adds to every event: the range's details and each end's number details. */
|
|
976
|
+
type NumberRangeDetails<T extends NumberValueType = "number"> = RangeDetails<NumberValue<T>, NoFlags, NumberValue<T>> & {
|
|
977
|
+
readonly startDetails: NumberDetails;
|
|
978
|
+
readonly endDetails: NumberDetails;
|
|
979
|
+
};
|
|
980
|
+
interface NumberRangeInputProps<T extends NumberValueType = "number"> extends Omit<TextInputBaseProps<NumberRange<T>, HTMLInputElement, NumberRangeDetails<T>>, "placeholder" | "prefix" | "suffix" | "ref" | "parse" | "format" | "controlProps">, NumberFormatProps<T>, Pick<NumberInputProps<T>, "min" | "max" | "step" | "largeStep" | "stepping" | "limitFractionDigits" | "decimalEntry" | "cleanInput" | "align" | "revertOnEscape"> {
|
|
981
|
+
/** `"[]"` (default): the end belongs to the range. `"[)"`: it does not, so 10–10 is empty. */
|
|
982
|
+
readonly bounds?: RangeBounds | undefined;
|
|
983
|
+
/** An end typed before its start: swapped (default) or an error. */
|
|
984
|
+
readonly reversed?: "swap" | "error" | undefined;
|
|
985
|
+
/** With `bounds="[)"`, allows a start equal to its end. */
|
|
986
|
+
readonly allowEmpty?: boolean | undefined;
|
|
987
|
+
/** The shortest span allowed, `end - start`. */
|
|
988
|
+
readonly minSpan?: NumberLimit<T> | undefined;
|
|
989
|
+
/** The longest span allowed. */
|
|
990
|
+
readonly maxSpan?: NumberLimit<T> | undefined;
|
|
991
|
+
/** Shows the span after the end ("Span: 10"), read with the end. */
|
|
992
|
+
readonly showSpan?: boolean | undefined;
|
|
993
|
+
readonly startPlaceholder?: string | undefined;
|
|
994
|
+
readonly endPlaceholder?: string | undefined;
|
|
995
|
+
/** The start's native control. */
|
|
996
|
+
readonly startRef?: Ref<HTMLInputElement> | undefined;
|
|
997
|
+
/** The end's native control. */
|
|
998
|
+
readonly endRef?: Ref<HTMLInputElement> | undefined;
|
|
999
|
+
}
|
|
1000
|
+
/**
|
|
1001
|
+
* Two number fields under one label, holding one range: `{ start, end }`,
|
|
1002
|
+
* either end `null` when open, and `null` when both are. The value is
|
|
1003
|
+
* always ordered: an end typed before its start is swapped (the texts
|
|
1004
|
+
* change places on commit) or, with `reversed="error"`, refused with a
|
|
1005
|
+
* message. Each end types, pastes and steps as a `NumberInput` (a step
|
|
1006
|
+
* stops at the other end); Tab moves between the ends, and the range
|
|
1007
|
+
* commits once when focus leaves both, or on Enter. `min` and `max` bound
|
|
1008
|
+
* both ends; `minSpan` and `maxSpan` the span, which `showSpan` writes
|
|
1009
|
+
* after the end. The end belongs to the range by default (`bounds="[]"`).
|
|
1010
|
+
* Every event carries `NumberRangeDetails`: which end changed, the span,
|
|
1011
|
+
* and each end's number details.
|
|
1012
|
+
*
|
|
1013
|
+
* Inside a `Field` it takes the field's label, description and messages;
|
|
1014
|
+
* outside one, `label` and `description` draw a `Field` around it.
|
|
1015
|
+
*/
|
|
1016
|
+
declare function NumberRangeInput<T extends NumberValueType = "number">(props: NumberRangeInputProps<T>): react.JSX.Element;
|
|
1017
|
+
|
|
1018
|
+
interface PercentInputProps<T extends NumberValueType = "number"> extends Omit<NumberInputProps<T>, "currency" | "currencyDisplay" | "unit" | "unitDisplay"> {
|
|
1019
|
+
/**
|
|
1020
|
+
* `"fraction"` (default): 0.12 is shown as 12 %, as Intl reads a
|
|
1021
|
+
* percent. `"percent"`: 12 is. `value`, `min`, `max` and `step` are in
|
|
1022
|
+
* these units; the default step is one percentage point.
|
|
1023
|
+
*/
|
|
1024
|
+
readonly scale?: PercentScale | undefined;
|
|
1025
|
+
}
|
|
1026
|
+
/**
|
|
1027
|
+
* A `NumberInput` for a percentage: the percent sign drawn where the
|
|
1028
|
+
* locale puts it (before the number in `tr-TR`), and the value stored as
|
|
1029
|
+
* a fraction (0.125 for 12.5 %) or as the percent number itself, by
|
|
1030
|
+
* `scale`. Fraction digit props count the digits of the number shown, and
|
|
1031
|
+
* a fraction is scaled exactly, so 12.3 % is 0.123.
|
|
1032
|
+
*/
|
|
1033
|
+
declare function PercentInput<T extends NumberValueType = "number">({ scale, ...props }: PercentInputProps<T>): react.JSX.Element;
|
|
1034
|
+
|
|
1035
|
+
interface PeriodInputProps<G extends PeriodGranularity = "month"> extends Omit<SegmentedInputProps<Period<G>, PeriodDetails>, "displayFormat"> {
|
|
1036
|
+
/** How long a period is: `"month"` by default. */
|
|
1037
|
+
readonly granularity?: G | undefined;
|
|
1038
|
+
/** The first period allowed, inclusive. */
|
|
1039
|
+
readonly min?: Period<G> | undefined;
|
|
1040
|
+
/** The last period allowed, inclusive. */
|
|
1041
|
+
readonly max?: Period<G> | undefined;
|
|
1042
|
+
/** The month a fiscal year starts in, 1 to 12; 1 by default. */
|
|
1043
|
+
readonly fiscalYearStart?: number | undefined;
|
|
1044
|
+
/** Whether "FY2026" names the year a fiscal year ends in (default) or starts in. */
|
|
1045
|
+
readonly fiscalYearNamedBy?: "start" | "end" | undefined;
|
|
1046
|
+
/** Typing `t`, `+1`, `-1`; on by default. */
|
|
1047
|
+
readonly shortcuts?: boolean | undefined;
|
|
1048
|
+
/** The zone "today" is in, for shortcuts, steps and the two-digit year: the runtime's by default. */
|
|
1049
|
+
readonly timeZone?: string | undefined;
|
|
1050
|
+
/** The calendar button and its popup, a grid of periods; on by default. */
|
|
1051
|
+
readonly picker?: boolean | undefined;
|
|
1052
|
+
/** The picker popup opened or closed, with why. */
|
|
1053
|
+
readonly onOpenChange?: ((change: PopupOpenChange) => void) | undefined;
|
|
1054
|
+
}
|
|
1055
|
+
/**
|
|
1056
|
+
* An accounting or reporting period typed in segments: a month as the
|
|
1057
|
+
* locale writes one (`11/2026` in en-US, `2026/11` in ja-JP), a quarter
|
|
1058
|
+
* (`Q3 2026`), a year, or a fiscal year, quarter or month (`FY2026`,
|
|
1059
|
+
* `FY2026 Q1`, `FY2026 P04`) counted from `fiscalYearStart` and named by
|
|
1060
|
+
* the year it ends in unless `fiscalYearNamedBy="start"`. Typing moves on
|
|
1061
|
+
* by itself, the arrow keys move between segments and step them, and the
|
|
1062
|
+
* field is one Tab stop. A letter or a sign opens a box for shortcuts (`t`
|
|
1063
|
+
* this period, `+1` the next, `-1` the previous), and a pasted period in
|
|
1064
|
+
* any common form (`2026-Q3`, `Nov 2026`, `FY26 P4`) is read whole. The
|
|
1065
|
+
* calendar button, F4 or Alt+ArrowDown opens a grid of the year's periods
|
|
1066
|
+
* (twelve years for a year granularity) to choose one from. Its
|
|
1067
|
+
* value is a `Period` string of the granularity (`"2026-11"`,
|
|
1068
|
+
* `"FY2026-P04"`), `null` when empty, and every event's
|
|
1069
|
+
* `PeriodDetails.range` holds the days it covers, half-open. `min` and
|
|
1070
|
+
* `max` add their messages. It takes every shared input prop: display
|
|
1071
|
+
* mode, `readOnly`, `disabled`, messages with their severity, density,
|
|
1072
|
+
* prefix and suffix, and the events of `@gridkitjs/forms`.
|
|
1073
|
+
*
|
|
1074
|
+
* Inside a `Field` it takes the field's label, description and messages;
|
|
1075
|
+
* outside one, `label` and `description` draw a `Field` around it.
|
|
1076
|
+
*/
|
|
1077
|
+
declare function PeriodInput<G extends PeriodGranularity = "month">(props: PeriodInputProps<G>): react.JSX.Element;
|
|
1078
|
+
|
|
1079
|
+
interface SearchInputProps extends TextInputBaseProps<string> {
|
|
1080
|
+
/**
|
|
1081
|
+
* Milliseconds typing must pause before the text is read
|
|
1082
|
+
* (`onBeforeChange`, `onChange`, `onValidate`); `onInput` fires at once,
|
|
1083
|
+
* and Enter reads at once. None by default.
|
|
1084
|
+
*/
|
|
1085
|
+
readonly debounce?: number | undefined;
|
|
1086
|
+
readonly ref?: Ref<HTMLInputElement> | undefined;
|
|
1087
|
+
}
|
|
1088
|
+
/**
|
|
1089
|
+
* A search box: `<input type="search">` (role `searchbox`) with a search
|
|
1090
|
+
* icon and a clear button, on the same machinery as `TextInput`. Its value
|
|
1091
|
+
* is a string, `null` when empty. Enter commits at once, reading the text
|
|
1092
|
+
* first even while a `debounce` is pending; Escape empties it, after
|
|
1093
|
+
* `onClear`, and passes on when it is already empty.
|
|
1094
|
+
*
|
|
1095
|
+
* Search on `onChange` with a `debounce` as the user types, or on
|
|
1096
|
+
* `onCommit` for "search on Enter".
|
|
1097
|
+
*/
|
|
1098
|
+
declare function SearchInput(props: SearchInputProps): react.JSX.Element;
|
|
1099
|
+
|
|
1100
|
+
interface TextInputProps extends TextInputBaseProps<string, TextControl> {
|
|
1101
|
+
/**
|
|
1102
|
+
* `"password"` hides the text and adds a reveal button. Email, phone and
|
|
1103
|
+
* URL keyboards come from `inputMode` and `autoComplete`: a native
|
|
1104
|
+
* `type="email"` would add the browser's own validation.
|
|
1105
|
+
*/
|
|
1106
|
+
readonly type?: "text" | "password" | undefined;
|
|
1107
|
+
/** A `<textarea>` that grows with its text. */
|
|
1108
|
+
readonly multiline?: boolean | undefined;
|
|
1109
|
+
/** Multiline: the lines shown when empty. */
|
|
1110
|
+
readonly minRows?: number | undefined;
|
|
1111
|
+
/** Multiline: the lines it grows to, before it scrolls. */
|
|
1112
|
+
readonly maxRows?: number | undefined;
|
|
1113
|
+
/**
|
|
1114
|
+
* The most characters (code points) the value may have. Typing past it
|
|
1115
|
+
* is allowed: the counter marks the overflow and the field shows an
|
|
1116
|
+
* error.
|
|
1117
|
+
*/
|
|
1118
|
+
readonly maxLength?: number | undefined;
|
|
1119
|
+
readonly minLength?: number | undefined;
|
|
1120
|
+
/** The whole value must match. */
|
|
1121
|
+
readonly pattern?: RegExp | undefined;
|
|
1122
|
+
/** The "12/50" counter under the box; on whenever `maxLength` is set. */
|
|
1123
|
+
readonly showCounter?: boolean | undefined;
|
|
1124
|
+
/**
|
|
1125
|
+
* Upper-cases the value as it is read, in the field's locale. The text is
|
|
1126
|
+
* shown upper-cased by CSS, so the caret never moves and input methods
|
|
1127
|
+
* are left alone; a commit writes the upper-cased text.
|
|
1128
|
+
*/
|
|
1129
|
+
readonly uppercase?: boolean | undefined;
|
|
1130
|
+
/** Drops leading and trailing whitespace from the value; never for a password. */
|
|
1131
|
+
readonly trim?: boolean | undefined;
|
|
1132
|
+
/** The reveal button of a password; on by default. */
|
|
1133
|
+
readonly revealable?: boolean | undefined;
|
|
1134
|
+
/** Escape puts back the last committed text; on by default. */
|
|
1135
|
+
readonly revertOnEscape?: boolean | undefined;
|
|
1136
|
+
readonly ref?: Ref<TextControl> | undefined;
|
|
1137
|
+
}
|
|
1138
|
+
/**
|
|
1139
|
+
* A text field: a single line, a password with a reveal button, or a
|
|
1140
|
+
* multiline `<textarea>` that grows with its text. Its value is a string,
|
|
1141
|
+
* `null` when empty. It draws the box the grid's controls share, with
|
|
1142
|
+
* optional prefix and suffix adornments, a clear button, a spinner and a
|
|
1143
|
+
* character counter, and takes every shared input prop: display mode,
|
|
1144
|
+
* `readOnly`, `disabled`, messages with their severity, density and the
|
|
1145
|
+
* events of `@gridkitjs/forms`.
|
|
1146
|
+
*
|
|
1147
|
+
* Inside a `Field` it takes the field's label, description and messages;
|
|
1148
|
+
* outside one, `label` and `description` draw a `Field` around it.
|
|
1149
|
+
*/
|
|
1150
|
+
declare function TextInput(props: TextInputProps): react.JSX.Element;
|
|
1151
|
+
|
|
1152
|
+
/** Which side of the box or track a toggle's label sits, in reading order. */
|
|
1153
|
+
type ToggleLabelPlacement = "end" | "start";
|
|
1154
|
+
/**
|
|
1155
|
+
* The props `Checkbox` and `Switch` share: every input's, less the text
|
|
1156
|
+
* input's (a toggle has no text to type, clear or load), with `label` as
|
|
1157
|
+
* the text beside the control.
|
|
1158
|
+
*/
|
|
1159
|
+
interface ToggleBaseProps<V> extends Omit<InputBaseProps<V>, "label" | "loading" | "onClear" | "ref"> {
|
|
1160
|
+
/**
|
|
1161
|
+
* The text beside the control, which names it and is part of what a
|
|
1162
|
+
* press hits. Inside a `Field`, the field's label names it too.
|
|
1163
|
+
*/
|
|
1164
|
+
readonly label?: ReactNode;
|
|
1165
|
+
/** The label after the control (`"end"`, the default) or before it. */
|
|
1166
|
+
readonly labelPlacement?: ToggleLabelPlacement | undefined;
|
|
1167
|
+
/** The native `<input type="checkbox">`. */
|
|
1168
|
+
readonly ref?: Ref<HTMLInputElement> | undefined;
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
interface CheckboxProps extends ToggleBaseProps<boolean> {
|
|
1172
|
+
/**
|
|
1173
|
+
* A flip can set `null`, drawn indeterminate: `false` → `true` → `null`
|
|
1174
|
+
* → `false`. Without it a flip never sets `null`, and an app's `null`
|
|
1175
|
+
* checks on the first flip.
|
|
1176
|
+
*/
|
|
1177
|
+
readonly threeState?: boolean | undefined;
|
|
1178
|
+
}
|
|
1179
|
+
/**
|
|
1180
|
+
* A checkbox. Its value is `true`, `false` or `null`, which is drawn
|
|
1181
|
+
* indeterminate ("mixed"); it starts `false`. Every flip, by a press or
|
|
1182
|
+
* <kbd>Space</kbd>, fires the change events and commits at once (`source`
|
|
1183
|
+
* and `trigger` `"toggle"`), with "Yes" or "No" as its text. `required`
|
|
1184
|
+
* means it must be checked; `readOnly` refuses flips and stays focusable;
|
|
1185
|
+
* display mode shows "Yes", "No" or a dash. Named by `label`, the text
|
|
1186
|
+
* beside the box, and by the label of a `Field` around it.
|
|
1187
|
+
*/
|
|
1188
|
+
declare function Checkbox(props: CheckboxProps): react.JSX.Element;
|
|
1189
|
+
|
|
1190
|
+
interface SwitchProps extends Omit<ToggleBaseProps<boolean>, "value" | "defaultValue"> {
|
|
1191
|
+
/** Present means controlled. A switch is on or off, never empty. */
|
|
1192
|
+
readonly value?: boolean | undefined;
|
|
1193
|
+
/** Off unless given. */
|
|
1194
|
+
readonly defaultValue?: boolean | undefined;
|
|
1195
|
+
/**
|
|
1196
|
+
* Shows "On" or "Off" beside the track. Screen readers hear the state
|
|
1197
|
+
* from the control, so the words are hidden from them.
|
|
1198
|
+
*/
|
|
1199
|
+
readonly showStateLabel?: boolean | undefined;
|
|
1200
|
+
}
|
|
1201
|
+
/**
|
|
1202
|
+
* A switch (`role="switch"`), for a setting that takes effect at once: on
|
|
1203
|
+
* or off, with no empty state. Every flip, by a press or <kbd>Space</kbd>,
|
|
1204
|
+
* fires the change events and commits (`source` and `trigger` `"toggle"`),
|
|
1205
|
+
* with "On" or "Off" as its text. `required` means it must be on;
|
|
1206
|
+
* `readOnly` refuses flips and stays focusable; display mode shows "On" or
|
|
1207
|
+
* "Off". The thumb moves to the reading end when on.
|
|
1208
|
+
*/
|
|
1209
|
+
declare function Switch(props: SwitchProps): react.JSX.Element;
|
|
1210
|
+
|
|
1211
|
+
export { Calendar, type CalendarLimitProps, type CalendarProps, type CalendarSettings, Checkbox, type CheckboxProps, DateInput, type DateInputProps, DateTimeInput, type DateTimeInputProps, type DateTimeValue, type DateTimeValueType, type DateTimeZoneProps, type DayLimits, type Density, DurationInput, type DurationInputProps, Field, type FieldBeforeChangeEvent, type FieldBeforeCommitEvent, type FieldBeforeInputEvent, type FieldChangeEvent, type FieldClearEvent, type FieldCommitEvent, type FieldControlBinding, type FieldControlProps, type FieldControlState, type FieldEventBase, type FieldFocusEvent, FieldGroup, type FieldGroupProps, type FieldHandlers, type FieldInput, type FieldInputEvent, type FieldInputKind, type FieldInputOptions, type FieldInputProps, type FieldMode, type FieldProps, type FieldSpan, type FieldValidateEvent, Fieldset, type FieldsetProps, Form, FormLayout, type FormLayoutProps, type FormProps, FormSection, type FormSectionProps, FormsProvider, type FormsProviderProps, type InputBaseProps, type InputHandle, type LabelPosition, type ManagedControlProps, MaskedInput, type MaskedInputProps, MessageSummary, type MessageSummaryProps, type NecessityIndicator, NumberInput, type NumberInputProps, type NumberLimit, type NumberRange, type NumberRangeDetails, NumberRangeInput, type NumberRangeInputProps, type NumberStepEvent, PercentInput, type PercentInputProps, PeriodInput, type PeriodInputProps, RangeCalendar, type RangeCalendarDetails, type RangeCalendarProps, SearchInput, type SearchInputProps, type SegmentedInputProps, Switch, type SwitchProps, TextInput, type TextInputBaseProps, type TextInputProps, TimeInput, type TimeInputProps, type TimeSettings, type ToggleBaseProps, type ToggleLabelPlacement, type UseFieldOptions, type UseFieldResult, useField, useFieldInput };
|