blob: 946e37532605d13d652697bf55bd9fc2f46485f7 (
plain)
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
|
import { ChangeEventHandler, FC, MouseEventHandler } from 'react';
import styles from './boolean-field.module.scss';
export type BooleanFieldProps = {
/**
* One or more ids that refers to the checkbox name.
*/
'aria-labelledby'?: string;
/**
* True if the field should be checked.
*/
checked: boolean;
/**
* Add classnames to the checkbox.
*/
className?: string;
/**
* Field id attribute.
*/
id: string;
/**
* True if the field should be visually hidden. Default: false.
*/
hidden?: boolean;
/**
* Field name attribute.
*/
name: string;
/**
* Callback function to handle state change.
*/
onChange: ChangeEventHandler<HTMLInputElement>;
/**
* A callback function to handle click.
*/
onClick?: MouseEventHandler<HTMLInputElement>;
/**
* The input type.
*/
type: 'checkbox' | 'radio';
/**
* Field name attribute.
*/
value: string;
};
/**
* BooleanField component
*
* Render a checkbox or a radio input type.
*/
const BooleanField: FC<BooleanFieldProps> = ({
className = '',
hidden = false,
...props
}) => {
const modifier = hidden ? 'hidden' : '';
return <input className={`${styles[modifier]} ${className}`} {...props} />;
};
export default BooleanField;
|