FilterMenu
mode apply/live · variant (6) × color (7) · size xs–xl · apply_color
Botão de filtro que abre painel com grupos de opções e mostra quantos filtros estão ativos.
Abrindo o painel de filtros
<.filter_menu id="fm01" open locale="pt_BR" label="Filtrar" icon="filter" size="sm" groups={[%{name: "status", label: "Status", caption: "Status", display: :section, type: :multiple, value: ["pago", "atrasado"], options: [{"Pago", "pago"}, {"Aberto", "aberto"}, {"Atrasado", "atrasado"}]}]} class="animate-[lu-flin2_4s_ease-out_infinite]" /> <div class="h-[200px]"></div>
mode apply/live · variant × color do botão · size
<div class="flex flex-col gap-3"> <div class="grid grid-cols-[80px_repeat(6,minmax(0,1fr))] items-center gap-x-3 gap-y-2.5"> <span></span> <span :for={v <- ~w(solid glow outline soft bordered flat)} class="text-center font-mono text-xs text-muted">{v}</span> <%= for color <- ~w(neutral primary secondary success error) do %> <span class="font-mono text-xs text-muted">{color}</span> <div :for={v <- ~w(solid glow outline soft bordered flat)} class="flex min-w-0 justify-center"> <.filter_menu id={"fm02-#{color}-#{v}"} label="Filtrar" icon="filter" color={color} variant={v} size="sm" locale="pt_BR" groups={[%{name: "status", label: "Status", caption: "Status", display: :section, type: :multiple, value: [], options: [{"Pago", "pago"}, {"Aberto", "aberto"}, {"Atrasado", "atrasado"}]}]} /> </div> <% end %> </div> <div class="flex flex-wrap items-center gap-2.5"> <.filter_menu :for={size <- ~w(xs sm md lg xl)} id={"fm02-size-#{size}"} label="Filtrar" icon="filter" size={size} locale="pt_BR" groups={[%{name: "status", label: "Status", caption: "Status", display: :section, type: :multiple, value: [], options: [{"Pago", "pago"}, {"Aberto", "aberto"}, {"Atrasado", "atrasado"}]}]} /> </div> </div>
Valores da API que completam a paridade
<div class="grid grid-cols-4 gap-3.5"> <div class="flex flex-col items-start gap-1.5"><.filter_menu id="fm04-info" label="Filtrar" icon="filter" color="info" variant="soft" size="sm" locale="pt_BR" groups={[%{name: "status", label: "Status", caption: "Status", display: :section, type: :multiple, value: [], options: [{"Pago", "pago"}, {"Aberto", "aberto"}, {"Atrasado", "atrasado"}]}]} /><span class="font-mono text-[11px] text-muted">color=info</span></div> <div class="flex flex-col items-start gap-1.5"><.filter_menu id="fm04-warning" label="Filtrar" icon="filter" color="warning" variant="soft" size="sm" locale="pt_BR" groups={[%{name: "status", label: "Status", caption: "Status", display: :section, type: :multiple, value: [], options: [{"Pago", "pago"}, {"Aberto", "aberto"}, {"Atrasado", "atrasado"}]}]} /><span class="font-mono text-[11px] text-muted">color=warning</span></div> </div>
Uso
<.filter_menu filters={@filters} active={@active_filters} />
Regras
- O botão mostra a contagem de filtros ativos.
- Rodapé com Limpar e Aplicar.
Referência da API
Todos os function components, atributos, valores e slots que este componente cobre.
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).
<.filter_menu>
| Attr | Type | Default | Values / notes |
|---|---|---|---|
id (required) |
:string |
||
label |
:string |
nil |
|
icon |
:string |
nil |
|
groups |
:list |
[] |
|
mode |
:string |
"apply" |
apply, live |
locale |
:string |
"en" |
en, pt_BR |
results |
:integer |
nil |
|
variant |
:string |
"outline" |
solid, glow, outline, soft, bordered, flat |
color |
:string |
"neutral" |
neutral, primary, secondary, info, success, warning, error |
size |
:string |
"md" |
xs, sm, md, lg, xl |
dashed |
:boolean |
false |
|
placement |
:string |
"bottom-start" |
bottom, bottom-end, bottom-start, left, left-end, left-start, right, right-end, right-start, top, top-end, top-start |
open |
:boolean |
false |
|
on_change |
:string |
nil |
|
on_apply |
:string |
nil |
|
on_clear |
:string |
nil |
|
target |
:any |
nil |
|
class |
:any |
nil |
Any other HTML/phx attribute goes to the root element.
Slots:
<:group>- attrs:name,label,icon,display,type,caption,custom,value<:trigger>- The text of the button, as markup (instead oflabel).