Notice, Chip, Autocomplete, loading indicators, release 0.4.0
Replacements for MUI pieces the LIS still uses: - Notice: inline error/warning/info/success message with title, action, close - Chip: static, selectable, with count or remove button; MultiSelect chips use it - Autocomplete: type-in field with suggestions, local filter or server search - Spinner, LoadingBar, indeterminate Progress - RadioGroup and Collapsible (height animation) from shadcn Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
7ac2af1b8b
commit
4d04e9af68
|
|
@ -18,7 +18,7 @@ src/styles.css тема (токены, шрифты, тёмный режим)
|
||||||
Пакет ставится прямо из git, версии — теги `vX.Y.Z`:
|
Пакет ставится прямо из git, версии — теги `vX.Y.Z`:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm i "git+https://git.med-logic.ru/medlogic/medkit.git#semver:^0.3.0"
|
npm i "git+https://git.med-logic.ru/medlogic/medkit.git#semver:^0.4.0"
|
||||||
```
|
```
|
||||||
|
|
||||||
`package-lock.json` фиксирует коммит; обновиться до свежего тега — `npm update @medkit/ui`. В medicine-ui kit подключён git-submodule в `packages/medkit` (npm workspace) — правки видны сразу.
|
`package-lock.json` фиксирует коммит; обновиться до свежего тега — `npm update @medkit/ui`. В medicine-ui kit подключён git-submodule в `packages/medkit` (npm workspace) — правки видны сразу.
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@medkit/ui",
|
"name": "@medkit/ui",
|
||||||
"version": "0.3.0",
|
"version": "0.4.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "Medkit — UI kit МИС «Медицина»: React 19 + Tailwind 4 + Radix (shadcn/ui)",
|
"description": "Medkit — UI kit МИС «Медицина»: React 19 + Tailwind 4 + Radix (shadcn/ui)",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ export * from "./ui/button"
|
||||||
export * from "./ui/calendar"
|
export * from "./ui/calendar"
|
||||||
export * from "./ui/card"
|
export * from "./ui/card"
|
||||||
export * from "./ui/checkbox"
|
export * from "./ui/checkbox"
|
||||||
|
export * from "./ui/collapsible"
|
||||||
export * from "./ui/command"
|
export * from "./ui/command"
|
||||||
export * from "./ui/context-menu"
|
export * from "./ui/context-menu"
|
||||||
export * from "./ui/dialog"
|
export * from "./ui/dialog"
|
||||||
|
|
@ -20,12 +21,14 @@ export * from "./ui/kbd"
|
||||||
export * from "./ui/label"
|
export * from "./ui/label"
|
||||||
export * from "./ui/popover"
|
export * from "./ui/popover"
|
||||||
export * from "./ui/progress"
|
export * from "./ui/progress"
|
||||||
|
export * from "./ui/radio-group"
|
||||||
export * from "./ui/scroll-area"
|
export * from "./ui/scroll-area"
|
||||||
export * from "./ui/select"
|
export * from "./ui/select"
|
||||||
export * from "./ui/separator"
|
export * from "./ui/separator"
|
||||||
export * from "./ui/sheet"
|
export * from "./ui/sheet"
|
||||||
export * from "./ui/skeleton"
|
export * from "./ui/skeleton"
|
||||||
export * from "./ui/sonner"
|
export * from "./ui/sonner"
|
||||||
|
export * from "./ui/spinner"
|
||||||
export * from "./ui/switch"
|
export * from "./ui/switch"
|
||||||
export * from "./ui/table"
|
export * from "./ui/table"
|
||||||
export * from "./ui/tabs"
|
export * from "./ui/tabs"
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,212 @@
|
||||||
|
import * as React from "react"
|
||||||
|
import { Command as CommandPrimitive } from "cmdk"
|
||||||
|
import { CheckIcon, SearchIcon, XIcon } from "lucide-react"
|
||||||
|
|
||||||
|
import { cn } from "../lib/utils"
|
||||||
|
import { CommandGroup, CommandItem, CommandList } from "../ui/command"
|
||||||
|
import { InputGroup, InputGroupAddon } from "../ui/input-group"
|
||||||
|
import { Popover, PopoverAnchor, PopoverContent } from "../ui/popover"
|
||||||
|
import { Spinner } from "../ui/spinner"
|
||||||
|
|
||||||
|
const norm = (v: string) => v.toLowerCase().replace(/ё/g, "е")
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Поиск с подсказками: печатают прямо в поле, варианты — списком под ним (как MUI Autocomplete).
|
||||||
|
* Значение — сам объект. Без `onSearchChange` фильтрует `options` по `getLabel`;
|
||||||
|
* с ним — ищет сервер: текст уходит в `onSearchChange` через `searchDelay` мс, `options` и `loading` — от запроса.
|
||||||
|
*/
|
||||||
|
export function Autocomplete<T>({
|
||||||
|
options,
|
||||||
|
value,
|
||||||
|
onChange,
|
||||||
|
getKey,
|
||||||
|
getLabel,
|
||||||
|
renderOption,
|
||||||
|
onSearchChange,
|
||||||
|
searchDelay = 300,
|
||||||
|
minSearchLength = 0,
|
||||||
|
loading = false,
|
||||||
|
emptyText = "Ничего не найдено",
|
||||||
|
hint,
|
||||||
|
placeholder,
|
||||||
|
autoFocus,
|
||||||
|
disabled,
|
||||||
|
invalid,
|
||||||
|
id,
|
||||||
|
className,
|
||||||
|
"aria-label": ariaLabel,
|
||||||
|
}: {
|
||||||
|
options: readonly T[]
|
||||||
|
value: T | null
|
||||||
|
onChange: (value: T | null) => void
|
||||||
|
getKey: (option: T) => string | number
|
||||||
|
/** Текст в поле после выбора; по нему же фильтруются варианты без `onSearchChange`. */
|
||||||
|
getLabel: (option: T) => string
|
||||||
|
/** Строка списка; по умолчанию — `getLabel`. */
|
||||||
|
renderOption?: (option: T) => React.ReactNode
|
||||||
|
/** Задан — варианты ищет сервер, сами не фильтруем. */
|
||||||
|
onSearchChange?: (search: string) => void
|
||||||
|
searchDelay?: number
|
||||||
|
/** Пока текст короче — список не ищется, показывается `hint` (только с `onSearchChange`). */
|
||||||
|
minSearchLength?: number
|
||||||
|
loading?: boolean
|
||||||
|
emptyText?: React.ReactNode
|
||||||
|
hint?: React.ReactNode
|
||||||
|
placeholder?: string
|
||||||
|
autoFocus?: boolean
|
||||||
|
disabled?: boolean
|
||||||
|
invalid?: boolean
|
||||||
|
id?: string
|
||||||
|
className?: string
|
||||||
|
"aria-label"?: string
|
||||||
|
}) {
|
||||||
|
const anchorRef = React.useRef<HTMLDivElement>(null)
|
||||||
|
const inputRef = React.useRef<HTMLInputElement>(null)
|
||||||
|
const [open, setOpen] = React.useState(false)
|
||||||
|
const [text, setText] = React.useState(value ? getLabel(value) : "")
|
||||||
|
// null — пользователь не печатает (после выбора или ухода из поля): показываем все варианты
|
||||||
|
const [query, setQuery] = React.useState<string | null>(null)
|
||||||
|
const [active, setActive] = React.useState("")
|
||||||
|
|
||||||
|
// значение сменили снаружи (сброс формы) — показываем его подпись
|
||||||
|
const valueKey = value == null ? null : getKey(value)
|
||||||
|
const [shownKey, setShownKey] = React.useState(valueKey)
|
||||||
|
if (shownKey !== valueKey) {
|
||||||
|
setShownKey(valueKey)
|
||||||
|
setText(value ? getLabel(value) : "")
|
||||||
|
setQuery(null)
|
||||||
|
}
|
||||||
|
|
||||||
|
const onSearchRef = React.useRef(onSearchChange)
|
||||||
|
React.useLayoutEffect(() => {
|
||||||
|
onSearchRef.current = onSearchChange
|
||||||
|
})
|
||||||
|
const server = !!onSearchChange
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (query === null || !onSearchRef.current) return
|
||||||
|
const timer = setTimeout(() => onSearchRef.current?.(query.trim()), searchDelay)
|
||||||
|
return () => clearTimeout(timer)
|
||||||
|
}, [query, searchDelay])
|
||||||
|
|
||||||
|
const search = (query ?? "").trim()
|
||||||
|
const items = server || !search ? options : options.filter((o) => norm(getLabel(o)).includes(norm(search)))
|
||||||
|
const tooShort = server && search.length < minSearchLength
|
||||||
|
const keys = items.map((o) => String(getKey(o)))
|
||||||
|
// подсвеченный вариант — всегда из текущего списка: Enter берёт первый
|
||||||
|
const activeKey = keys.includes(active) ? active : (keys[0] ?? "")
|
||||||
|
// вариант выбран и пользователь ещё не печатает — подсказка «от N символов» не нужна
|
||||||
|
const hasContent = tooShort ? !!hint && !(query === null && value) : true
|
||||||
|
|
||||||
|
const pick = (option: T) => {
|
||||||
|
onChange(option)
|
||||||
|
setText(getLabel(option))
|
||||||
|
setQuery(null)
|
||||||
|
setOpen(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
const restore = () => {
|
||||||
|
setOpen(false)
|
||||||
|
setQuery(null)
|
||||||
|
setText(value ? getLabel(value) : "")
|
||||||
|
}
|
||||||
|
|
||||||
|
const isInside = (target: EventTarget | null) => !!target && !!anchorRef.current?.contains(target as Node)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<CommandPrimitive
|
||||||
|
shouldFilter={false}
|
||||||
|
loop
|
||||||
|
value={activeKey}
|
||||||
|
onValueChange={setActive}
|
||||||
|
className={cn("w-full", className)}
|
||||||
|
>
|
||||||
|
<Popover open={open && hasContent && !disabled} onOpenChange={(next) => !next && setOpen(false)}>
|
||||||
|
<PopoverAnchor asChild>
|
||||||
|
<InputGroup ref={anchorRef} data-disabled={disabled || undefined}>
|
||||||
|
<InputGroupAddon>
|
||||||
|
<SearchIcon />
|
||||||
|
</InputGroupAddon>
|
||||||
|
<CommandPrimitive.Input
|
||||||
|
ref={inputRef}
|
||||||
|
id={id}
|
||||||
|
data-slot="input-group-control"
|
||||||
|
value={text}
|
||||||
|
onValueChange={(next) => {
|
||||||
|
setText(next)
|
||||||
|
setQuery(next)
|
||||||
|
setOpen(true)
|
||||||
|
if (!next && value) onChange(null)
|
||||||
|
}}
|
||||||
|
onFocus={() => setOpen(true)}
|
||||||
|
onClick={() => setOpen(true)}
|
||||||
|
onBlur={restore}
|
||||||
|
onKeyDown={(e) => {
|
||||||
|
if (!open && (e.key === "ArrowDown" || e.key === "ArrowUp")) setOpen(true)
|
||||||
|
}}
|
||||||
|
autoFocus={autoFocus}
|
||||||
|
disabled={disabled}
|
||||||
|
placeholder={placeholder}
|
||||||
|
aria-label={ariaLabel ?? placeholder}
|
||||||
|
aria-invalid={invalid}
|
||||||
|
autoComplete="off"
|
||||||
|
className="h-full min-w-0 flex-1 bg-transparent pr-2 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50"
|
||||||
|
/>
|
||||||
|
{(loading || (text && !disabled)) && (
|
||||||
|
<InputGroupAddon align="inline-end">
|
||||||
|
{loading && <Spinner />}
|
||||||
|
{text && !disabled && (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
aria-label="Очистить"
|
||||||
|
tabIndex={-1}
|
||||||
|
onMouseDown={(e) => e.preventDefault()}
|
||||||
|
onClick={() => {
|
||||||
|
if (value) onChange(null)
|
||||||
|
setText("")
|
||||||
|
setQuery("")
|
||||||
|
setOpen(true)
|
||||||
|
inputRef.current?.focus()
|
||||||
|
}}
|
||||||
|
className="grid size-5 place-items-center rounded text-muted-foreground hover:bg-muted hover:text-foreground"
|
||||||
|
>
|
||||||
|
<XIcon className="size-3.5" />
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</InputGroupAddon>
|
||||||
|
)}
|
||||||
|
</InputGroup>
|
||||||
|
</PopoverAnchor>
|
||||||
|
<PopoverContent
|
||||||
|
align="start"
|
||||||
|
className="w-(--radix-popover-trigger-width) min-w-56 p-0"
|
||||||
|
onOpenAutoFocus={(e) => e.preventDefault()}
|
||||||
|
onCloseAutoFocus={(e) => e.preventDefault()}
|
||||||
|
onInteractOutside={(e) => isInside(e.target) && e.preventDefault()}
|
||||||
|
onFocusOutside={(e) => isInside(e.target) && e.preventDefault()}
|
||||||
|
// клик по варианту не должен уводить фокус из поля (иначе blur закроет список до выбора)
|
||||||
|
onMouseDown={(e) => e.preventDefault()}
|
||||||
|
>
|
||||||
|
<CommandList>
|
||||||
|
{tooShort ? (
|
||||||
|
<div className="px-3 py-4 text-center text-sm text-muted-foreground">{hint}</div>
|
||||||
|
) : !items.length ? (
|
||||||
|
<div className="px-3 py-4 text-center text-sm text-muted-foreground">{loading ? "Поиск…" : emptyText}</div>
|
||||||
|
) : (
|
||||||
|
<CommandGroup>
|
||||||
|
{items.map((o, i) => {
|
||||||
|
const selected = valueKey !== null && getKey(o) === valueKey
|
||||||
|
return (
|
||||||
|
<CommandItem key={keys[i]} value={keys[i]} onSelect={() => pick(o)}>
|
||||||
|
<CheckIcon className={cn("size-4", selected ? "text-primary" : "invisible")} />
|
||||||
|
<div className="min-w-0 flex-1">{renderOption ? renderOption(o) : getLabel(o)}</div>
|
||||||
|
</CommandItem>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</CommandGroup>
|
||||||
|
)}
|
||||||
|
</CommandList>
|
||||||
|
</PopoverContent>
|
||||||
|
</Popover>
|
||||||
|
</CommandPrimitive>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,148 @@
|
||||||
|
import * as React from "react"
|
||||||
|
import { XIcon } from "lucide-react"
|
||||||
|
|
||||||
|
import { cn } from "../lib/utils"
|
||||||
|
import type { StatusTone } from "./status-badge"
|
||||||
|
|
||||||
|
export type ChipTone = StatusTone | "primary"
|
||||||
|
export type ChipVariant = "soft" | "outline" | "solid"
|
||||||
|
|
||||||
|
const toneClass: Record<ChipTone, Record<ChipVariant | "hover", string>> = {
|
||||||
|
primary: {
|
||||||
|
soft: "border-transparent bg-primary/10 text-primary",
|
||||||
|
outline: "border-primary/30 text-primary",
|
||||||
|
solid: "border-primary bg-primary text-primary-foreground",
|
||||||
|
hover: "hover:border-primary/40 hover:bg-primary/5 hover:text-foreground",
|
||||||
|
},
|
||||||
|
positive: {
|
||||||
|
soft: "border-transparent bg-success-soft text-success",
|
||||||
|
outline: "border-success/30 text-success",
|
||||||
|
solid: "border-success bg-success text-white",
|
||||||
|
hover: "hover:border-success/40 hover:bg-success-soft",
|
||||||
|
},
|
||||||
|
info: {
|
||||||
|
soft: "border-transparent bg-info-soft text-info",
|
||||||
|
outline: "border-info/30 text-info",
|
||||||
|
solid: "border-info bg-info text-white",
|
||||||
|
hover: "hover:border-info/40 hover:bg-info-soft",
|
||||||
|
},
|
||||||
|
warning: {
|
||||||
|
soft: "border-transparent bg-warning-soft text-warning",
|
||||||
|
outline: "border-warning/40 text-warning",
|
||||||
|
solid: "border-warning bg-warning text-black/85",
|
||||||
|
hover: "hover:border-warning/50 hover:bg-warning-soft",
|
||||||
|
},
|
||||||
|
negative: {
|
||||||
|
soft: "border-transparent bg-coral-soft text-coral",
|
||||||
|
outline: "border-coral/30 text-coral",
|
||||||
|
solid: "border-coral bg-coral text-white",
|
||||||
|
hover: "hover:border-coral/40 hover:bg-coral-soft",
|
||||||
|
},
|
||||||
|
neutral: {
|
||||||
|
soft: "border-transparent bg-muted text-muted-foreground",
|
||||||
|
outline: "border-border text-muted-foreground",
|
||||||
|
solid: "border-foreground bg-foreground text-background",
|
||||||
|
hover: "hover:border-primary/40 hover:bg-primary/5 hover:text-foreground",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
const sizeClass = {
|
||||||
|
sm: { root: "h-5 gap-1 px-1.5 text-[11px]", remove: "pr-0.5", x: "size-4" },
|
||||||
|
md: { root: "h-6 gap-1.5 px-2.5 text-xs", remove: "pr-1", x: "size-4.5" },
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Метка-тег: статичная («cito», «повтор»), выбираемая (фильтр, причина — `onClick` + `selected`),
|
||||||
|
* со счётчиком (`count`) и с крестиком (`onRemove`). Кликабельная по умолчанию — `outline`,
|
||||||
|
* выбранная — сплошная в цвет тона (нейтральная — в основной цвет).
|
||||||
|
*/
|
||||||
|
export function Chip({
|
||||||
|
tone = "neutral",
|
||||||
|
variant,
|
||||||
|
size = "md",
|
||||||
|
selected,
|
||||||
|
onClick,
|
||||||
|
count,
|
||||||
|
onRemove,
|
||||||
|
icon,
|
||||||
|
title,
|
||||||
|
disabled,
|
||||||
|
className,
|
||||||
|
children,
|
||||||
|
}: {
|
||||||
|
tone?: ChipTone
|
||||||
|
variant?: ChipVariant
|
||||||
|
size?: "sm" | "md"
|
||||||
|
selected?: boolean
|
||||||
|
onClick?: () => void
|
||||||
|
count?: number
|
||||||
|
onRemove?: () => void
|
||||||
|
icon?: React.ReactNode
|
||||||
|
title?: string
|
||||||
|
disabled?: boolean
|
||||||
|
className?: string
|
||||||
|
children: React.ReactNode
|
||||||
|
}) {
|
||||||
|
const sizes = sizeClass[size]
|
||||||
|
const colors = selected
|
||||||
|
? toneClass[tone === "neutral" ? "primary" : tone].solid
|
||||||
|
: cn(toneClass[tone][variant ?? (onClick ? "outline" : "soft")], onClick && !disabled && toneClass[tone].hover)
|
||||||
|
const root = cn(
|
||||||
|
"inline-flex w-fit shrink-0 items-center rounded-full border font-medium whitespace-nowrap transition outline-none [&_svg]:size-3 [&_svg]:shrink-0",
|
||||||
|
"focus-visible:ring-[3px] focus-visible:ring-ring/50 has-[button:focus-visible]:ring-[3px] has-[button:focus-visible]:ring-ring/50",
|
||||||
|
sizes.root,
|
||||||
|
onRemove && sizes.remove,
|
||||||
|
colors,
|
||||||
|
disabled && "opacity-50",
|
||||||
|
className,
|
||||||
|
)
|
||||||
|
const body = (
|
||||||
|
<>
|
||||||
|
{icon}
|
||||||
|
{children}
|
||||||
|
{count != null && <span className="font-mono text-[11px] tabular-nums opacity-70">{count}</span>}
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
|
||||||
|
if (onClick && !onRemove)
|
||||||
|
return (
|
||||||
|
<button type="button" aria-pressed={selected} title={title} disabled={disabled} onClick={onClick} className={root}>
|
||||||
|
{body}
|
||||||
|
</button>
|
||||||
|
)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<span title={title} aria-disabled={disabled || undefined} className={root}>
|
||||||
|
{onClick ? (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
aria-pressed={selected}
|
||||||
|
disabled={disabled}
|
||||||
|
onClick={onClick}
|
||||||
|
className="inline-flex items-center gap-[inherit] outline-none"
|
||||||
|
>
|
||||||
|
{body}
|
||||||
|
</button>
|
||||||
|
) : (
|
||||||
|
body
|
||||||
|
)}
|
||||||
|
{onRemove && (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
aria-label={typeof children === "string" ? `Убрать ${children}` : "Убрать"}
|
||||||
|
disabled={disabled}
|
||||||
|
onClick={(e) => {
|
||||||
|
e.stopPropagation()
|
||||||
|
onRemove()
|
||||||
|
}}
|
||||||
|
className={cn(
|
||||||
|
"grid place-items-center rounded-full opacity-60 transition outline-none hover:bg-current/15 hover:opacity-100",
|
||||||
|
sizes.x,
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<XIcon />
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</span>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
// Составные компоненты Medkit. Витрина — /ui в medicine-ui (src/pages/ui/ui-page.tsx).
|
// Составные компоненты Medkit. Витрина — /ui в medicine-ui (src/pages/ui/ui-page.tsx).
|
||||||
|
export * from "./autocomplete"
|
||||||
|
export * from "./chip"
|
||||||
export * from "./code-block"
|
export * from "./code-block"
|
||||||
export * from "./combobox"
|
export * from "./combobox"
|
||||||
export * from "./confirm-dialog"
|
export * from "./confirm-dialog"
|
||||||
|
|
@ -12,8 +14,10 @@ export * from "./file-drop"
|
||||||
export * from "./file-gallery"
|
export * from "./file-gallery"
|
||||||
export * from "./form-field"
|
export * from "./form-field"
|
||||||
export * from "./info-section"
|
export * from "./info-section"
|
||||||
|
export * from "./loading-bar"
|
||||||
export * from "./login-form"
|
export * from "./login-form"
|
||||||
export * from "./multi-select"
|
export * from "./multi-select"
|
||||||
|
export * from "./notice"
|
||||||
export * from "./notify"
|
export * from "./notify"
|
||||||
export * from "./page-frame"
|
export * from "./page-frame"
|
||||||
export * from "./page-tabs"
|
export * from "./page-tabs"
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
import * as React from "react"
|
||||||
|
|
||||||
|
import { cn } from "../lib/utils"
|
||||||
|
import { Progress } from "../ui/progress"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Бегущая полоса по верхнему краю блока — фоновое обновление списка (у родителя `relative`).
|
||||||
|
* Появляется через `delay` мс, чтобы не мигать на быстрых запросах.
|
||||||
|
*/
|
||||||
|
export function LoadingBar({ active, delay = 150, className }: { active: boolean; delay?: number; className?: string }) {
|
||||||
|
const [shown, setShown] = React.useState(false)
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (!active) return
|
||||||
|
const timer = setTimeout(() => setShown(true), delay)
|
||||||
|
return () => {
|
||||||
|
clearTimeout(timer)
|
||||||
|
setShown(false)
|
||||||
|
}
|
||||||
|
}, [active, delay])
|
||||||
|
|
||||||
|
if (!active || !shown) return null
|
||||||
|
return (
|
||||||
|
<Progress
|
||||||
|
aria-label="Обновление"
|
||||||
|
className={cn("pointer-events-none absolute inset-x-0 top-0 z-10 h-0.5 rounded-none bg-transparent", className)}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
@ -4,6 +4,7 @@ import { CheckIcon, ChevronDownIcon, XIcon } from "lucide-react"
|
||||||
import { cn } from "../lib/utils"
|
import { cn } from "../lib/utils"
|
||||||
import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from "../ui/command"
|
import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from "../ui/command"
|
||||||
import { Popover, PopoverContent, PopoverTrigger } from "../ui/popover"
|
import { Popover, PopoverContent, PopoverTrigger } from "../ui/popover"
|
||||||
|
import { Chip } from "./chip"
|
||||||
|
|
||||||
export interface MultiSelectOption<T extends string = string> {
|
export interface MultiSelectOption<T extends string = string> {
|
||||||
readonly value: T
|
readonly value: T
|
||||||
|
|
@ -78,23 +79,13 @@ export function MultiSelect<T extends string>({
|
||||||
</span>
|
</span>
|
||||||
) : (
|
) : (
|
||||||
value.map((v) => (
|
value.map((v) => (
|
||||||
<span
|
<Chip
|
||||||
key={v}
|
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"
|
onRemove={() => toggle(v)}
|
||||||
|
className="gap-1 rounded-md border-transparent bg-secondary pl-2 text-secondary-foreground"
|
||||||
>
|
>
|
||||||
{labelOf(v)}
|
{labelOf(v)}
|
||||||
<button
|
</Chip>
|
||||||
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>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,60 @@
|
||||||
|
import * as React from "react"
|
||||||
|
import { XIcon } from "lucide-react"
|
||||||
|
|
||||||
|
import { cn } from "../lib/utils"
|
||||||
|
import { NOTIFY_ICON, type NotifyType } from "./notify"
|
||||||
|
|
||||||
|
const toneClass: Record<NotifyType, string> = {
|
||||||
|
error: "border-coral/25 bg-coral-soft text-coral",
|
||||||
|
warning: "border-warning/30 bg-warning-soft text-warning",
|
||||||
|
info: "border-info/20 bg-info-soft text-info",
|
||||||
|
success: "border-success/20 bg-success-soft text-success",
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Плашка-сообщение на месте содержимого: ошибка запроса, предупреждение, подсказка.
|
||||||
|
* `action` — кнопка справа, `onClose` — крестик; `icon={false}` убирает иконку.
|
||||||
|
*/
|
||||||
|
export function Notice({
|
||||||
|
tone = "error",
|
||||||
|
title,
|
||||||
|
icon = true,
|
||||||
|
action,
|
||||||
|
onClose,
|
||||||
|
className,
|
||||||
|
children,
|
||||||
|
}: {
|
||||||
|
tone?: NotifyType
|
||||||
|
title?: React.ReactNode
|
||||||
|
icon?: boolean
|
||||||
|
action?: React.ReactNode
|
||||||
|
onClose?: () => void
|
||||||
|
className?: string
|
||||||
|
children?: React.ReactNode
|
||||||
|
}) {
|
||||||
|
const Icon = NOTIFY_ICON[tone]
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
role={tone === "error" ? "alert" : "status"}
|
||||||
|
className={cn("flex items-start gap-2.5 rounded-lg border px-3 py-2 text-sm", toneClass[tone], className)}
|
||||||
|
>
|
||||||
|
{icon && <Icon className="mt-0.5 size-4 shrink-0" />}
|
||||||
|
<div className="min-w-0 flex-1 break-words">
|
||||||
|
{title && <div className="font-semibold">{title}</div>}
|
||||||
|
{children && <div className={cn(title && "mt-0.5 text-foreground/80")}>{children}</div>}
|
||||||
|
</div>
|
||||||
|
{action && <div className="-my-0.5 shrink-0 self-center">{action}</div>}
|
||||||
|
{onClose && (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={onClose}
|
||||||
|
aria-label="Закрыть"
|
||||||
|
className="-mr-1 grid size-5 shrink-0 place-items-center rounded opacity-70 transition hover:bg-current/10 hover:opacity-100"
|
||||||
|
>
|
||||||
|
<XIcon className="size-3.5" />
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
@ -19,11 +19,19 @@ const TOASTER_ID = "notify"
|
||||||
/** Переход по href из карточки; без роутера — обычная навигация браузера. */
|
/** Переход по href из карточки; без роутера — обычная навигация браузера. */
|
||||||
const NavigateContext = React.createContext<(href: string) => void>((href) => window.location.assign(href))
|
const NavigateContext = React.createContext<(href: string) => void>((href) => window.location.assign(href))
|
||||||
|
|
||||||
const typeMeta: Record<NotifyType, { icon: LucideIcon; tile: string; bar: string; duration: number }> = {
|
/** Иконка по типу сообщения — общая для тостов и Notice. */
|
||||||
success: { icon: CircleCheckIcon, tile: "bg-success-soft text-success", bar: "bg-success", duration: 5000 },
|
export const NOTIFY_ICON: Record<NotifyType, LucideIcon> = {
|
||||||
info: { icon: InfoIcon, tile: "bg-info-soft text-info", bar: "bg-info", duration: 6000 },
|
success: CircleCheckIcon,
|
||||||
warning: { icon: TriangleAlertIcon, tile: "bg-warning-soft text-warning", bar: "bg-warning", duration: 8000 },
|
info: InfoIcon,
|
||||||
error: { icon: OctagonXIcon, tile: "bg-coral-soft text-coral", bar: "bg-coral", duration: 10000 },
|
warning: TriangleAlertIcon,
|
||||||
|
error: OctagonXIcon,
|
||||||
|
}
|
||||||
|
|
||||||
|
const typeMeta: Record<NotifyType, { tile: string; bar: string; duration: number }> = {
|
||||||
|
success: { tile: "bg-success-soft text-success", bar: "bg-success", duration: 5000 },
|
||||||
|
info: { tile: "bg-info-soft text-info", bar: "bg-info", duration: 6000 },
|
||||||
|
warning: { tile: "bg-warning-soft text-warning", bar: "bg-warning", duration: 8000 },
|
||||||
|
error: { tile: "bg-coral-soft text-coral", bar: "bg-coral", duration: 10000 },
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface NotifyOptions {
|
export interface NotifyOptions {
|
||||||
|
|
@ -79,7 +87,8 @@ function NotifyCard({
|
||||||
actionLabel = "Перейти",
|
actionLabel = "Перейти",
|
||||||
}: Omit<NotifyOptions, "duration"> & { id: string | number; type: NotifyType }) {
|
}: Omit<NotifyOptions, "duration"> & { id: string | number; type: NotifyType }) {
|
||||||
const navigate = React.useContext(NavigateContext)
|
const navigate = React.useContext(NavigateContext)
|
||||||
const { icon: Icon, tile, bar } = typeMeta[type]
|
const { tile, bar } = typeMeta[type]
|
||||||
|
const Icon = NOTIFY_ICON[type]
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
|
|
||||||
|
|
@ -175,6 +175,13 @@
|
||||||
0%, 100% { opacity: 1; }
|
0%, 100% { opacity: 1; }
|
||||||
50% { opacity: 0.3; }
|
50% { opacity: 0.3; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Progress без value и LoadingBar: отрезок бежит слева направо */
|
||||||
|
--animate-progress-indeterminate: progress-indeterminate 1.2s ease-in-out infinite;
|
||||||
|
@keyframes progress-indeterminate {
|
||||||
|
0% { transform: translateX(-100%); }
|
||||||
|
100% { transform: translateX(300%); }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@layer base {
|
@layer base {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,40 @@
|
||||||
|
import * as React from "react"
|
||||||
|
import { cn } from "../lib/utils"
|
||||||
|
import { Collapsible as CollapsiblePrimitive } from "radix-ui"
|
||||||
|
|
||||||
|
function Collapsible({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof CollapsiblePrimitive.Root>) {
|
||||||
|
return <CollapsiblePrimitive.Root data-slot="collapsible" {...props} />
|
||||||
|
}
|
||||||
|
|
||||||
|
function CollapsibleTrigger({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof CollapsiblePrimitive.CollapsibleTrigger>) {
|
||||||
|
return (
|
||||||
|
<CollapsiblePrimitive.CollapsibleTrigger
|
||||||
|
data-slot="collapsible-trigger"
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Открытие и закрытие анимируются по высоте (tw-animate-css). Блок без Trigger —
|
||||||
|
// <Collapsible open={open}><CollapsibleContent> прямо в ячейке второй строки таблицы.
|
||||||
|
function CollapsibleContent({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof CollapsiblePrimitive.CollapsibleContent>) {
|
||||||
|
return (
|
||||||
|
<CollapsiblePrimitive.CollapsibleContent
|
||||||
|
data-slot="collapsible-content"
|
||||||
|
className={cn(
|
||||||
|
"overflow-hidden data-[state=closed]:animate-collapsible-up data-[state=open]:animate-collapsible-down",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export { Collapsible, CollapsibleTrigger, CollapsibleContent }
|
||||||
|
|
@ -15,13 +15,22 @@ function Progress({
|
||||||
"relative h-2 w-full overflow-hidden rounded-full bg-primary/20",
|
"relative h-2 w-full overflow-hidden rounded-full bg-primary/20",
|
||||||
className
|
className
|
||||||
)}
|
)}
|
||||||
|
value={value}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
<ProgressPrimitive.Indicator
|
{/* Без value — неизвестно, сколько осталось: бегущий отрезок */}
|
||||||
data-slot="progress-indicator"
|
{value == null ? (
|
||||||
className="h-full w-full flex-1 bg-primary transition-all"
|
<ProgressPrimitive.Indicator
|
||||||
style={{ transform: `translateX(-${100 - (value || 0)}%)` }}
|
data-slot="progress-indicator"
|
||||||
/>
|
className="h-full w-1/3 animate-progress-indeterminate rounded-full bg-primary"
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<ProgressPrimitive.Indicator
|
||||||
|
data-slot="progress-indicator"
|
||||||
|
className="h-full w-full flex-1 bg-primary transition-all"
|
||||||
|
style={{ transform: `translateX(-${100 - value}%)` }}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</ProgressPrimitive.Root>
|
</ProgressPrimitive.Root>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,42 @@
|
||||||
|
import * as React from "react"
|
||||||
|
import { cn } from "../lib/utils"
|
||||||
|
import { CircleIcon } from "lucide-react"
|
||||||
|
import { RadioGroup as RadioGroupPrimitive } from "radix-ui"
|
||||||
|
|
||||||
|
function RadioGroup({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof RadioGroupPrimitive.Root>) {
|
||||||
|
return (
|
||||||
|
<RadioGroupPrimitive.Root
|
||||||
|
data-slot="radio-group"
|
||||||
|
className={cn("grid gap-3", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function RadioGroupItem({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof RadioGroupPrimitive.Item>) {
|
||||||
|
return (
|
||||||
|
<RadioGroupPrimitive.Item
|
||||||
|
data-slot="radio-group-item"
|
||||||
|
className={cn(
|
||||||
|
"aspect-square size-4 shrink-0 rounded-full border border-input text-primary shadow-xs transition-[color,box-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 dark:bg-input/30 dark:aria-invalid:ring-destructive/40",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<RadioGroupPrimitive.Indicator
|
||||||
|
data-slot="radio-group-indicator"
|
||||||
|
className="relative flex items-center justify-center"
|
||||||
|
>
|
||||||
|
<CircleIcon className="absolute top-1/2 left-1/2 size-2 -translate-x-1/2 -translate-y-1/2 fill-primary" />
|
||||||
|
</RadioGroupPrimitive.Indicator>
|
||||||
|
</RadioGroupPrimitive.Item>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export { RadioGroup, RadioGroupItem }
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
import * as React from "react"
|
||||||
|
import { cn } from "../lib/utils"
|
||||||
|
import { Loader2Icon } from "lucide-react"
|
||||||
|
|
||||||
|
function Spinner({ className, ...props }: React.ComponentProps<"svg">) {
|
||||||
|
return (
|
||||||
|
<Loader2Icon
|
||||||
|
role="status"
|
||||||
|
aria-label="Загрузка"
|
||||||
|
className={cn("size-4 animate-spin", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export { Spinner }
|
||||||
Loading…
Reference in New Issue