04 · Formulários — seleção
Chip
Filtros rápidos: selecionável, com contagem, adicionar
Chip interativo para filtros rápidos; alterna ao clicar.
Ligando filtros
Hoje
Pagos
Entrega
Atrasados
.heex
<div class="flex flex-wrap items-center gap-2"><.chip class="animate-[mo-chipon_8s_infinite]">Hoje</.chip><.chip class="animate-[mo-chipon_8s_infinite] [animation-delay:2s]">Pagos</.chip><.chip class="animate-[mo-chipon_8s_infinite] [animation-delay:4s]">Entrega</.chip><.chip class="animate-[mo-chipon_8s_infinite] [animation-delay:6s]">Atrasados</.chip></div>
Experimente: o chip alterna e o x remove
Situação: Aprovação
.heex
<div class="flex flex-wrap items-center gap-2.5"> <.chip :for={{label, sel} <- [{"Hoje", true}, {"Atrasados", false}, {"Pagos", false}, {"Pro", false}]} selected={sel}>{label}</.chip> <.chip id="chip-live-rm" label="Situação: Aprovação" on_remove={Phoenix.LiveView.JS.hide(to: "#chip-live-rm")} /> </div>
Uso
<.chip selected={@pro?} phx-click="toggle" value="pro">Pro</.chip>
Regras
- Raio 10, como botão pequeno; o ativo fica
inverse. - Chip tracejado “+ Filtro” abre o FilterMenu.
Referência da API
Todos os function components, atributos, valores e slots que este componente cobre.
The chip: a small tag for a quick filter, an applied filter or a selected person.
<.chip>Hoje</.chip>
<.chip selected={@pro?} phx-click="toggle" value="pro">Pro</.chip>
<.chip selected={false} count={12}>Atrasados</.chip>
<.chip dashed icon="plus">Filtro</.chip>
<.chip label="Situação: Aprovação" on_remove={JS.hide(to: "#c1")} id="c1" />
<.chip avatar="Marina Costa" on_remove="remove_person" id="p-1">Marina Costa</.chip>
<.chip patch={~p"/extract?account=1"} label="Conta 1" />
<.chip label="Aberta" remove_patch={~p"/tasks"} />
- a plain chip is a
<span>; withselected(true/false) it is a toggle button (aria-pressed, the chosen state is the inverse colour) that flips in the browser unless you give it aphx-click;dashedandphx-clickmake it a button too; - with
href,navigateorpatchit is a link and has no x; on_remove(an event name, pushed with%{"id" => id}totarget, or aJScommand) adds the x button;remove_patchmakes the x apatchlink instead;sizeis the height:sm24px (chips inside a field),md30px (default),lg32px (<.chip size="lg">); padding, font and icon stay the same.
<.chip>
| Attr | Type | Default | Values / notes |
|---|---|---|---|
label |
:string |
nil |
|
selected |
:boolean |
nil |
true/false makes the chip a toggle. |
dashed |
:boolean |
false |
|
tone |
:string |
nil |
nil, default, acc |
size |
:string |
"md" |
sm, md, lg - Height: 24px, 30px or 32px. |
icon |
:string |
nil |
|
count |
:any |
nil |
|
avatar |
:string |
nil |
|
avatar_color |
:string |
nil |
|
avatar_src |
:string |
nil |
|
on_remove |
:any |
nil |
|
remove_patch |
:string |
nil |
|
id |
:string |
nil |
|
target |
:any |
nil |
|
remove_label |
:string |
"Remove" |
|
class |
:any |
nil |
Any other HTML/phx attribute goes to the root element, including href, navigate, patch, method, download, value, disabled.
Slots:
<:inner_block>