-
Notifications
You must be signed in to change notification settings - Fork 3
/
Wizard.tsx
65 lines (62 loc) · 1.5 KB
/
Wizard.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import * as React from "react";
import { Stack, ThemeProvider, Typography } from "@mui/material";
import { WizardProps, WizardThemeOverrideProps } from "./Wizard.types";
/**
* The Wizard component allows you to create a multi-step form.
* It handles title and layout.
*/
export default function Wizard({ title, children, maxWidth }: WizardProps) {
return (
<ThemeOverride maxWidth={maxWidth}>
<Stack
sx={{
display: "flex",
flexDirection: "column",
height: "100%",
px: 3
}}
>
{typeof title === "string" ? (
<Typography
variant="h5"
color="textPrimary"
sx={{
fontWeight: 700,
maxWidth: theme => theme?.layout?.content?.maxWidth,
mb: 2,
mt: 1,
mx: "auto",
width: "100%"
}}
>
{title}
</Typography>
) : (
title
)}
{children}
</Stack>
</ThemeOverride>
);
}
/**
* Internal wrapper for ThemeProvider that overrides the layout.content.maxWidth if maxWidth is provided.
*/
function ThemeOverride({ children, maxWidth }: WizardThemeOverrideProps) {
return maxWidth ? (
<ThemeProvider
theme={baseTheme => ({
...baseTheme,
layout: {
content: {
maxWidth
}
}
})}
>
{children}
</ThemeProvider>
) : (
<React.Fragment>{children}</React.Fragment>
);
}