Skip to content

Commit b7903ec

Browse files
committed
Mobile responsive variant of new Dialog component
1 parent 1b351be commit b7903ec

5 files changed

Lines changed: 62 additions & 23 deletions

File tree

src/components/design_system/dialog/Dialog.stories.tsx

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,6 @@ import Dialog from "./Dialog";
55
const meta: Meta<typeof Dialog> = {
66
title: "Components/Design System/Dialog",
77
component: Dialog,
8-
decorators: [
9-
(Story) => (
10-
<>
11-
<div id="anchor">
12-
<Story />
13-
</div>
14-
<div style={{ height: "8rem" }}></div>
15-
</>
16-
),
17-
],
188
};
199
export default meta;
2010

@@ -28,5 +18,6 @@ export const Default: Story = {
2818
children: <p style={{ width: "100%" }}>Testing, testing testing</p>,
2919
cancelLabel: "Cancel",
3020
confirmLabel: "Save",
21+
fullScreenOnMobile: true,
3122
},
3223
};

src/components/design_system/dialog/Dialog.tsx

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
import { ReactNode } from "react";
22
import {
3+
AppBar,
34
Dialog as MuiDialog,
45
DialogActions,
56
DialogContent,
67
DialogTitle,
8+
IconButton,
9+
Toolbar,
10+
useMediaQuery,
711
} from "@mui/material";
12+
import { useTheme } from "@mui/material/styles";
13+
import { ArrowBack } from "@mui/icons-material";
814
import Button from "@/components/design_system/button/Button";
915

1016
interface DialogProps {
1117
cancelLabel?: string;
1218
children: ReactNode;
1319
confirmLabel?: string;
20+
fullScreenOnMobile: boolean;
21+
onCancel?: () => void;
22+
onConfirm?: () => void;
1423
open: boolean;
1524
size: "xs" | "sm" | "md" | "lg" | "xl";
1625
title: ReactNode;
@@ -20,19 +29,55 @@ function Dialog({
2029
cancelLabel,
2130
children,
2231
confirmLabel,
32+
fullScreenOnMobile = false,
33+
onCancel,
34+
onConfirm,
2335
open,
2436
size = "sm",
2537
title,
2638
}: DialogProps) {
39+
const theme = useTheme();
40+
const isMobile = useMediaQuery(theme.breakpoints.down("sm"));
41+
2742
return (
28-
<MuiDialog open={open} fullWidth maxWidth={size}>
29-
<DialogTitle align="center" variant="h3">
43+
<MuiDialog
44+
open={open}
45+
fullScreen={fullScreenOnMobile && isMobile}
46+
fullWidth
47+
maxWidth={size}
48+
>
49+
{isMobile && (
50+
<AppBar position="fixed">
51+
<Toolbar>
52+
<IconButton
53+
onClick={() => onCancel?.()}
54+
color="inherit"
55+
sx={{ padding: "1.25rem" }}
56+
>
57+
<ArrowBack />
58+
</IconButton>
59+
</Toolbar>
60+
</AppBar>
61+
)}
62+
<DialogTitle
63+
align="center"
64+
variant="h3"
65+
sx={{ paddingTop: { xs: "5.5rem", sm: "1.5rem" } }}
66+
>
3067
{title}
3168
</DialogTitle>
3269
<DialogContent>{children}</DialogContent>
3370
<DialogActions>
34-
{cancelLabel && <Button variant="secondary">{cancelLabel}</Button>}
35-
{confirmLabel && <Button variant="primary">{confirmLabel}</Button>}
71+
{cancelLabel && (
72+
<Button variant="secondary" onClick={() => onCancel?.()}>
73+
Cancel
74+
</Button>
75+
)}
76+
{confirmLabel && (
77+
<Button variant="primary" onClick={() => onConfirm?.()}>
78+
Confirm
79+
</Button>
80+
)}
3681
</DialogActions>
3782
</MuiDialog>
3883
);

src/components/header/Header.module.css

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,6 @@
22
padding: 1rem;
33
}
44

5-
.toolbar {
6-
background-color: var(--primary-40);
7-
display: flex;
8-
justify-content: space-between;
9-
box-shadow: 0;
10-
padding: 0;
11-
}
12-
135
.burger {
146
color: var(--primary-99);
157
}

src/components/header/Header.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default function Header() {
2323
return (
2424
<>
2525
<AppBar position="fixed" sx={{ display: "block" }}>
26-
<Toolbar className={classes.toolbar}>
26+
<Toolbar>
2727
<Link href="/">
2828
<Image
2929
src="/img/compass-logo-white.svg"

src/theme.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,5 +408,16 @@ export const compassTheme = createTheme({
408408
indicatorColor: "transparent",
409409
},
410410
},
411+
MuiToolbar: {
412+
styleOverrides: {
413+
root: {
414+
backgroundColor: "var(--primary-40)",
415+
boxShadow: "0",
416+
display: "flex",
417+
justifyContent: "space-between",
418+
padding: "0",
419+
},
420+
},
421+
},
411422
},
412423
});

0 commit comments

Comments
 (0)