File size: 1,304 Bytes
1e92f2d |
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 |
// @flow
import * as React from "react";
import cn from "classnames";
import Form from "./";
import type { FormEvents, FocusEvents } from "../../";
export type Props = {|
...FormEvents,
...FocusEvents,
+className?: string,
/**
* Wrap the checkbox with a label
*/
+label?: string,
+value?: string | number | boolean,
+name?: string,
+checked?: boolean,
+disabled?: boolean,
+readOnly?: boolean,
+isInline?: boolean,
|};
function FormCheckbox({
className,
label,
value,
name,
checked,
disabled,
readOnly,
onChange,
onFocus,
onBlur,
isInline,
}: Props): React.Node {
const classes = cn(
"custom-control custom-checkbox",
{ "custom-control-inline": isInline },
className
);
const inputComponent = (
<Form.Input
type="checkbox"
name={name}
value={value}
checked={checked}
className={classes}
disabled={disabled}
readOnly={readOnly}
onChange={onChange}
onBlur={onBlur}
onFocus={onFocus}
/>
);
return label ? (
<label className={classes}>
{inputComponent}
<span className="custom-control-label">{label}</span>
</label>
) : (
inputComponent
);
}
FormCheckbox.displayName = "Form.Checkbox";
/** @component */
export default FormCheckbox;
|