LedgerUI.Components.Accordion (LedgerUI v0.2.0)

Copy Markdown View Source

A list of sections that open under their titles (<.accordion> with <.accordion_item>).

<.accordion id="faq" variant="bordered">
  <.accordion_item id="faq-1" title="Accordion Item 1" open>
    <p>Lorem ipsum dolor sit amet.</p>
  </.accordion_item>
  <.accordion_item id="faq-2" title="Accordion Item 2">...</.accordion_item>
</.accordion>

<.accordion id="help" variant="primary" color="warning">...</.accordion>

Variants: canvas (default), basic, border-bottom, bordered, divided, primary and advanced (a :header of your own per item, with the chevron at its end). color tints the primary style. One section is open at a time; multiple lets them open independently.

The browser owns which sections are open (the LedgerUI.Collapse hook, priv/static/ledger_ui/hooks/collapse.js); the server's open wins when it changes, LedgerUI.open/close/toggle("faq-1") work and on_open / on_close push %{"id" => item_id} when they are event names. The ARIA is rendered by the server: the header is a role="button" with tabindex="0", aria-expanded and aria-controls, the body a role="region" labelled by the header; the hook only updates aria-expanded.

Summary

Functions

accordion(assigns)

Attributes

  • id (:string) (required)
  • variant (:string) - Defaults to "canvas". Must be one of "advanced", "basic", "border-bottom", "bordered", "canvas", "divided", or "primary".
  • color (:string) - Defaults to "primary". Must be one of "primary", "secondary", "info", "success", "warning", or "error".
  • multiple (:boolean) - Defaults to false.
  • class (:any) - Defaults to nil.
  • Global attributes are accepted.

Slots

  • item - A section, its content the body: one accordion_item/1, with the id <id>-<position>. Accepts attributes:
    • title (:string)
    • open (:boolean)
    • id (:string)
    • class (:any)
  • inner_block - accordion_item/1s, after the <:item>s.

accordion_item(assigns)

Attributes

  • id (:string) (required)
  • title (:string) - Defaults to nil.
  • open (:boolean) - Defaults to false.
  • on_open (:any) - Defaults to nil.
  • on_close (:any) - Defaults to nil.
  • target (:any) - Defaults to nil.
  • toggle_label (:string) - Defaults to "Toggle".
  • class (:any) - Defaults to nil.
  • trigger_class (:any) - Defaults to nil.
  • Global attributes are accepted.

Slots

  • header
  • inner_block