1
1
import React from 'react' ;
2
- import usePaginatorContext , { PaginatorContextProvider } from '~/components/paginator/paginator-context' ;
2
+ import usePaginatorContext , {
3
+ PaginatorContextProvider
4
+ } from '~/components/paginator/paginator-context' ;
3
5
import usePagesContext , { PagesContextProvider } from './pages-context' ;
4
6
import { FormattedMessage } from 'react-intl' ;
5
7
import ButtonRow from './buttons' ;
@@ -13,24 +15,22 @@ function MarkupChildren({children}: {children: React.ReactNode[]}) {
13
15
const { isVisible} = usePaginatorContext ( ) ;
14
16
const { validatedPages, activeRef} = usePagesContext ( ) ;
15
17
16
- return (
17
- children . map ( ( child , i ) => {
18
- const isActive = isVisible ( i ) ;
19
- const pageNumber = i + 1 ;
20
- const isValidated = pageNumber in validatedPages ;
18
+ return children . map ( ( child , i ) => {
19
+ const isActive = isVisible ( i ) ;
20
+ const pageNumber = i + 1 ;
21
+ const isValidated = pageNumber in validatedPages ;
21
22
22
- return (
23
- < div
24
- className = { isValidated ? 'validated' : undefined }
25
- hidden = { ! isActive }
26
- ref = { isActive ? activeRef : null }
27
- key = { i }
28
- >
29
- { child }
30
- </ div >
31
- ) ;
32
- } )
33
- ) ;
23
+ return (
24
+ < div
25
+ className = { isValidated ? 'validated' : undefined }
26
+ hidden = { ! isActive }
27
+ ref = { isActive ? activeRef : null }
28
+ key = { i }
29
+ >
30
+ { child }
31
+ </ div >
32
+ ) ;
33
+ } ) ;
34
34
}
35
35
36
36
function PageCount ( ) {
@@ -39,32 +39,41 @@ function PageCount() {
39
39
40
40
return (
41
41
< div className = "page-count" >
42
- < FormattedMessage id = "form.step-of" values = { { current : currentPage , total : pages } } />
42
+ < FormattedMessage
43
+ id = "form.step-of"
44
+ values = { { current : currentPage , total : pages } }
45
+ />
43
46
</ div >
44
47
) ;
45
48
}
46
49
47
50
type MultiPageFormProps = {
48
51
children : React . ReactNode [ ] ;
49
- validatePage ?: ( p : unknown ) => boolean ;
50
- onPageChange ?: ( p : unknown ) => boolean ;
52
+ validatePage ?: ( p : number ) => boolean ;
53
+ onPageChange ?: ( p : number ) => void ;
51
54
onSubmit : ( form : HTMLFormElement ) => void ;
52
55
submitting : boolean ;
53
56
// onSubmit is redefined above to be simpler
54
57
} & Omit < React . FormHTMLAttributes < HTMLFormElement > , 'onSubmit' > ;
55
58
56
59
function MultiPageFormInContext ( {
57
60
children,
58
- validatePage= pass , onPageChange= pass , onSubmit,
59
- submitting, ...formParams
61
+ validatePage = pass ,
62
+ onPageChange = pass ,
63
+ onSubmit,
64
+ submitting,
65
+ ...formParams
60
66
} : MultiPageFormProps ) {
61
67
const formRef = React . useRef < HTMLFormElement > ( null ) ;
62
68
63
69
return (
64
70
< div className = "multi-page-form" >
65
71
< form
66
- acceptCharset = "UTF-8" className = "form"
67
- method = "post" ref = { formRef } { ...formParams }
72
+ acceptCharset = "UTF-8"
73
+ className = "form"
74
+ method = "post"
75
+ ref = { formRef }
76
+ { ...formParams }
68
77
aria-label = "form"
69
78
>
70
79
< PagesContextProvider
@@ -76,10 +85,9 @@ function MultiPageFormInContext({
76
85
>
77
86
< MarkupChildren children = { children } />
78
87
< PageCount />
79
- {
80
- submitting &&
81
- < div className = "big-message" > Submitting...</ div >
82
- }
88
+ { submitting && (
89
+ < div className = "big-message" > Submitting...</ div >
90
+ ) }
83
91
< ButtonRow disabled = { submitting } { ...{ formRef, onSubmit} } />
84
92
</ PagesContextProvider >
85
93
</ form >
0 commit comments