diff --git a/src/components/Alert/Alert.stories.tsx b/src/components/Alert/Alert.stories.tsx index 92cd8a23c0e..ffe3aa755ee 100644 --- a/src/components/Alert/Alert.stories.tsx +++ b/src/components/Alert/Alert.stories.tsx @@ -5,7 +5,7 @@ import { Meta, StoryObj } from "@storybook/react" import Alert from "." const meta = { - title: "Molecules / Action Feedback / Alerts", + title: "Molecules / Action Feedback / Old Alerts", component: Alert, decorators: [ (Story) => ( diff --git a/src/components/ui/__stories__/Alert.stories.tsx b/src/components/ui/__stories__/Alert.stories.tsx new file mode 100644 index 00000000000..2488d7968a9 --- /dev/null +++ b/src/components/ui/__stories__/Alert.stories.tsx @@ -0,0 +1,87 @@ +import * as React from "react" +import { MdInfoOutline } from "react-icons/md" +import { Meta, StoryObj } from "@storybook/react" + +import { + Alert, + AlertCloseButton, + AlertContent, + AlertDescription, + AlertTitle, +} from "../alert" +import { Center } from "../flex" + +const meta = { + title: "Molecules / Action Feedback / Alerts", + component: Alert, + parameters: { + layout: "none", + }, + decorators: [ + (Story) => ( +
+ +
+ ), + ], +} satisfies Meta + +export default meta + +type Story = StoryObj + +const DEMO_TITLE = "Alert or callout title" +const DEMO_DESC = "This is an alert to be used for important information." + +const VARIANTS = ["info", "error", "success", "warning", "update"] as const + +export const Variants: Story = { + render: (args) => ( +
+ {VARIANTS.map((variant) => ( + + + {DEMO_TITLE} + This is a {variant} alert + + + ))} +
+ ), +} + +export const WithCloseButton: Story = { + render: (args) => ( +
+ {VARIANTS.map((variant) => ( + + + {DEMO_TITLE} + {DEMO_DESC} + + + + ))} +
+ ), +} + +export const Banner: Story = { + render: (args) => ( +
+ {VARIANTS.map((variant) => ( + + + + Banner use case + +

{DEMO_DESC}

+

{DEMO_DESC}

+
+
+ +
+ ))} +
+ ), +} diff --git a/src/components/ui/alert.tsx b/src/components/ui/alert.tsx new file mode 100644 index 00000000000..98bf3af0e4b --- /dev/null +++ b/src/components/ui/alert.tsx @@ -0,0 +1,92 @@ +import * as React from "react" +import { cva, type VariantProps } from "class-variance-authority" +import { MdClose } from "react-icons/md" + +import { cn } from "@/lib/utils/cn" + +import { Button } from "./buttons/Button" + +const alertVariants = cva( + "flex flex-row gap-4 items-center rounded-lg border p-4", + { + variants: { + variant: { + info: "bg-background-highlight border", + error: + "border-error bg-error-light [&_h6]:text-error [&_svg]:text-error text-gray-800", + success: + "border-success bg-success-light [&_h6]:text-success [&_svg]:text-success text-gray-800", + warning: + "border-attention-outline bg-attention-light [&_h6]:text-attention [&_svg]:text-attention text-gray-800", + update: + "bg-primary-low-contrast border-primary-high-contrast [&_h6]:text-primary-high-contrast [&_svg]:text-primary-high-contrast", + }, + size: { + // Useful for banner alerts + full: "rounded-none border-none w-full", + }, + }, + defaultVariants: { + variant: "info", + }, + } +) + +const Alert = React.forwardRef< + HTMLDivElement, + React.HTMLAttributes & VariantProps +>(({ className, variant, size, ...props }, ref) => ( +
+)) +Alert.displayName = "Alert" + +const AlertContent = React.forwardRef< + HTMLDivElement, + React.HTMLAttributes +>(({ className, ...props }, ref) => ( +
+)) +AlertContent.displayName = "AlertContent" + +const AlertTitle = React.forwardRef< + HTMLParagraphElement, + React.HTMLAttributes +>(({ className, ...props }, ref) => ( +
+)) +AlertTitle.displayName = "AlertTitle" + +const AlertDescription = React.forwardRef< + HTMLParagraphElement, + React.HTMLAttributes +>(({ className, ...props }, ref) => ( +
+)) +AlertDescription.displayName = "AlertDescription" + +const AlertCloseButton = React.forwardRef< + HTMLButtonElement, + React.ButtonHTMLAttributes +>(({ className, ...props }, ref) => ( + +)) +AlertCloseButton.displayName = "AlertCloseButton" + +export { Alert, AlertCloseButton, AlertContent, AlertDescription, AlertTitle } diff --git a/src/styles/global.css b/src/styles/global.css index c9665543ce5..3c7d61dd69e 100644 --- a/src/styles/global.css +++ b/src/styles/global.css @@ -148,7 +148,9 @@ /* Complementary Set */ --attention-outline: var(--attention-light); - --error-light: var(--error-light); + --error: var(--red-500); + --error-light: var(--red-100); + --error-outline: var(--error); /* ! Deprecating error-neutral */ --error-netural: var(--red-900);