Skip to content

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

GDGT-2460 Update Toast styles (#80327)

Stas Gavrylova90f1170baf4
diff --git a/.loki/reference/chrome_laptop_Design_System_Colors_Default.png b/.loki/reference/chrome_laptop_Design_System_Colors_Default.png
index edce4a5c715..774267e3f09 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/Toaster/Toaster.module.css b/frontend/src/metabase/common/components/Toaster/Toaster.module.css
new file mode 100644
index 00000000000..06d4eb29a72
--- /dev/null
+++ b/frontend/src/metabase/common/components/Toaster/Toaster.module.css
@@ -0,0 +1,132 @@
+.toast {
+ position: relative;
+ bottom: -0.625rem;
+ overflow-x: hidden;
+ min-width: 18.75rem;
+ max-width: 31.25rem;
+ width: fit-content;
+ padding: var(--mantine-spacing-md);
+ background-color: var(--mb-color-tooltip-background);
+
+ /* Radius from Figma, no matching step in Mantine. */
+ border-radius: 0.75rem;
+ box-shadow: var(--mantine-shadow-sm);
+ opacity: 0;
+ transition: all 200ms ease-out;
+}
+
+/* Hide the Notification's colored side line. */
+.toast::before {
+ display: none;
+}
+
+[data-mantine-color-scheme="dark"] .toast {
+ border: 0.5px solid var(--mb-color-border-neutral-strong);
+}
+
+.toast[data-show] {
+ bottom: 0;
+ opacity: 1;
+}
+
+.toast[data-fixed] {
+ position: fixed;
+ bottom: 0.625rem;
+ left: 1.25rem;
+}
+
+.toast[data-fixed][data-show] {
+ bottom: 1.25rem;
+}
+
+.icon {
+ width: auto;
+ height: auto;
+ margin-right: var(--mantine-spacing-sm);
+ background-color: transparent;
+ color: var(--mb-color-tooltip-text);
+}
+
+.body {
+ min-width: 0;
+ margin-right: 0;
+}
+
+.message {
+ line-height: var(--mantine-line-height-lg);
+ overflow-wrap: anywhere;
+}
+
+.button {
+ padding: var(--mantine-spacing-xs) var(--mantine-spacing-sm);
+ border-radius: var(--mantine-radius-sm);
+ font-size: var(--mantine-font-size-sm);
+ font-weight: bold;
+ line-height: var(--mantine-line-height-lg);
+ white-space: nowrap;
+ flex-shrink: 0;
+ cursor: pointer;
+ transition: background-color 200ms ease;
+ box-shadow: var(--mantine-shadow-xs);
+}
+
+.button:disabled {
+ background-color: var(--mb-color-button-on_dark-disabled);
+ color: var(--mb-color-button-label-on_dark-disabled);
+ border: none;
+ box-shadow: none;
+ cursor: default;
+}
+
+.primary {
+ background-color: var(--mb-color-button-on_dark-primary-default);
+ color: var(--mb-color-button-label-on_dark-primary);
+}
+
+.primary:hover:not(:disabled) {
+ background-color: var(--mb-color-button-on_dark-primary-hover);
+}
+
+.primary:active:not(:disabled) {
+ background-color: var(--mb-color-button-on_dark-primary-pressed);
+}
+
+.secondary {
+ background-color: var(--mb-color-button-on_dark-secondary-default);
+ color: var(--mb-color-button-label-on_dark-secondary);
+ border: 0.5px solid var(--mb-color-border-on_dark);
+}
+
+.secondary:hover:not(:disabled) {
+ background-color: var(--mb-color-button-on_dark-secondary-hover);
+}
+
+.secondary:active:not(:disabled) {
+ background-color: var(--mb-color-button-on_dark-secondary-pressed);
+}
+
+.dismiss {
+ width: 1.5rem;
+ height: 1.5rem;
+ min-width: 0;
+ min-height: 0;
+ flex-shrink: 0;
+ margin-left: var(--mantine-spacing-lg);
+ border-radius: var(--mantine-radius-xs);
+ color: var(--mb-color-tooltip-text);
+ cursor: pointer;
+ transition: background-color 200ms ease;
+}
+
+.toast[data-has-actions] .dismiss {
+ margin-left: var(--mantine-spacing-md);
+}
+
+.dismiss:hover {
+ background-color: var(--mb-color-button-on_dark-secondary-hover);
+ color: var(--mb-color-tooltip-text);
+}
+
+.dismiss:active {
+ background-color: var(--mb-color-button-on_dark-secondary-pressed);
+}
diff --git a/frontend/src/metabase/common/components/Toaster/Toaster.stories.tsx b/frontend/src/metabase/common/components/Toaster/Toaster.stories.tsx
index dd7c3b32221..b2c639a4f25 100644
--- a/frontend/src/metabase/common/components/Toaster/Toaster.stories.tsx
+++ b/frontend/src/metabase/common/components/Toaster/Toaster.stories.tsx
@@ -1,10 +1,42 @@
import type { StoryFn } from "@storybook/react";
-import { Toaster, type ToasterProps } from "./Toaster";
+import { Icon, Stack } from "metabase/ui";
+import {
+ StoryJsx,
+ StorySection,
+ StoryShowcase,
+} from "metabase/ui/stories/showcase";
+
+import { Toast, Toaster, type ToasterProps } from "./Toaster";
export default {
title: "App/Dashboard/Toaster",
component: Toaster,
+ argTypes: {
+ message: { control: { type: "text" } },
+ confirmText: { control: { type: "text" } },
+ secondaryText: { control: { type: "text" } },
+ isShown: { control: { type: "boolean" } },
+ fixed: { control: { type: "boolean" } },
+ leftSection: {
+ options: ["none", "icon"],
+ mapping: {
+ none: undefined,
+ icon: <Icon name="model" size={16} c="tooltip-text" />,
+ },
+ control: { type: "radio" },
+ },
+ rightSection: {
+ options: ["none", "icon"],
+ mapping: {
+ none: undefined,
+ icon: <Icon name="gear" size={16} c="tooltip-text" />,
+ },
+ control: { type: "radio" },
+ },
+ onConfirm: { action: "confirmed" },
+ onDismiss: { action: "dismissed" },
+ },
};
const Template: StoryFn<ToasterProps> = (args) => {
@@ -17,12 +49,114 @@ export const Default = {
args: {
message:
"Would you like to be notified when this dashboard is done loading?",
+ confirmText: "Turn on",
+ secondaryText: "Later",
isShown: true,
+ fixed: false,
+ leftSection: "none",
+ rightSection: "none",
onConfirm: () => {
alert("Confirmed");
},
+ onSecondary: () => {
+ alert("Secondary");
+ },
onDismiss: () => {
alert("Dismissed");
},
},
};
+
+const noop = () => undefined;
+
+export const Overview = {
+ render: () => (
+ <StoryShowcase title="Toast">
+ <StorySection
+ title="No buttons"
+ description="Message with icon and a close button."
+ >
+ <Stack gap="sm" align="flex-start">
+ <StoryJsx>{`<Toast message="..." leftSection={<Icon name="model" size={16} />} onDismiss={...} />`}</StoryJsx>
+ <Toast
+ show
+ message="The title goes here"
+ leftSection={<Icon name="model" size={16} c="tooltip-text" />}
+ onDismiss={noop}
+ />
+ </Stack>
+ </StorySection>
+
+ <StorySection title="One button" description="A primary confirm action.">
+ <Stack gap="sm" align="flex-start">
+ <StoryJsx>{`<Toast message="..." confirmText="Button" onConfirm={...} onDismiss={...} />`}</StoryJsx>
+ <Toast
+ show
+ message="The title goes here"
+ leftSection={<Icon name="model" size={16} c="tooltip-text" />}
+ confirmText="Button"
+ onConfirm={noop}
+ onDismiss={noop}
+ />
+ </Stack>
+ </StorySection>
+
+ <StorySection
+ title="Two buttons"
+ description="Primary confirm plus a secondary action."
+ >
+ <Stack gap="sm" align="flex-start">
+ <StoryJsx>{`<Toast message="..." confirmText="Apply" secondaryText="Cancel" onConfirm={...} onSecondary={...} />`}</StoryJsx>
+ <Toast
+ show
+ message="The title goes here"
+ leftSection={<Icon name="model" size={16} c="tooltip-text" />}
+ confirmText="Apply"
+ secondaryText="Cancel"
+ onConfirm={noop}
+ onSecondary={noop}
+ onDismiss={noop}
+ />
+ </Stack>
+ </StorySection>
+
+ <StorySection
+ title="Not closable"
+ description="The close button can be hidden (as used by the dashboard filter-apply toast)."
+ >
+ <Stack gap="sm" align="flex-start">
+ <StoryJsx>{`<Toast message="..." canClose={false} confirmText="Apply" secondaryText="Cancel" />`}</StoryJsx>
+ <Toast
+ show
+ canClose={false}
+ message="You've changed 2 filters."
+ confirmText="Apply"
+ secondaryText="Cancel"
+ onConfirm={noop}
+ onSecondary={noop}
+ />
+ </Stack>
+ </StorySection>
+
+ <StorySection
+ title="Long message"
+ description="The message wraps; buttons keep their size."
+ >
+ <Stack gap="sm" align="flex-start">
+ <Toast
+ show
+ message="This is a much longer toast message that should wrap onto multiple lines to demonstrate how the toast lays out its content when the text does not fit on a single line."
+ confirmText="Confirm"
+ secondaryText="Cancel"
+ onConfirm={noop}
+ onSecondary={noop}
+ onDismiss={noop}
+ />
+ </Stack>
+ </StorySection>
+ </StoryShowcase>
+ ),
+ parameters: {
+ controls: { include: ["theme"] },
+ },
+};
diff --git a/frontend/src/metabase/common/components/Toaster/Toaster.styled.tsx b/frontend/src/metabase/common/components/Toaster/Toaster.styled.tsx
deleted file mode 100644
index 4e01bd96513..00000000000
--- a/frontend/src/metabase/common/components/Toaster/Toaster.styled.tsx
+++ /dev/null
@@ -1,77 +0,0 @@
-// eslint-disable-next-line no-restricted-imports
-import styled from "@emotion/styled";
-
-interface ToasterContainerProps {
- show: boolean;
- fixed?: boolean;
-}
-
-export const ToasterContainer = styled.div<ToasterContainerProps>`
- display: flex;
- flex-direction: row;
- overflow-x: hidden;
- min-width: 300px;
- max-width: 500px;
- width: fit-content;
- background-color: var(--mb-color-text-primary);
- padding: 16px;
- border-radius: 6px;
- ${(props) =>
- props.fixed
- ? `position: fixed;
- bottom: ${props.show ? "20px" : "10px"};
- left: 20px;`
- : `position: relative;
- bottom: ${props.show ? "0px" : "-10px"};`}
- opacity: ${(props) => (props.show ? 1 : 0)};
- transition: all 200ms ease-out;
- column-gap: 16px;
- align-items: center;
-`;
-
-export const ToasterMessage = styled.p`
- color: var(--mb-color-text-primary-inverse);
- min-width: 150px;
- max-width: 320px;
- flex: 1;
- line-height: 24px;
- font-size: 14px;
- margin: 0;
-`;
-
-export const ToasterButton = styled.button`
- display: flex;
- padding: 7px 18px;
- background-color: color-mix(
- in srgb,
- var(--mb-color-background_page-primary) 10%,
- transparent
- );
- border-radius: 6px;
- color: var(--mb-color-text-primary-inverse);
- height: fit-content;
- font-size: 14px;
- font-weight: bold;
- transition: background 200ms ease;
- white-space: nowrap;
- flex-shrink: 0;
-
- &:hover {
- cursor: pointer;
- background-color: color-mix(
- in srgb,
- var(--mb-color-background_page-primary) 30%,
- transparent
- );
- }
-`;
-
-export const ToasterDismiss = styled.button`
- cursor: pointer;
- transition: color 200ms ease;
- color: var(--mb-color-text-primary-inverse);
-
- &:hover {
- color: color-mix(in srgb, var(--mb-color-text-primary-inverse), white 30%);
- }
-`;
diff --git a/frontend/src/metabase/common/components/Toaster/Toaster.tsx b/frontend/src/metabase/common/components/Toaster/Toaster.tsx
index 1bfe7f97441..34bdc845e7c 100644
--- a/frontend/src/metabase/common/components/Toaster/Toaster.tsx
+++ b/frontend/src/metabase/common/components/Toaster/Toaster.tsx
@@ -1,17 +1,25 @@
-import type { HTMLAttributes } from "react";
+import cx from "classnames";
+import type { HTMLAttributes, ReactNode } from "react";
import { useEffect, useState } from "react";
import { t } from "ttag";
-import { Icon, Portal } from "metabase/ui";
-
import {
- ToasterButton,
- ToasterContainer,
- ToasterDismiss,
- ToasterMessage,
-} from "./Toaster.styled";
+ Group,
+ Icon,
+ Notification,
+ Portal,
+ Text,
+ UnstyledButton,
+} from "metabase/ui";
+
+import S from "./Toaster.module.css";
-export interface ToastProps extends HTMLAttributes<HTMLDivElement> {
+// `color` is omitted because the native HTML attribute's `string` type
+// conflicts with Mantine's `NotificationProps["color"]` union.
+export interface ToastProps extends Omit<
+ HTMLAttributes<HTMLDivElement>,
+ "color"
+> {
message: string;
confirmText?: string;
confirmAriaLabel?: string;
@@ -21,7 +29,9 @@ export interface ToastProps extends HTMLAttributes<HTMLDivElement> {
canClose?: boolean;
secondaryText?: string;
secondaryAriaLabel?: string;
- onConfirm: () => void;
+ leftSection?: ReactNode;
+ rightSection?: ReactNode;
+ onConfirm?: () => void;
onDismiss?: () => void;
onSecondary?: () => void;
"data-testid"?: string;
@@ -37,53 +47,91 @@ export const Toast = ({
canClose = true,
secondaryText,
secondaryAriaLabel = t`Cancel`,
+ leftSection,
+ rightSection,
onConfirm,
onDismiss,
onSecondary,
className,
"data-testid": dataTestId = "toast",
...divProps
-}: ToastProps): JSX.Element => (
- <ToasterContainer
- data-testid={dataTestId}
- show={show}
- fixed={fixed}
- className={className}
- {...divProps}
- >
- <ToasterMessage>{message}</ToasterMessage>
- {secondaryText && onSecondary && (
- <ToasterButton onClick={onSecondary} aria-label={secondaryAriaLabel}>
- {secondaryText}
- </ToasterButton>
- )}
- <ToasterButton onClick={onConfirm} aria-label={confirmAriaLabel}>
- {confirmText}
- </ToasterButton>
- {canClose && (
- <ToasterDismiss onClick={onDismiss} aria-label={closeAriaLabel}>
- <Icon name="close" />
- </ToasterDismiss>
- )}
- </ToasterContainer>
-);
+}: ToastProps): JSX.Element => {
+ const hasActions = Boolean(
+ onConfirm || (secondaryText && onSecondary) || rightSection,
+ );
+
+ return (
+ <Notification
+ className={cx(S.toast, className)}
+ classNames={{
+ icon: S.icon,
+ body: S.body,
+ closeButton: S.dismiss,
+ }}
+ data-testid={dataTestId}
+ data-show={show ? true : undefined}
+ data-fixed={fixed ? true : undefined}
+ data-has-actions={hasActions ? true : undefined}
+ icon={leftSection}
+ withBorder={false}
+ withCloseButton={canClose}
+ onClose={onDismiss}
+ closeButtonProps={{
+ "aria-label": closeAriaLabel,
+ icon: <Icon name="close" size={12} />,
+ }}
+ {...divProps}
+ >
+ <Group gap="lg" align="center" wrap="nowrap">
+ <Text className={S.message} flex={1} c="tooltip-text" fz="md">
+ {message}
+ </Text>
+ {hasActions && (
+ <Group gap="sm" align="center" wrap="nowrap">
+ {onConfirm && (
+ <UnstyledButton
+ className={cx(S.button, S.primary)}
+ onClick={onConfirm}
+ aria-label={confirmAriaLabel}
+ >
+ {confirmText}
+ </UnstyledButton>
+ )}
+ {secondaryText && onSecondary && (
+ <UnstyledButton
+ className={cx(S.button, S.secondary)}
+ onClick={onSecondary}
+ aria-label={secondaryAriaLabel}
+ >
+ {secondaryText}
+ </UnstyledButton>
+ )}
+ {rightSection}
+ </Group>
+ )}
+ </Group>
+ </Notification>
+ );
+};
export interface ToasterProps extends HTMLAttributes<HTMLDivElement> {
message: string;
confirmText?: string;
isShown: boolean;
fixed?: boolean;
+ leftSection?: ReactNode;
+ rightSection?: ReactNode;
onConfirm: () => void;
onDismiss: () => void;
}
-// TODO: Port to Mantine Notifications or consolidate with Undo-style toasts or
-// BulkActionsToast
export const Toaster = ({
message,
confirmText = t`Turn on`,
isShown,
fixed,
+ leftSection,
+ rightSection,
onConfirm,
onDismiss,
className,
@@ -113,6 +161,8 @@ export const Toaster = ({
confirmText={confirmText}
show={open}
fixed={fixed}
+ leftSection={leftSection}
+ rightSection={rightSection}
onConfirm={onConfirm}
onDismiss={onDismiss}
className={className}
diff --git a/frontend/src/metabase/ui/colors/constants/themes/dark.ts b/frontend/src/metabase/ui/colors/constants/themes/dark.ts
index daaa5dbdfc0..17a97997e0a 100644
--- a/frontend/src/metabase/ui/colors/constants/themes/dark.ts
+++ b/frontend/src/metabase/ui/colors/constants/themes/dark.ts
@@ -129,6 +129,17 @@ const actualColors = {
"border-neutral-strong": baseColors.orionAlphaInverse[30],
"border-neutral-strongest": baseColors.orionAlphaInverse[50],
"border-neutral-subtle": baseColors.orionAlphaInverse[10],
+ "border-on_dark": baseColors.orionAlphaInverse[20],
+ "button-label-on_dark-disabled": baseColors.orionAlphaInverse[40],
+ "button-label-on_dark-primary": baseColors.orionAlpha[80],
+ "button-label-on_dark-secondary": baseColors.white,
+ "button-on_dark-disabled": baseColors.orionAlphaInverse[10],
+ "button-on_dark-primary-default": baseColors.white,
+ "button-on_dark-primary-hover": baseColors.orion[20],
+ "button-on_dark-primary-pressed": baseColors.orion[30],
+ "button-on_dark-secondary-default": baseColors.orionAlphaInverse[10],
+ "button-on_dark-secondary-hover": baseColors.orionAlphaInverse[20],
+ "button-on_dark-secondary-pressed": baseColors.orionAlphaInverse[10],
"core-blue-saturated": baseColors.ocean[40],
"core-brand-hover": baseColors.brand[30],
"core-gold": baseColors.gold,
diff --git a/frontend/src/metabase/ui/colors/constants/themes/light.ts b/frontend/src/metabase/ui/colors/constants/themes/light.ts
index 3e8eddc5c1c..c879d82b868 100644
--- a/frontend/src/metabase/ui/colors/constants/themes/light.ts
+++ b/frontend/src/metabase/ui/colors/constants/themes/light.ts
@@ -127,6 +127,17 @@ const actualColors = {
"border-neutral-strong": baseColors.orionAlpha[30],
"border-neutral-strongest": baseColors.orionAlpha[50],
"border-neutral-subtle": baseColors.orionAlpha[10],
+ "border-on_dark": baseColors.orionAlphaInverse[20],
+ "button-label-on_dark-disabled": baseColors.orionAlphaInverse[40],
+ "button-label-on_dark-primary": baseColors.orionAlpha[80],
+ "button-label-on_dark-secondary": baseColors.white,
+ "button-on_dark-disabled": baseColors.orionAlphaInverse[10],
+ "button-on_dark-primary-default": baseColors.white,
+ "button-on_dark-primary-hover": baseColors.orion[20],
+ "button-on_dark-primary-pressed": baseColors.orion[30],
+ "button-on_dark-secondary-default": baseColors.orionAlphaInverse[10],
+ "button-on_dark-secondary-hover": baseColors.orionAlphaInverse[20],
+ "button-on_dark-secondary-pressed": baseColors.orionAlphaInverse[10],
"core-blue-saturated": baseColors.ocean[60],
"core-brand-hover": baseColors.brand[50],
"core-gold": baseColors.gold,
diff --git a/frontend/src/metabase/ui/colors/types/color-keys.ts b/frontend/src/metabase/ui/colors/types/color-keys.ts
index 24ec64bf9a0..fa9317473db 100644
--- a/frontend/src/metabase/ui/colors/types/color-keys.ts
+++ b/frontend/src/metabase/ui/colors/types/color-keys.ts
@@ -119,6 +119,17 @@ export type MetabaseColorKey =
| "border-neutral-strong"
| "border-neutral-strongest"
| "border-neutral-subtle"
+ | "border-on_dark"
+ | "button-label-on_dark-disabled"
+ | "button-label-on_dark-primary"
+ | "button-label-on_dark-secondary"
+ | "button-on_dark-disabled"
+ | "button-on_dark-primary-default"
+ | "button-on_dark-primary-hover"
+ | "button-on_dark-primary-pressed"
+ | "button-on_dark-secondary-default"
+ | "button-on_dark-secondary-hover"
+ | "button-on_dark-secondary-pressed"
| "core-blue-saturated"
| "core-brand"
| "core-brand-hover"
diff --git a/frontend/src/metabase/ui/components/feedback/Notification/index.ts b/frontend/src/metabase/ui/components/feedback/Notification/index.ts
new file mode 100644
index 00000000000..19175633ef5
--- /dev/null
+++ b/frontend/src/metabase/ui/components/feedback/Notification/index.ts
@@ -0,0 +1,2 @@
+export { Notification } from "@mantine/core";
+export type { NotificationProps } from "@mantine/core";
diff --git a/frontend/src/metabase/ui/components/feedback/index.ts b/frontend/src/metabase/ui/components/feedback/index.ts
index c0035c3e0c8..cc3af303e0b 100644
--- a/frontend/src/metabase/ui/components/feedback/index.ts
+++ b/frontend/src/metabase/ui/components/feedback/index.ts
@@ -1,5 +1,6 @@
export * from "./Loader";
export * from "./Alert";
+export * from "./Notification";
export * from "./Progress";
export * from "./RingProgress";
export * from "./Skeleton";