medkit/src/kit/status-badge.tsx

87 lines
2.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { cn } from "../lib/utils"
export type StatusTone = "positive" | "info" | "warning" | "negative" | "neutral"
const toneClass: Record<StatusTone, string> = {
positive: "bg-success-soft text-success border-success/20",
info: "bg-info-soft text-info border-info/20",
warning: "bg-warning-soft text-warning border-warning/30",
negative: "bg-coral-soft text-coral border-coral/25",
neutral: "bg-muted text-muted-foreground border-border",
}
const dotClass: Record<StatusTone, string> = {
positive: "bg-success",
info: "bg-info",
warning: "bg-warning",
negative: "bg-coral",
neutral: "bg-muted-foreground/60",
}
/**
* Цветная точка статуса — во вкладках, списках, рядом с подписью.
* `pulse` — мигает: идёт процесс («подключение», «ожидание связи»).
*/
export function StatusDot({
tone,
pulse,
className,
}: {
/** Без тона точка берёт цвет текста. */
tone?: StatusTone
pulse?: boolean
className?: string
}) {
return (
<span
aria-hidden
className={cn(
"size-1.5 shrink-0 rounded-full",
tone ? dotClass[tone] : "bg-current",
pulse && "animate-status-pulse motion-reduce:animate-none",
className,
)}
/>
)
}
const sizeClass = {
sm: "gap-1 px-1.5 py-px text-2xs",
md: "gap-1.5 px-2 py-0.5 text-xs",
lg: "gap-2 px-2.5 py-1 text-sm",
}
/**
* Статус с цветной точкой: «Работает», «Записан», «Неявка»… `pulse` — точка мигает («Подключение…»).
* `size="sm"` — в плотных строках таблиц и рядом с мелкими метками, `"lg"` — в шапке карточки или страницы.
*/
export function StatusBadge({
tone,
size = "md",
dot = true,
pulse,
className,
children,
}: {
tone: StatusTone
size?: "sm" | "md" | "lg"
dot?: boolean
pulse?: boolean
className?: string
children: React.ReactNode
}) {
return (
<span
className={cn(
"inline-flex items-center rounded-md border font-semibold whitespace-nowrap",
sizeClass[size],
toneClass[tone],
className,
)}
>
{dot && <StatusDot pulse={pulse} className={cn(size === "lg" && "size-2")} />}
{children}
</span>
)
}