LedgerUI.Components.Fab (LedgerUI v0.2.0)

Copy Markdown View Source

Floating action buttons: fab/1, one button (the canvas's solid ink button, or the retracting pill) and fab_dial/1, a speed-dial that opens a column of actions.

<.fab id="new" label="Novo pedido" phx-click="new_order">
  <:icon><.icon name="plus" size="md" /></:icon>
</.fab>
<.fab id="ask" label="Pergunte ao assistente" variant="pill" phx-click="open_assistant" />
<.fab id="help" label="Precisa de ajuda?" variant="pill" retract="auto" retract_after={6000} />
<.fab id="chat" label="Chat" variant="pill" retract="always" color="light" position="bottom-left" badge={3} />

<.fab_dial id="quick" label="Ações rápidas">
  <:action label="Novo contato" phx-click="new_contact"><.icon name="user-plus" /></:action>
  <:action label="Enviar arquivo" phx-click="upload"><.icon name="upload" /></:action>
</.fab_dial>

Position

Both are fixed to the viewport corner (fixed, the default; --ledger-z-fab, 90, keeps them under modals and drawers). fixed={false} leaves them absolute in the nearest positioned ancestor, which is how the showcase demos show them inside a box. offset moves a button from its corner, in pixels.

Hooks

  • LedgerUI.Fab (priv/static/ledger_ui/hooks/fab.js), only for retract="auto": expands the pill, retracts it after retract_after ms or on scroll, expands it again on hover and focus. data-state is kept across patches (keep-data-state).
  • LedgerUI.FabDial (priv/static/ledger_ui/hooks/fab_dial.js): click toggles, Escape closes and returns focus, arrows/Home/End walk the actions, a click outside or focus leaving closes it.

Summary

Functions

fab(assigns)

Attributes

  • id (:string) (required)
  • label (:string) (required) - Always rendered, and the aria-label.
  • position (:string) - Defaults to "bottom-right". Must be one of "bottom-right", "bottom-left", "top-right", or "top-left".
  • color (:string) - Defaults to "assistant". Must be one of "assistant", "primary", "dark", or "light".
  • size (:string) - Defaults to "md". Must be one of "md", or "lg".
  • variant (:string) - Defaults to "canvas". Must be one of "canvas", or "pill".
  • offset (:integer) - Distance from the corner, in pixels. Defaults to nil.
  • retract (:string) - Defaults to "hover". Must be one of "hover", "auto", "never", or "always".
  • retract_after (:integer) - Milliseconds before retract="auto" retracts. Defaults to 4000.
  • expanded (:boolean) - Forces the pill open, whatever retract says. Defaults to false.
  • badge (:any) - A count or short text on the bubble's corner. Defaults to nil.
  • fixed (:boolean) - Fixed to the viewport (false: absolute in its parent). Defaults to true.
  • type (:string) - Defaults to "button".
  • disabled (:boolean) - Defaults to false.
  • class (:any) - Defaults to nil.
  • style (:string) - Defaults to nil.
  • Global attributes are accepted. Supports all globals plus: ["href", "navigate", "patch", "method", "download", "target", "rel", "replace", "form", "name", "value"].

Slots

  • icon - The glyph (a sparkle by default).
  • inner_block - Replaces the visible label text (label stays the aria-label).

fab_dial(assigns)

Attributes

  • id (:string) (required)
  • label (:string) (required) - The button's aria-label and the name of the menu.
  • position (:string) - Defaults to "bottom-right". Must be one of "bottom-right", "bottom-left", "top-right", or "top-left".
  • color (:string) - Kept for API parity with fab/1. Defaults to "primary". Must be one of "assistant", "primary", "dark", or "light".
  • size (:string) - Kept for API parity with fab/1. Defaults to "md". Must be one of "md", or "lg".
  • variant (:string) - Defaults to "canvas". Must be one of "canvas", or "pill".
  • offset (:integer) - Defaults to nil.
  • open (:boolean) - The initial state; after mount the hook owns it. Defaults to false.
  • fixed (:boolean) - Fixed to the viewport (false: absolute in its parent). Defaults to true.
  • class (:any) - Defaults to nil.
  • style (:string) - Defaults to nil.
  • Global attributes are accepted.

Slots

  • icon - The glyph of the button, a plus by default; it turns while open.
  • action (required) - A mini action: the icon is its content. Accepts attributes:
    • label (:string) (required)
    • href (:string)
    • navigate (:string)
    • patch (:string)
    • phx-click (:any)
    • phx-target (:any)
    • disabled (:boolean)
    • class (:any)