Elffuss BraidHub

kikocis/continue public

c657d7bd6e88 · 1.5 KiBRawPermalink
1import {
2 CheckCircleIcon,
3 ExclamationCircleIcon,
4 ExclamationTriangleIcon,
5 InformationCircleIcon,
6} from "@heroicons/react/24/solid";
7import { ReactNode } from "react";
8import { vscBackground } from "..";
9
10type AlertTypes = "info" | "success" | "warning" | "error";
11type AlertSize = "sm" | "lg";
12
13export interface AlertProps {
14 children?: ReactNode;
15 type?: AlertTypes;
16 size?: AlertSize;
17}
18
19type AlertConfig = {
20 [key in AlertTypes]: {
21 Icon: any;
22 };
23};
24
25const ALERT_CONFIGS: AlertConfig = {
26 info: {
27 Icon: InformationCircleIcon,
28 },
29 success: {
30 Icon: CheckCircleIcon,
31 },
32 warning: {
33 Icon: ExclamationTriangleIcon,
34 },
35 error: {
36 Icon: ExclamationCircleIcon,
37 },
38};
39
40const alertSizes = {
41 sm: "px-2 py-1.5 rounded border-l-2",
42 lg: "px-4 py-3 rounded-lg border-l-4",
43};
44
45const iconSizes = {
46 sm: "h-3 w-3",
47 lg: "h-5 w-5",
48};
49
50const spacingSizes = {
51 sm: "ml-1.5",
52 lg: "ml-3",
53};
54
55function Alert({ children, type = "info", size = "lg" }: AlertProps) {
56 const { Icon } = ALERT_CONFIGS[type];
57
58 return (
59 <div
60 className={`bg-editor-foreground opacity-70 shadow-none ${alertSizes[size]}`}
61 >
62 <div className="flex items-center">
63 <Icon
64 className={`flex-shrink-0 ${iconSizes[size]}`}
65 style={{ color: vscBackground }}
66 />
67
68 <div className={spacingSizes[size]} style={{ color: vscBackground }}>
69 {children}
70 </div>
71 </div>
72 </div>
73 );
74}
75
76export default Alert;