Add popover filters and calendar alignment
This commit is contained in:
parent
3cb17740c5
commit
a948542326
|
|
@ -153,6 +153,7 @@ export function DateInput({
|
||||||
invalid,
|
invalid,
|
||||||
captionLayout = "label",
|
captionLayout = "label",
|
||||||
yearCaption = "select",
|
yearCaption = "select",
|
||||||
|
calendarAlign = "end",
|
||||||
onErrorChange,
|
onErrorChange,
|
||||||
id,
|
id,
|
||||||
disabled,
|
disabled,
|
||||||
|
|
@ -167,6 +168,8 @@ export function DateInput({
|
||||||
captionLayout?: "label" | "dropdown"
|
captionLayout?: "label" | "dropdown"
|
||||||
/** Год в шапке календаря. «input» — набрать цифрами, когда список годов длинный. */
|
/** Год в шапке календаря. «input» — набрать цифрами, когда список годов длинный. */
|
||||||
yearCaption?: "select" | "input"
|
yearCaption?: "select" | "input"
|
||||||
|
/** Выравнивание всплывающего календаря относительно поля. */
|
||||||
|
calendarAlign?: "start" | "center" | "end"
|
||||||
/** Сообщение о неправильном вводе — чтобы показать его в FormField. */
|
/** Сообщение о неправильном вводе — чтобы показать его в FormField. */
|
||||||
onErrorChange?: (error: string | undefined) => void
|
onErrorChange?: (error: string | undefined) => void
|
||||||
id?: string
|
id?: string
|
||||||
|
|
@ -222,7 +225,7 @@ export function DateInput({
|
||||||
</InputGroupAddon>
|
</InputGroupAddon>
|
||||||
</InputGroup>
|
</InputGroup>
|
||||||
</PopoverAnchor>
|
</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
|
<Calendar
|
||||||
mode="single"
|
mode="single"
|
||||||
required
|
required
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,7 @@ export function DateRangeInput({
|
||||||
min,
|
min,
|
||||||
max,
|
max,
|
||||||
presets = DEFAULT_RANGE_PRESETS,
|
presets = DEFAULT_RANGE_PRESETS,
|
||||||
|
calendarAlign = "start",
|
||||||
invalid,
|
invalid,
|
||||||
onErrorChange,
|
onErrorChange,
|
||||||
disabled,
|
disabled,
|
||||||
|
|
@ -57,6 +58,8 @@ export function DateRangeInput({
|
||||||
onChange: (value: DateRangeValue) => void
|
onChange: (value: DateRangeValue) => void
|
||||||
/** Пустой массив — без быстрых периодов. */
|
/** Пустой массив — без быстрых периодов. */
|
||||||
presets?: readonly DateRangePreset[]
|
presets?: readonly DateRangePreset[]
|
||||||
|
/** Выравнивание всплывающего календаря относительно поля. */
|
||||||
|
calendarAlign?: "start" | "center" | "end"
|
||||||
invalid?: boolean
|
invalid?: boolean
|
||||||
/** Сообщение о неправильном вводе (в том числе перевёрнутом диапазоне) — для FormField. */
|
/** Сообщение о неправильном вводе (в том числе перевёрнутом диапазоне) — для FormField. */
|
||||||
onErrorChange?: (error: string | undefined) => void
|
onErrorChange?: (error: string | undefined) => void
|
||||||
|
|
@ -147,7 +150,7 @@ export function DateRangeInput({
|
||||||
</InputGroupAddon>
|
</InputGroupAddon>
|
||||||
</InputGroup>
|
</InputGroup>
|
||||||
</PopoverAnchor>
|
</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 && (
|
{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">
|
<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) => {
|
{presets.map((preset) => {
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import { RotateCwIcon, SlidersHorizontalIcon } from "lucide-react"
|
||||||
|
|
||||||
import { cn } from "../lib/utils"
|
import { cn } from "../lib/utils"
|
||||||
import { Button } from "../ui/button"
|
import { Button } from "../ui/button"
|
||||||
|
import { Popover, PopoverClose, PopoverContent, PopoverTrigger } from "../ui/popover"
|
||||||
import { ScrollArea } from "../ui/scroll-area"
|
import { ScrollArea } from "../ui/scroll-area"
|
||||||
import {
|
import {
|
||||||
Sheet,
|
Sheet,
|
||||||
|
|
@ -26,6 +27,7 @@ export function FilterBar({
|
||||||
more,
|
more,
|
||||||
moreCount = 0,
|
moreCount = 0,
|
||||||
moreTitle = "Фильтры",
|
moreTitle = "Фильтры",
|
||||||
|
moreVariant = "sheet",
|
||||||
activeCount = 0,
|
activeCount = 0,
|
||||||
onReset,
|
onReset,
|
||||||
className,
|
className,
|
||||||
|
|
@ -37,6 +39,8 @@ export function FilterBar({
|
||||||
moreCount?: number
|
moreCount?: number
|
||||||
/** Заголовок панели. */
|
/** Заголовок панели. */
|
||||||
moreTitle?: string
|
moreTitle?: string
|
||||||
|
/** Как открыть расширенные фильтры: в боковой панели или всплывающим слоем над контентом. */
|
||||||
|
moreVariant?: "sheet" | "popover"
|
||||||
/** Сколько фильтров отличается от умолчания: точка на «Сбросить», число — в подсказке. */
|
/** Сколько фильтров отличается от умолчания: точка на «Сбросить», число — в подсказке. */
|
||||||
activeCount?: number
|
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>
|
<div className="flex min-w-[min(100%,16rem)] flex-1 flex-wrap items-center gap-2.5">{children}</div>
|
||||||
{(more != null || onReset) && (
|
{(more != null || onReset) && (
|
||||||
<div className="ml-auto flex h-9 shrink-0 items-center gap-1">
|
<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 && (
|
{onReset && (
|
||||||
<Button
|
<Button
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
|
|
@ -109,12 +68,102 @@ export function FilterBar({
|
||||||
<Dotted on={activeCount > 0}>Сбросить</Dotted>
|
<Dotted on={activeCount > 0}>Сбросить</Dotted>
|
||||||
</Button>
|
</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>
|
||||||
)}
|
)}
|
||||||
</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} />
|
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({
|
function PopoverContent({
|
||||||
className,
|
className,
|
||||||
align = "center",
|
align = "center",
|
||||||
|
|
@ -79,6 +85,7 @@ function PopoverDescription({
|
||||||
export {
|
export {
|
||||||
Popover,
|
Popover,
|
||||||
PopoverTrigger,
|
PopoverTrigger,
|
||||||
|
PopoverClose,
|
||||||
PopoverContent,
|
PopoverContent,
|
||||||
PopoverAnchor,
|
PopoverAnchor,
|
||||||
PopoverHeader,
|
PopoverHeader,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue