medkit/src/kit/content-tabs.tsx

87 lines
3.2 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 { type LucideIcon } from "lucide-react"
import { cn } from "../lib/utils"
import { StatusDot, type StatusTone } from "./status-badge"
export interface ContentTabItem<T extends string = string> {
readonly id: T
readonly label: string
readonly icon?: LucideIcon
/** Счётчик справа от подписи; вкладка с нулём приглушена. */
readonly count?: number
/** Цветная точка статуса перед подписью — вкладки-фильтры по статусам. */
readonly tone?: StatusTone
readonly disabled?: boolean
}
/**
* Контентные вкладки внутри страницы/карточки.
* `line` — подчёркивание (разделы карточки), `pill` — заливка (переключатели в блоках).
* Вкладки-фильтры по статусам: `{ id, label, count, tone }`, первая — «Все» без тона.
*/
export function ContentTabs<T extends string>({
tabs,
value,
onValueChange,
variant = "line",
className,
}: {
tabs: readonly ContentTabItem<T>[]
value: T
onValueChange: (value: T) => void
variant?: "line" | "pill"
className?: string
}) {
return (
<div
role="tablist"
className={cn(
"scrollbar-none flex shrink-0 items-center gap-1 overflow-x-auto",
variant === "line" && "border-b px-3",
variant === "pill" && "w-fit rounded-xl bg-muted/70 p-1",
className,
)}
>
{tabs.map((tab) => {
const active = tab.id === value
return (
<button
key={tab.id}
type="button"
role="tab"
aria-selected={active}
disabled={tab.disabled}
onClick={() => onValueChange(tab.id)}
className={cn(
"relative flex shrink-0 items-center gap-2 text-sm font-medium whitespace-nowrap transition-colors outline-none focus-visible:ring-2 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-40",
variant === "line" && "h-10 px-3",
variant === "line" && (active ? "text-foreground" : "text-muted-foreground hover:text-foreground"),
variant === "pill" && "h-8 rounded-lg px-3",
variant === "pill" &&
(active ? "bg-card text-foreground shadow-xs" : "text-muted-foreground hover:text-foreground"),
tab.count === 0 && !active && "opacity-60",
)}
>
{tab.icon && <tab.icon className={cn("size-4", active && "text-primary")} />}
{tab.tone && <StatusDot tone={tab.tone} />}
{tab.label}
{tab.count !== undefined && (
<span
className={cn(
"rounded-md px-1.5 text-[11px] leading-5 font-semibold tabular",
active ? "bg-primary/10 text-primary" : "bg-muted text-muted-foreground",
)}
>
{tab.count}
</span>
)}
{variant === "line" && active && (
<span className="absolute inset-x-2 -bottom-px h-0.5 rounded-full bg-primary" />
)}
</button>
)
})}
</div>
)
}