/*! Strand UI | MIT License | dillingerstaffing.com */ import type { ComponentChildren, JSX } from "preact"; import { forwardRef } from "preact/compat"; import { cx } from "../../internal/index.js"; export interface BadgeProps extends Omit, "children"> { /** A count, or a dot. */ variant?: "dot" | "count"; /** Colour status. */ status?: "default" | "teal" | "blue" | "amber" | "red"; /** The number shown by the count variant. */ count?: number; /** Counts above this render as "N+". */ maxCount?: number; /** Pulse: the thing it marks is live. */ live?: boolean; /** Content the badge overlays at its top-right corner. */ children?: ComponentChildren; } /** * Small status indicator or notification count, inline or overlaid on content. * * @example * */ export const Badge = forwardRef( ({ variant = "count", status = "default", count, maxCount = 99, live = false, className = "", children, ...rest }, ref) => { const hasChildren = children != null && children !== false; const displayValue = variant === "count" ? (count != null && count > maxCount ? `${maxCount}+` : count) : null; const ariaLabel = variant === "dot" ? "Status indicator" : count != null ? `${count} notifications` : undefined; const badge = ( {displayValue} ); return ( {hasChildren && children} {badge} ); }, ); Badge.displayName = "Badge";