Skip to content

Commit 192f33f

Browse files
committed
fix: make Callout a thin wrapper around InfoBox to set suitable defaults
1 parent 02bc77e commit 192f33f

File tree

2 files changed

+30
-195
lines changed

2 files changed

+30
-195
lines changed

apps/developer-hub/src/components/Callout/index.module.scss

Lines changed: 0 additions & 136 deletions
This file was deleted.
Lines changed: 30 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,37 @@
1-
"use client";
1+
import { InfoBox, VARIANTS } from "@pythnetwork/component-library/InfoBox";
2+
import type { ComponentProps, ReactNode } from "react";
3+
import { Case } from "../Case";
24

3-
import { Link } from "@pythnetwork/component-library/unstyled/Link";
4-
import clsx from "clsx";
5-
import type { ComponentProps, ElementType, ReactNode } from "react";
6-
7-
import styles from "./index.module.scss";
8-
9-
export const VARIANTS = [
10-
"default",
11-
"primary",
12-
"secondary",
13-
"tertiary",
14-
"error",
15-
"info",
16-
"warning",
17-
"important",
18-
"success",
19-
] as const;
20-
21-
type OwnProps = {
5+
type Props = ComponentProps<"div"> & {
6+
icon?: ReactNode;
7+
header?: ReactNode;
228
variant?: (typeof VARIANTS)[number] | undefined;
23-
icon?: ReactNode | undefined;
24-
nonInteractive?: boolean | undefined;
259
};
2610

27-
export type Props<T extends ElementType> = Omit<
28-
ComponentProps<T>,
29-
keyof OwnProps
30-
> &
31-
OwnProps;
32-
33-
export const Callout = (
34-
props: (Props<"div"> & { nonInteractive?: true }) | Props<typeof Link>,
35-
) => {
36-
if (props.nonInteractive) {
37-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
38-
const { nonInteractive, ...otherProps } = props;
39-
return <div {...calloutProps(otherProps)} />;
40-
} else if ("href" in props) {
41-
return <Link {...calloutProps(props)} />;
42-
} else {
43-
return <div {...calloutProps(props)} />;
44-
}
11+
const DEFAULT_ICONS: Record<(typeof VARIANTS)[number], string> = {
12+
neutral: "⦿",
13+
info: "💡",
14+
warning: "⚠️",
15+
error: "❗",
16+
data: "💾",
17+
success: "🎉",
4518
};
4619

47-
const calloutProps = <T extends ElementType>({
48-
className,
49-
variant = "default",
50-
children,
20+
export const Callout = ({
5121
icon,
52-
...props
53-
}: Props<T>) => ({
54-
...props,
55-
"data-variant": variant,
56-
className: clsx(styles.callout, className),
57-
children: (
58-
<>
59-
<div className={styles.hover} />
60-
<div className={styles.body}>
61-
{Boolean(icon) && <div className={styles.icon}>{icon}</div>}
62-
<div>{children}</div>
63-
</div>
64-
</>
65-
),
66-
});
22+
header,
23+
variant = "info",
24+
children,
25+
...rest
26+
}: Props) => {
27+
return (
28+
<InfoBox
29+
icon={icon ?? DEFAULT_ICONS[variant] ?? DEFAULT_ICONS["info"]}
30+
header={header ?? <Case variant="APA Title Case">{variant}</Case>}
31+
variant={variant}
32+
{...rest}
33+
>
34+
{children}
35+
</InfoBox>
36+
);
37+
};

0 commit comments

Comments
 (0)