diff --git a/src/components/Alert/Alert.stories.tsx b/src/components/Alert/Alert.stories.tsx index 45e3da65..3b480fd4 100644 --- a/src/components/Alert/Alert.stories.tsx +++ b/src/components/Alert/Alert.stories.tsx @@ -8,7 +8,18 @@ export default { export const Playground = { args: { - state: "success", + title: "", text: "An alert example", + state: "success", + size: "small", + type: "default", + showIcon: true, + dismissible: false }, + argTypes: { + state: { control: "select", options: ["neutral", "info", "success", "warning", "danger"] }, + type: { control: "radio", options: ["default", "banner"] }, + size: { control: "radio", options: ["medium", "small"] }, + } + }; diff --git a/src/components/Alert/Alert.tsx b/src/components/Alert/Alert.tsx index 7d11bc73..d6afc192 100644 --- a/src/components/Alert/Alert.tsx +++ b/src/components/Alert/Alert.tsx @@ -1,15 +1,17 @@ import { Icon } from "@/components"; import { IconName } from "@/components/Icon/types"; -import { useState } from "react"; +import { useState, ReactNode } from "react"; import styled from "styled-components"; +type AlertType = "default" | "banner" type AlertSize = "small" | "medium"; type AlertState = "neutral" | "success" | "warning" | "danger" | "info"; export type AlertProps = { state?: AlertState; title?: string; - text: string; + text: ReactNode; size?: AlertSize; + type?: AlertType; showIcon?: boolean; dismissible?: boolean; }; @@ -21,11 +23,13 @@ const stateIconMap: Record = { danger: "warning", info: "information", }; + const Alert = ({ text, title = "", size = "small", state = "neutral", + type = "default", showIcon = true, dismissible, ...delegated @@ -36,6 +40,7 @@ const Alert = ({ @@ -43,6 +48,7 @@ const Alert = ({ ` display: flex; - border-radius: ${props => props.theme.click.alert.radii.end}; + border-radius: ${({ $type, theme }) => + $type === "banner" ? theme.sizes[0] : theme.click.alert.radii.end}; + justify-content: ${({ $type }) => + $type === "banner" ? "center" : "start"}; overflow: hidden; background-color: ${({ $state = "neutral", theme }) => theme.click.alert.color.background[$state]}; color: ${({ $state = "neutral", theme }) => theme.click.alert.color.text[$state]}; `; -const IconWrapper = styled.div<{ $state: AlertState; $size: AlertSize }>` +const IconWrapper = styled.div<{ $state: AlertState; $size: AlertSize; $type: AlertType }>` display: flex; align-items: center; + background-color: ${({ $state = "neutral", $type, theme }) => + $type === "banner" ? "none" : theme.click.alert.color.iconBackground[$state]}; ${({ $state = "neutral", $size, theme }) => ` - background-color: ${theme.click.alert.color.iconBackground[$state]}; color: ${theme.click.alert.color.iconForeground[$state]}; padding: ${theme.click.alert[$size].space.y} ${theme.click.alert[$size].space.x}; `}