File tree Expand file tree Collapse file tree
src/common/components/form Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import React from 'react' ;
2+ import { useField } from 'formik' ;
3+ import Checkbox , { CheckboxProps } from '@material-ui/core/Checkbox' ;
4+ import FormControlLabel from '@material-ui/core/FormControlLabel' ;
5+ import FormControl from '@material-ui/core/FormControl' ;
6+ import FormHelperText from '@material-ui/core/FormHelperText' ;
7+ import * as classes from './checkbox.styles' ;
8+
9+ interface Props extends CheckboxProps {
10+ label ?: string ;
11+ labelPlacement ?: 'end' | 'start' | 'top' | 'bottom' ;
12+ error ?: boolean ;
13+ helperText ?: string ;
14+ }
15+
16+ export const CheckboxComponent : React . FunctionComponent < Props > = props => {
17+ const {
18+ label,
19+ labelPlacement,
20+ error,
21+ name,
22+ checked,
23+ onChange,
24+ onBlur,
25+ ...checkboxProps
26+ } = props ;
27+ const [ field , meta ] = Boolean ( name ) ? useField ( name ) : [ ] ;
28+ const hasError = error || Boolean ( meta && meta . touched && meta . error ) ;
29+ const helperText = Boolean ( field ) ? meta ?. error : props . helperText ;
30+
31+ return (
32+ < FormControl
33+ className = { classes . root }
34+ error = { hasError }
35+ fullWidth = { true }
36+ margin = "normal"
37+ >
38+ < FormControlLabel
39+ control = {
40+ < Checkbox
41+ { ...checkboxProps }
42+ name = { name }
43+ checked = { checked || field ?. value }
44+ onChange = { onChange || field ?. onChange }
45+ onBlur = { onBlur || field ?. onBlur }
46+ />
47+ }
48+ label = { label }
49+ labelPlacement = { labelPlacement }
50+ />
51+
52+ { hasError && < FormHelperText > { helperText } </ FormHelperText > }
53+ </ FormControl >
54+ ) ;
55+ } ;
Original file line number Diff line number Diff line change 1+ import { css } from 'emotion' ;
2+ import { theme } from 'core/theme' ;
3+
4+ export const root = css `
5+ justify-content : flex-end;
6+ ` ;
Original file line number Diff line number Diff line change 1+ export * from './checkbox.component' ;
Original file line number Diff line number Diff line change 11export * from './form.component' ;
22export * from './text-field.component' ;
3+ export * from './checkbox' ;
You can’t perform that action at this time.
0 commit comments