Update Badge.tsx
This commit is contained in:
@@ -6,14 +6,16 @@
|
|||||||
*/
|
*/
|
||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
|
|
||||||
type BadgeVariant = "solid" | "soft" | "outline";
|
type BadgeVariant = "solid" | "soft" | "outline" | "light";
|
||||||
type BadgeSize = "xs" | "sm" | "md";
|
type BadgeSize = "xs" | "sm" | "md";
|
||||||
type BadgeTone = "brand" | "success" | "warning" | "danger" | "info" | "neutral";
|
type BadgeTone = "brand" | "success" | "warning" | "danger" | "info" | "neutral";
|
||||||
|
type BadgeColor = "success" | "warning" | "error" | "danger" | "info" | "primary" | "brand" | "light" | "neutral";
|
||||||
|
|
||||||
interface BadgeProps {
|
interface BadgeProps {
|
||||||
variant?: BadgeVariant; // Visual treatment
|
variant?: BadgeVariant; // Visual treatment (light maps to soft)
|
||||||
size?: BadgeSize; // Badge size
|
size?: BadgeSize; // Badge size
|
||||||
tone?: BadgeTone; // Badge color tone
|
tone?: BadgeTone; // Badge color tone
|
||||||
|
color?: BadgeColor; // Alias for tone (for backward compatibility)
|
||||||
startIcon?: React.ReactNode; // Icon at the start
|
startIcon?: React.ReactNode; // Icon at the start
|
||||||
endIcon?: React.ReactNode; // Icon at the end
|
endIcon?: React.ReactNode; // Icon at the end
|
||||||
children: React.ReactNode; // Badge content
|
children: React.ReactNode; // Badge content
|
||||||
@@ -74,14 +76,36 @@ const sizeClasses: Record<BadgeSize, string> = {
|
|||||||
|
|
||||||
const Badge: React.FC<BadgeProps> = ({
|
const Badge: React.FC<BadgeProps> = ({
|
||||||
variant = "soft",
|
variant = "soft",
|
||||||
tone = "brand",
|
tone,
|
||||||
|
color,
|
||||||
size = "sm",
|
size = "sm",
|
||||||
startIcon,
|
startIcon,
|
||||||
endIcon,
|
endIcon,
|
||||||
children,
|
children,
|
||||||
className = "",
|
className = "",
|
||||||
}) => {
|
}) => {
|
||||||
const toneClass = toneStyles[tone][variant];
|
// Map color prop to tone (for backward compatibility)
|
||||||
|
const resolvedTone: BadgeTone = tone || (() => {
|
||||||
|
if (!color) return "brand";
|
||||||
|
// Map color values to tone values
|
||||||
|
const colorToToneMap: Record<string, BadgeTone> = {
|
||||||
|
"success": "success",
|
||||||
|
"warning": "warning",
|
||||||
|
"error": "danger",
|
||||||
|
"danger": "danger",
|
||||||
|
"info": "info",
|
||||||
|
"primary": "brand",
|
||||||
|
"brand": "brand",
|
||||||
|
"light": "neutral",
|
||||||
|
"neutral": "neutral",
|
||||||
|
};
|
||||||
|
return colorToToneMap[color] || "brand";
|
||||||
|
})();
|
||||||
|
|
||||||
|
// Map variant "light" to "soft" (for backward compatibility)
|
||||||
|
const resolvedVariant: "solid" | "soft" | "outline" = variant === "light" ? "soft" : variant;
|
||||||
|
|
||||||
|
const toneClass = toneStyles[resolvedTone][resolvedVariant];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<span
|
<span
|
||||||
|
|||||||
Reference in New Issue
Block a user