medkit/src/kit/person-chip.tsx

62 lines
1.7 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 { XIcon } from "lucide-react"
import { cn } from "../lib/utils"
export function initialsOf(name: string) {
const parts = name.replace(/\./g, " ").trim().split(/\s+/)
return ((parts[0]?.[0] ?? "") + (parts[1]?.[0] ?? "")).toUpperCase() || "?"
}
/** Кружок с инициалами сотрудника. */
export function PersonAvatar({ name, className }: { name: string; className?: string }) {
return (
<span
aria-hidden
className={cn(
"grid size-8 shrink-0 place-items-center rounded-full bg-accent text-xs font-semibold text-accent-foreground",
className,
)}
>
{initialsOf(name)}
</span>
)
}
/** Сотрудник чипом: инициалы, имя, опционально «убрать». */
export function PersonChip({
name,
highlight,
onRemove,
className,
}: {
name: string
/** Подсветить (например, текущего пользователя). */
highlight?: boolean
onRemove?: () => void
className?: string
}) {
return (
<span
className={cn(
"inline-flex h-7 items-center gap-1.5 rounded-full border bg-card pr-1 pl-0.5 text-xs font-medium",
!onRemove && "pr-2.5",
highlight && "border-primary/30 bg-accent/60",
className,
)}
>
<PersonAvatar name={name} className="size-6 text-3xs" />
{name}
{onRemove && (
<button
type="button"
aria-label={`Убрать ${name}`}
onClick={onRemove}
className="grid size-5 place-items-center rounded-full text-muted-foreground transition hover:bg-muted hover:text-foreground"
>
<XIcon className="size-3" />
</button>
)}
</span>
)
}