1
- import { makeStyles } from "@mui/styles" ;
2
- import { AlphaBadge } from "components/DeploySettingsLayout/Badges" ;
3
- import {
4
- FormFooterProps as BaseFormFooterProps ,
5
- FormFooter as BaseFormFooter ,
6
- } from "components/FormFooter/FormFooter" ;
7
- import { Stack } from "components/Stack/Stack" ;
1
+ import { type Interpolation , type Theme , useTheme } from "@emotion/react" ;
8
2
import {
9
3
createContext ,
10
- FC ,
11
- HTMLProps ,
12
- PropsWithChildren ,
4
+ type FC ,
5
+ type HTMLProps ,
6
+ type PropsWithChildren ,
13
7
useContext ,
14
8
} from "react" ;
15
- import { combineClasses } from "utils/combineClasses" ;
9
+ import { AlphaBadge } from "components/DeploySettingsLayout/Badges" ;
10
+ import { Stack } from "components/Stack/Stack" ;
11
+ import {
12
+ FormFooter as BaseFormFooter ,
13
+ FormFooterProps ,
14
+ type FormFooterStyles ,
15
+ } from "../FormFooter/FormFooter" ;
16
16
17
17
type FormContextValue = { direction ?: "horizontal" | "vertical" } ;
18
18
@@ -24,14 +24,22 @@ type FormProps = HTMLProps<HTMLFormElement> & {
24
24
direction ?: FormContextValue [ "direction" ] ;
25
25
} ;
26
26
27
- export const Form : FC < FormProps > = ( { direction, className , ...formProps } ) => {
28
- const styles = useStyles ( { direction } ) ;
27
+ export const Form : FC < FormProps > = ( { direction, ...formProps } ) => {
28
+ const theme = useTheme ( ) ;
29
29
30
30
return (
31
31
< FormContext . Provider value = { { direction } } >
32
32
< form
33
33
{ ...formProps }
34
- className = { combineClasses ( [ styles . form , className ] ) }
34
+ css = { {
35
+ display : "flex" ,
36
+ flexDirection : "column" ,
37
+ gap : theme . spacing ( direction === "horizontal" ? 10 : 5 ) ,
38
+
39
+ [ theme . breakpoints . down ( "md" ) ] : {
40
+ gap : theme . spacing ( 8 ) ,
41
+ } ,
42
+ } }
35
43
/>
36
44
</ FormContext . Provider >
37
45
) ;
@@ -71,28 +79,50 @@ export const FormSection: FC<
71
79
alpha ?: boolean ;
72
80
}
73
81
> = ( { children, title, description, classes = { } , alpha = false } ) => {
74
- const formContext = useContext ( FormContext ) ;
75
- const styles = useStyles ( formContext ) ;
82
+ const { direction } = useContext ( FormContext ) ;
83
+ const theme = useTheme ( ) ;
76
84
77
85
return (
78
- < div className = { combineClasses ( [ styles . formSection , classes . root ] ) } >
86
+ < div
87
+ css = { {
88
+ display : "flex" ,
89
+ alignItems : "flex-start" ,
90
+ flexDirection : direction === "horizontal" ? "row" : "column" ,
91
+ gap : theme . spacing ( direction === "horizontal" ? 15 : 3 ) ,
92
+
93
+ [ theme . breakpoints . down ( "md" ) ] : {
94
+ flexDirection : "column" ,
95
+ gap : theme . spacing ( 2 ) ,
96
+ } ,
97
+ } }
98
+ className = { classes . root }
99
+ >
79
100
< div
80
- className = { combineClasses ( [
81
- classes . sectionInfo ,
82
- styles . formSectionInfo ,
83
- ] ) }
101
+ css = { {
102
+ width : "100%" ,
103
+ maxWidth : direction === "horizontal" ? 312 : undefined ,
104
+ flexShrink : 0 ,
105
+ position : direction === "horizontal" ? "sticky" : undefined ,
106
+ top : theme . spacing ( 3 ) ,
107
+
108
+ [ theme . breakpoints . down ( "md" ) ] : {
109
+ width : "100%" ,
110
+ position : "initial" as const ,
111
+ } ,
112
+ } }
113
+ className = { classes . sectionInfo }
84
114
>
85
115
< h2
86
- className = { combineClasses ( [
116
+ css = { [
87
117
styles . formSectionInfoTitle ,
88
118
alpha && styles . formSectionInfoTitleAlpha ,
89
- classes . infoTitle ,
90
- ] ) }
119
+ ] }
120
+ className = { classes . infoTitle }
91
121
>
92
122
{ title }
93
123
{ alpha && < AlphaBadge /> }
94
124
</ h2 >
95
- < div className = { styles . formSectionInfoDescription } > { description } </ div >
125
+ < div css = { styles . formSectionInfoDescription } > { description } </ div >
96
126
</ div >
97
127
98
128
{ children }
@@ -101,108 +131,55 @@ export const FormSection: FC<
101
131
} ;
102
132
103
133
export const FormFields : FC < PropsWithChildren > = ( { children } ) => {
104
- const styles = useStyles ( ) ;
105
134
return (
106
- < Stack
107
- direction = "column"
108
- spacing = { 2.5 }
109
- className = { styles . formSectionFields }
110
- >
135
+ < Stack direction = "column" spacing = { 2.5 } css = { styles . formSectionFields } >
111
136
{ children }
112
137
</ Stack >
113
138
) ;
114
139
} ;
115
140
116
- export const FormFooter : FC < BaseFormFooterProps > = ( props ) => {
117
- const formFooterStyles = useFormFooterStyles ( ) ;
118
- return (
119
- < BaseFormFooter
120
- { ...props }
121
- styles = { { ...formFooterStyles , ...props . styles } }
122
- />
123
- ) ;
124
- } ;
125
- const getFlexDirection = ( { direction } : FormContextValue = { } ) :
126
- | "row"
127
- | "column" =>
128
- direction === "horizontal" ? ( "row" as const ) : ( "column" as const ) ;
129
-
130
- const useStyles = makeStyles ( ( theme ) => ( {
131
- form : {
132
- display : "flex" ,
133
- flexDirection : "column" ,
134
- gap : ( { direction } : FormContextValue = { } ) =>
135
- direction === "horizontal" ? theme . spacing ( 10 ) : theme . spacing ( 5 ) ,
136
-
137
- [ theme . breakpoints . down ( "md" ) ] : {
138
- gap : theme . spacing ( 8 ) ,
139
- } ,
140
- } ,
141
-
142
- formSection : {
143
- display : "flex" ,
144
- alignItems : "flex-start" ,
145
- gap : ( { direction } : FormContextValue = { } ) =>
146
- direction === "horizontal" ? theme . spacing ( 15 ) : theme . spacing ( 3 ) ,
147
- flexDirection : getFlexDirection ,
148
-
149
- [ theme . breakpoints . down ( "md" ) ] : {
150
- flexDirection : "column" ,
151
- gap : theme . spacing ( 2 ) ,
152
- } ,
153
- } ,
154
-
155
- formSectionInfo : {
156
- width : "100%" ,
157
- maxWidth : ( { direction } : FormContextValue = { } ) =>
158
- direction === "horizontal" ? 312 : undefined ,
159
- flexShrink : 0 ,
160
- position : ( { direction } : FormContextValue = { } ) =>
161
- direction === "horizontal" ? "sticky" : undefined ,
162
- top : theme . spacing ( 3 ) ,
163
-
164
- [ theme . breakpoints . down ( "md" ) ] : {
165
- width : "100%" ,
166
- position : "initial" as const ,
167
- } ,
168
- } ,
169
-
170
- formSectionInfoTitle : {
141
+ const styles = {
142
+ formSectionInfoTitle : ( theme ) => ( {
171
143
fontSize : 20 ,
172
144
color : theme . palette . text . primary ,
173
145
fontWeight : 400 ,
174
146
margin : 0 ,
175
147
marginBottom : theme . spacing ( 1 ) ,
176
- } ,
148
+ } ) ,
177
149
178
- formSectionInfoTitleAlpha : {
150
+ formSectionInfoTitleAlpha : ( theme ) => ( {
179
151
display : "flex" ,
180
152
flexDirection : "row" ,
181
153
alignItems : "center" ,
182
154
gap : theme . spacing ( 1.5 ) ,
183
- } ,
155
+ } ) ,
184
156
185
- formSectionInfoDescription : {
157
+ formSectionInfoDescription : ( theme ) => ( {
186
158
fontSize : 14 ,
187
159
color : theme . palette . text . secondary ,
188
160
lineHeight : "160%" ,
189
161
margin : 0 ,
190
- } ,
162
+ } ) ,
191
163
192
164
formSectionFields : {
193
165
width : "100%" ,
194
166
} ,
195
- } ) ) ;
167
+ } satisfies Record < string , Interpolation < Theme > > ;
168
+
169
+ export const FormFooter = ( props : Exclude < FormFooterProps , "styles" > ) => (
170
+ < BaseFormFooter { ...props } styles = { footerStyles } />
171
+ ) ;
196
172
197
- const useFormFooterStyles = makeStyles ( ( theme ) => ( {
198
- button : {
173
+ const footerStyles = {
174
+ button : ( theme ) => ( {
199
175
minWidth : theme . spacing ( 23 ) ,
200
176
201
177
[ theme . breakpoints . down ( "md" ) ] : {
202
178
width : "100%" ,
203
179
} ,
204
- } ,
205
- footer : {
180
+ } ) ,
181
+
182
+ footer : ( theme ) => ( {
206
183
display : "flex" ,
207
184
alignItems : "center" ,
208
185
justifyContent : "flex-start" ,
@@ -213,5 +190,5 @@ const useFormFooterStyles = makeStyles((theme) => ({
213
190
flexDirection : "column" ,
214
191
gap : theme . spacing ( 1 ) ,
215
192
} ,
216
- } ,
217
- } ) ) ;
193
+ } ) ,
194
+ } satisfies FormFooterStyles ;
0 commit comments