# Day filter

A filter of days for any filter menu: the presets a page names, a custom range on the kit's one calendar, and a chip that says the choice in words.

Live variants: https://design.arcadia.is/components/day-filter

```tsx
import {
  DayFilter, DayFilterChip, presetRange, dayRangeOf, dayRangeWords,
  dayFilterRows,
} from "@arcadia/ui";
```

Open Filters to choose a kind or a date range. Remove an active filter from its chip.

```tsx
import { useState, useRef } from "react";
import {
  Chip, DayFilterChip, Menu, MenuTrigger, IconButton, MenuContent, MenuSearch,
  MenuGroup, MenuCheckboxItem, DayFilter, MenuEmpty,
} from "@arcadia/ui";

function SearchFilters() {
  const [kinds, setKinds] = useState<ReadonlySet<string>>(() => new Set(["Cards"]));
  const [days, setDays] = useState<DayRange | null>({ first: "2026-11-03", last: "2026-11-09" });
  const [query, setQuery] = useState("");
  const filter = useRef<HTMLButtonElement>(null);
  const seen = (word: string) => word.toLowerCase().includes(query.trim().toLowerCase());
  const tick = (kind: string, on: boolean) => setKinds((s) => { const n = new Set(s); if (on) n.add(kind); else n.delete(kind); return n; });
  const shown = KINDS.filter(seen);
  return (
    <div {...stylex.props(DayFilterStyles.bar)}>
      <Menu onOpenChange={(open) => { if (!open) setQuery(""); }}>
        <MenuTrigger render={<IconButton ref={filter} icon="filter" label="Filters" variant="secondary" />} />
        <MenuContent align="start" width={240} aria-label="Filters"
          search={<MenuSearch autoFocus placeholder="Filter by" value={query} onChange={(e) => setQuery(e.target.value)} />}>
          {shown.length > 0 && (
            <MenuGroup label="Kind">
              {shown.map((k) => <MenuCheckboxItem key={k} closeOnClick={false} checked={kinds.has(k)} onCheckedChange={(on) => tick(k, on)}>{k}</MenuCheckboxItem>)}
            </MenuGroup>
          )}
          <DayFilter value={days} onChange={setDays} query={query} today={DayFilterTODAY} />
          {shown.length === 0 && !DAY_ROWS.some(seen) && <MenuEmpty>No matches</MenuEmpty>}
        </MenuContent>
      </Menu>
      {[...kinds].map((k) => <Chip key={k} variant="outline" onRemove={() => { tick(k, false); filter.current?.focus(); }} removeLabel={`Remove ${k}`}>{k}</Chip>)}
      {days && <DayFilterChip value={days} today={DayFilterTODAY} onRemove={() => { setDays(null); filter.current?.focus(); }} />}
    </div>
  )
```

## Accessibility

The rows are radio rows in a group named by its `label`, Date unless it says otherwise. Custom range turns the surface into a dialog named Custom range that holds the calendar: a grid labelled by its month, one Tab stop, the grid `aria-multiselectable` and each chosen day selected. Tab moves through the month's buttons and the days, and past them out of the menu; Escape goes back to the rows with the focus on Custom range.

Under forced colours, which drop every fill, each chosen day stands on the system's highlight. The chip's remove button is named for the choice: Remove Nov 3 to Nov 9.

- Enter + Space: On a row: choose it; on Custom range, show the calendar
- ← + →: A day back or on
- ↑ + ↓: A week back or on
- Page Up + Page Down: A month back or on, a year with Shift
- Enter: In the calendar: the start, then the end
- Esc: Back to the rows, then close the menu

## API reference

### DayFilter

- `value` (`DayRange | null`, required): The days chosen, or none: pass back what `onChange` gave, so a preset keeps its name.
- `onChange` (`(range: DayRange) => void`, required): Called with the days chosen: a preset's at once, a range once its second day is pressed.
- `label` (`string`, default `"Date"`): The group's name over its rows.
- `ranges` (`DayFilterRanges`): The presets it shows, one to four of `DAY_PRESETS` (more is refused), drawn in the kit's order whatever order they are named in. Default: Today, Last 7 days and Last 30 days.
- `custom` (`boolean`, default `true`): `false`: no Custom range row, the presets alone. The last row.
- `query` (`string`, default `""`): What the filter menu's search row holds: only the rows whose words hold it stay, and with none the group goes.
- `today` (`Day`): The day it is, given by the product so a test and a server agree. Default: the machine's own, in the reader's zone.
- `locale` (`string`): The reader's locale: the calendar's words and week, and the days' words. Default: the platform's.
- `min` (`Day`): The first day the calendar offers.
- `max` (`Day`): The last day the calendar offers.

### DayFilterChip

- `value` (`{ first: Day; last: Day; preset?: DayPreset }`, required): The days in force.
- `onRemove` (`() => void`, required): Takes the filter away.
- `today` (`Day`): The day it is, as the filter's.
- `locale` (`string`): The reader's locale, as the filter's.
