55 lines
1.3 KiB
TypeScript
55 lines
1.3 KiB
TypeScript
import {
|
|
type CSSProperties,
|
|
} from "react";
|
|
import { mergeClass } from "../../styles/utils/merge-class";
|
|
import { displayRecipe } from "../../styles/recipes/display-recipe";
|
|
import { dotSizeRecipe } from "../../styles/recipes/dot-size-recipe";
|
|
import type { CommonProps } from "../../utils/CommonProps";
|
|
import { brandRecipe } from "../../styles/recipes/brand-recipe";
|
|
|
|
export type BadgeProps = CommonProps & {
|
|
size?: "xs" | "sm" | "md" | "lg";
|
|
} & {
|
|
isDot?: boolean;
|
|
indicatorContent?: string;
|
|
};
|
|
|
|
export const Badge = (props: BadgeProps) => {
|
|
const {
|
|
indicatorContent = "",
|
|
isDot = false,
|
|
size = "md",
|
|
children,
|
|
className = "",
|
|
ref,
|
|
...rest
|
|
} = props;
|
|
|
|
const wrapperStyle: CSSProperties = {
|
|
position: "relative",
|
|
height: "fit",
|
|
width: "fit",
|
|
};
|
|
|
|
const indicatorStyle: CSSProperties = {
|
|
position: "absolute",
|
|
top: 0,
|
|
right: 0,
|
|
transform: "translate(50%,-50%)",
|
|
borderRadius: "9999px",
|
|
};
|
|
|
|
|
|
|
|
const indicatorClass = mergeClass(displayRecipe(), dotSizeRecipe({ size }), brandRecipe({ brand: "danger" }), "pointer-events--none", className);
|
|
|
|
return (
|
|
<div {...rest} ref={ref} style={wrapperStyle}>
|
|
{children}
|
|
<div className={indicatorClass} style={indicatorStyle}>
|
|
{indicatorContent}
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|