From 9407527d58fa31c34b105da185ba64acb5d17093 Mon Sep 17 00:00:00 2001 From: Matt Date: Mon, 13 Jan 2025 12:13:21 -0500 Subject: [PATCH] [Debt] Updates `Toast` component and `react-toastify` (#12426) * Update Toast * Update story * Remove role attribute role is on parent * Add ToastWithLink * Fix import order --- packages/toast/package.json | 3 +- .../src/components/Toast/Toast.stories.tsx | 81 +++--- packages/toast/src/components/Toast/Toast.tsx | 2 +- packages/toast/src/components/Toast/toast.css | 192 ++------------ .../src/components/ToastAlert/ToastAlert.tsx | 14 ++ .../components/ToastMessage/ToastMessage.tsx | 16 -- packages/toast/src/toast.tsx | 28 +-- pnpm-lock.yaml | 236 +++++++++++++++--- 8 files changed, 300 insertions(+), 272 deletions(-) create mode 100644 packages/toast/src/components/ToastAlert/ToastAlert.tsx delete mode 100644 packages/toast/src/components/ToastMessage/ToastMessage.tsx diff --git a/packages/toast/package.json b/packages/toast/package.json index b1c601f0b72..c11017c8ffa 100644 --- a/packages/toast/package.json +++ b/packages/toast/package.json @@ -16,12 +16,13 @@ }, "dependencies": { "@heroicons/react": "^2.2.0", - "react-toastify": "^10.0.6" + "react-toastify": "^11.0.2" }, "devDependencies": { "@faker-js/faker": "^9.3.0", "@gc-digital-talent/eslint-config": "workspace:*", "@gc-digital-talent/storybook-helpers": "workspace:*", + "@gc-digital-talent/ui": "workspace:*", "@storybook/react": "^8.4.7", "@types/react": "^18.3.13", "eslint": "^8.57.0", diff --git a/packages/toast/src/components/Toast/Toast.stories.tsx b/packages/toast/src/components/Toast/Toast.stories.tsx index 9cc5baa5114..789ebff51a2 100644 --- a/packages/toast/src/components/Toast/Toast.stories.tsx +++ b/packages/toast/src/components/Toast/Toast.stories.tsx @@ -1,43 +1,68 @@ -import type { StoryFn, Meta } from "@storybook/react"; -import { faker } from "@faker-js/faker/locale/en"; +import { useEffect } from "react"; +import type { Meta, StoryObj } from "@storybook/react"; -import { OverlayOrDialogDecorator } from "@gc-digital-talent/storybook-helpers"; +import { + allModes, + OverlayOrDialogDecorator, +} from "@gc-digital-talent/storybook-helpers"; +import { Link } from "@gc-digital-talent/ui"; import toast from "../../toast"; import Toast from "./Toast"; import "./toast.css"; -interface StoryArgs { - text: string; - longText: string; -} - -faker.seed(0); - -export default { +const meta = { component: Toast, + argTypes: { + disableTransition: { control: "boolean" }, + autoClose: { control: "boolean" }, + }, args: { - text: "Toast text", - longText: faker.lorem.sentences(3), + disableTransition: true, + autoClose: false, }, decorators: [OverlayOrDialogDecorator], -} as Meta; + parameters: { + chromatic: { + modes: { + light: allModes.light, + dark: allModes.dark, + }, + delay: 1500, + }, + }, +} satisfies Meta; +export default meta; -const Template: StoryFn = (args) => { - const { text, longText } = args; +type Story = StoryObj; - toast.info(text); - toast.info(longText); - toast.success(text); - toast.warning(text); - toast.error(text); +const ToastWithLink = () => ( + <> + Toast info with{" "} + + link + + +); - // avoid animations with Chromatic snapshots - return ( -
- -
- ); +const Template = () => { + useEffect(() => { + setTimeout(() => { + toast.info("Toast info text", { autoClose: false }); + toast.info(, { + autoClose: false, + }); + toast.info( + "Toast info with three sentences. Text sentence two. Toast text sentence three.", + { autoClose: false }, + ); + toast.success("Toast success text", { autoClose: false }); + toast.warning("Toast warning text", { autoClose: false }); + }, 100); + }, []); + return ; }; -export const Default = Template.bind({}); +export const Default: Story = { + render: () =>