Skip to content

Commit d081862

Browse files
authored
Merge pull request #479 from code0-tech/feat/#474
Alert component
2 parents 9c1d4e5 + 7bdd513 commit d081862

File tree

4 files changed

+77
-0
lines changed

4 files changed

+77
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import {Meta} from "@storybook/react";
2+
import {Alert} from "./Alert";
3+
import React from "react";
4+
5+
export default {
6+
title: "Alert",
7+
component: Alert
8+
} as Meta
9+
10+
export const AlertExample = () => {
11+
return <Alert color={"error"}>
12+
This is an alert message!
13+
</Alert>
14+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
@use "../../styles/helpers";
2+
@use "../../styles/box";
3+
@use "../../styles/variables";
4+
5+
.alert {
6+
padding: variables.$md;
7+
font-size: variables.$sm;
8+
position: relative;
9+
display: flex;
10+
align-items: center;
11+
gap: variables.$xxs;
12+
13+
& {
14+
@include helpers.fontStyle();
15+
@include helpers.borderRadius();
16+
}
17+
18+
> svg {
19+
min-width: variables.$md;
20+
min-height: variables.$md;
21+
}
22+
}
23+
24+
@each $name, $color in variables.$colors {
25+
.alert--#{$name} {
26+
@include box.box($color);
27+
}
28+
}

src/components/alert/Alert.tsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import React from "react";
2+
import {Code0Component, Color, mergeCode0Props} from "../../utils";
3+
import {
4+
IconAlertCircle,
5+
IconCircleCheck,
6+
IconCircleDot,
7+
IconCircleX,
8+
IconInfoCircle,
9+
IconProps
10+
} from "@tabler/icons-react";
11+
import "./Alert.style.scss"
12+
13+
export interface AlertProps extends Code0Component<HTMLDivElement> {
14+
color?: Color
15+
children: React.ReactNode
16+
}
17+
18+
export const Alert: React.FC<AlertProps> = (props) => {
19+
const {color = "secondary", children, ...rest} = props
20+
21+
const icons: Record<Color, React.ReactElement<IconProps>> = {
22+
"primary": <IconCircleDot size={16}/>,
23+
"secondary": <IconCircleDot size={16}/>,
24+
"info": <IconInfoCircle size={16}/>,
25+
"success": <IconCircleCheck size={16}/>,
26+
"warning": <IconAlertCircle size={16}/>,
27+
"error": <IconCircleX size={16}/>,
28+
}
29+
30+
return <div {...mergeCode0Props(`alert alert--${color}`, rest)}>
31+
{icons[color]}
32+
{children}
33+
</div>
34+
}

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export * from "./components/alert/Alert"
12
export * from "./components/avatar/Avatar"
23
export * from "./components/badge/Badge"
34
export * from "./components/breadcrumb/Breadcrumb"

0 commit comments

Comments
 (0)