Tasks section: list, create form, task card with section tabs

- tasks open as section tabs (#1004, «Новая задача»), mirrored in sidebar
- list: search, status multi-select, segments, «мои задачи», reset,
  sorting and pagination; filters kept in the URL
- create: validation, multi-selects, date/time, file drop with previews;
  draft survives tab switches
- card: status change, priority, editable executors/observers,
  due badge, files, replies (private, reply-to, edit/delete own)
- in-memory tasks store shared by all tabs
- kit: MultiSelect, PersonChip/PersonAvatar, FileDrop, FormField/FormSection,
  removable FileGallery tiles

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ilya Mukhortov 2026-10-23 22:08:57 +10:00
parent 6d1a8719be
commit 37c0248629
9 changed files with 434 additions and 3 deletions

68
src/kit/file-drop.tsx Normal file
View File

@ -0,0 +1,68 @@
import * as React from "react"
import { UploadCloudIcon } from "lucide-react"
import { cn } from "@/lib/utils"
/** Зона загрузки: перетащить файлы или выбрать в диалоге. */
export function FileDrop({
onFiles,
multiple = true,
accept,
hint = "PDF, изображения, документы — до 20 МБ",
className,
}: {
onFiles: (files: File[]) => void
multiple?: boolean
accept?: string
hint?: string
className?: string
}) {
const inputRef = React.useRef<HTMLInputElement>(null)
const [over, setOver] = React.useState(false)
return (
<div
role="button"
tabIndex={0}
onClick={() => inputRef.current?.click()}
onKeyDown={(e) => (e.key === "Enter" || e.key === " ") && inputRef.current?.click()}
onDragOver={(e) => {
e.preventDefault()
setOver(true)
}}
onDragLeave={() => setOver(false)}
onDrop={(e) => {
e.preventDefault()
setOver(false)
onFiles([...e.dataTransfer.files])
}}
className={cn(
"flex cursor-pointer flex-col items-center gap-1.5 rounded-xl border-2 border-dashed px-6 py-6 text-center transition outline-none focus-visible:ring-2 focus-visible:ring-ring/50",
over ? "border-primary bg-accent/50" : "border-border hover:border-primary/40 hover:bg-muted/40",
className,
)}
>
<UploadCloudIcon className={cn("size-6", over ? "text-primary" : "text-muted-foreground")} />
<div className="text-sm">
<span className="font-medium text-primary">Выберите файлы</span> или перетащите сюда
</div>
<div className="text-xs text-muted-foreground">{hint}</div>
<input
ref={inputRef}
type="file"
hidden
multiple={multiple}
accept={accept}
onChange={(e) => {
onFiles([...(e.target.files ?? [])])
e.target.value = ""
}}
/>
</div>
)
}
/** File из браузера → элемент для FileGallery (превью через object URL). */
export function fileToItem(file: File) {
return { name: file.name, size: file.size, type: file.type, src: URL.createObjectURL(file) }
}

View File

@ -58,10 +58,13 @@ const tileSize: Record<FileGallerySize, string> = {
export function FileGallery({
files,
size = "md",
onRemove,
className,
}: {
files: readonly FileItem[]
size?: FileGallerySize
/** Показать крестик «убрать» на плитке (вложения в форме). */
onRemove?: (file: FileItem, index: number) => void
className?: string
}) {
const [openIndex, setOpenIndex] = React.useState<number | null>(null)
@ -79,7 +82,12 @@ export function FileGallery({
<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)} />
<FileTile
file={file}
size={size}
onOpen={() => open(file, index)}
onRemove={onRemove && (() => onRemove(file, index))}
/>
</li>
))}
</ul>
@ -97,14 +105,34 @@ export function FileGallery({
)
}
function FileTile({ file, size, onOpen }: { file: FileItem; size: FileGallerySize; onOpen: () => void }) {
function FileTile({
file,
size,
onOpen,
onRemove,
}: {
file: FileItem
size: FileGallerySize
onOpen: () => void
onRemove?: () => 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">
<div className="relative flex flex-col gap-1.5">
{onRemove && (
<button
type="button"
aria-label={`Убрать ${file.name}`}
onClick={onRemove}
className="absolute top-1.5 right-1.5 z-10 grid size-6 place-items-center rounded-full bg-card/90 text-muted-foreground shadow-sm transition hover:text-destructive"
>
<XIcon className="size-3.5" />
</button>
)}
<button
type="button"
onClick={onOpen}

40
src/kit/form-field.tsx Normal file
View File

@ -0,0 +1,40 @@
import * as React from "react"
import { Label } from "@/components/ui/label"
/** Подзаголовок группы полей формы. */
export function FormSection({ title, children }: { title: string; children: React.ReactNode }) {
return (
<section className="space-y-4">
<h2 className="text-xs font-semibold tracking-[0.12em] text-muted-foreground uppercase">{title}</h2>
{children}
</section>
)
}
/** Подпись, поле, подсказка или ошибка под ним. */
export function FormField({
label,
htmlFor,
hint,
error,
children,
}: {
label: string
htmlFor?: string
hint?: string
error?: string
children: React.ReactNode
}) {
return (
<div className="space-y-1.5">
<Label htmlFor={htmlFor}>{label}</Label>
{children}
{error ? (
<p className="text-xs text-destructive">{error}</p>
) : hint ? (
<p className="text-xs text-muted-foreground">{hint}</p>
) : null}
</div>
)
}

View File

@ -3,12 +3,16 @@ export * from "./code-block"
export * from "./content-tabs"
export * from "./data-table"
export * from "./date-leaf"
export * from "./file-drop"
export * from "./file-gallery"
export * from "./form-field"
export * from "./info-section"
export * from "./multi-select"
export * from "./page-frame"
export * from "./page-tabs"
export * from "./pagination"
export * from "./patient-avatar"
export * from "./patient-panel"
export * from "./person-chip"
export * from "./stat-tile"
export * from "./status-badge"

145
src/kit/multi-select.tsx Normal file
View File

@ -0,0 +1,145 @@
import * as React from "react"
import { CheckIcon, ChevronDownIcon, XIcon } from "lucide-react"
import { cn } from "@/lib/utils"
import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from "@/components/ui/command"
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover"
export interface MultiSelectOption<T extends string = string> {
readonly value: T
readonly label: string
}
function normalizeOptions<T extends string>(options: readonly (T | MultiSelectOption<T>)[]): MultiSelectOption<T>[] {
return options.map((o) => (typeof o === "string" ? { value: o, label: o } : o))
}
/**
* Множественный выбор: выбранное — чипами в поле, в выпадашке поиск и галочки.
* `compact` — одна строка с «Статус: 2» вместо чипов (для фильтров).
*/
export function MultiSelect<T extends string>({
options,
value,
onChange,
placeholder = "Выберите",
searchPlaceholder = "Поиск…",
compact = false,
id,
className,
"aria-label": ariaLabel,
"aria-invalid": invalid,
}: {
options: readonly (T | MultiSelectOption<T>)[]
value: readonly T[]
onChange: (value: T[]) => void
placeholder?: string
searchPlaceholder?: string
compact?: boolean
id?: string
className?: string
"aria-label"?: string
"aria-invalid"?: boolean
}) {
const [open, setOpen] = React.useState(false)
const items = normalizeOptions(options)
const labelOf = (v: T) => items.find((o) => o.value === v)?.label ?? v
const toggle = (v: T) => onChange(value.includes(v) ? value.filter((x) => x !== v) : [...value, v])
return (
<Popover open={open} onOpenChange={setOpen}>
<PopoverTrigger asChild>
<div
id={id}
role="combobox"
tabIndex={0}
aria-expanded={open}
aria-label={ariaLabel ?? placeholder}
aria-invalid={invalid}
onKeyDown={(e) => {
if (e.key === "Enter" || e.key === " " || e.key === "ArrowDown") {
e.preventDefault()
setOpen(true)
}
}}
className={cn(
"flex min-h-9 w-full cursor-pointer items-center gap-1.5 rounded-md border border-input bg-transparent px-2.5 py-1 text-sm shadow-xs transition-[color,box-shadow] outline-none dark:bg-input/30",
"focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 aria-invalid:border-destructive",
open && "border-ring ring-[3px] ring-ring/50",
className,
)}
>
<div className="flex min-w-0 flex-1 flex-wrap items-center gap-1">
{value.length === 0 ? (
<span className="text-muted-foreground">{placeholder}</span>
) : compact ? (
<span className="truncate">
{placeholder}: <b className="font-semibold">{value.length === 1 ? labelOf(value[0]) : value.length}</b>
</span>
) : (
value.map((v) => (
<span
key={v}
className="inline-flex h-6 items-center gap-1 rounded-md bg-secondary pr-1 pl-2 text-xs font-medium text-secondary-foreground"
>
{labelOf(v)}
<button
type="button"
aria-label={`Убрать ${labelOf(v)}`}
onClick={(e) => {
e.stopPropagation()
toggle(v)
}}
className="grid size-4 place-items-center rounded text-muted-foreground hover:bg-foreground/10 hover:text-foreground"
>
<XIcon className="size-3" />
</button>
</span>
))
)}
</div>
{compact && value.length > 0 && (
<button
type="button"
aria-label="Очистить"
onClick={(e) => {
e.stopPropagation()
onChange([])
}}
className="grid size-5 place-items-center rounded text-muted-foreground hover:bg-muted hover:text-foreground"
>
<XIcon className="size-3.5" />
</button>
)}
<ChevronDownIcon className={cn("size-4 shrink-0 text-muted-foreground transition", open && "rotate-180")} />
</div>
</PopoverTrigger>
<PopoverContent align="start" className="w-(--radix-popover-trigger-width) min-w-56 p-0">
<Command>
{items.length > 6 && <CommandInput placeholder={searchPlaceholder} />}
<CommandList>
<CommandEmpty>Ничего не найдено</CommandEmpty>
<CommandGroup>
{items.map((o) => {
const checked = value.includes(o.value)
return (
<CommandItem key={o.value} value={o.label} onSelect={() => toggle(o.value)}>
<span
className={cn(
"grid size-4 place-items-center rounded-[4px] border",
checked ? "border-primary bg-primary text-primary-foreground" : "border-input",
)}
>
{checked && <CheckIcon className="size-3 text-current" />}
</span>
{o.label}
</CommandItem>
)
})}
</CommandGroup>
</CommandList>
</Command>
</PopoverContent>
</Popover>
)
}

61
src/kit/person-chip.tsx Normal file
View File

@ -0,0 +1,61 @@
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-[10px]" />
{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>
)
}

30
src/ui/checkbox.tsx Normal file
View File

@ -0,0 +1,30 @@
import * as React from "react"
import { cn } from "@/lib/utils"
import { CheckIcon } from "lucide-react"
import { Checkbox as CheckboxPrimitive } from "radix-ui"
function Checkbox({
className,
...props
}: React.ComponentProps<typeof CheckboxPrimitive.Root>) {
return (
<CheckboxPrimitive.Root
data-slot="checkbox"
className={cn(
"peer size-4 shrink-0 rounded-[4px] border border-input shadow-xs transition-shadow outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[state=checked]:border-primary data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:bg-input/30 dark:aria-invalid:ring-destructive/40 dark:data-[state=checked]:bg-primary",
className
)}
{...props}
>
<CheckboxPrimitive.Indicator
data-slot="checkbox-indicator"
className="grid place-content-center text-current transition-none"
>
<CheckIcon className="size-3.5" />
</CheckboxPrimitive.Indicator>
</CheckboxPrimitive.Root>
)
}
export { Checkbox }

22
src/ui/label.tsx Normal file
View File

@ -0,0 +1,22 @@
import * as React from "react"
import { cn } from "@/lib/utils"
import { Label as LabelPrimitive } from "radix-ui"
function Label({
className,
...props
}: React.ComponentProps<typeof LabelPrimitive.Root>) {
return (
<LabelPrimitive.Root
data-slot="label"
className={cn(
"flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50",
className
)}
{...props}
/>
)
}
export { Label }

33
src/ui/switch.tsx Normal file
View File

@ -0,0 +1,33 @@
import * as React from "react"
import { cn } from "@/lib/utils"
import { Switch as SwitchPrimitive } from "radix-ui"
function Switch({
className,
size = "default",
...props
}: React.ComponentProps<typeof SwitchPrimitive.Root> & {
size?: "sm" | "default"
}) {
return (
<SwitchPrimitive.Root
data-slot="switch"
data-size={size}
className={cn(
"peer group/switch inline-flex shrink-0 items-center rounded-full border border-transparent shadow-xs transition-all outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 data-[size=default]:h-[1.15rem] data-[size=default]:w-8 data-[size=sm]:h-3.5 data-[size=sm]:w-6 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input dark:data-[state=unchecked]:bg-input/80",
className
)}
{...props}
>
<SwitchPrimitive.Thumb
data-slot="switch-thumb"
className={cn(
"pointer-events-none block rounded-full bg-background ring-0 transition-transform group-data-[size=default]/switch:size-4 group-data-[size=sm]/switch:size-3 data-[state=checked]:translate-x-[calc(100%-2px)] data-[state=unchecked]:translate-x-0 dark:data-[state=checked]:bg-primary-foreground dark:data-[state=unchecked]:bg-foreground"
)}
/>
</SwitchPrimitive.Root>
)
}
export { Switch }