-
Notifications
You must be signed in to change notification settings - Fork 96
Expand file tree
/
Copy pathcheckbox.js
More file actions
41 lines (37 loc) · 1.27 KB
/
checkbox.js
File metadata and controls
41 lines (37 loc) · 1.27 KB
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
import React from 'react';
import { Checkbox as AntCheckbox } from 'antd';
import MultipleChoiceList from '../multiple-choice-list/multiple-choice-list';
import { useFieldApi } from '@data-driven-forms/react-form-renderer';
import IsRequired from '../is-required';
import FormGroup from '../form-group';
export const SingleCheckbox = (props) => {
const { input, isReadOnly, isDisabled, isRequired, label, helperText, description, validateOnMount, meta, FormItemProps, ...rest } = useFieldApi({
...props,
type: 'checkbox',
});
return (
<FormGroup
label={label}
meta={meta}
validateOnMount={validateOnMount}
helperText={helperText}
description={description}
FormItemProps={FormItemProps}
isRequired={isRequired}
hideLabel
>
<AntCheckbox
checked={input.checked}
{...input}
defaultValue={input.value ? input.value : undefined}
disabled={isDisabled || isReadOnly}
value={input.name}
{...rest}
>
{isRequired ? <IsRequired>{label}</IsRequired> : label}
</AntCheckbox>
</FormGroup>
);
};
const Checkbox = ({ options, ...props }) => (options ? <MultipleChoiceList options={options} {...props} /> : <SingleCheckbox {...props} />);
export default Checkbox;