Add popover filters and calendar alignment

This commit is contained in:
Ilya Mukhortov 2026-10-30 16:08:30 +10:00
parent 3cb17740c5
commit a948542326
4 changed files with 109 additions and 47 deletions

View File

@ -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

View File

@ -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) => {

View File

@ -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,18 +55,56 @@ 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">
{onReset && (
<Button
variant="ghost"
size="sm"
disabled={!activeCount}
onClick={onReset}
title={activeCount ? `Включено фильтров: ${activeCount}` : undefined}
className="text-muted-foreground"
>
<RotateCwIcon />
<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>
<Button
variant="outline"
size="sm"
title={moreCount ? `Включено расширенных фильтров: ${moreCount}` : undefined}
className="shrink-0"
>
<SlidersHorizontalIcon />
<Dotted on={moreCount > 0}>Ещё</Dotted>
</Button>
<MoreButton moreCount={moreCount} />
</SheetTrigger>
{/* Как модальное окно кита (EditDialog): плавающая карточка с отступом от края,
шапка с иконкой, поля — на белых карточках, «Отмена/Готово» — внизу. */}
@ -95,23 +137,30 @@ export function FilterBar({
</SheetFooter>
</SheetContent>
</Sheet>
)
)}
{onReset && (
</div>
)}
</div>
)
}
function MoreButton({
moreCount,
className,
...props
}: { moreCount: number } & React.ComponentProps<typeof Button>) {
return (
<Button
variant="ghost"
{...props}
variant="outline"
size="sm"
disabled={!activeCount}
onClick={onReset}
title={activeCount ? `Включено фильтров: ${activeCount}` : undefined}
className="text-muted-foreground"
title={moreCount ? `Включено расширенных фильтров: ${moreCount}` : undefined}
className={cn("shrink-0", className)}
>
<RotateCwIcon />
<Dotted on={activeCount > 0}>Сбросить</Dotted>
<SlidersHorizontalIcon />
<Dotted on={moreCount > 0}>Ещё</Dotted>
</Button>
)}
</div>
)}
</div>
)
}

View File

@ -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,