Extract reusable kit components and add /ui showcase
Kit (src/components/kit): PageTabs, ContentTabs, PatientPanel, DataTable with sorting, Pagination, FileGallery (image lightbox, PDF preview), StatusBadge, StatTile, InfoSection/Field, DateLeaf, PageFrame, CodeBlock. Patient pages now use them; search results are sortable; documents show attachments. Replace next-themes with a small ThemeProvider (React 19 warned about its inline script). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
687a880a08
commit
6d1a8719be
|
|
@ -0,0 +1,23 @@
|
||||||
|
import { CopyIcon } from "lucide-react"
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
import { copyToClipboard } from "@/lib/clipboard"
|
||||||
|
|
||||||
|
/** Фрагмент кода с кнопкой копирования. */
|
||||||
|
export function CodeBlock({ code, className }: { code: string; className?: string }) {
|
||||||
|
return (
|
||||||
|
<div className={cn("group relative", className)}>
|
||||||
|
<pre className="overflow-x-auto rounded-xl bg-muted/70 p-4 font-mono text-[13px] leading-relaxed text-foreground/90">
|
||||||
|
<code>{code}</code>
|
||||||
|
</pre>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
aria-label="Скопировать код"
|
||||||
|
onClick={() => copyToClipboard(code, "Код скопирован")}
|
||||||
|
className="absolute top-2 right-2 grid size-7 place-items-center rounded-md bg-card text-muted-foreground opacity-0 shadow-xs transition group-hover:opacity-100 hover:text-foreground"
|
||||||
|
>
|
||||||
|
<CopyIcon className="size-3.5" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,80 @@
|
||||||
|
import { type LucideIcon } from "lucide-react"
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
|
export interface ContentTabItem<T extends string = string> {
|
||||||
|
readonly id: T
|
||||||
|
readonly label: string
|
||||||
|
readonly icon?: LucideIcon
|
||||||
|
/** Счётчик справа от подписи. */
|
||||||
|
readonly count?: number
|
||||||
|
readonly disabled?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Контентные вкладки внутри страницы/карточки.
|
||||||
|
* `line` — подчёркивание (разделы карточки), `pill` — заливка (переключатели в блоках).
|
||||||
|
*/
|
||||||
|
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.icon && <tab.icon className={cn("size-4", active && "text-primary")} />}
|
||||||
|
{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>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,141 @@
|
||||||
|
import * as React from "react"
|
||||||
|
import { ArrowDownIcon, ArrowUpIcon, ChevronsUpDownIcon } from "lucide-react"
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
|
export type SortDirection = "asc" | "desc"
|
||||||
|
|
||||||
|
export interface SortState {
|
||||||
|
readonly id: string
|
||||||
|
readonly direction: SortDirection
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface DataColumn<T> {
|
||||||
|
readonly id: string
|
||||||
|
readonly header: React.ReactNode
|
||||||
|
readonly cell: (row: T, index: number) => React.ReactNode
|
||||||
|
/** Компаратор — колонка становится сортируемой. */
|
||||||
|
readonly sort?: (a: T, b: T) => number
|
||||||
|
readonly className?: string
|
||||||
|
readonly headerClassName?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Отсортировать строки по словарю компараторов {columnId: compare}. */
|
||||||
|
export function sortBy<T>(
|
||||||
|
rows: readonly T[],
|
||||||
|
comparators: Readonly<Record<string, ((a: T, b: T) => number) | undefined>>,
|
||||||
|
sort: SortState | null,
|
||||||
|
) {
|
||||||
|
const compare = sort && comparators[sort.id]
|
||||||
|
if (!sort || !compare) return [...rows]
|
||||||
|
const dir = sort.direction === "asc" ? 1 : -1
|
||||||
|
return [...rows].sort((a, b) => dir * compare(a, b))
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Отсортировать строки по колонкам таблицы (для пагинации снаружи). */
|
||||||
|
export function sortRows<T>(rows: readonly T[], columns: readonly DataColumn<T>[], sort: SortState | null) {
|
||||||
|
return sortBy(rows, Object.fromEntries(columns.map((c) => [c.id, c.sort])), sort)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Клик по заголовку: по возрастанию → по убыванию → без сортировки. */
|
||||||
|
export function nextSort(current: SortState | null, id: string): SortState | null {
|
||||||
|
if (current?.id !== id) return { id, direction: "asc" }
|
||||||
|
if (current.direction === "asc") return { id, direction: "desc" }
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Таблица кита: липкая шапка, сортировка по клику на заголовок,
|
||||||
|
* кликабельные строки. Строки передаются уже отсортированными/порезанными
|
||||||
|
* (см. sortRows) — так таблица одинаково работает с пагинацией и без неё.
|
||||||
|
*/
|
||||||
|
export function DataTable<T>({
|
||||||
|
columns,
|
||||||
|
rows,
|
||||||
|
getRowId,
|
||||||
|
sort,
|
||||||
|
onSortChange,
|
||||||
|
onRowClick,
|
||||||
|
rowProps,
|
||||||
|
rowClassName,
|
||||||
|
empty,
|
||||||
|
className,
|
||||||
|
}: {
|
||||||
|
columns: readonly DataColumn<T>[]
|
||||||
|
rows: readonly T[]
|
||||||
|
getRowId: (row: T) => React.Key
|
||||||
|
sort?: SortState | null
|
||||||
|
onSortChange?: (sort: SortState | null) => void
|
||||||
|
onRowClick?: (row: T, event: React.MouseEvent) => void
|
||||||
|
rowProps?: (row: T, index: number) => React.HTMLAttributes<HTMLTableRowElement>
|
||||||
|
rowClassName?: (row: T, index: number) => string | false | undefined
|
||||||
|
empty?: React.ReactNode
|
||||||
|
className?: string
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<table className={cn("w-full text-sm", className)}>
|
||||||
|
<thead className="sticky top-0 z-10 border-b bg-card/95 backdrop-blur">
|
||||||
|
<tr className="text-left text-xs text-muted-foreground">
|
||||||
|
{columns.map((col) => {
|
||||||
|
const active = sort?.id === col.id
|
||||||
|
const Icon = !active ? ChevronsUpDownIcon : sort.direction === "asc" ? ArrowUpIcon : ArrowDownIcon
|
||||||
|
return (
|
||||||
|
<th
|
||||||
|
key={col.id}
|
||||||
|
aria-sort={active ? (sort.direction === "asc" ? "ascending" : "descending") : undefined}
|
||||||
|
className={cn("h-10 px-3 font-medium first:pl-5 last:pr-5", col.headerClassName)}
|
||||||
|
>
|
||||||
|
{col.sort && onSortChange ? (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => onSortChange(nextSort(sort ?? null, col.id))}
|
||||||
|
className={cn(
|
||||||
|
"-mx-1 inline-flex items-center gap-1 rounded px-1 transition hover:text-foreground",
|
||||||
|
active && "text-foreground",
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{col.header}
|
||||||
|
<Icon className={cn("size-3.5", !active && "opacity-50")} />
|
||||||
|
</button>
|
||||||
|
) : (
|
||||||
|
col.header
|
||||||
|
)}
|
||||||
|
</th>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{rows.map((row, i) => {
|
||||||
|
const extra = rowProps?.(row, i)
|
||||||
|
return (
|
||||||
|
<tr
|
||||||
|
key={getRowId(row)}
|
||||||
|
{...extra}
|
||||||
|
onClick={onRowClick ? (e) => onRowClick(row, e) : extra?.onClick}
|
||||||
|
className={cn(
|
||||||
|
"border-b border-border/60 transition-colors last:border-b-0",
|
||||||
|
onRowClick && "cursor-pointer hover:bg-muted/50",
|
||||||
|
rowClassName?.(row, i),
|
||||||
|
extra?.className,
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{columns.map((col) => (
|
||||||
|
<td key={col.id} className={cn("px-3 py-2.5 first:pl-5 last:pr-5", col.className)}>
|
||||||
|
{col.cell(row, i)}
|
||||||
|
</td>
|
||||||
|
))}
|
||||||
|
</tr>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
{!rows.length && empty && (
|
||||||
|
<tr>
|
||||||
|
<td colSpan={columns.length} className="py-12 text-center text-sm text-muted-foreground">
|
||||||
|
{empty}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
)}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
|
const WEEKDAYS = ["вс", "пн", "вт", "ср", "чт", "пт", "сб"]
|
||||||
|
const MONTHS = ["янв", "фев", "мар", "апр", "мая", "июн", "июл", "авг", "сен", "окт", "ноя", "дек"]
|
||||||
|
|
||||||
|
/** Дата приёма «листком календаря». */
|
||||||
|
export function DateLeaf({ date, upcoming }: { date: string; upcoming?: boolean }) {
|
||||||
|
const [d, m, y] = date.split(".").map(Number)
|
||||||
|
const weekday = WEEKDAYS[new Date(y, m - 1, d).getDay()]
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={cn(
|
||||||
|
"flex w-12 shrink-0 flex-col items-center overflow-hidden rounded-lg border bg-card text-center leading-none",
|
||||||
|
upcoming ? "border-primary/30" : "",
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className={cn(
|
||||||
|
"w-full py-1 text-[10px] font-semibold uppercase",
|
||||||
|
upcoming ? "bg-primary text-primary-foreground" : "bg-muted text-muted-foreground",
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{weekday}
|
||||||
|
</div>
|
||||||
|
<div className="pt-1.5 text-lg font-semibold tabular">{d}</div>
|
||||||
|
<div className="pb-1.5 text-[10px] text-muted-foreground">
|
||||||
|
{MONTHS[m - 1]} {String(y).slice(2)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,295 @@
|
||||||
|
import * as React from "react"
|
||||||
|
import {
|
||||||
|
ChevronLeftIcon,
|
||||||
|
ChevronRightIcon,
|
||||||
|
DownloadIcon,
|
||||||
|
FileArchiveIcon,
|
||||||
|
FileIcon,
|
||||||
|
FileTextIcon,
|
||||||
|
ImageIcon,
|
||||||
|
XIcon,
|
||||||
|
} from "lucide-react"
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
import { formatBytes } from "@/lib/format"
|
||||||
|
import { Dialog, DialogContent, DialogDescription, DialogTitle } from "@/components/ui/dialog"
|
||||||
|
|
||||||
|
export interface FileItem {
|
||||||
|
readonly name: string
|
||||||
|
/** Размер в байтах. */
|
||||||
|
readonly size: number
|
||||||
|
readonly type?: string
|
||||||
|
/** Ссылка на файл; без неё — только карточка без просмотра. */
|
||||||
|
readonly src?: string
|
||||||
|
readonly description?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export type FileGallerySize = "sm" | "md" | "lg"
|
||||||
|
|
||||||
|
export function isImageFile(file: FileItem) {
|
||||||
|
return Boolean(file.type?.startsWith("image/")) || /\.(jpe?g|png|gif|webp|bmp)$/i.test(file.name)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isPdfFile(file: FileItem) {
|
||||||
|
return Boolean(file.type?.includes("pdf")) || /\.pdf$/i.test(file.name)
|
||||||
|
}
|
||||||
|
|
||||||
|
function fileIcon(file: FileItem) {
|
||||||
|
if (isImageFile(file)) return ImageIcon
|
||||||
|
if (isPdfFile(file)) return FileTextIcon
|
||||||
|
if (/\.(zip|rar|7z)$/i.test(file.name)) return FileArchiveIcon
|
||||||
|
return FileIcon
|
||||||
|
}
|
||||||
|
|
||||||
|
function extension(file: FileItem) {
|
||||||
|
return file.name.split(".").pop()?.toUpperCase() ?? ""
|
||||||
|
}
|
||||||
|
|
||||||
|
const tileSize: Record<FileGallerySize, string> = {
|
||||||
|
sm: "w-24",
|
||||||
|
md: "w-32",
|
||||||
|
lg: "w-44",
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Список файлов плитками. Клик по изображению — лайтбокс со стрелками,
|
||||||
|
* по PDF — встроенный просмотрщик, остальное — скачивание.
|
||||||
|
*/
|
||||||
|
export function FileGallery({
|
||||||
|
files,
|
||||||
|
size = "md",
|
||||||
|
className,
|
||||||
|
}: {
|
||||||
|
files: readonly FileItem[]
|
||||||
|
size?: FileGallerySize
|
||||||
|
className?: string
|
||||||
|
}) {
|
||||||
|
const [openIndex, setOpenIndex] = React.useState<number | null>(null)
|
||||||
|
const images = files.filter((f) => isImageFile(f) && f.src)
|
||||||
|
const opened = openIndex === null ? null : files[openIndex]
|
||||||
|
|
||||||
|
const open = (file: FileItem, index: number) => {
|
||||||
|
if (!file.src) return
|
||||||
|
if (isImageFile(file) || isPdfFile(file)) setOpenIndex(index)
|
||||||
|
else window.open(file.src, "_blank", "noopener")
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<ul className={cn("flex flex-wrap gap-3", className)}>
|
||||||
|
{files.map((file, index) => (
|
||||||
|
<li key={file.name} className={cn("group", tileSize[size])}>
|
||||||
|
<FileTile file={file} size={size} onOpen={() => open(file, index)} />
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
{opened && isImageFile(opened) && (
|
||||||
|
<ImageLightbox
|
||||||
|
images={images}
|
||||||
|
index={Math.max(0, images.indexOf(opened))}
|
||||||
|
onIndexChange={(i) => setOpenIndex(files.indexOf(images[i]))}
|
||||||
|
onClose={() => setOpenIndex(null)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{opened && isPdfFile(opened) && <PdfPreview file={opened} onClose={() => setOpenIndex(null)} />}
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function FileTile({ file, size, onOpen }: { file: FileItem; size: FileGallerySize; onOpen: () => void }) {
|
||||||
|
const [broken, setBroken] = React.useState(false)
|
||||||
|
const Icon = fileIcon(file)
|
||||||
|
const image = isImageFile(file) && file.src && !broken
|
||||||
|
const previewable = Boolean(file.src) && (isImageFile(file) || isPdfFile(file))
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col gap-1.5">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={onOpen}
|
||||||
|
disabled={!file.src}
|
||||||
|
className={cn(
|
||||||
|
"relative aspect-square w-full overflow-hidden rounded-xl bg-muted transition outline-none focus-visible:ring-2 focus-visible:ring-ring/60",
|
||||||
|
previewable && "cursor-zoom-in hover:ring-2 hover:ring-primary/30",
|
||||||
|
!file.src && "cursor-default",
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{image ? (
|
||||||
|
<img
|
||||||
|
src={file.src}
|
||||||
|
alt={file.description ?? file.name}
|
||||||
|
loading="lazy"
|
||||||
|
onError={() => setBroken(true)}
|
||||||
|
className="size-full object-cover transition duration-300 group-hover:scale-105"
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<span className="grid size-full place-items-center text-muted-foreground">
|
||||||
|
<span className="flex flex-col items-center gap-1.5">
|
||||||
|
<Icon className={cn(size === "sm" ? "size-5" : "size-7")} />
|
||||||
|
<span className="text-[10px] font-semibold tracking-wider">{extension(file)}</span>
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
<div className="min-w-0 px-0.5">
|
||||||
|
{file.description && size !== "sm" && (
|
||||||
|
<div className="truncate text-xs font-medium" title={file.description}>
|
||||||
|
{file.description}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<div className="truncate text-xs text-muted-foreground" title={file.name}>
|
||||||
|
{file.name}
|
||||||
|
</div>
|
||||||
|
<div className="mt-0.5 flex items-center justify-between text-[11px] text-muted-foreground tabular">
|
||||||
|
{formatBytes(file.size)}
|
||||||
|
{file.src && (
|
||||||
|
<a
|
||||||
|
href={file.src}
|
||||||
|
download={file.name}
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener"
|
||||||
|
aria-label={`Скачать ${file.name}`}
|
||||||
|
className="rounded p-0.5 text-primary transition hover:bg-accent"
|
||||||
|
>
|
||||||
|
<DownloadIcon className="size-3.5" />
|
||||||
|
</a>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function ImageLightbox({
|
||||||
|
images,
|
||||||
|
index,
|
||||||
|
onIndexChange,
|
||||||
|
onClose,
|
||||||
|
}: {
|
||||||
|
images: readonly FileItem[]
|
||||||
|
index: number
|
||||||
|
onIndexChange: (index: number) => void
|
||||||
|
onClose: () => void
|
||||||
|
}) {
|
||||||
|
const file = images[index]
|
||||||
|
const go = React.useCallback(
|
||||||
|
(delta: number) => onIndexChange((index + delta + images.length) % images.length),
|
||||||
|
[index, images.length, onIndexChange],
|
||||||
|
)
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
const onKey = (e: KeyboardEvent) => {
|
||||||
|
if (e.key === "ArrowRight") go(1)
|
||||||
|
if (e.key === "ArrowLeft") go(-1)
|
||||||
|
}
|
||||||
|
window.addEventListener("keydown", onKey)
|
||||||
|
return () => window.removeEventListener("keydown", onKey)
|
||||||
|
}, [go])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog open onOpenChange={(v) => !v && onClose()}>
|
||||||
|
<DialogContent
|
||||||
|
showCloseButton={false}
|
||||||
|
className="max-w-[min(92vw,1100px)] gap-0 overflow-hidden border-0 bg-black/95 p-0 text-white sm:max-w-[min(92vw,1100px)]"
|
||||||
|
>
|
||||||
|
<DialogTitle className="sr-only">{file.description ?? file.name}</DialogTitle>
|
||||||
|
<DialogDescription className="sr-only">Просмотр изображения</DialogDescription>
|
||||||
|
<div className="relative grid min-h-[50vh] place-items-center">
|
||||||
|
<img src={file.src} alt={file.description ?? file.name} className="max-h-[80vh] w-auto object-contain" />
|
||||||
|
{images.length > 1 && (
|
||||||
|
<>
|
||||||
|
<LightboxButton side="left" label="Предыдущее" onClick={() => go(-1)}>
|
||||||
|
<ChevronLeftIcon />
|
||||||
|
</LightboxButton>
|
||||||
|
<LightboxButton side="right" label="Следующее" onClick={() => go(1)}>
|
||||||
|
<ChevronRightIcon />
|
||||||
|
</LightboxButton>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-3 border-t border-white/10 px-4 py-3 text-sm">
|
||||||
|
<div className="min-w-0 flex-1">
|
||||||
|
<div className="truncate font-medium">{file.description ?? file.name}</div>
|
||||||
|
<div className="text-xs text-white/60">
|
||||||
|
{file.name} · {formatBytes(file.size)}
|
||||||
|
{images.length > 1 && ` · ${index + 1} из ${images.length}`}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<a
|
||||||
|
href={file.src}
|
||||||
|
download={file.name}
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener"
|
||||||
|
className="grid size-8 place-items-center rounded-lg hover:bg-white/10"
|
||||||
|
aria-label="Скачать"
|
||||||
|
>
|
||||||
|
<DownloadIcon className="size-4" />
|
||||||
|
</a>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={onClose}
|
||||||
|
className="grid size-8 place-items-center rounded-lg hover:bg-white/10"
|
||||||
|
aria-label="Закрыть"
|
||||||
|
>
|
||||||
|
<XIcon className="size-4" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function LightboxButton({
|
||||||
|
side,
|
||||||
|
label,
|
||||||
|
onClick,
|
||||||
|
children,
|
||||||
|
}: {
|
||||||
|
side: "left" | "right"
|
||||||
|
label: string
|
||||||
|
onClick: () => void
|
||||||
|
children: React.ReactNode
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
aria-label={label}
|
||||||
|
onClick={onClick}
|
||||||
|
className={cn(
|
||||||
|
"absolute top-1/2 grid size-10 -translate-y-1/2 place-items-center rounded-full bg-white/10 backdrop-blur transition hover:bg-white/20 [&_svg]:size-5",
|
||||||
|
side === "left" ? "left-3" : "right-3",
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</button>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function PdfPreview({ file, onClose }: { file: FileItem; onClose: () => void }) {
|
||||||
|
return (
|
||||||
|
<Dialog open onOpenChange={(v) => !v && onClose()}>
|
||||||
|
<DialogContent className="flex h-[88vh] max-w-[min(92vw,1000px)] flex-col gap-0 p-0 sm:max-w-[min(92vw,1000px)]">
|
||||||
|
<div className="flex items-center gap-3 border-b px-4 py-3 pr-12">
|
||||||
|
<FileTextIcon className="size-4 text-primary" />
|
||||||
|
<div className="min-w-0 flex-1">
|
||||||
|
<DialogTitle className="truncate text-sm">{file.description ?? file.name}</DialogTitle>
|
||||||
|
<DialogDescription className="text-xs">
|
||||||
|
{file.name} · {formatBytes(file.size)}
|
||||||
|
</DialogDescription>
|
||||||
|
</div>
|
||||||
|
<a
|
||||||
|
href={file.src}
|
||||||
|
download={file.name}
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener"
|
||||||
|
className="inline-flex items-center gap-1.5 rounded-md px-2 py-1 text-sm text-primary hover:bg-accent"
|
||||||
|
>
|
||||||
|
<DownloadIcon className="size-4" /> Скачать
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<iframe src={file.src} title={file.name} className="min-h-0 w-full flex-1 rounded-b-lg bg-muted" />
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
// Переиспользуемые компоненты МИС «Медицина». Витрина — /ui (src/pages/ui/ui-page.tsx).
|
||||||
|
export * from "./code-block"
|
||||||
|
export * from "./content-tabs"
|
||||||
|
export * from "./data-table"
|
||||||
|
export * from "./date-leaf"
|
||||||
|
export * from "./file-gallery"
|
||||||
|
export * from "./info-section"
|
||||||
|
export * from "./page-frame"
|
||||||
|
export * from "./page-tabs"
|
||||||
|
export * from "./pagination"
|
||||||
|
export * from "./patient-avatar"
|
||||||
|
export * from "./patient-panel"
|
||||||
|
export * from "./stat-tile"
|
||||||
|
export * from "./status-badge"
|
||||||
|
|
@ -0,0 +1,63 @@
|
||||||
|
import * as React from "react"
|
||||||
|
import { CopyIcon, type LucideIcon } from "lucide-react"
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
import { copyToClipboard } from "@/lib/clipboard"
|
||||||
|
|
||||||
|
/** Смысловой блок на мягкой подложке: иконка + заголовок, справа — действие. */
|
||||||
|
export function InfoSection({
|
||||||
|
icon: Icon,
|
||||||
|
title,
|
||||||
|
action,
|
||||||
|
className,
|
||||||
|
children,
|
||||||
|
}: {
|
||||||
|
icon?: LucideIcon
|
||||||
|
title: React.ReactNode
|
||||||
|
action?: React.ReactNode
|
||||||
|
className?: string
|
||||||
|
children: React.ReactNode
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<section className={cn("rounded-xl bg-muted/50", className)}>
|
||||||
|
<h3 className="flex items-center gap-2 px-4 pt-3.5 pb-1 text-sm font-semibold">
|
||||||
|
{Icon && <Icon className="size-4 text-primary" />}
|
||||||
|
{title}
|
||||||
|
{action && <span className="ml-auto font-normal">{action}</span>}
|
||||||
|
</h3>
|
||||||
|
<div className="space-y-3 px-4 pt-2 pb-4">{children}</div>
|
||||||
|
</section>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Подпись + значение; с `copy` — кнопка копирования при наведении. */
|
||||||
|
export function Field({
|
||||||
|
label,
|
||||||
|
copy,
|
||||||
|
className,
|
||||||
|
children,
|
||||||
|
}: {
|
||||||
|
label: string
|
||||||
|
copy?: string
|
||||||
|
className?: string
|
||||||
|
children: React.ReactNode
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<div className={cn("group min-w-0 text-sm", className)}>
|
||||||
|
<div className="flex items-center gap-1 text-xs text-muted-foreground">
|
||||||
|
{label}
|
||||||
|
{copy && (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
aria-label={`Скопировать: ${label}`}
|
||||||
|
onClick={() => copyToClipboard(copy)}
|
||||||
|
className="opacity-0 transition group-hover:opacity-100 hover:text-primary"
|
||||||
|
>
|
||||||
|
<CopyIcon className="size-3" />
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="mt-0.5 break-words">{children}</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,49 @@
|
||||||
|
import * as React from "react"
|
||||||
|
import { type LucideIcon } from "lucide-react"
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
import { ScrollArea } from "@/components/ui/scroll-area"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Рамка раздела без вкладок: карточка с шапкой (иконка, заголовок, действия)
|
||||||
|
* и прокручиваемым телом. Разделы со вкладками используют SectionFrame.
|
||||||
|
*/
|
||||||
|
export function PageFrame({
|
||||||
|
icon: Icon,
|
||||||
|
title,
|
||||||
|
actions,
|
||||||
|
toolbar,
|
||||||
|
scroll = true,
|
||||||
|
className,
|
||||||
|
children,
|
||||||
|
}: {
|
||||||
|
icon?: LucideIcon
|
||||||
|
title: React.ReactNode
|
||||||
|
actions?: React.ReactNode
|
||||||
|
/** Строка под шапкой: фильтры, поиск. */
|
||||||
|
toolbar?: React.ReactNode
|
||||||
|
/** false — тело само управляет прокруткой (списки с панелью деталей). */
|
||||||
|
scroll?: boolean
|
||||||
|
className?: string
|
||||||
|
children: React.ReactNode
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<div className="flex min-h-0 flex-1 flex-col p-2 lg:p-3">
|
||||||
|
<div className="flex min-h-0 flex-1 flex-col overflow-hidden rounded-xl border bg-card shadow-[0_1px_2px_rgba(15,40,60,0.04)]">
|
||||||
|
<header className="flex h-12 shrink-0 items-center gap-2 border-b px-4">
|
||||||
|
{Icon && <Icon className="size-4 text-primary" />}
|
||||||
|
<h1 className="text-sm font-semibold">{title}</h1>
|
||||||
|
{actions && <div className="ml-auto flex items-center gap-2">{actions}</div>}
|
||||||
|
</header>
|
||||||
|
{toolbar && <div className="shrink-0 border-b px-4 py-3">{toolbar}</div>}
|
||||||
|
{scroll ? (
|
||||||
|
<ScrollArea className="min-h-0 flex-1">
|
||||||
|
<div className={className}>{children}</div>
|
||||||
|
</ScrollArea>
|
||||||
|
) : (
|
||||||
|
<div className={cn("flex min-h-0 flex-1", className)}>{children}</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,181 @@
|
||||||
|
import * as React from "react"
|
||||||
|
import { XIcon, type LucideIcon } from "lucide-react"
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
import { ContextMenu, ContextMenuContent, ContextMenuTrigger } from "@/components/ui/context-menu"
|
||||||
|
import { Kbd } from "@/components/ui/kbd"
|
||||||
|
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip"
|
||||||
|
|
||||||
|
export type PageTabTone = "male" | "female" | "neutral"
|
||||||
|
|
||||||
|
export interface PageTabItem {
|
||||||
|
readonly id: string
|
||||||
|
readonly label: string
|
||||||
|
/** Иконка вместо буквы (обычно у корневой вкладки-списка). */
|
||||||
|
readonly icon?: LucideIcon
|
||||||
|
readonly letter?: string
|
||||||
|
readonly tone?: PageTabTone
|
||||||
|
/** Красная точка — у пациента есть важная отметка. */
|
||||||
|
readonly alert?: boolean
|
||||||
|
/** Нельзя закрыть и перетащить. */
|
||||||
|
readonly pinned?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
const toneClass: Record<PageTabTone, string> = {
|
||||||
|
male: "bg-male/15 text-male",
|
||||||
|
female: "bg-female/15 text-female",
|
||||||
|
neutral: "bg-muted text-muted-foreground",
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Вкладки страницы — чипы в шапке раздела: иконка или буква, цвет пола,
|
||||||
|
* закрытие (крестик / средняя кнопка), перетаскивание, контекстное меню.
|
||||||
|
* Чисто презентационный: состояние и навигация — снаружи.
|
||||||
|
*/
|
||||||
|
export function PageTabs({
|
||||||
|
tabs,
|
||||||
|
activeId,
|
||||||
|
onSelect,
|
||||||
|
onClose,
|
||||||
|
onMove,
|
||||||
|
renderMenu,
|
||||||
|
actions,
|
||||||
|
hotkeyHints = false,
|
||||||
|
className,
|
||||||
|
}: {
|
||||||
|
tabs: readonly PageTabItem[]
|
||||||
|
activeId: string | null
|
||||||
|
onSelect: (id: string) => void
|
||||||
|
onClose?: (id: string) => void
|
||||||
|
onMove?: (fromId: string, toId: string) => void
|
||||||
|
/** Содержимое контекстного меню вкладки (пункты ContextMenuItem). */
|
||||||
|
renderMenu?: (tab: PageTabItem) => React.ReactNode
|
||||||
|
actions?: React.ReactNode
|
||||||
|
/** Показывать в подсказке Alt+N. */
|
||||||
|
hotkeyHints?: boolean
|
||||||
|
className?: string
|
||||||
|
}) {
|
||||||
|
const [dragId, setDragId] = React.useState<string | null>(null)
|
||||||
|
const scrollerRef = React.useRef<HTMLDivElement>(null)
|
||||||
|
|
||||||
|
// Активная вкладка всегда видна, даже если их много.
|
||||||
|
React.useEffect(() => {
|
||||||
|
scrollerRef.current
|
||||||
|
?.querySelector<HTMLElement>('[data-active="true"]')
|
||||||
|
?.scrollIntoView({ block: "nearest", inline: "nearest", behavior: "smooth" })
|
||||||
|
}, [activeId, tabs.length])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={cn("flex h-12 shrink-0 items-center gap-2 border-b px-2", className)}>
|
||||||
|
<div
|
||||||
|
ref={scrollerRef}
|
||||||
|
role="tablist"
|
||||||
|
aria-label="Вкладки"
|
||||||
|
className="scrollbar-none flex min-w-0 flex-1 items-center gap-1 overflow-x-auto"
|
||||||
|
>
|
||||||
|
{tabs.map((tab, index) => {
|
||||||
|
const active = tab.id === activeId
|
||||||
|
const closable = Boolean(onClose) && !tab.pinned
|
||||||
|
const chip = (
|
||||||
|
<div
|
||||||
|
role="tab"
|
||||||
|
tabIndex={0}
|
||||||
|
aria-selected={active}
|
||||||
|
data-active={active}
|
||||||
|
draggable={Boolean(onMove) && !tab.pinned}
|
||||||
|
onClick={() => onSelect(tab.id)}
|
||||||
|
onKeyDown={(e) => {
|
||||||
|
if (e.key === "Enter" || e.key === " ") {
|
||||||
|
e.preventDefault()
|
||||||
|
onSelect(tab.id)
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
onAuxClick={(e) => {
|
||||||
|
if (e.button === 1 && closable) {
|
||||||
|
e.preventDefault()
|
||||||
|
onClose?.(tab.id)
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
onMouseDown={(e) => e.button === 1 && e.preventDefault()}
|
||||||
|
onDragStart={(e) => {
|
||||||
|
setDragId(tab.id)
|
||||||
|
e.dataTransfer.effectAllowed = "move"
|
||||||
|
}}
|
||||||
|
onDragOver={(e) => {
|
||||||
|
if (onMove && dragId && dragId !== tab.id && !tab.pinned) {
|
||||||
|
e.preventDefault()
|
||||||
|
onMove(dragId, tab.id)
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
onDragEnd={() => setDragId(null)}
|
||||||
|
className={cn(
|
||||||
|
"group/tab relative flex h-8 max-w-56 shrink-0 cursor-pointer items-center gap-2 rounded-lg px-2.5 text-[13px] font-medium outline-none select-none",
|
||||||
|
"transition-colors duration-150 focus-visible:ring-2 focus-visible:ring-ring/60",
|
||||||
|
active ? "bg-accent text-accent-foreground" : "text-muted-foreground hover:bg-muted hover:text-foreground",
|
||||||
|
dragId === tab.id && "opacity-50",
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{tab.icon ? (
|
||||||
|
<tab.icon className={cn("size-4", active && "text-primary")} />
|
||||||
|
) : (
|
||||||
|
<span
|
||||||
|
className={cn(
|
||||||
|
"relative grid size-5 shrink-0 place-items-center rounded-md text-[11px] font-semibold",
|
||||||
|
toneClass[tab.tone ?? "neutral"],
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{tab.letter ?? tab.label[0]}
|
||||||
|
{tab.alert && (
|
||||||
|
<span className="absolute -top-0.5 -right-0.5 size-2 rounded-full bg-coral ring-2 ring-card" />
|
||||||
|
)}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<Tooltip delayDuration={600}>
|
||||||
|
<TooltipTrigger asChild>
|
||||||
|
<span className="truncate">{tab.label}</span>
|
||||||
|
</TooltipTrigger>
|
||||||
|
<TooltipContent side="bottom" className="flex items-center gap-2">
|
||||||
|
{tab.label}
|
||||||
|
{hotkeyHints && index < 8 && <Kbd>Alt {index + 1}</Kbd>}
|
||||||
|
</TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
|
|
||||||
|
{closable && (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
aria-label={`Закрыть вкладку ${tab.label}`}
|
||||||
|
onClick={(e) => {
|
||||||
|
e.stopPropagation()
|
||||||
|
onClose?.(tab.id)
|
||||||
|
}}
|
||||||
|
className={cn(
|
||||||
|
"-mr-1 grid size-5 shrink-0 place-items-center rounded-md text-current/60 transition hover:bg-foreground/10 hover:text-current",
|
||||||
|
active ? "opacity-100" : "opacity-0 group-hover/tab:opacity-100 focus-visible:opacity-100",
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<XIcon className="size-3.5" />
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<React.Fragment key={tab.id}>
|
||||||
|
{renderMenu ? (
|
||||||
|
<ContextMenu>
|
||||||
|
<ContextMenuTrigger asChild>{chip}</ContextMenuTrigger>
|
||||||
|
<ContextMenuContent className="w-56">{renderMenu(tab)}</ContextMenuContent>
|
||||||
|
</ContextMenu>
|
||||||
|
) : (
|
||||||
|
chip
|
||||||
|
)}
|
||||||
|
{tab.pinned && index < tabs.length - 1 && <span className="mx-1 h-5 w-px shrink-0 bg-border" />}
|
||||||
|
</React.Fragment>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
{actions && <div className="flex shrink-0 items-center gap-1">{actions}</div>}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,114 @@
|
||||||
|
import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react"
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
|
const DEFAULT_SIZES = [15, 30, 50] as const
|
||||||
|
|
||||||
|
/** Номера страниц с многоточиями: 1 … 4 5 6 … 12 */
|
||||||
|
function pageList(current: number, pages: number): (number | "gap")[] {
|
||||||
|
if (pages <= 7) return Array.from({ length: pages }, (_, i) => i)
|
||||||
|
const set = new Set([0, pages - 1, current - 1, current, current + 1])
|
||||||
|
const sorted = [...set].filter((p) => p >= 0 && p < pages).sort((a, b) => a - b)
|
||||||
|
return sorted.flatMap((p, i) => (i > 0 && p - sorted[i - 1] > 1 ? ["gap" as const, p] : [p]))
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Пагинация под таблицей: «1 – 15 из 42», страницы, размер страницы.
|
||||||
|
* `page` — с нуля.
|
||||||
|
*/
|
||||||
|
export function Pagination({
|
||||||
|
total,
|
||||||
|
page,
|
||||||
|
size,
|
||||||
|
onPageChange,
|
||||||
|
onSizeChange,
|
||||||
|
sizeOptions = DEFAULT_SIZES,
|
||||||
|
className,
|
||||||
|
}: {
|
||||||
|
total: number
|
||||||
|
page: number
|
||||||
|
size: number
|
||||||
|
onPageChange: (page: number) => void
|
||||||
|
onSizeChange?: (size: number) => void
|
||||||
|
sizeOptions?: readonly number[]
|
||||||
|
className?: string
|
||||||
|
}) {
|
||||||
|
const pages = Math.max(1, Math.ceil(total / size))
|
||||||
|
const current = Math.min(page, pages - 1)
|
||||||
|
const from = total ? current * size + 1 : 0
|
||||||
|
const to = Math.min((current + 1) * size, total)
|
||||||
|
|
||||||
|
const pageButton = "grid h-7 min-w-7 place-items-center rounded-md px-1.5 text-xs font-medium tabular transition"
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={cn("flex flex-wrap items-center justify-between gap-3 px-4 py-2.5", className)}>
|
||||||
|
<span className="rounded-md bg-muted px-2 py-1 text-xs text-muted-foreground tabular">
|
||||||
|
{from} – {to} из {total}
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<div className="flex items-center gap-0.5">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
aria-label="Предыдущая страница"
|
||||||
|
disabled={current === 0}
|
||||||
|
onClick={() => onPageChange(current - 1)}
|
||||||
|
className={cn(pageButton, "text-muted-foreground hover:bg-muted disabled:opacity-30")}
|
||||||
|
>
|
||||||
|
<ChevronLeftIcon className="size-4" />
|
||||||
|
</button>
|
||||||
|
{pageList(current, pages).map((p, i) =>
|
||||||
|
p === "gap" ? (
|
||||||
|
<span key={`gap-${i}`} className="px-1 text-xs text-muted-foreground">
|
||||||
|
…
|
||||||
|
</span>
|
||||||
|
) : (
|
||||||
|
<button
|
||||||
|
key={p}
|
||||||
|
type="button"
|
||||||
|
aria-current={p === current ? "page" : undefined}
|
||||||
|
onClick={() => onPageChange(p)}
|
||||||
|
className={cn(
|
||||||
|
pageButton,
|
||||||
|
p === current ? "bg-accent text-accent-foreground" : "text-muted-foreground hover:bg-muted",
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{p + 1}
|
||||||
|
</button>
|
||||||
|
),
|
||||||
|
)}
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
aria-label="Следующая страница"
|
||||||
|
disabled={current >= pages - 1}
|
||||||
|
onClick={() => onPageChange(current + 1)}
|
||||||
|
className={cn(pageButton, "text-muted-foreground hover:bg-muted disabled:opacity-30")}
|
||||||
|
>
|
||||||
|
<ChevronRightIcon className="size-4" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{onSizeChange ? (
|
||||||
|
<div className="flex items-center gap-0.5 rounded-lg bg-muted p-0.5">
|
||||||
|
{sizeOptions.map((s) => (
|
||||||
|
<button
|
||||||
|
key={s}
|
||||||
|
type="button"
|
||||||
|
onClick={() => {
|
||||||
|
onSizeChange(s)
|
||||||
|
onPageChange(0)
|
||||||
|
}}
|
||||||
|
className={cn(
|
||||||
|
"h-6 rounded-md px-2 text-xs font-medium tabular transition",
|
||||||
|
s === size ? "bg-card text-foreground shadow-xs" : "text-muted-foreground hover:text-foreground",
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{s}
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<span />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,53 @@
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"
|
||||||
|
|
||||||
|
export type Gender = "male" | "female"
|
||||||
|
|
||||||
|
export interface AvatarPerson {
|
||||||
|
readonly lastName: string
|
||||||
|
readonly firstName: string
|
||||||
|
readonly gender: Gender
|
||||||
|
readonly photoUrl?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export function PatientAvatar({
|
||||||
|
patient,
|
||||||
|
className,
|
||||||
|
ring = false,
|
||||||
|
}: {
|
||||||
|
patient: AvatarPerson
|
||||||
|
className?: string
|
||||||
|
ring?: boolean
|
||||||
|
}) {
|
||||||
|
const female = patient.gender === "female"
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Avatar
|
||||||
|
className={cn(
|
||||||
|
"size-9",
|
||||||
|
ring && "ring-2 ring-offset-2 ring-offset-card",
|
||||||
|
ring && (female ? "ring-female/70" : "ring-male/70"),
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{patient.photoUrl && <AvatarImage src={patient.photoUrl} alt="" className="object-cover" />}
|
||||||
|
<AvatarFallback
|
||||||
|
className={cn("font-semibold", female ? "bg-female/15 text-female" : "bg-male/15 text-male")}
|
||||||
|
>
|
||||||
|
{patient.lastName[0]}
|
||||||
|
{patient.firstName[0]}
|
||||||
|
</AvatarFallback>
|
||||||
|
</Avatar>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function GenderMark({ gender, className }: { gender: Gender; className?: string }) {
|
||||||
|
return (
|
||||||
|
<span
|
||||||
|
title={gender === "female" ? "Женский" : "Мужской"}
|
||||||
|
className={cn("font-semibold", gender === "female" ? "text-female" : "text-male", className)}
|
||||||
|
>
|
||||||
|
{gender === "female" ? "♀" : "♂"}
|
||||||
|
</span>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,102 @@
|
||||||
|
import * as React from "react"
|
||||||
|
import { CopyIcon, IdCardIcon, PhoneIcon, StethoscopeIcon } from "lucide-react"
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
import { copyToClipboard } from "@/lib/clipboard"
|
||||||
|
import { pluralYears } from "@/lib/format"
|
||||||
|
import { ContentTabs, type ContentTabItem } from "./content-tabs"
|
||||||
|
import { GenderMark, PatientAvatar, type AvatarPerson } from "./patient-avatar"
|
||||||
|
|
||||||
|
export interface PatientPanelPerson extends AvatarPerson {
|
||||||
|
readonly middleName?: string
|
||||||
|
readonly birthDate: string
|
||||||
|
readonly age: number
|
||||||
|
readonly phone?: string
|
||||||
|
readonly cardNumber?: string
|
||||||
|
readonly doctor?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Шапка пациента: аватар, ФИО, пол, дата рождения, контакты, действия справа
|
||||||
|
* и (необязательно) вкладки разделов карточки под ней. Лёгкая заливка — в цвет пола.
|
||||||
|
*/
|
||||||
|
export function PatientPanel<T extends string>({
|
||||||
|
person: p,
|
||||||
|
actions,
|
||||||
|
tabs,
|
||||||
|
activeTab,
|
||||||
|
onTabChange,
|
||||||
|
className,
|
||||||
|
}: {
|
||||||
|
person: PatientPanelPerson
|
||||||
|
actions?: React.ReactNode
|
||||||
|
tabs?: readonly ContentTabItem<T>[]
|
||||||
|
activeTab?: T
|
||||||
|
onTabChange?: (tab: T) => void
|
||||||
|
className?: string
|
||||||
|
}) {
|
||||||
|
const female = p.gender === "female"
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={cn("shrink-0", className)}>
|
||||||
|
<header className="relative overflow-hidden border-b">
|
||||||
|
<div
|
||||||
|
className={cn(
|
||||||
|
"pointer-events-none absolute inset-0 opacity-[0.09]",
|
||||||
|
female
|
||||||
|
? "bg-[radial-gradient(ellipse_at_top_left,var(--female)_0%,transparent_55%)]"
|
||||||
|
: "bg-[radial-gradient(ellipse_at_top_left,var(--male)_0%,transparent_55%)]",
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div className="relative flex flex-wrap items-center gap-x-3 gap-y-2 px-5 py-2.5">
|
||||||
|
<PatientAvatar patient={p} ring className="size-9" />
|
||||||
|
|
||||||
|
<div className="min-w-0 flex-1 leading-tight">
|
||||||
|
<div className="flex flex-wrap items-baseline gap-x-2">
|
||||||
|
<h1 className="text-base font-semibold tracking-tight">
|
||||||
|
{p.lastName} {p.firstName} {p.middleName}
|
||||||
|
</h1>
|
||||||
|
<GenderMark gender={p.gender} className="text-sm" />
|
||||||
|
<span className="text-sm text-muted-foreground tabular">
|
||||||
|
{p.birthDate} · <span className="text-foreground">{pluralYears(p.age)}</span>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="mt-0.5 flex flex-wrap items-center gap-x-4 text-[13px] text-muted-foreground">
|
||||||
|
{p.phone && (
|
||||||
|
<a href={`tel:${p.phone}`} className="inline-flex items-center gap-1.5 text-primary hover:underline">
|
||||||
|
<PhoneIcon className="size-3.5" />
|
||||||
|
{p.phone}
|
||||||
|
</a>
|
||||||
|
)}
|
||||||
|
{p.cardNumber && (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => copyToClipboard(p.cardNumber!, "Номер карты скопирован")}
|
||||||
|
className="group inline-flex items-center gap-1.5 hover:text-foreground"
|
||||||
|
>
|
||||||
|
<IdCardIcon className="size-3.5" />
|
||||||
|
<span className="font-mono text-foreground">{p.cardNumber}</span>
|
||||||
|
<CopyIcon className="size-3 opacity-0 transition group-hover:opacity-100" />
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
{p.doctor && (
|
||||||
|
<span className="inline-flex items-center gap-1.5">
|
||||||
|
<StethoscopeIcon className="size-3.5" />
|
||||||
|
<span className="text-foreground">{p.doctor}</span>
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{actions && <div className="flex items-center gap-2">{actions}</div>}
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
{tabs && activeTab !== undefined && onTabChange && (
|
||||||
|
<ContentTabs tabs={tabs} value={activeTab} onValueChange={onTabChange} />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,39 @@
|
||||||
|
import { type LucideIcon } from "lucide-react"
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
import type { StatusTone } from "./status-badge"
|
||||||
|
|
||||||
|
const toneClass: Record<StatusTone, string> = {
|
||||||
|
positive: "text-success bg-success-soft",
|
||||||
|
info: "text-info bg-info-soft",
|
||||||
|
warning: "text-warning bg-warning-soft",
|
||||||
|
negative: "text-coral bg-coral-soft",
|
||||||
|
neutral: "text-muted-foreground bg-muted",
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Плитка с числом: «32 консультации», «2 неявки». */
|
||||||
|
export function StatTile({
|
||||||
|
icon: Icon,
|
||||||
|
value,
|
||||||
|
label,
|
||||||
|
tone = "neutral",
|
||||||
|
className,
|
||||||
|
}: {
|
||||||
|
icon: LucideIcon
|
||||||
|
value: React.ReactNode
|
||||||
|
label: string
|
||||||
|
tone?: StatusTone
|
||||||
|
className?: string
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<div className={cn("flex items-center gap-3 rounded-xl bg-muted/50 p-4", className)}>
|
||||||
|
<div className={cn("grid size-10 shrink-0 place-items-center rounded-lg", toneClass[tone])}>
|
||||||
|
<Icon className="size-5" />
|
||||||
|
</div>
|
||||||
|
<div className="min-w-0">
|
||||||
|
<div className="text-2xl leading-none font-semibold tabular">{value}</div>
|
||||||
|
<div className="mt-1 text-xs text-muted-foreground">{label}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
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",
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Статус с цветной точкой: «Работает», «Записан», «Неявка»… */
|
||||||
|
export function StatusBadge({
|
||||||
|
tone,
|
||||||
|
dot = true,
|
||||||
|
className,
|
||||||
|
children,
|
||||||
|
}: {
|
||||||
|
tone: StatusTone
|
||||||
|
dot?: boolean
|
||||||
|
className?: string
|
||||||
|
children: React.ReactNode
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<span
|
||||||
|
className={cn(
|
||||||
|
"inline-flex items-center gap-1.5 rounded-md border px-2 py-0.5 text-xs font-semibold whitespace-nowrap",
|
||||||
|
toneClass[tone],
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{dot && <span className="size-1.5 rounded-full bg-current" />}
|
||||||
|
{children}
|
||||||
|
</span>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
import { toast } from "sonner"
|
||||||
|
|
||||||
|
/** Скопировать значение и показать подтверждение. */
|
||||||
|
export function copyToClipboard(value: string, title = "Скопировано") {
|
||||||
|
void navigator.clipboard?.writeText(value)
|
||||||
|
toast.success(title, { description: value })
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
/** Русское склонение по числу: plural(3, "день", "дня", "дней") → "дня". */
|
||||||
|
export function plural(count: number, one: string, few: string, many: string) {
|
||||||
|
const mod10 = count % 10
|
||||||
|
const mod100 = count % 100
|
||||||
|
if (mod100 >= 11 && mod100 <= 14) return many
|
||||||
|
if (mod10 === 1) return one
|
||||||
|
if (mod10 >= 2 && mod10 <= 4) return few
|
||||||
|
return many
|
||||||
|
}
|
||||||
|
|
||||||
|
export function pluralYears(age: number) {
|
||||||
|
return `${age} ${plural(age, "год", "года", "лет")}`
|
||||||
|
}
|
||||||
|
|
||||||
|
export function formatBytes(bytes: number) {
|
||||||
|
if (bytes < 1024) return `${bytes} B`
|
||||||
|
const units = ["KB", "MB", "GB"]
|
||||||
|
let value = bytes / 1024
|
||||||
|
let unit = 0
|
||||||
|
while (value >= 1024 && unit < units.length - 1) {
|
||||||
|
value /= 1024
|
||||||
|
unit++
|
||||||
|
}
|
||||||
|
return `${value.toFixed(1)} ${units[unit]}`
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,45 @@
|
||||||
|
import * as React from "react"
|
||||||
|
|
||||||
|
type Theme = "light" | "dark"
|
||||||
|
|
||||||
|
const STORAGE_KEY = "ml.theme"
|
||||||
|
|
||||||
|
const ThemeContext = React.createContext<{ theme: Theme; resolvedTheme: Theme; setTheme: (t: Theme) => void } | null>(
|
||||||
|
null,
|
||||||
|
)
|
||||||
|
|
||||||
|
function readTheme(): Theme {
|
||||||
|
try {
|
||||||
|
return localStorage.getItem(STORAGE_KEY) === "dark" ? "dark" : "light"
|
||||||
|
} catch {
|
||||||
|
return "light"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Светлая/тёмная тема: класс `dark` на <html>, выбор помнится в localStorage. */
|
||||||
|
export function ThemeProvider({ children }: { children: React.ReactNode }) {
|
||||||
|
const [theme, setThemeState] = React.useState<Theme>(readTheme)
|
||||||
|
|
||||||
|
React.useLayoutEffect(() => {
|
||||||
|
document.documentElement.classList.toggle("dark", theme === "dark")
|
||||||
|
document.documentElement.style.colorScheme = theme
|
||||||
|
}, [theme])
|
||||||
|
|
||||||
|
const setTheme = React.useCallback((next: Theme) => {
|
||||||
|
setThemeState(next)
|
||||||
|
try {
|
||||||
|
localStorage.setItem(STORAGE_KEY, next)
|
||||||
|
} catch {
|
||||||
|
/* noop */
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
const value = React.useMemo(() => ({ theme, resolvedTheme: theme, setTheme }), [theme, setTheme])
|
||||||
|
return <ThemeContext.Provider value={value}>{children}</ThemeContext.Provider>
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useTheme() {
|
||||||
|
const ctx = React.useContext(ThemeContext)
|
||||||
|
if (!ctx) throw new Error("useTheme must be used inside <ThemeProvider>")
|
||||||
|
return ctx
|
||||||
|
}
|
||||||
|
|
@ -6,11 +6,11 @@ import {
|
||||||
OctagonXIcon,
|
OctagonXIcon,
|
||||||
TriangleAlertIcon,
|
TriangleAlertIcon,
|
||||||
} from "lucide-react"
|
} from "lucide-react"
|
||||||
import { useTheme } from "next-themes"
|
import { useTheme } from "@/components/theme-provider"
|
||||||
import { Toaster as Sonner, type ToasterProps } from "sonner"
|
import { Toaster as Sonner, type ToasterProps } from "sonner"
|
||||||
|
|
||||||
const Toaster = ({ ...props }: ToasterProps) => {
|
const Toaster = ({ ...props }: ToasterProps) => {
|
||||||
const { theme = "system" } = useTheme()
|
const { theme } = useTheme()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Sonner
|
<Sonner
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue