From 93f590b06d970f46c76b6f4b5674f1f340a09816 Mon Sep 17 00:00:00 2001 From: Pablo Pettinari Date: Fri, 9 Aug 2024 18:51:44 +0200 Subject: [PATCH 1/3] add new shadcn alert component --- src/components/Alert/Alert.stories.tsx | 2 +- .../ui/__stories__/Alert.stories.tsx | 89 ++++++++++++++++++ src/components/ui/alert.tsx | 92 +++++++++++++++++++ src/styles/global.css | 4 +- 4 files changed, 185 insertions(+), 2 deletions(-) create mode 100644 src/components/ui/__stories__/Alert.stories.tsx create mode 100644 src/components/ui/alert.tsx 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..ee6d8cda40a --- /dev/null +++ b/src/components/ui/__stories__/Alert.stories.tsx @@ -0,0 +1,89 @@ +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..df199ddf232 --- /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 "../../../tailwind/ui/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 c221c3b83e9..4f6ce60ee64 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); From f97757392536fca06dfc9634b56f796e23d629db Mon Sep 17 00:00:00 2001 From: Pablo Pettinari Date: Tue, 13 Aug 2024 16:55:04 +0200 Subject: [PATCH 2/3] fix import --- src/components/ui/alert.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/ui/alert.tsx b/src/components/ui/alert.tsx index df199ddf232..98bf3af0e4b 100644 --- a/src/components/ui/alert.tsx +++ b/src/components/ui/alert.tsx @@ -4,7 +4,7 @@ import { MdClose } from "react-icons/md" import { cn } from "@/lib/utils/cn" -import { Button } from "../../../tailwind/ui/buttons/Button" +import { Button } from "./buttons/Button" const alertVariants = cva( "flex flex-row gap-4 items-center rounded-lg border p-4", From d5ee22b2dd0ccbac7c376e492f40d86e21d8de05 Mon Sep 17 00:00:00 2001 From: Pablo Pettinari Date: Thu, 15 Aug 2024 14:20:28 +0200 Subject: [PATCH 3/3] remove pre tag --- src/components/ui/__stories__/Alert.stories.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/components/ui/__stories__/Alert.stories.tsx b/src/components/ui/__stories__/Alert.stories.tsx index ee6d8cda40a..2488d7968a9 100644 --- a/src/components/ui/__stories__/Alert.stories.tsx +++ b/src/components/ui/__stories__/Alert.stories.tsx @@ -42,9 +42,7 @@ export const Variants: Story = { {DEMO_TITLE} - - This is a
{variant}
alert -
+ This is a {variant} alert
))}