1- import { Form , Formik , FormikValues } from 'formik' ;
1+ import { Form , Formik , FormikProps , FormikValues } from 'formik' ;
22import { useCallback } from 'react' ;
33import { WebviewApi } from 'vscode-webview' ;
44import Validator from 'validatorjs' ;
@@ -11,13 +11,17 @@ interface Props {
1111}
1212
1313export const Renderer : React . FC < Props > = ( { wizard, vscode } ) => {
14- const initialValues : FormikValues = wizard . fields . reduce ( ( acc : FormikValues , field ) => {
15- if ( field . type === WizardInput . Select && field . multiple ) {
16- acc [ field . id ] = field . initialValue ?? [ ] ;
14+ const initialValues : FormikValues = wizard . tabs . reduce ( ( acc : FormikValues , tab ) => {
15+ tab . fields . reduce ( ( acc : FormikValues , field ) => {
16+ if ( field . type === WizardInput . Select && field . multiple ) {
17+ acc [ field . id ] = field . initialValue ?? [ ] ;
18+ return acc ;
19+ }
20+
21+ acc [ field . id ] = field . initialValue ?? '' ;
1722 return acc ;
18- }
23+ } , { } ) ;
1924
20- acc [ field . id ] = field . initialValue ?? '' ;
2125 return acc ;
2226 } , { } ) ;
2327
@@ -27,7 +31,6 @@ export const Renderer: React.FC<Props> = ({ wizard, vscode }) => {
2731
2832 const handleValidation = useCallback ( ( values : FormikValues ) => {
2933 if ( wizard . validation ) {
30- console . log ( wizard . validation ) ;
3134 const validation = new Validator ( values , wizard . validation , wizard . validationMessages ) ;
3235
3336 validation . passes ( ) ;
@@ -39,16 +42,34 @@ export const Renderer: React.FC<Props> = ({ wizard, vscode }) => {
3942 } , [ ] ) ;
4043
4144 return (
42- < main className = "p-6 w-full" >
45+ < main >
4346 < Formik initialValues = { initialValues } onSubmit = { handleSubmit } validate = { handleValidation } >
44- < Form >
45- { wizard . fields . map ( field => {
46- return < FieldRenderer key = { field . id } field = { field } /> ;
47- } ) }
48- < div className = "mt-4 flex gap-4" >
49- < vscode-button type = "submit" > Submit</ vscode-button >
50- </ div >
51- </ Form >
47+ { ( props : FormikProps < any > ) => {
48+ return (
49+ < >
50+ < vscode-tabs >
51+ { wizard . tabs . map ( tab => {
52+ return (
53+ < >
54+ < vscode-tab-header slot = "header" > { tab . title } </ vscode-tab-header >
55+ < vscode-tab-panel >
56+ < p > { tab . description } </ p >
57+ < br />
58+ { tab . fields . map ( field => {
59+ return < FieldRenderer key = { field . id } field = { field } /> ;
60+ } ) }
61+ </ vscode-tab-panel >
62+ </ >
63+ ) ;
64+ } ) }
65+ </ vscode-tabs >
66+ < br />
67+ < vscode-button disabled = { ! props . dirty || ! props . isValid } type = "submit" >
68+ Submit
69+ </ vscode-button >
70+ </ >
71+ ) ;
72+ } }
5273 </ Formik >
5374 </ main >
5475 ) ;
0 commit comments