Skip to content

Commit 1b351be

Browse files
committed
Starting a reusable Dialog component
1 parent d9835c9 commit 1b351be

File tree

3 files changed

+95
-0
lines changed

3 files changed

+95
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import type { Meta, StoryObj } from "@storybook/react";
2+
3+
import Dialog from "./Dialog";
4+
5+
const meta: Meta<typeof Dialog> = {
6+
title: "Components/Design System/Dialog",
7+
component: Dialog,
8+
decorators: [
9+
(Story) => (
10+
<>
11+
<div id="anchor">
12+
<Story />
13+
</div>
14+
<div style={{ height: "8rem" }}></div>
15+
</>
16+
),
17+
],
18+
};
19+
export default meta;
20+
21+
type Story = StoryObj<typeof Dialog>;
22+
23+
export const Default: Story = {
24+
args: {
25+
open: true,
26+
size: "sm",
27+
title: "Dialog Test",
28+
children: <p style={{ width: "100%" }}>Testing, testing testing</p>,
29+
cancelLabel: "Cancel",
30+
confirmLabel: "Save",
31+
},
32+
};
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { ReactNode } from "react";
2+
import {
3+
Dialog as MuiDialog,
4+
DialogActions,
5+
DialogContent,
6+
DialogTitle,
7+
} from "@mui/material";
8+
import Button from "@/components/design_system/button/Button";
9+
10+
interface DialogProps {
11+
cancelLabel?: string;
12+
children: ReactNode;
13+
confirmLabel?: string;
14+
open: boolean;
15+
size: "xs" | "sm" | "md" | "lg" | "xl";
16+
title: ReactNode;
17+
}
18+
19+
function Dialog({
20+
cancelLabel,
21+
children,
22+
confirmLabel,
23+
open,
24+
size = "sm",
25+
title,
26+
}: DialogProps) {
27+
return (
28+
<MuiDialog open={open} fullWidth maxWidth={size}>
29+
<DialogTitle align="center" variant="h3">
30+
{title}
31+
</DialogTitle>
32+
<DialogContent>{children}</DialogContent>
33+
<DialogActions>
34+
{cancelLabel && <Button variant="secondary">{cancelLabel}</Button>}
35+
{confirmLabel && <Button variant="primary">{confirmLabel}</Button>}
36+
</DialogActions>
37+
</MuiDialog>
38+
);
39+
}
40+
41+
export default Dialog;

src/theme.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,28 @@ export const compassTheme = createTheme({
156156
disableRipple: true,
157157
},
158158
},
159+
MuiDialogActions: {
160+
styleOverrides: {
161+
root: {
162+
padding: ".5rem 1.5rem 1.5rem 1.5rem",
163+
},
164+
},
165+
},
166+
MuiDialogTitle: {
167+
styleOverrides: {
168+
root: {
169+
paddingTop: "1.5rem",
170+
paddingBottom: "2rem",
171+
},
172+
},
173+
},
174+
MuiDialogContent: {
175+
styleOverrides: {
176+
root: {
177+
padding: "0 1.5rem 1.5rem 1.5rem",
178+
},
179+
},
180+
},
159181
MuiInputLabel: {
160182
styleOverrides: {
161183
root: {

0 commit comments

Comments
 (0)