@@ -98,6 +98,20 @@ export const Form: React.FC<FormProps> = props => {
9898 if ( key . escape ) {
9999 focusManager . focus ( '0' ) ;
100100 setFocusedElement ( 0 ) ;
101+ return ;
102+ }
103+
104+ if ( input === 'a' ) {
105+ duplicateCurrentSection ( ) ;
106+ return ;
107+ }
108+
109+ if ( input === 'r' && sections . length > 1 ) {
110+ removeCurrentSection ( ) ;
111+ }
112+
113+ if ( input === 's' && canSubmitForm ) {
114+ onSubmitForm ( ) ;
101115 }
102116 } ,
103117 { isActive : ! editingField }
@@ -112,7 +126,6 @@ export const Form: React.FC<FormProps> = props => {
112126
113127 setSections ( newTabs ) ;
114128 setValue ( [ ...value ] ) ;
115- onChangeTab ( currentTab + 1 )
116129 }
117130
118131 const removeCurrentSection = ( ) => {
@@ -137,66 +150,62 @@ export const Form: React.FC<FormProps> = props => {
137150 < Box width = "100%" height = "90%" flexDirection = "column" overflowY = "hidden" >
138151 < FormHeader { ...props } headerRef = { headerRef } form = { form } currentTab = { currentTab } onChangeTab = { onChangeTab } editingField = { editingField } />
139152 < ScrollArea height = { fullHeight - headerHeight } key = { currentTab } isStart = { focusedElement === - 1 } numFields = { sections [ currentTab ] . fields . length } editingMode = { ! ! editingField } >
140- { ! editingField && (
141- < Box flexDirection = 'column' >
142- < Box marginLeft = { 1 } marginTop = { 1 } >
143- < Text bold > { sections [ currentTab ] . title } </ Text >
144- </ Box >
145- < Text > { ' {' } </ Text >
146- </ Box >
147- ) }
148- < Box flexDirection = "column" >
149- { currentTab > sections . length - 1
150- ? null
151- : sections [ currentTab ] . fields . map ( ( field , index ) => (
152- < FormFieldRenderer
153- id = { `${ index } ` }
154- field = { field }
155- key = { field . name + currentTab }
156- form = { form }
157- value = { value [ currentTab ] [ field . name ] }
158- onExit = { onFieldExit }
159- onChange = { v => setValueAndPropagate ( currentTab , { ...value [ currentTab ] , [ field . name ] : v } ) }
160- onSetEditingField = { setEditingField }
161- editingField = { editingField }
162- customManagers = { props . customManagers }
163- />
164- ) ) }
165- { ! editingField && (
166- < Text > { ' }' } </ Text >
167- ) }
168- </ Box >
169- { ! editingField && (
170- < Box flexDirection = "row" marginTop = { 1 } >
171- < Box flexDirection = "column" flexGrow = { 1 } width = '40%' >
172- { ! editingField && sections [ currentTab ] . description && (
173- < Box marginX = { 1 } flexDirection = 'column' >
174- < Text underline > Description:</ Text >
175- < DescriptionRenderer description = { sections [ currentTab ] ?. description } />
176- {
177- sections [ currentTab ] . fields [ focusedElement ] ?. description && (
178- < Box flexDirection = "column" >
179- < Text > </ Text >
180- < Text underline > { upperFirstLetter ( sections [ currentTab ] . fields [ focusedElement ] ?. label ) } :</ Text >
181- < DescriptionRenderer description = { sections [ currentTab ] . fields [ focusedElement ] ?. description } />
182- </ Box >
183- )
184- }
153+ < Box flexDirection = 'row' >
154+ < Box flexDirection = 'column' width = '80%' >
155+ { ! editingField && (
156+ < Box flexDirection = 'column' >
157+ < Box marginLeft = { 1 } marginTop = { 1 } >
158+ < Text bold > { sections [ currentTab ] . title } </ Text >
185159 </ Box >
160+ < Text > { ' {' } </ Text >
161+ </ Box >
162+ ) }
163+ < Box flexDirection = "column" >
164+ { currentTab > sections . length - 1
165+ ? null
166+ : sections [ currentTab ] . fields . map ( ( field , index ) => (
167+ < FormFieldRenderer
168+ id = { `${ index } ` }
169+ field = { field }
170+ key = { field . name + currentTab }
171+ form = { form }
172+ value = { value [ currentTab ] [ field . name ] }
173+ onExit = { onFieldExit }
174+ onChange = { v => setValueAndPropagate ( currentTab , { ...value [ currentTab ] , [ field . name ] : v } ) }
175+ onSetEditingField = { setEditingField }
176+ editingField = { editingField }
177+ customManagers = { props . customManagers }
178+ />
179+ ) ) }
180+ { ! editingField && (
181+ < Text > { ' }' } </ Text >
186182 ) }
187183 </ Box >
188- < Box flexDirection = "column" flexGrow = { 1 } width = '40%' >
189- < Box flexDirection = "row-reverse" >
190- < Button label = "Add (duplicate)" id = { 'addButton' } onClicked = { ( ) => duplicateCurrentSection ( ) } />
191- </ Box >
192- < Box flexDirection = "row-reverse" >
193- < Button label = "Remove" id = { 'removeButton' } isEnabled = { sections . length > 1 } onClicked = { ( ) => removeCurrentSection ( ) } />
194- </ Box >
195- < Box flexDirection = "row-reverse" >
196- < SubmitButton canSubmit = { canSubmitForm } onSubmit = { onSubmitForm } />
184+ </ Box >
185+
186+ < Box flexDirection = "column" >
187+ { ! editingField && sections [ currentTab ] . description && (
188+ < Box marginX = { 1 } marginTop = { 1 } flexDirection = 'column' >
189+ < Text underline > Description:</ Text >
190+ < DescriptionRenderer description = { sections [ currentTab ] ?. description } />
197191 </ Box >
192+ ) }
193+ </ Box >
194+
195+ </ Box >
196+ { ! editingField && (
197+ < Box flexDirection = 'column' marginTop = { 1 } >
198+ < Box flexDirection = "row" >
199+ < Button label = "[A]dd resource" id = { 'addButton' } onClicked = { ( ) => duplicateCurrentSection ( ) } margin = { 0 } padding = { 0 } />
200+ < Button label = "[R]emove resource" id = { 'removeButton' } isEnabled = { sections . length > 1 } onClicked = { ( ) => removeCurrentSection ( ) } margin = { 0 } padding = { 0 } />
201+ < SubmitButton canSubmit = { canSubmitForm } onSubmit = { onSubmitForm } />
198202 </ Box >
203+ < Text dimColor color = 'gray' > Up/down: navigate options.</ Text >
204+ < Text dimColor color = 'gray' > Left/right: navigate between resources.</ Text >
205+ < Text dimColor color = 'gray' > Enter: select or edit</ Text >
199206 </ Box >
207+
208+ // </Box>
200209 ) }
201210 </ ScrollArea >
202211 </ Box >
0 commit comments