mirror of
https://github.com/outline/outline.git
synced 2026-11-28 00:09:58 +03:00
* Redesign search filters * Design refinement * Search filter polish: chip states, Text components, Published filter * Encode search filters as <field>.<operator> URL params Filters read and write a standard <field>.<operator>=<value> format, a bare key reads as eq, and the previous dateFilter, statusFilter and titleFilter params are still read. * Add custom date ranges to search date filters Updated, Created and Published get a Custom option that opens a range calendar in a modal. The range is stored as <field>.gte and <field>.lte dates and sent to the API as whole days in local time. * Keep date filter chip shown while its range dialog is open * Align calendar with modal edges The calendar had its own 12px padding, so in modals it sat inside the title and footer edges. The popovers that need the space now pad it. * Search filter refinements: menu height, chip spacing, steady results line * Simplify search filters and address review comments Parse each filter once per URL change, unify URL writes, share status and date helpers with the server, add a maxHeight prop to MenuContent, ignore counts from obsolete searches, and show the empty state for filter-only searches. * Refine filter chip remove button and skip animation on auto-opened menus
120 lines
3.3 KiB
TypeScript
120 lines
3.3 KiB
TypeScript
import * as PopoverPrimitive from "@radix-ui/react-popover";
|
|
import { Slot } from "@radix-ui/react-slot";
|
|
import { set } from "date-fns";
|
|
import * as React from "react";
|
|
import { useTranslation } from "react-i18next";
|
|
import { RemoveScroll } from "react-remove-scroll";
|
|
import styled from "styled-components";
|
|
import { Calendar } from "../../components/Calendar";
|
|
import { depths, s, borderRadius } from "../../styles";
|
|
import { dateLocale, toISODate, toISODateTime } from "../../utils/date";
|
|
|
|
type Props = {
|
|
/** The currently selected date, if any. */
|
|
selectedDate?: Date;
|
|
/** Whether the selected date is time-specific. */
|
|
includeTime?: boolean;
|
|
/** The user's language, used to localise the calendar. */
|
|
language?: Parameters<typeof dateLocale>[0];
|
|
/** Called with the new ISO string when a day is picked. */
|
|
onChange: (modelId: string) => void;
|
|
/** The trigger element the calendar popover is anchored to. */
|
|
children: React.ReactNode;
|
|
};
|
|
|
|
/**
|
|
* The interactive calendar popover for a date mention. It lives in its own
|
|
* module so that its browser-only dependencies (Radix, react-day-picker) are
|
|
* loaded lazily and stay out of the editor schema graph, which is also imported
|
|
* on the server.
|
|
*
|
|
* @returns the popover wrapping the provided trigger.
|
|
*/
|
|
export default function DateMentionPicker({
|
|
selectedDate,
|
|
includeTime,
|
|
language,
|
|
onChange,
|
|
children,
|
|
}: Props) {
|
|
const { t } = useTranslation();
|
|
const [open, setOpen] = React.useState(false);
|
|
|
|
const handleSelect = React.useCallback(
|
|
(date: Date) => {
|
|
setOpen(false);
|
|
|
|
// The calendar only changes the day, so an existing time is carried over.
|
|
if (includeTime && selectedDate) {
|
|
onChange(
|
|
toISODateTime(
|
|
set(date, {
|
|
hours: selectedDate.getHours(),
|
|
minutes: selectedDate.getMinutes(),
|
|
})
|
|
)
|
|
);
|
|
return;
|
|
}
|
|
|
|
onChange(toISODate(date));
|
|
},
|
|
[onChange, includeTime, selectedDate]
|
|
);
|
|
|
|
return (
|
|
<PopoverPrimitive.Root open={open} onOpenChange={setOpen}>
|
|
<PopoverPrimitive.Trigger
|
|
asChild
|
|
onMouseDown={(e) => e.stopPropagation()}
|
|
>
|
|
{children}
|
|
</PopoverPrimitive.Trigger>
|
|
<PopoverPrimitive.Portal>
|
|
<PopoverPrimitive.Content
|
|
asChild
|
|
sideOffset={4}
|
|
align="start"
|
|
aria-label={t("Choose a date")}
|
|
onOpenAutoFocus={(e) => e.preventDefault()}
|
|
>
|
|
<RemoveScroll as={Slot} allowPinchZoom>
|
|
<DatePopoverContent>
|
|
<Calendar
|
|
required
|
|
mode="single"
|
|
selected={selectedDate}
|
|
defaultMonth={selectedDate}
|
|
onSelect={handleSelect}
|
|
locale={dateLocale(language)}
|
|
/>
|
|
</DatePopoverContent>
|
|
</RemoveScroll>
|
|
</PopoverPrimitive.Content>
|
|
</PopoverPrimitive.Portal>
|
|
</PopoverPrimitive.Root>
|
|
);
|
|
}
|
|
|
|
const DatePopoverContent = styled.div`
|
|
z-index: ${depths.modal};
|
|
padding: 12px;
|
|
background: ${s("menuBackground")};
|
|
box-shadow: ${s("menuShadow")};
|
|
${borderRadius(8)}
|
|
outline: none;
|
|
|
|
&[data-state="open"] {
|
|
animation: fadeIn 150ms ease;
|
|
}
|
|
|
|
@keyframes fadeIn {
|
|
from {
|
|
opacity: 0;
|
|
}
|
|
to {
|
|
opacity: 1;
|
|
}
|
|
}
|
|
`;
|