/
forms.ts
178 lines (143 loc) · 4.38 KB
/
forms.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
import type { NumOrString } from "@thi.ng/api";
import type {
Attribs,
AttribVal,
BooleanAttrib,
MultiStringAttrib,
NumericAttrib,
RelAttribs,
StringAttrib,
} from "./api";
import { defElement } from "./def";
export interface FormAttribs extends RelAttribs {
"accept-charset": MultiStringAttrib;
action: StringAttrib;
autocomplete: AttribVal<"on" | "off">;
enctype: StringAttrib;
method: StringAttrib;
novalidate: BooleanAttrib;
target: StringAttrib;
}
export const form = defElement<Partial<FormAttribs>>("form");
export interface FieldsetAttribs extends Attribs {
disabled: BooleanAttrib;
form: StringAttrib;
name: StringAttrib;
}
export const fieldset = defElement<Partial<FieldsetAttribs>>("fieldset");
export const legend = defElement("legend");
export interface InputAttribs extends Attribs, FieldsetAttribs {
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill
autocomplete: StringAttrib;
autofocus: BooleanAttrib;
list: StringAttrib;
readonly: BooleanAttrib;
required: BooleanAttrib;
type: StringAttrib;
value: AttribVal<NumOrString>;
}
export interface InputCheckboxAttribs extends InputAttribs {
checked: BooleanAttrib;
indeterminate: BooleanAttrib;
}
export interface InputRadioAttribs extends InputAttribs {
checked: BooleanAttrib;
}
export interface InputFileAttribs extends InputAttribs {
accept: MultiStringAttrib;
capture: AttribVal<"user" | "environment">;
multiple: BooleanAttrib;
}
export interface InputTextAttribs extends InputAttribs {
dirname: StringAttrib;
minlength: NumericAttrib;
maxlength: NumericAttrib;
pattern: StringAttrib;
placeholder: StringAttrib;
size: NumericAttrib;
}
export interface TextAreaAttribs extends InputTextAttribs {
cols: NumericAttrib;
rows: NumericAttrib;
wrap: AttribVal<"hard" | "soft" | "off">;
}
export interface InputNumericAttribs extends InputAttribs {
min: NumericAttrib;
max: NumericAttrib;
step: NumericAttrib;
value: NumericAttrib;
}
export const button = defElement<Partial<InputAttribs>>("button");
export const checkbox = defElement<Partial<InputCheckboxAttribs>, never>(
"input",
{
type: "checkbox",
}
);
export const radio = defElement<Partial<InputRadioAttribs>, never>("input", {
type: "radio",
});
export const inputColor = defElement<Partial<InputAttribs>, never>("input", {
type: "color",
});
export const inputFile = defElement<Partial<InputFileAttribs>, never>("input", {
type: "file",
});
export const inputPass = defElement<Partial<InputTextAttribs>, never>("input", {
type: "password",
});
export const inputNumber = defElement<Partial<InputNumericAttribs>, never>(
"input",
{ type: "number" }
);
export const inputRange = defElement<Partial<InputNumericAttribs>, never>(
"input",
{ type: "range" }
);
export const inputSearch = defElement<Partial<InputTextAttribs>, never>(
"input",
{
type: "search",
}
);
export const inputText = defElement<Partial<InputTextAttribs>, never>("input", {
type: "text",
});
export const textArea = defElement<Partial<TextAreaAttribs>, never>("textarea");
export interface OptionAttribs {
disabled: BooleanAttrib;
label: StringAttrib;
selected: BooleanAttrib;
value: AttribVal<NumOrString>;
}
export const option = defElement<Partial<OptionAttribs>, string>("option");
export interface OptGroupAttribs {
disabled: BooleanAttrib;
label: StringAttrib;
}
export const optGroup = defElement<Partial<OptGroupAttribs>>("optgroup");
export interface SelectAttribs extends InputAttribs {
multiple: BooleanAttrib;
size: NumericAttrib;
}
export const select = defElement<Partial<SelectAttribs>>("select");
export interface LabelAttribs extends Partial<Attribs> {
for: StringAttrib;
form?: StringAttrib;
}
export const label = defElement<LabelAttribs>("label");
export interface MeterAttribs extends Attribs {
min: NumericAttrib;
max: NumericAttrib;
low: NumericAttrib;
high: NumericAttrib;
optimum: NumericAttrib;
value: NumericAttrib;
form: StringAttrib;
}
export const meter = defElement<Partial<MeterAttribs>>("meter");
export interface ProgressAttribs extends Attribs {
max: NumericAttrib;
value: NumericAttrib;
}
export const progress = defElement<Partial<ProgressAttribs>>("progress");