1
- import { makeStyles } from "@mui/styles" ;
2
- import { FC , ReactNode , FormEventHandler } from "react" ;
1
+ import type { FC , ReactNode , FormEventHandler } from "react" ;
3
2
import Button from "@mui/material/Button" ;
3
+ import { type CSSObject , useTheme } from "@emotion/react" ;
4
4
5
- export const Fieldset : FC < {
5
+ interface FieldsetProps {
6
6
children : ReactNode ;
7
7
title : string | JSX . Element ;
8
8
subtitle ?: string | JSX . Element ;
9
9
validation ?: string | JSX . Element | false ;
10
10
button ?: JSX . Element | false ;
11
11
onSubmit : FormEventHandler < HTMLFormElement > ;
12
12
isSubmitting ?: boolean ;
13
- } > = ( {
14
- title,
15
- subtitle,
16
- children,
17
- validation,
18
- button,
19
- onSubmit,
20
- isSubmitting,
21
- } ) => {
22
- const styles = useStyles ( ) ;
13
+ }
14
+
15
+ export const Fieldset : FC < FieldsetProps > = ( props ) => {
16
+ const {
17
+ title,
18
+ subtitle,
19
+ children,
20
+ validation,
21
+ button,
22
+ onSubmit,
23
+ isSubmitting,
24
+ } = props ;
25
+ const theme = useTheme ( ) ;
23
26
24
27
return (
25
- < form className = { styles . fieldset } onSubmit = { onSubmit } >
26
- < header className = { styles . header } >
27
- < div className = { styles . title } > { title } </ div >
28
- { subtitle && < div className = { styles . subtitle } > { subtitle } </ div > }
29
- < div className = { styles . body } > { children } </ div >
28
+ < form
29
+ css = { {
30
+ borderRadius : theme . spacing ( 1 ) ,
31
+ border : `1px solid ${ theme . palette . divider } ` ,
32
+ background : theme . palette . background . paper ,
33
+ marginTop : theme . spacing ( 4 ) ,
34
+ } }
35
+ onSubmit = { onSubmit }
36
+ >
37
+ < header css = { { padding : theme . spacing ( 3 ) } } >
38
+ < div
39
+ css = { {
40
+ fontSize : theme . spacing ( 2.5 ) ,
41
+ margin : 0 ,
42
+ fontWeight : 600 ,
43
+ } }
44
+ >
45
+ { title }
46
+ </ div >
47
+ { subtitle && (
48
+ < div
49
+ css = { {
50
+ color : theme . palette . text . secondary ,
51
+ fontSize : 14 ,
52
+ marginTop : theme . spacing ( 1 ) ,
53
+ } }
54
+ >
55
+ { subtitle }
56
+ </ div >
57
+ ) }
58
+ < div
59
+ css = { [
60
+ theme . typography . body2 as CSSObject ,
61
+ { paddingTop : theme . spacing ( 2 ) } ,
62
+ ] }
63
+ >
64
+ { children }
65
+ </ div >
30
66
</ header >
31
- < footer className = { styles . footer } >
32
- < div className = { styles . validation } > { validation } </ div >
67
+ < footer
68
+ css = { [
69
+ theme . typography . body2 as CSSObject ,
70
+ {
71
+ background : theme . palette . background . paperLight ,
72
+ padding : `${ theme . spacing ( 2 ) } ${ theme . spacing ( 3 ) } ` ,
73
+ display : "flex" ,
74
+ alignItems : "center" ,
75
+ justifyContent : "space-between" ,
76
+ } ,
77
+ ] }
78
+ >
79
+ < div css = { { color : theme . palette . text . secondary } } > { validation } </ div >
33
80
{ button || (
34
81
< Button type = "submit" disabled = { isSubmitting } >
35
82
Submit
@@ -39,40 +86,3 @@ export const Fieldset: FC<{
39
86
</ form >
40
87
) ;
41
88
} ;
42
-
43
- const useStyles = makeStyles ( ( theme ) => ( {
44
- fieldset : {
45
- borderRadius : theme . spacing ( 1 ) ,
46
- border : `1px solid ${ theme . palette . divider } ` ,
47
- background : theme . palette . background . paper ,
48
- marginTop : theme . spacing ( 4 ) ,
49
- } ,
50
- title : {
51
- fontSize : theme . spacing ( 2.5 ) ,
52
- margin : 0 ,
53
- fontWeight : 600 ,
54
- } ,
55
- subtitle : {
56
- color : theme . palette . text . secondary ,
57
- fontSize : 14 ,
58
- marginTop : theme . spacing ( 1 ) ,
59
- } ,
60
- body : {
61
- ...theme . typography . body2 ,
62
- paddingTop : theme . spacing ( 2 ) ,
63
- } ,
64
- validation : {
65
- color : theme . palette . text . secondary ,
66
- } ,
67
- header : {
68
- padding : theme . spacing ( 3 ) ,
69
- } ,
70
- footer : {
71
- ...theme . typography . body2 ,
72
- background : theme . palette . background . paperLight ,
73
- padding : `${ theme . spacing ( 2 ) } ${ theme . spacing ( 3 ) } ` ,
74
- display : "flex" ,
75
- alignItems : "center" ,
76
- justifyContent : "space-between" ,
77
- } ,
78
- } ) ) ;
0 commit comments