mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-03-21 18:04:39 -05:00
51 lines
1.2 KiB
TypeScript
51 lines
1.2 KiB
TypeScript
import clsx from "clsx";
|
|
import { Check, CircleAlert, OctagonAlert, TriangleAlert } from "lucide-react";
|
|
import type * as React from "react";
|
|
import { assertUnreachable } from "~/utils/types";
|
|
import styles from "./Alert.module.css";
|
|
|
|
export type AlertVariation = "INFO" | "WARNING" | "ERROR" | "SUCCESS";
|
|
|
|
export function Alert({
|
|
children,
|
|
textClassName,
|
|
alertClassName,
|
|
variation = "INFO",
|
|
tiny = false,
|
|
}: {
|
|
children: React.ReactNode;
|
|
textClassName?: string;
|
|
alertClassName?: string;
|
|
variation?: AlertVariation;
|
|
tiny?: boolean;
|
|
}) {
|
|
return (
|
|
<div
|
|
className={clsx(styles.alert, alertClassName, {
|
|
[styles.tiny]: tiny,
|
|
[styles.warning]: variation === "WARNING",
|
|
[styles.error]: variation === "ERROR",
|
|
[styles.success]: variation === "SUCCESS",
|
|
})}
|
|
>
|
|
<Icon variation={variation} />{" "}
|
|
<div className={textClassName}>{children}</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function Icon({ variation }: { variation: AlertVariation }) {
|
|
switch (variation) {
|
|
case "INFO":
|
|
return <CircleAlert />;
|
|
case "WARNING":
|
|
return <TriangleAlert />;
|
|
case "ERROR":
|
|
return <OctagonAlert />;
|
|
case "SUCCESS":
|
|
return <Check />;
|
|
default:
|
|
assertUnreachable(variation);
|
|
}
|
|
}
|