# `LedgerUI.Components.FilterMenu`
[🔗](https://github.com/devaction-labs/ledger_ui/blob/v0.2.0/lib/ledger_ui/components/filter_menu.ex#L1)

A filter button that opens a menu of filters: one row per group that opens a second panel to
its side with the group's options as checkboxes (or radios), plus flat sections (a sort order)
in the same menu. Behaviour lives in the `LedgerUI.FilterMenu` hook
(`priv/static/ledger_ui/hooks/filter_menu.js`): opening, submenus, keyboard (arrows, Enter,
Esc, `ArrowRight` into a submenu) and staging never leave the browser.

    <.form for={@form} phx-submit="apply_filters">
      <.filter_menu id="orders-filter" label="Filtrar" locale="pt_BR" variant="outline" size="sm"
        groups={[
          %{name: "filter[status]", label: "Status", icon: "checkmark-circle-02",
            value: @filter["status"],
            options: [{"Faturado", "invoiced", 3}, {"Aprovado", "approved", 2}]},
          %{name: "filter[sort]", label: "Ordenar por", caption: "Ordenar por",
            display: :section, type: :single, value: @filter["sort"],
            options: [{"Mais recentes", "recent"}, {"Maior valor", "value"}]}
        ]} />
    </.form>

Every option is a real input (`filter[status][]` for a multiple group, `filter[sort]` for a
single one), so a form posts them. In `mode="apply"` (default) ticks only stage: the group's
row shows how many are staged, Apply shows how many records they leave (the options' `count`,
or `results`), Clear unticks the filter groups and closing the menu any other way takes the
staged values back; the trigger shows how many values are applied (the groups' `value`).
`mode="live"` has no Apply: every tick reaches the form's `phx-change` and `on_change`.

`on_change`, `on_apply` and `on_clear` push `%{"id" => id, "values" => %{group_name => [..] | "x"}}`
to `target`. A `:single` group takes `custom: true` (or the row's text): a last row that
opens two date fields; the value is then `"custom:FROM..TO"` (ISO days), parsed by
`custom_range/1`. A `:group` slot takes the same attributes as a group and your own content
(any checkbox/radio inputs with a `name`, and `data-lu-count` for what Apply counts).

# `custom_range`

Parses the text of a custom period.

    iex> LedgerUI.Components.FilterMenu.custom_range("custom:2026-11-01..2026-11-13")
    {~D[2026-11-01], ~D[2026-11-13]}
    iex> LedgerUI.Components.FilterMenu.custom_range("7d")
    nil

# `filter_menu`

## Attributes

* `id` (`:string`) (required)
* `label` (`:string`) - Defaults to `nil`.
* `icon` (`:string`) - Defaults to `nil`.
* `groups` (`:list`) - Defaults to `[]`.
* `mode` (`:string`) - Defaults to `"apply"`. Must be one of `"apply"`, or `"live"`.
* `locale` (`:string`) - Defaults to `"en"`. Must be one of `"en"`, or `"pt_BR"`.
* `results` (`:integer`) - Defaults to `nil`.
* `variant` (`:string`) - Defaults to `"outline"`. Must be one of `"solid"`, `"glow"`, `"outline"`, `"soft"`, `"bordered"`, or `"flat"`.
* `color` (`:string`) - Defaults to `"neutral"`. Must be one of `"neutral"`, `"primary"`, `"secondary"`, `"info"`, `"success"`, `"warning"`, or `"error"`.
* `size` (`:string`) - Defaults to `"md"`. Must be one of `"xs"`, `"sm"`, `"md"`, `"lg"`, or `"xl"`.
* `dashed` (`:boolean`) - Defaults to `false`.
* `placement` (`:string`) - Defaults to `"bottom-start"`.
* `open` (`:boolean`) - Defaults to `false`.
* `on_change` (`:string`) - Defaults to `nil`.
* `on_apply` (`:string`) - Defaults to `nil`.
* `on_clear` (`:string`) - Defaults to `nil`.
* `target` (`:any`) - Defaults to `nil`.
* `class` (`:any`) - Defaults to `nil`.
* Global attributes are accepted.
## Slots

* `group` - Accepts attributes:

  * `name` (`:string`)
  * `label` (`:string`)
  * `icon` (`:string`)
  * `display` (`:any`)
  * `type` (`:any`)
  * `caption` (`:string`)
  * `custom` (`:any`)
  * `value` (`:any`)
* `trigger` - The text of the button, as markup (instead of `label`).

---

*Consult [api-reference.md](api-reference.md) for complete listing*
