11import { ChangeEvent , FocusEvent } from 'react'
22
3+ import { PageDivider } from '../../page-divider'
34import { FormDefinition } from '../form-definition.model'
45import { FormGroup } from '../form-group.model'
56import { FormInputModel } from '../form-input.model'
67
78import { FormCardSet } from './form-card-set'
89import FormGroupItem from './form-group-item/FormGroupItem'
9- import { InputRating , InputText , InputTextarea } from './form-input'
10+ import { InputImagePicker , InputRating , InputText , InputTextarea } from './form-input'
1011import { FormInputRow } from './form-input-row'
1112import { InputTextTypes } from './form-input/input-text/InputText'
1213import FormRadio from './form-radio'
@@ -23,15 +24,18 @@ const FormGroups: (props: FormGroupsProps) => JSX.Element = (props: FormGroupsPr
2324
2425 const { formDef, onBlur, onChange } : FormGroupsProps = props
2526
26- const getTabIndex : ( input : FormInputModel , index : number ) => number = ( input , index ) => {
27+ function getTabIndex ( input : FormInputModel , index : number ) : number {
2728 const tabIndex : number = input . notTabbable ? - 1 : index + 1 + ( formDef . tabIndexStart || 0 )
2829 return tabIndex
2930 }
3031
31- const renderInputField : ( input : FormInputModel , index : number ) => JSX . Element | undefined = ( input , index ) => {
32+ function renderInputField ( input : FormInputModel , index : number ) : JSX . Element | undefined {
33+
3234 const tabIndex : number = getTabIndex ( input , index )
3335
3436 let inputElement : JSX . Element
37+
38+ /* tslint:disable:cyclomatic-complexity */
3539 switch ( input . type ) {
3640
3741 case 'rating' :
@@ -40,23 +44,33 @@ const FormGroups: (props: FormGroupsProps) => JSX.Element = (props: FormGroupsPr
4044 { ...input }
4145 onChange = { onChange }
4246 tabIndex = { tabIndex }
43- value = { input . value }
47+ value = { input . value as number | undefined }
4448 />
4549 )
4650 break
47-
4851 case 'textarea' :
4952 inputElement = (
5053 < InputTextarea
5154 { ...input }
5255 onBlur = { onBlur }
5356 onChange = { onChange }
5457 tabIndex = { tabIndex }
55- value = { input . value }
58+ value = { input . value as string | undefined }
5659 />
5760 )
5861 break
5962 case 'checkbox' :
63+ inputElement = (
64+ < InputText
65+ { ...input }
66+ checked = { ! ! input . value }
67+ onBlur = { onBlur }
68+ onChange = { onChange }
69+ tabIndex = { tabIndex }
70+ type = 'checkbox'
71+ />
72+ )
73+ break
6074 case 'radio' :
6175 inputElement = (
6276 < FormRadio
@@ -75,6 +89,15 @@ const FormGroups: (props: FormGroupsProps) => JSX.Element = (props: FormGroupsPr
7589 />
7690 )
7791 break
92+ case 'image-picker' :
93+ inputElement = (
94+ < InputImagePicker
95+ { ...input }
96+ onChange = { onChange }
97+ value = { input . value }
98+ />
99+ )
100+ break
78101 default :
79102 inputElement = (
80103 < InputText
@@ -83,7 +106,7 @@ const FormGroups: (props: FormGroupsProps) => JSX.Element = (props: FormGroupsPr
83106 onChange = { onChange }
84107 tabIndex = { tabIndex }
85108 type = { input . type as InputTextTypes || 'text' }
86- value = { input . value }
109+ value = { input . value as string | undefined }
87110 />
88111 )
89112 break
@@ -100,14 +123,29 @@ const FormGroups: (props: FormGroupsProps) => JSX.Element = (props: FormGroupsPr
100123 )
101124 }
102125
103- const formGroups : Array < JSX . Element | undefined > = formDef ?. groups ?. map ( ( element : FormGroup , index : number ) => {
104- return < FormGroupItem key = { `element-${ index } ` } group = { element } renderFormInput = { renderInputField } totalGroupCount = { formDef . groups ?. length || 0 } />
105- } ) || [ ]
126+ const formGroups : Array < JSX . Element | undefined > = formDef ?. groups
127+ ?. map ( ( element : FormGroup , index : number ) => {
128+ return (
129+ < FormGroupItem
130+ key = { `element-${ index } ` }
131+ group = { element }
132+ renderFormInput = { renderInputField }
133+ totalGroupCount = { formDef . groups ?. length || 0 }
134+ renderDividers = { props . formDef . groupsOptions ?. renderGroupDividers }
135+ />
136+ )
137+ } )
138+ || [ ]
106139
107140 return (
108- < div className = { styles [ 'form-groups' ] } >
109- { formGroups }
110- </ div >
141+ < >
142+ < div className = { styles [ 'form-groups' ] } style = { props . formDef . groupsOptions ?. groupWrapStyles } >
143+ { formGroups }
144+ </ div >
145+ {
146+ props . formDef . groupsOptions ?. renderGroupDividers === false && < PageDivider />
147+ }
148+ </ >
111149 )
112150}
113151
0 commit comments