Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

GDGT-3288: Restyle Modal to the Figma spec (#83518)

Will Fry828cd7661ce2
diff --git a/.loki/reference/chrome_laptop_Components_Overlays_Modal_Opened.png b/.loki/reference/chrome_laptop_Components_Overlays_Modal_Opened.png
index 5762b35d473..25fa59e172e 100644
Binary files a/.loki/reference/chrome_laptop_Components_Overlays_Modal_Opened.png and b/.loki/reference/chrome_laptop_Components_Overlays_Modal_Opened.png differ
diff --git a/.loki/reference/chrome_laptop_Design_System_Colors_Default.png b/.loki/reference/chrome_laptop_Design_System_Colors_Default.png
index db456e30be7..7ade1240daf 100644
Binary files a/.loki/reference/chrome_laptop_Design_System_Colors_Default.png and b/.loki/reference/chrome_laptop_Design_System_Colors_Default.png differ
diff --git a/frontend/src/metabase/common/components/ConfirmModal/ConfirmModal.tsx b/frontend/src/metabase/common/components/ConfirmModal/ConfirmModal.tsx
index db5ee4ea5cc..edc73a27379 100644
--- a/frontend/src/metabase/common/components/ConfirmModal/ConfirmModal.tsx
+++ b/frontend/src/metabase/common/components/ConfirmModal/ConfirmModal.tsx
@@ -5,9 +5,9 @@ import _ from "underscore";
import {
Button,
type ButtonProps,
- Flex,
Modal,
type ModalProps,
+ Stack,
Text,
} from "metabase/ui";
@@ -51,34 +51,32 @@ export const ConfirmModal = ({
return (
<Modal title={title} onClose={onClose} size="lg" {...props}>
- <Flex direction="column" gap="xl" mt="lg">
+ <Stack gap="xl">
{content ? <Text>{content}</Text> : null}
<Text>{message}</Text>
- <Flex align="center" justify="space-between" gap="lg">
- {errorMessage ? (
- <Text c="feedback-negative">{errorMessage} </Text>
- ) : (
- <div />
- )}
- <Flex align="center" justify="flex-end" gap="lg">
- {closeButtonText && (
- <Button {...closeButtonProps} onClick={onClose}>
- {closeButtonText}
- </Button>
- )}
- <Button
- color="negative"
- variant="filled"
- data-autofocus
- {...confirmButtonProps}
- disabled={confirmButtonProps.disabled || confirming}
- onClick={handleConfirm}
- >
- {confirmButtonText}
- </Button>
- </Flex>
- </Flex>
- </Flex>
+ </Stack>
+ <Modal.Footer>
+ {errorMessage && (
+ <Text c="feedback-negative" flex={1}>
+ {errorMessage}
+ </Text>
+ )}
+ {closeButtonText && (
+ <Button {...closeButtonProps} onClick={onClose}>
+ {closeButtonText}
+ </Button>
+ )}
+ <Button
+ color="negative"
+ variant="filled"
+ data-autofocus
+ {...confirmButtonProps}
+ disabled={confirmButtonProps.disabled || confirming}
+ onClick={handleConfirm}
+ >
+ {confirmButtonText}
+ </Button>
+ </Modal.Footer>
</Modal>
);
};
diff --git a/frontend/src/metabase/common/components/Sidesheet/Sidesheet.tsx b/frontend/src/metabase/common/components/Sidesheet/Sidesheet.tsx
index 89ff073e8c3..3f494a0db0d 100644
--- a/frontend/src/metabase/common/components/Sidesheet/Sidesheet.tsx
+++ b/frontend/src/metabase/common/components/Sidesheet/Sidesheet.tsx
@@ -59,7 +59,11 @@ export function Sidesheet({
h="100dvh"
>
{withOverlay && (
- <Modal.Overlay {...overlayProps} data-testid="modal-overlay" />
+ <Modal.Overlay
+ bg="overlay"
+ {...overlayProps}
+ data-testid="modal-overlay"
+ />
)}
<Modal.Content
transitionProps={{ duration: 0 }}
@@ -78,6 +82,7 @@ export function Sidesheet({
aria-labelledby={titleId}
>
<Modal.Header
+ className={Styles.SidesheetHeader}
bg="background_surface-primary"
px={SIDESHEET_HORIZONTAL_PADDING}
pt="xl"
diff --git a/frontend/src/metabase/common/components/Sidesheet/sidesheet.module.css b/frontend/src/metabase/common/components/Sidesheet/sidesheet.module.css
index 16ed14844ec..777c7e960e4 100644
--- a/frontend/src/metabase/common/components/Sidesheet/sidesheet.module.css
+++ b/frontend/src/metabase/common/components/Sidesheet/sidesheet.module.css
@@ -23,6 +23,13 @@
}
}
+.SidesheetHeader {
+ /* Modal headers top-align the title against a 24px close button; ours is larger */
+ &:not([data-css-specificity-hack="🤷‍♀️"]) {
+ align-items: center;
+ }
+}
+
.SidesheetCloseButton {
/* Modal.module.css uses !important for the close color and icon size. */
color: var(--mb-color-text-primary) !important;
diff --git a/frontend/src/metabase/ui/colors/constants/base-colors.ts b/frontend/src/metabase/ui/colors/constants/base-colors.ts
index 200e38a454b..a350c26de7f 100644
--- a/frontend/src/metabase/ui/colors/constants/base-colors.ts
+++ b/frontend/src/metabase/ui/colors/constants/base-colors.ts
@@ -8,6 +8,10 @@
const baseColors = {
white: "hsla(0, 0%, 100%, 1.00)",
black: "hsla(0, 0%, 0%, 1.00)",
+ blackAlpha: {
+ 10: "hsla(0, 0%, 0%, 0.10)",
+ 35: "hsla(0, 0%, 0%, 0.35)",
+ },
transparent: "hsla(0, 0%, 100%, 0)",
gold: "hsla(50.6, 100%, 50%, 1)",
upsellGem: "hsla(190, 100%, 50%, 1)",
diff --git a/frontend/src/metabase/ui/colors/constants/themes/dark.ts b/frontend/src/metabase/ui/colors/constants/themes/dark.ts
index 9f3761956b1..7cf92620f7f 100644
--- a/frontend/src/metabase/ui/colors/constants/themes/dark.ts
+++ b/frontend/src/metabase/ui/colors/constants/themes/dark.ts
@@ -240,7 +240,8 @@ const getActualColors = (brand: BrandRamp) => ({
"illustration-tertiary-brand": brand[90],
"input-background": baseColors.orionAlphaInverse[10],
"input-focus": baseColors.blue[70],
- "modal-overlay": baseColors.orionAlpha[70],
+ "modal-border": baseColors.orionAlphaInverse[30], // Matches border-neutral-strong
+ "modal-overlay": baseColors.blackAlpha[35],
"navbar-admin": baseColors.octopus[80],
"navbar-admin-inverse": baseColors.octopus[60],
"navbar-admin-secondary": baseColors.octopus[60],
diff --git a/frontend/src/metabase/ui/colors/constants/themes/light.ts b/frontend/src/metabase/ui/colors/constants/themes/light.ts
index 3290931d456..f06030b958f 100644
--- a/frontend/src/metabase/ui/colors/constants/themes/light.ts
+++ b/frontend/src/metabase/ui/colors/constants/themes/light.ts
@@ -246,7 +246,8 @@ const getActualColors = (brand: BrandRamp) => ({
"illustration-tertiary-brand": brand[5],
"input-background": baseColors.orionAlpha[5],
"input-focus": baseColors.blue[20],
- "modal-overlay": baseColors.orionAlpha[60],
+ "modal-border": baseColors.transparent,
+ "modal-overlay": baseColors.blackAlpha[10],
"navbar-admin": baseColors.octopus[60],
"navbar-admin-inverse": baseColors.octopus[80],
"navbar-admin-secondary": baseColors.octopus[40],
diff --git a/frontend/src/metabase/ui/colors/types/color-keys.ts b/frontend/src/metabase/ui/colors/types/color-keys.ts
index 58a8bea2004..f8d1328000a 100644
--- a/frontend/src/metabase/ui/colors/types/color-keys.ts
+++ b/frontend/src/metabase/ui/colors/types/color-keys.ts
@@ -229,6 +229,7 @@ export type MetabaseColorKey =
| "illustration-tertiary-brand"
| "input-background"
| "input-focus"
+ | "modal-border"
| "modal-overlay"
| "segmented_control-hover"
| "segmented_control-pressed"
diff --git a/frontend/src/metabase/ui/components/overlays/Modal/Modal.config.tsx b/frontend/src/metabase/ui/components/overlays/Modal/Modal.config.tsx
index 6bff05de7a9..37c84286db4 100644
--- a/frontend/src/metabase/ui/components/overlays/Modal/Modal.config.tsx
+++ b/frontend/src/metabase/ui/components/overlays/Modal/Modal.config.tsx
@@ -22,6 +22,7 @@ export const modalOverrides = {
content: cx(Styles.content, ZIndex.Overlay, Animation.popInFromBottom),
inner: cx(ZIndex.Overlay, Layout.left, Animation.popInFromBottom),
header: Styles.header,
+ body: Styles.body,
close: Styles.ModalCloseButton,
},
}),
@@ -31,15 +32,16 @@ export const modalOverrides = {
centered: true,
size: "lg",
shadow: "lg_outline",
- radius: "xs",
- padding: "lg",
+ radius: "lg",
+ padding: DEFAULT_MODAL_SPACING,
withinPortal: true,
},
}),
- ModalHeader: Modal.Header.extend({
+ // The content is a Paper, which would otherwise use the Paper theme radius
+ ModalContent: Modal.Content.extend({
defaultProps: {
- pb: "sm",
+ radius: "lg",
},
}),
diff --git a/frontend/src/metabase/ui/components/overlays/Modal/Modal.mdx b/frontend/src/metabase/ui/components/overlays/Modal/Modal.mdx
index e2c75066b85..70269ac3f86 100644
--- a/frontend/src/metabase/ui/components/overlays/Modal/Modal.mdx
+++ b/frontend/src/metabase/ui/components/overlays/Modal/Modal.mdx
@@ -14,6 +14,33 @@ Our themed wrapper around [Mantine Modal](https://v6.mantine.dev/core/modal/).
- [Mantine Modal Docs](https://v6.mantine.dev/core/modal/)
+## Usage
+
+Pass the heading as `title` and put the action buttons in a `Modal.Footer` as the last child, so the title, body and buttons always get the same placement and spacing.
+
+```tsx
+<Modal title={t`Delete this database?`} opened={opened} onClose={onClose}>
+ <Text>{t`This can't be undone.`}</Text>
+ <Modal.Footer>
+ <Button onClick={onClose}>{t`Cancel`}</Button>
+ <Button variant="filled" color="negative">{t`Delete`}</Button>
+ </Modal.Footer>
+</Modal>
+```
+
+### Layouts
+
+- `layout="default"` left-aligns the title and body, and right-aligns the buttons.
+- `layout="centered"` centre-aligns everything, stacks the buttons with the primary one on top, and shows an optional `illustration` above the title.
+
+Don't confuse `layout` with Mantine's `centered` prop, which sets the modal's vertical position in the viewport.
+
+<Canvas of={ModalStories.Overview} />
+
+### Custom layouts
+
+`Modal.Root`, `Modal.Overlay`, `Modal.Content`, `Modal.Header`, `Modal.Title`, `Modal.CloseButton` and `Modal.Body` are an escape hatch for modals that don't fit the standard structure, such as side sheets. Prefer the props above where you can.
+
## Guidelines
### Modal headings should be in sentence case.
diff --git a/frontend/src/metabase/ui/components/overlays/Modal/Modal.module.css b/frontend/src/metabase/ui/components/overlays/Modal/Modal.module.css
index 92d3022a414..76b22034386 100644
--- a/frontend/src/metabase/ui/components/overlays/Modal/Modal.module.css
+++ b/frontend/src/metabase/ui/components/overlays/Modal/Modal.module.css
@@ -3,9 +3,9 @@
}
.title {
- font-size: var(--mantine-font-size-xl);
+ font-size: var(--mantine-h4-font-size);
font-weight: var(--mantine-heading-font-weight);
- line-height: var(--mantine-line-height-md);
+ line-height: var(--mantine-h4-line-height);
flex: 1 1 auto;
min-width: 0;
overflow-wrap: break-word;
@@ -17,26 +17,73 @@
}
.content {
- background-color: var(--mb-color-background_page-primary);
- border: 1px solid var(--mb-color-border-neutral);
+ background-color: var(--mb-color-background_surface-primary);
+ border: 0.5px solid var(--mb-color-modal-border);
}
.header {
- background-color: var(--mb-color-background_page-primary);
+ align-items: flex-start;
+ gap: var(--mantine-spacing-md);
+ padding-bottom: var(--mantine-spacing-lg);
+ padding-inline-end: var(--mantine-spacing-xl);
+ background-color: var(--mb-color-background_surface-primary);
+
+ /* Centres a single-line title against the close button */
+ .title {
+ padding-block: var(--mantine-spacing-xxxs);
+ }
}
.ModalCloseButton {
- color: var(--mb-color-text-disabled) !important;
- padding: 0;
- width: rem(18px);
- height: rem(18px);
+ --cb-size: rem(24px);
+ --cb-icon-size: rem(12px);
+ --cb-radius: var(--mantine-radius-xxs);
+
+ color: var(--mb-color-icon-primary);
+ background-color: var(--mb-color-button-subtle-neutral-default);
&:hover {
- color: var(--mb-color-text-secondary) !important;
+ background-color: var(--mb-color-button-subtle-neutral-hover);
+ }
+
+ &:active {
+ background-color: var(--mb-color-button-subtle-neutral-pressed);
+ }
+}
+
+.footer {
+ display: flex;
+ justify-content: flex-end;
+ align-items: center;
+ gap: var(--mantine-spacing-md);
+ margin-top: var(--mantine-spacing-lg);
+}
+
+.centeredHeading {
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ gap: var(--mantine-spacing-xl);
+ margin-bottom: var(--mantine-spacing-xxs);
+}
+
+.root[data-layout="centered"] {
+ .header {
+ justify-content: flex-end;
+ }
+
+ .body {
+ padding-inline: var(--mantine-spacing-xxl);
+ padding-bottom: rem(64px);
+ text-align: center;
}
- svg {
- width: 20px !important;
- height: 20px !important;
+ .footer {
+ flex-direction: column-reverse;
+ align-items: stretch;
+ width: rem(256px);
+ max-width: 100%;
+ margin-top: var(--mantine-spacing-xl);
+ margin-inline: auto;
}
}
diff --git a/frontend/src/metabase/ui/components/overlays/Modal/Modal.stories.tsx b/frontend/src/metabase/ui/components/overlays/Modal/Modal.stories.tsx
index 269c9ef0e9f..b5bb9ce44c5 100644
--- a/frontend/src/metabase/ui/components/overlays/Modal/Modal.stories.tsx
+++ b/frontend/src/metabase/ui/components/overlays/Modal/Modal.stories.tsx
@@ -1,11 +1,37 @@
-import { useState } from "react";
+import type { StoryFn } from "@storybook/react";
+import { Fragment, type ReactNode, useState } from "react";
-import { Box, Button, Flex, Modal, type ModalProps, Text } from "metabase/ui";
+import {
+ Box,
+ Button,
+ Checkbox,
+ Flex,
+ MODAL_LAYOUTS,
+ Modal,
+ type ModalLayout,
+ type ModalProps,
+ Select,
+ SimpleGrid,
+ Stack,
+ Text,
+ TextInput,
+ Textarea,
+} from "metabase/ui";
+import {
+ StoryJsx,
+ StoryLabel,
+ StoryShowcase,
+} from "metabase/ui/stories/showcase";
+
+import S from "./Modal.module.css";
+import { NO_ANIMATION_MODAL_PROPS } from "./constants";
const args = {
centered: true,
fullScreen: false,
+ layout: "default",
size: "md",
+ withCloseButton: true,
};
const argTypes = {
@@ -15,6 +41,10 @@ const argTypes = {
fullScreen: {
control: { type: "boolean" },
},
+ layout: {
+ options: MODAL_LAYOUTS,
+ control: { type: "inline-radio" },
+ },
title: {
control: { type: "text" },
},
@@ -24,6 +54,67 @@ const argTypes = {
options: ["xs", "sm", "md", "lg", "xl", "auto"],
},
},
+ withCloseButton: {
+ control: { type: "boolean" },
+ },
+};
+
+// Figma's placeholder is #D9D9D9 (light) / #5C666E (dark); border-neutral is the closest token
+const IllustrationPlaceholder = () => (
+ <Box w={96} h={96} bg="border-neutral" style={{ borderRadius: "50%" }} />
+);
+
+const InviteTeammateForm = ({ onCancel }: { onCancel?: () => void }) => (
+ <form onSubmit={(event) => event.preventDefault()}>
+ <Stack gap="md">
+ <Text>{"They'll get an email with a link to set up their account."}</Text>
+ <SimpleGrid cols={2} spacing="md">
+ <TextInput label="First name" placeholder="Ada" />
+ <TextInput label="Last name" placeholder="Lovelace" />
+ </SimpleGrid>
+ <TextInput label="Email" placeholder="[email protected]" type="email" />
+ <Select
+ label="Group"
+ data={["All Users", "Analysts", "Administrators"]}
+ defaultValue="All Users"
+ />
+ <Textarea
+ label="Message"
+ description="Optional. Included in the invite email."
+ placeholder="Welcome aboard!"
+ minRows={3}
+ autosize
+ />
+ <Checkbox label="Send a reminder if they haven't joined after a week" />
+ </Stack>
+ <Modal.Footer>
+ <Button onClick={onCancel}>Cancel</Button>
+ <Button type="submit" variant="filled">
+ Send invite
+ </Button>
+ </Modal.Footer>
+ </form>
+);
+
+const WithFormTemplate = (args: ModalProps) => {
+ const [isOpen, setOpen] = useState(false);
+ const handleOpen = () => setOpen(true);
+ const handleClose = () => setOpen(false);
+ return (
+ <Flex justify="center">
+ <Button variant="filled" onClick={handleOpen}>
+ Open example
+ </Button>
+ <Modal
+ title="Invite a teammate"
+ {...args}
+ opened={isOpen}
+ onClose={handleClose}
+ >
+ <InviteTeammateForm onCancel={handleClose} />
+ </Modal>
+ </Flex>
+ );
};
const SimpleWithTitleTemplate = (args: ModalProps) => {
@@ -41,11 +132,11 @@ const SimpleWithTitleTemplate = (args: ModalProps) => {
opened={isOpen}
onClose={handleClose}
>
- <Flex direction="row" justify="flex-end" mt="lg">
- <Button type="submit" variant="filled" ml="sm">
+ <Modal.Footer>
+ <Button type="submit" variant="filled">
Add
</Button>
- </Flex>
+ </Modal.Footer>
</Modal>
</Flex>
);
@@ -70,14 +161,12 @@ const ConfirmationTemplate = (args: ModalProps) => {
This cannot be undone, and questions that rely on this data will no
longer work.
</Text>
- <Flex direction="row" justify="flex-end" mt="lg">
- <Button type="submit" ml="sm">
- Cancel
- </Button>
- <Button type="submit" variant="filled" color="negative" ml="sm">
+ <Modal.Footer>
+ <Button onClick={handleClose}>Cancel</Button>
+ <Button type="submit" variant="filled" color="negative">
Delete
</Button>
- </Flex>
+ </Modal.Footer>
</Modal>
</Flex>
);
@@ -99,11 +188,11 @@ const SingleButtonTemplate = (args: ModalProps) => {
onClose={handleClose}
>
<Text>Sometimes all you need is one option.</Text>
- <Flex direction="row" justify="flex-end" mt="lg">
- <Button type="submit" variant="filled" ml="sm">
+ <Modal.Footer>
+ <Button type="submit" variant="filled">
Add
</Button>
- </Flex>
+ </Modal.Footer>
</Modal>
</Flex>
);
@@ -113,11 +202,11 @@ const OpenedTemplate = (args: ModalProps) => (
<Box w="100vw" h="100vh">
<Modal {...args} title="Add to dashboard?" opened onClose={() => undefined}>
<Text>Choose a dashboard for this question.</Text>
- <Flex direction="row" justify="flex-end" mt="lg">
+ <Modal.Footer>
<Button type="submit" variant="filled">
Add
</Button>
- </Flex>
+ </Modal.Footer>
</Modal>
</Box>
);
@@ -137,17 +226,217 @@ const NoBodyTextTemplate = (args: ModalProps) => {
opened={isOpen}
onClose={handleClose}
>
- <Flex direction="row" justify="flex-end" mt="lg">
+ <Modal.Footer>
<Button onClick={handleClose}>Not now</Button>
- <Button type="submit" variant="filled" ml="sm">
+ <Button type="submit" variant="filled">
Add
</Button>
- </Flex>
+ </Modal.Footer>
</Modal>
</Flex>
);
};
+const CenteredTemplate = (args: ModalProps) => {
+ const [isOpen, setOpen] = useState(false);
+ const handleOpen = () => setOpen(true);
+ const handleClose = () => setOpen(false);
+ return (
+ <Flex justify="center">
+ <Button variant="filled" onClick={handleOpen}>
+ Open example
+ </Button>
+ <Modal
+ title="Your trial has started"
+ illustration={<IllustrationPlaceholder />}
+ {...args}
+ layout="centered"
+ opened={isOpen}
+ onClose={handleClose}
+ >
+ <Text>You have 14 days to try out every feature.</Text>
+ <Modal.Footer>
+ <Button onClick={handleClose}>Maybe later</Button>
+ <Button variant="filled">Get started</Button>
+ </Modal.Footer>
+ </Modal>
+ </Flex>
+ );
+};
+
+interface OverviewRow {
+ id: string;
+ label: string;
+ title: string;
+ body?: string;
+ withCloseButton?: boolean;
+ footer?: ReactNode;
+ /** Replaces the body and footer, e.g. a form that wraps both */
+ content?: ReactNode;
+ /** Layouts to show the row in. Defaults to all of them */
+ layouts?: readonly ModalLayout[];
+ height?: number;
+}
+
+const PRIMARY_BUTTON = <Button variant="filled">Button</Button>;
+
+const OVERVIEW_ROWS: readonly OverviewRow[] = [
+ {
+ id: "single-button",
+ label: "One button",
+ title: "Modal",
+ body: "An accessible overlay dialog.",
+ footer: PRIMARY_BUTTON,
+ },
+ {
+ id: "two-buttons",
+ label: "Two buttons",
+ title: "Modal",
+ body: "An accessible overlay dialog.",
+ footer: (
+ <>
+ <Button>Cancel</Button>
+ {PRIMARY_BUTTON}
+ </>
+ ),
+ },
+ {
+ id: "close-hover",
+ label: "Close button hover",
+ title: "Modal",
+ body: "An accessible overlay dialog.",
+ footer: PRIMARY_BUTTON,
+ },
+ {
+ id: "no-close-button",
+ label: "No close button",
+ title: "Modal",
+ body: "An accessible overlay dialog.",
+ withCloseButton: false,
+ footer: PRIMARY_BUTTON,
+ },
+ {
+ id: "no-body",
+ label: "No body text",
+ title: "Modal",
+ footer: PRIMARY_BUTTON,
+ },
+ {
+ id: "long-title",
+ label: "Long title",
+ title:
+ "A much longer modal title that wraps onto a second line to show how it sits next to the close button",
+ body: "An accessible overlay dialog.",
+ footer: PRIMARY_BUTTON,
+ },
+ {
+ id: "footer-message",
+ label: "Footer message",
+ title: "Modal",
+ body: "An accessible overlay dialog.",
+ footer: (
+ <>
+ <Text c="feedback-negative" flex={1}>
+ Something went wrong
+ </Text>
+ <Button>Cancel</Button>
+ {PRIMARY_BUTTON}
+ </>
+ ),
+ },
+ {
+ id: "form",
+ label: "Form",
+ title: "Invite a teammate",
+ content: <InviteTeammateForm />,
+ layouts: ["default"],
+ height: 680,
+ },
+];
+
+const OVERVIEW_CELL_WIDTH = 480;
+const OVERVIEW_CELL_HEIGHT = 480;
+
+const OverviewCell = ({
+ row,
+ layout,
+}: {
+ row: OverviewRow;
+ layout: ModalLayout;
+}) => (
+ // The transform makes the cell the containing block for the modal's
+ // fixed-position wrapper, so each modal renders inside its own cell.
+ <Box
+ data-state-row={row.id}
+ pos="relative"
+ w={OVERVIEW_CELL_WIDTH}
+ h={row.height ?? OVERVIEW_CELL_HEIGHT}
+ style={{ transform: "translateZ(0)" }}
+ >
+ <Modal
+ {...NO_ANIMATION_MODAL_PROPS}
+ opened
+ onClose={() => undefined}
+ withinPortal={false}
+ withOverlay={false}
+ lockScroll={false}
+ trapFocus={false}
+ returnFocus={false}
+ // The default offsets are viewport units, which would shrink the
+ // modal inside its fixed-size cell as the window gets wider
+ xOffset={0}
+ yOffset={0}
+ size={432}
+ layout={layout}
+ title={row.title}
+ withCloseButton={row.withCloseButton ?? true}
+ illustration={
+ layout === "centered" ? <IllustrationPlaceholder /> : undefined
+ }
+ >
+ {row.content ?? (
+ <>
+ {row.body && <Text>{row.body}</Text>}
+ <Modal.Footer>{row.footer}</Modal.Footer>
+ </>
+ )}
+ </Modal>
+ </Box>
+);
+
+const OverviewTemplate: StoryFn<ModalProps> = () => (
+ <StoryShowcase title="Modal">
+ <Box
+ style={{
+ display: "grid",
+ gridTemplateColumns: `9rem repeat(${MODAL_LAYOUTS.length}, max-content)`,
+ columnGap: "2rem",
+ rowGap: "1rem",
+ alignItems: "center",
+ }}
+ >
+ <div />
+ {MODAL_LAYOUTS.map((layout) => (
+ <StoryJsx key={layout}>{`<Modal layout="${layout}" />`}</StoryJsx>
+ ))}
+ {OVERVIEW_ROWS.map((row) => (
+ <Fragment key={row.id}>
+ <StoryLabel>{row.label}</StoryLabel>
+ {MODAL_LAYOUTS.map((layout) =>
+ (row.layouts ?? MODAL_LAYOUTS).includes(layout) ? (
+ <OverviewCell key={layout} row={row} layout={layout} />
+ ) : (
+ <StoryLabel key={layout}>
+ Use the default layout for forms
+ </StoryLabel>
+ ),
+ )}
+ </Fragment>
+ ))}
+ </Box>
+ </StoryShowcase>
+);
+
export default {
title: "Components/Overlays/Modal",
component: Modal,
@@ -155,6 +444,16 @@ export default {
argTypes,
};
+export const Overview = {
+ render: OverviewTemplate,
+ parameters: {
+ pseudo: {
+ hover: [`[data-state-row="close-hover"] .${S.ModalCloseButton}`],
+ },
+ controls: { include: ["theme"] },
+ },
+};
+
export const SentenceCaseTitles = {
render: SimpleWithTitleTemplate,
name: "Sentence case titles",
@@ -164,6 +463,15 @@ export const Confirmation = {
render: ConfirmationTemplate,
};
+export const WithForm = {
+ render: WithFormTemplate,
+ name: "With form",
+};
+
+export const Centered = {
+ render: CenteredTemplate,
+};
+
export const Opened = {
render: OpenedTemplate,
};
diff --git a/frontend/src/metabase/ui/components/overlays/Modal/index.tsx b/frontend/src/metabase/ui/components/overlays/Modal/index.tsx
index fb0c59936a2..65071d5091c 100644
--- a/frontend/src/metabase/ui/components/overlays/Modal/index.tsx
+++ b/frontend/src/metabase/ui/components/overlays/Modal/index.tsx
@@ -1,21 +1,57 @@
import {
+ Box,
+ type BoxProps,
+ type ElementProps,
Modal as MantineModal,
- type ModalProps,
- type ModalRootProps,
+ type ModalProps as MantineModalProps,
+ type ModalRootProps as MantineModalRootProps,
} from "@mantine/core";
+import cx from "classnames";
+import type { ReactNode } from "react";
import { PreventEagerPortal } from "metabase/ui";
import { useGatedCloseProps } from "metabase/ui/components/overlays/overlay-stack";
import { useDisableCommandPalette } from "metabase/ui/hooks/use-disable-command-palette";
-export type { ModalProps } from "@mantine/core";
+import S from "./Modal.module.css";
+
export { useModalsStack } from "@mantine/core";
export * from "./Modal.config";
export * from "./constants";
-export function Modal(props: ModalProps) {
+export const MODAL_LAYOUTS = ["default", "centered"] as const;
+
+export type ModalLayout = (typeof MODAL_LAYOUTS)[number];
+
+interface ModalLayoutProps {
+ /**
+ * How the modal's contents are arranged. `default` left-aligns the title
+ * and body and right-aligns the footer buttons. `centered` centre-aligns
+ * everything, stacks the footer buttons, and puts the title (and any
+ * `illustration`) at the top of the body.
+ */
+ layout?: ModalLayout;
+}
+
+export interface ModalProps extends MantineModalProps, ModalLayoutProps {
+ /** Rendered above the title. Only used by the `centered` layout. */
+ illustration?: ReactNode;
+}
+
+export interface ModalRootProps
+ extends MantineModalRootProps, ModalLayoutProps {}
+
+export function Modal({
+ layout = "default",
+ illustration,
+ title,
+ children,
+ ...props
+}: ModalProps) {
const closeProps = useGatedCloseProps(props);
+ const isCentered = layout === "centered";
+ const hasCenteredHeading = isCentered && (illustration != null || !!title);
useDisableCommandPalette({
disabled: props.opened,
@@ -25,14 +61,24 @@ export function Modal(props: ModalProps) {
<PreventEagerPortal {...props}>
<MantineModal
{...props}
+ data-layout={layout}
+ title={isCentered ? undefined : title}
closeOnClickOutside={closeProps.closeOnClickOutside}
closeOnEscape={closeProps.closeOnEscape}
- />
+ >
+ {hasCenteredHeading && (
+ <div className={S.centeredHeading}>
+ {illustration}
+ {title && <MantineModal.Title>{title}</MantineModal.Title>}
+ </div>
+ )}
+ {children}
+ </MantineModal>
</PreventEagerPortal>
);
}
-function ModalRoot(props: ModalRootProps) {
+function ModalRoot({ layout = "default", ...props }: ModalRootProps) {
const closeProps = useGatedCloseProps(props);
useDisableCommandPalette({
@@ -42,12 +88,20 @@ function ModalRoot(props: ModalRootProps) {
<PreventEagerPortal>
<MantineModal.Root
{...props}
+ data-layout={layout}
closeOnClickOutside={closeProps.closeOnClickOutside}
closeOnEscape={closeProps.closeOnEscape}
/>
</PreventEagerPortal>
);
}
+
+export interface ModalFooterProps extends BoxProps, ElementProps<"div"> {}
+
+function ModalFooter({ className, ...props }: ModalFooterProps) {
+ return <Box className={cx(S.footer, className)} {...props} />;
+}
+
Modal.Root = ModalRoot;
Modal.Overlay = MantineModal.Overlay;
Modal.Content = MantineModal.Content;
@@ -55,4 +109,5 @@ Modal.CloseButton = MantineModal.CloseButton;
Modal.Header = MantineModal.Header;
Modal.Title = MantineModal.Title;
Modal.Body = MantineModal.Body;
+Modal.Footer = ModalFooter;
// Modal.NativeScrollArea = MantineModal.NativeScrollArea;