-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.ts
67 lines (58 loc) · 1.04 KB
/
types.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
// Documentation purpose only
type Config = {
portalId: string
formId: string
fields: Array<TextField | CheckboxField | SelectField>
submitLabel?: string
debug?: boolean
apiKey?: string
}
// field types
type Field = {
name: string
label: string
required?: boolean
// other props can be passed down
// e.g. `className`, `pattern`, `aria-*`
}
type TextField = Field & {
type?: 'text' | 'email' | 'textarea'
value?: string
}
type SelectField = Field & {
type: 'select'
options: string[]
}
type CheckboxField = Field & {
type: 'checkbox'
value?: boolean
}
type RadioField = Field & {
tyep: 'radio'
options: string[]
}
/*
Example:
useHubspotForm(config)
*/
const config: Config = {
portalId: '...',
formId: '...',
fields: [
{ name: 'name', label: 'Name', required: true },
{
name: 'movie',
label: 'Favorite movie',
type: 'select',
options: [
'Star Wars: Episode V - The Empire Strikes Back',
'Interstellar',
'Lightyear',
],
value: 'Interstellar',
},
// ...
],
// debug: true,
// apiKey: '...',
}