Skip to content

Commit 0b9ba45

Browse files
committed
feat: add defaults to InfoBox
1 parent c8e141a commit 0b9ba45

File tree

1 file changed

+47
-4
lines changed
  • packages/component-library/src/InfoBox

1 file changed

+47
-4
lines changed

packages/component-library/src/InfoBox/index.tsx

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
"use client";
22

3+
import {
4+
Confetti,
5+
DotOutline,
6+
HardDrives,
7+
Info,
8+
WarningCircle,
9+
XCircle,
10+
} from "@phosphor-icons/react";
311
import clsx from "clsx";
412
import type { ComponentProps, ReactNode } from "react";
513

@@ -14,9 +22,44 @@ export const VARIANTS = [
1422
"success",
1523
] as const;
1624

25+
const DEFAULTS: Default = {
26+
neutral: {
27+
header: "-",
28+
icon: <DotOutline />,
29+
},
30+
info: {
31+
header: "Info",
32+
icon: <Info />,
33+
},
34+
warning: {
35+
header: "Warning",
36+
icon: <WarningCircle />,
37+
},
38+
error: {
39+
header: "Error",
40+
icon: <XCircle />,
41+
},
42+
data: {
43+
header: "Data",
44+
icon: <HardDrives />,
45+
},
46+
success: {
47+
header: "Success",
48+
icon: <Confetti />,
49+
},
50+
};
51+
52+
type Default = Record<
53+
(typeof VARIANTS)[number],
54+
{
55+
header: string;
56+
icon: ReactNode;
57+
}
58+
>;
59+
1760
type Props = ComponentProps<"div"> & {
18-
icon: ReactNode;
19-
header: ReactNode;
61+
icon?: ReactNode;
62+
header?: ReactNode;
2063
variant?: (typeof VARIANTS)[number] | undefined;
2164
};
2265

@@ -33,9 +76,9 @@ export const InfoBox = ({
3376
data-variant={variant}
3477
{...props}
3578
>
36-
<div className={styles.icon}>{icon}</div>
79+
<div className={styles.icon}>{icon ?? DEFAULTS[variant].icon}</div>
3780
<div className={styles.body}>
38-
<h3 className={styles.header}>{header}</h3>
81+
<h3 className={styles.header}>{header ?? DEFAULTS[variant].header}</h3>
3982
<div className={styles.contents}>{children}</div>
4083
</div>
4184
</div>

0 commit comments

Comments
 (0)