12 · Sobreposições

Popover

placement (12) · trigger_on click/hover · com seta opcional

Painel flutuante ancorado a um gatilho, para detalhes e formulários curtos.

Clique abre e fecha

.heex
<div class="relative h-[200px]">
  <div class="absolute top-5 left-[30px]">
    <.popover id="pop-ticket" placement="right-start" width="260px">
      <:trigger :let={aria}><.button canvas appearance="default" icon="info" aria-label="Sobre" {aria} /></:trigger>
      <:title>Ticket médio</:title>
      <span class="mt-1.5 block text-[13px] leading-[18px] text-muted">Faturamento dividido pelo número de pedidos pagos no período.</span>
    </.popover>
  </div>
</div>

placement (12) · trigger_on click/hover

Ticket médio · R$ 168,40
Ticket médio · R$ 168,40
Ticket médio · R$ 168,40
Ticket médio · R$ 168,40
Ticket médio · R$ 168,40
Ticket médio · R$ 168,40
Ticket médio · R$ 168,40
Ticket médio · R$ 168,40
Ticket médio · R$ 168,40
Ticket médio · R$ 168,40
Ticket médio · R$ 168,40
Ticket médio · R$ 168,40
trigger_on=click (clique)
trigger_on=hover (passe o ponteiro)
.heex
<div class="overflow-x-auto">
<div class="min-w-[640px]">
<div class="grid grid-cols-3 gap-x-4 gap-y-2">
  <div :for={p <- ~w(top-start top top-end bottom-start bottom bottom-end)} class="relative flex h-[110px] items-center justify-center">
    <.tooltip id={"pp-#{p}"} color="light" placement={p} text="Ticket médio · R$ 168,40" arrow={false} open><.button color="neutral" variant="outline" size="sm" shape="rounded">{p}</.button></.tooltip>
  </div>
</div>
<div class="mt-2 grid grid-cols-2 gap-x-4 gap-y-1">
  <%= for {l, r} <- [{"right-start", "left-start"}, {"right", "left"}, {"right-end", "left-end"}] do %>
    <div class="flex h-[84px] items-center justify-start pl-4">
      <.tooltip id={"pp-#{l}"} color="light" placement={l} text="Ticket médio · R$ 168,40" arrow={false} open><.button color="neutral" variant="outline" size="sm" shape="rounded">{l}</.button></.tooltip>
    </div>
    <div class="flex h-[84px] items-center justify-end pr-4">
      <.tooltip id={"pp-#{r}"} color="light" placement={r} text="Ticket médio · R$ 168,40" arrow={false} open><.button color="neutral" variant="outline" size="sm" shape="rounded">{r}</.button></.tooltip>
    </div>
  <% end %>
</div>
</div>
</div>
<div class="mt-4 flex flex-wrap items-start gap-x-10 gap-y-6">
  <div :for={{t, label} <- [{"click", "trigger_on=click (clique)"}, {"hover", "trigger_on=hover (passe o ponteiro)"}]} class="flex flex-col items-start gap-2">
    <span class="font-mono text-xs text-muted">{label}</span>
    <div class="h-[150px] w-[260px]">
      <.popover id={"pop-t-#{t}"} placement="bottom-start" trigger_on={t} width="260px">
        <:trigger :let={aria}><.button canvas appearance="default" icon="info" aria-label="Sobre" {aria} /></:trigger>
        <:title>Ticket médio</:title>
        <span class="mt-1.5 block text-[13px] leading-[18px] text-muted">Faturamento dividido pelo número de pedidos pagos no período.</span>
      </.popover>
    </div>
  </div>
</div>

Uso

<.popover id="kpi-info"><:trigger>…</:trigger>…</.popover>

Regras

  • Fecha ao clicar fora; não use para ações críticas.

Referência da API

Todos os function components, atributos, valores e slots que este componente cobre.

A card with an arrow next to its trigger (<.popover>), for more than a tooltip holds.

<.popover id="lesson">
  <:trigger><.button variant="primary">Lessons</.button></:trigger>
  <:title>Group Lesson</:title>
  <p class="mt-2">Lorem ipsum dolor sit amet.</p>
</.popover>

<.popover id="john" trigger_on="hover" placement="top" width="192px">...</.popover>

Opens and closes from the browser (LedgerUI.toggle("lesson")), from the server (LedgerUI.close(socket, "lesson")) or from open; a click outside and Esc close it. The LedgerUI.Float hook (priv/static/ledger_ui/hooks/float.js) places it (placement, fallbacks when there is no room, offset), draws the arrow and runs on_open / on_close (an event name with payload %{"id" => id} to target, or a %JS{}).

The panel is a role="dialog" named by its :title or by label. width is the card's width (272px by default; nil leaves it to its content).

<.popover>

Attr Type Default Values / notes
id (required) :string
open :boolean false
placement :string "right-start" bottom-start, bottom, bottom-end, top-start, top, top-end, left-start, left, left-end, right-start, right, right-end
fallbacks :list ["bottom", "top"]
offset :integer 12
trigger_on :string "click" click, hover
arrow :boolean true
on_open :any nil
on_close :any nil
target :any nil
label :string nil
class :any nil Merged into the card.
width :string "272px" The card's width; nil for its content's.

Any other HTML/phx attribute goes to the root element.

Slots:

  • <:inner_block>
  • <:title>
  • <:trigger> (required)