Skip to content

Commit

Permalink
Adding banner style alert (#199)
Browse files Browse the repository at this point in the history
* Adding banner style alert

* Using token rather than a number.

---------

Co-authored-by: Fábio Neves <[email protected]>
  • Loading branch information
gjones and fneves authored Nov 7, 2023
1 parent 91441c9 commit aa160ec
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
13 changes: 12 additions & 1 deletion src/components/Alert/Alert.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"] },
}

};
21 changes: 16 additions & 5 deletions src/components/Alert/Alert.tsx
Original file line number Diff line number Diff line change
@@ -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;
};
Expand All @@ -21,11 +23,13 @@ const stateIconMap: Record<AlertState, IconName> = {
danger: "warning",
info: "information",
};

const Alert = ({
text,
title = "",
size = "small",
state = "neutral",
type = "default",
showIcon = true,
dismissible,
...delegated
Expand All @@ -36,13 +40,15 @@ const Alert = ({
<Wrapper
$size={size}
$state={state}
$type={type}
data-testid="click-alert"
{...delegated}
>
{showIcon && (
<IconWrapper
$state={state}
$size={size}
$type={type}
>
<StyledIcon
$size={size}
Expand Down Expand Up @@ -77,20 +83,25 @@ const Alert = ({
const Wrapper = styled.div<{
$state: AlertState;
$size: AlertSize;
$type: AlertType;
}>`
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};
`}
Expand Down

1 comment on commit aa160ec

@vercel
Copy link

@vercel vercel bot commented on aa160ec Nov 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

click-ui – ./

click-ui-clickhouse.vercel.app
click-ui.vercel.app
click-ui-git-main-clickhouse.vercel.app

Please sign in to comment.