-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfields.jsx
65 lines (60 loc) · 1.73 KB
/
fields.jsx
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
// TODO: add error handling
export const Input = ({ label, value, className, ...props }) => (
<label htmlFor={props.name} className={className} data-type={props.type || 'text'}>
<small>{label}{props.required && <span>*</span>}</small>
<input
id={props.name}
placeholder={label}
defaultValue={value}
{...props}
/>
</label>
)
export const Textarea = ({ label, value, className, ...props }) => (
<label htmlFor={props.name} className={className} data-type={props.type}>
<small>{label}{props.required && <span>*</span>}</small>
<textarea
id={props.name}
placeholder={label}
defaultValue={value}
{...props}
/>
</label>
)
export const Select = ({ label, options, value = '', className, ...props }) => (
<label htmlFor={props.name} className={className} data-type={props.type}>
<small>{label}{props.required && <span>*</span>}</small>
<select id={props.name} defaultValue={value} {...props}>
<option value="" disabled>Please select</option>
{options?.map((option, key) => (
<option value={option} key={key}>{option}</option>
))}
</select>
</label>
)
export const Checkbox = ({ label, value, className, ...props }) => (
<label htmlFor={props.name} className={className} data-type={props.type}>
<input
id={props.name}
defaultChecked={value}
defaultValue={value}
{...props}
/>
{label}
</label>
)
export const Radio = ({ label, options, value, className, ...props }) => (
<div className={className} data-type={props.type}>
<small>{label}{props.required && <span>*</span>}</small>
{options?.map((option, key) => (
<label key={key}>
<input
defaultChecked={value === option}
defaultValue={value === option && option}
{...props}
/>
{option}
</label>
))}
</div>
)