UNPKG

2.64 kBTypeScriptView Raw
1/**
2 * A Field describes a single field in an action or form.
3 *
4 * Fields can be used to automatically render forms or other UIs based on
5 * hypermedia actions.
6 */
7export interface BaseField<TType extends string, TValue> {
8 /**
9 * Name of the field.
10 *
11 * Typically this is the property that will get sent to a server.
12 */
13 name: string;
14 /**
15 * Type describes the type of the property.
16 *
17 * This is similar to the HTML5 "type" attribute on forms.
18 */
19 type: TType;
20 /**
21 * The current (pre-filed) value on the form.
22 */
23 value?: TValue;
24 /**
25 * This could be used to describe a sample value.
26 */
27 placeholder?: TValue;
28 /**
29 * Whether this field is required for submitting the form.
30 */
31 required: boolean;
32 /**
33 * Render the field as read-only.
34 */
35 readOnly: boolean;
36 /**
37 * A human-readable label for the field.
38 */
39 label?: string;
40}
41/**
42 * A checkbox basically behaves like a boolean.
43 */
44export declare type Checkbox = BaseField<'checkbox', boolean>;
45/**
46 * A color picker.
47 */
48export declare type Color = BaseField<'color', string>;
49/**
50 * A 'date' field.
51 */
52export declare type Date = BaseField<'date', string>;
53/**
54 * @deprecated
55 */
56export declare type DateTime = BaseField<'datetime', Date>;
57export declare type DateTimeLocal = BaseField<'datetime-local', Date>;
58export declare type Email = BaseField<'email', string>;
59export declare type File = BaseField<'file', never>;
60export declare type Hidden = BaseField<'hidden', string>;
61export interface Number extends BaseField<'number', number> {
62 max?: number;
63 min?: number;
64 step?: number;
65}
66export declare type Month = BaseField<'month', string>;
67export declare type Password = BaseField<'password', string>;
68export interface Radio extends BaseField<'radio', string> {
69 options?: Map<string, string>;
70}
71export interface Range extends BaseField<'range', number> {
72 max?: number;
73 min?: number;
74 step?: number;
75}
76export declare type Search = BaseField<'search', string>;
77export declare type Tel = BaseField<'tel', string>;
78export interface Text extends BaseField<'text', string> {
79 minLength?: number;
80 maxLength?: number;
81 pattern?: RegExp;
82 options?: Map<string, string>;
83}
84export declare type Time = BaseField<'time', string>;
85export declare type Url = BaseField<'url', string>;
86export declare type Week = BaseField<'week', string>;
87export declare type Field = Checkbox | Color | Date | DateTime | DateTimeLocal | Email | File | Hidden | Number | Month | Password | Radio | Range | Search | Tel | Text | Time | Url | Week;