Add popover filters and calendar alignment
This commit is contained in:
parent
3cb17740c5
commit
a948542326
|
|
@ -153,6 +153,7 @@ export function DateInput({
|
|||
invalid,
|
||||
captionLayout = "label",
|
||||
yearCaption = "select",
|
||||
calendarAlign = "end",
|
||||
onErrorChange,
|
||||
id,
|
||||
disabled,
|
||||
|
|
@ -167,6 +168,8 @@ export function DateInput({
|
|||
captionLayout?: "label" | "dropdown"
|
||||
/** Год в шапке календаря. «input» — набрать цифрами, когда список годов длинный. */
|
||||
yearCaption?: "select" | "input"
|
||||
/** Выравнивание всплывающего календаря относительно поля. */
|
||||
calendarAlign?: "start" | "center" | "end"
|
||||
/** Сообщение о неправильном вводе — чтобы показать его в FormField. */
|
||||
onErrorChange?: (error: string | undefined) => void
|
||||
id?: string
|
||||
|
|
@ -222,7 +225,7 @@ export function DateInput({
|
|||
</InputGroupAddon>
|
||||
</InputGroup>
|
||||
</PopoverAnchor>
|
||||
<PopoverContent align="end" collisionPadding={8} className="w-auto p-0" {...popover.contentProps}>
|
||||
<PopoverContent align={calendarAlign} collisionPadding={8} className="w-auto p-0" {...popover.contentProps}>
|
||||
<Calendar
|
||||
mode="single"
|
||||
required
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ export function DateRangeInput({
|
|||
min,
|
||||
max,
|
||||
presets = DEFAULT_RANGE_PRESETS,
|
||||
calendarAlign = "start",
|
||||
invalid,
|
||||
onErrorChange,
|
||||
disabled,
|
||||
|
|
@ -57,6 +58,8 @@ export function DateRangeInput({
|
|||
onChange: (value: DateRangeValue) => void
|
||||
/** Пустой массив — без быстрых периодов. */
|
||||
presets?: readonly DateRangePreset[]
|
||||
/** Выравнивание всплывающего календаря относительно поля. */
|
||||
calendarAlign?: "start" | "center" | "end"
|
||||
invalid?: boolean
|
||||
/** Сообщение о неправильном вводе (в том числе перевёрнутом диапазоне) — для FormField. */
|
||||
onErrorChange?: (error: string | undefined) => void
|
||||
|
|
@ -147,7 +150,7 @@ export function DateRangeInput({
|
|||
</InputGroupAddon>
|
||||
</InputGroup>
|
||||
</PopoverAnchor>
|
||||
<PopoverContent align="start" collisionPadding={8} className="flex w-auto max-w-[calc(100vw-1rem)] flex-col p-0 md:flex-row" {...popover.contentProps}>
|
||||
<PopoverContent align={calendarAlign} collisionPadding={8} className="flex w-auto max-w-[calc(100vw-1rem)] flex-col p-0 md:flex-row" {...popover.contentProps}>
|
||||
{presets.length > 0 && (
|
||||
<div className="flex gap-1 overflow-x-auto border-b p-2 md:w-44 md:flex-col md:border-r md:border-b-0">
|
||||
{presets.map((preset) => {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import { RotateCwIcon, SlidersHorizontalIcon } from "lucide-react"
|
|||
|
||||
import { cn } from "../lib/utils"
|
||||
import { Button } from "../ui/button"
|
||||
import { Popover, PopoverClose, PopoverContent, PopoverTrigger } from "../ui/popover"
|
||||
import { ScrollArea } from "../ui/scroll-area"
|
||||
import {
|
||||
Sheet,
|
||||
|
|
@ -26,6 +27,7 @@ export function FilterBar({
|
|||
more,
|
||||
moreCount = 0,
|
||||
moreTitle = "Фильтры",
|
||||
moreVariant = "sheet",
|
||||
activeCount = 0,
|
||||
onReset,
|
||||
className,
|
||||
|
|
@ -37,6 +39,8 @@ export function FilterBar({
|
|||
moreCount?: number
|
||||
/** Заголовок панели. */
|
||||
moreTitle?: string
|
||||
/** Как открыть расширенные фильтры: в боковой панели или всплывающим слоем над контентом. */
|
||||
moreVariant?: "sheet" | "popover"
|
||||
/** Сколько фильтров отличается от умолчания: точка на «Сбросить», число — в подсказке. */
|
||||
activeCount?: number
|
||||
/** Без него кнопки «Сбросить» нет. */
|
||||
|
|
@ -51,51 +55,6 @@ export function FilterBar({
|
|||
<div className="flex min-w-[min(100%,16rem)] flex-1 flex-wrap items-center gap-2.5">{children}</div>
|
||||
{(more != null || onReset) && (
|
||||
<div className="ml-auto flex h-9 shrink-0 items-center gap-1">
|
||||
{more != null && (
|
||||
<Sheet>
|
||||
<SheetTrigger asChild>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
title={moreCount ? `Включено расширенных фильтров: ${moreCount}` : undefined}
|
||||
className="shrink-0"
|
||||
>
|
||||
<SlidersHorizontalIcon />
|
||||
<Dotted on={moreCount > 0}>Ещё</Dotted>
|
||||
</Button>
|
||||
</SheetTrigger>
|
||||
{/* Как модальное окно кита (EditDialog): плавающая карточка с отступом от края,
|
||||
шапка с иконкой, поля — на белых карточках, «Отмена/Готово» — внизу. */}
|
||||
<SheetContent
|
||||
side="right"
|
||||
className="inset-y-2 right-2 h-auto w-[calc(100%-1rem)] gap-0 overflow-hidden rounded-xl border sm:max-w-sm"
|
||||
>
|
||||
<SheetHeader className="border-b px-5 py-4 pr-12">
|
||||
<SheetTitle className="flex items-center gap-2 text-base">
|
||||
<SlidersHorizontalIcon className="size-4 text-primary" />
|
||||
{moreTitle}
|
||||
</SheetTitle>
|
||||
{/* Описание нужно Radix для доступности; видно только скринридерам. */}
|
||||
<SheetDescription className="sr-only">Фильтры применяются сразу</SheetDescription>
|
||||
</SheetHeader>
|
||||
<ScrollArea className="min-h-0 flex-1">
|
||||
<div className="flex flex-col gap-4 p-5">{more}</div>
|
||||
</ScrollArea>
|
||||
<SheetFooter className="flex-row items-center justify-between border-t px-5 py-3">
|
||||
{onReset ? (
|
||||
<Button variant="ghost" disabled={!activeCount} onClick={onReset} className="text-muted-foreground">
|
||||
<RotateCwIcon /> Сбросить все
|
||||
</Button>
|
||||
) : (
|
||||
<span />
|
||||
)}
|
||||
<SheetClose asChild>
|
||||
<Button>Готово</Button>
|
||||
</SheetClose>
|
||||
</SheetFooter>
|
||||
</SheetContent>
|
||||
</Sheet>
|
||||
)}
|
||||
{onReset && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
|
|
@ -109,12 +68,102 @@ export function FilterBar({
|
|||
<Dotted on={activeCount > 0}>Сбросить</Dotted>
|
||||
</Button>
|
||||
)}
|
||||
{more != null && (
|
||||
moreVariant === "popover" ? (
|
||||
<Popover>
|
||||
<PopoverTrigger asChild>
|
||||
<MoreButton moreCount={moreCount} />
|
||||
</PopoverTrigger>
|
||||
<PopoverContent
|
||||
align="end"
|
||||
sideOffset={8}
|
||||
collisionPadding={8}
|
||||
className="flex max-h-[min(36rem,calc(100vh-1rem))] w-[min(24rem,calc(100vw-1rem))] flex-col overflow-hidden rounded-xl p-0 shadow-lg"
|
||||
>
|
||||
<div className="flex items-center gap-2 border-b px-5 py-4 text-base font-semibold">
|
||||
<SlidersHorizontalIcon className="size-4 text-primary" />
|
||||
{moreTitle}
|
||||
</div>
|
||||
<ScrollArea className="min-h-0 flex-1">
|
||||
<div className="flex flex-col gap-4 p-5">{more}</div>
|
||||
</ScrollArea>
|
||||
<div className="flex items-center justify-between border-t px-5 py-3">
|
||||
{onReset ? (
|
||||
<Button variant="ghost" disabled={!activeCount} onClick={onReset} className="text-muted-foreground">
|
||||
<RotateCwIcon /> Сбросить все
|
||||
</Button>
|
||||
) : (
|
||||
<span />
|
||||
)}
|
||||
<PopoverClose asChild>
|
||||
<Button>Готово</Button>
|
||||
</PopoverClose>
|
||||
</div>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
) : (
|
||||
<Sheet>
|
||||
<SheetTrigger asChild>
|
||||
<MoreButton moreCount={moreCount} />
|
||||
</SheetTrigger>
|
||||
{/* Как модальное окно кита (EditDialog): плавающая карточка с отступом от края,
|
||||
шапка с иконкой, поля — на белых карточках, «Отмена/Готово» — внизу. */}
|
||||
<SheetContent
|
||||
side="right"
|
||||
className="inset-y-2 right-2 h-auto w-[calc(100%-1rem)] gap-0 overflow-hidden rounded-xl border sm:max-w-sm"
|
||||
>
|
||||
<SheetHeader className="border-b px-5 py-4 pr-12">
|
||||
<SheetTitle className="flex items-center gap-2 text-base">
|
||||
<SlidersHorizontalIcon className="size-4 text-primary" />
|
||||
{moreTitle}
|
||||
</SheetTitle>
|
||||
{/* Описание нужно Radix для доступности; видно только скринридерам. */}
|
||||
<SheetDescription className="sr-only">Фильтры применяются сразу</SheetDescription>
|
||||
</SheetHeader>
|
||||
<ScrollArea className="min-h-0 flex-1">
|
||||
<div className="flex flex-col gap-4 p-5">{more}</div>
|
||||
</ScrollArea>
|
||||
<SheetFooter className="flex-row items-center justify-between border-t px-5 py-3">
|
||||
{onReset ? (
|
||||
<Button variant="ghost" disabled={!activeCount} onClick={onReset} className="text-muted-foreground">
|
||||
<RotateCwIcon /> Сбросить все
|
||||
</Button>
|
||||
) : (
|
||||
<span />
|
||||
)}
|
||||
<SheetClose asChild>
|
||||
<Button>Готово</Button>
|
||||
</SheetClose>
|
||||
</SheetFooter>
|
||||
</SheetContent>
|
||||
</Sheet>
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function MoreButton({
|
||||
moreCount,
|
||||
className,
|
||||
...props
|
||||
}: { moreCount: number } & React.ComponentProps<typeof Button>) {
|
||||
return (
|
||||
<Button
|
||||
{...props}
|
||||
variant="outline"
|
||||
size="sm"
|
||||
title={moreCount ? `Включено расширенных фильтров: ${moreCount}` : undefined}
|
||||
className={cn("shrink-0", className)}
|
||||
>
|
||||
<SlidersHorizontalIcon />
|
||||
<Dotted on={moreCount > 0}>Ещё</Dotted>
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Переключатель для панели расширенных фильтров: строка-карточка — подпись и подсказка слева,
|
||||
* тумблер справа; нажимается вся строка. Включённая строка подсвечена рамкой акцентного цвета.
|
||||
|
|
|
|||
|
|
@ -15,6 +15,12 @@ function PopoverTrigger({
|
|||
return <PopoverPrimitive.Trigger data-slot="popover-trigger" {...props} />
|
||||
}
|
||||
|
||||
function PopoverClose({
|
||||
...props
|
||||
}: React.ComponentProps<typeof PopoverPrimitive.Close>) {
|
||||
return <PopoverPrimitive.Close data-slot="popover-close" {...props} />
|
||||
}
|
||||
|
||||
function PopoverContent({
|
||||
className,
|
||||
align = "center",
|
||||
|
|
@ -79,6 +85,7 @@ function PopoverDescription({
|
|||
export {
|
||||
Popover,
|
||||
PopoverTrigger,
|
||||
PopoverClose,
|
||||
PopoverContent,
|
||||
PopoverAnchor,
|
||||
PopoverHeader,
|
||||
|
|
|
|||
Loading…
Reference in New Issue