Skip to content

Commit

Permalink
Add support for full screen dialogs (#3019)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesricky authored Jan 3, 2025
1 parent 9f2a127 commit 5ba64aa
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
12 changes: 12 additions & 0 deletions .changeset/four-terms-hope.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"@comet/admin-theme": minor
---

Add support and styling for full screen dialogs using the `fullScreen` prop

```tsx
<Dialog open fullScreen>
<DialogTitle>Dialog Title</DialogTitle>
<DialogContent>Dialog content</DialogContent>
</Dialog>
```
5 changes: 5 additions & 0 deletions packages/admin/admin-theme/src/componentsTheme/MuiDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,10 @@ export const getMuiDialog: GetMuiComponentTheme<"MuiDialog"> = (component, { spa
paperFullWidth: {
width: `calc(100% - ${spacing(16)})`,
},
paperFullScreen: {
borderRadius: 0,
maxWidth: "none",
margin: 0,
},
}),
});
29 changes: 9 additions & 20 deletions storybook/src/admin/mui/Dialog.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { CancelButton, Dialog, Field, FinalFormCheckbox, FinalFormInput, FinalFormSelect, OkayButton } from "@comet/admin";
import { CancelButton, CheckboxField, Dialog, OkayButton, SelectField, TextField } from "@comet/admin";
import { Save } from "@comet/admin-icons";
import { Button, DialogActions, DialogContent, DialogContentText, DialogProps, FormControlLabel, MenuItem } from "@mui/material";
import { Button, DialogActions, DialogContent, DialogContentText, DialogProps } from "@mui/material";
import { Form } from "react-final-form";

type DialogSize = Exclude<DialogProps["maxWidth"], false> | "fullWidth";
type DialogSize = Exclude<DialogProps["maxWidth"], false> | "fullWidth" | "fullScreen";

type DialogSizeOptions = {
[label: string]: DialogSize;
Expand All @@ -16,6 +16,7 @@ const dialogSizeOptions: DialogSizeOptions = {
"LG (1280px)": "lg",
"XL (1920px)": "xl",
FullWidth: "fullWidth",
FullScreen: "fullScreen",
};

const selectOptions = [
Expand Down Expand Up @@ -74,12 +75,12 @@ export const _Dialog = {
render={({ handleSubmit }) => (
<form onSubmit={handleSubmit}>
<Dialog
scroll="body"
title={selectedDialogTitle}
onClose={selectedDialogOnClose === "callback" ? () => console.log("Dialog closed") : undefined}
open={true}
fullWidth={selectedDialogSize === "fullWidth"}
maxWidth={selectedDialogSize !== "fullWidth" && selectedDialogSize}
fullScreen={selectedDialogSize === "fullScreen"}
maxWidth={selectedDialogSize !== "fullWidth" && selectedDialogSize !== "fullScreen" && selectedDialogSize}
>
<>{selectedDialogSize === "xs" ? <ConfirmationDialogContent /> : <DefaultDialogContent />}</>
</Dialog>
Expand Down Expand Up @@ -108,21 +109,9 @@ function DefaultDialogContent() {
Lorem ipsum nullam quis risus eget urna mollis ornare vel eu leo. Nullam id dolor id nibh ultricies vehicula ut id elit. Vivamus
sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Curabitur blandit tempus porttitor.
</DialogContentText>
<Field name="text" label="Textfield" component={FinalFormInput} fullWidth />
<Field name="select" label="Select" fullWidth>
{(props) => (
<FinalFormSelect {...props} fullWidth>
{selectOptions.map((option) => (
<MenuItem value={option.value} key={option.value}>
{option.label}
</MenuItem>
))}
</FinalFormSelect>
)}
</Field>
<Field name="checked" type="checkbox" fullWidth>
{(props) => <FormControlLabel label="Checkbox" control={<FinalFormCheckbox {...props} />} />}
</Field>
<TextField name="text" label="Textfield" fullWidth />
<SelectField name="select" label="Select" fullWidth options={selectOptions} />
<CheckboxField name="checked" label="Checkbox" fullWidth />
</DialogContent>
<DialogActions>
<CancelButton />
Expand Down

0 comments on commit 5ba64aa

Please sign in to comment.