LedgerUI.Components.Collapse (LedgerUI v0.2.0)

Copy Markdown View Source

A section that opens and closes under its trigger (<.collapse>) and a text clamped to a few lines with a "show more" link (<.collapse_text>).

<.collapse id="details">
  <:trigger>Shipping details</:trigger>
  <p>Ships in two days.</p>
</.collapse>

<.collapse id="files" open chevron="down" variant="section">
  <:trigger>My files</:trigger>
  ...
</.collapse>

<.collapse_text id="desc" lines={2} more="Show more" less="Show less">
  Long text...
</.collapse_text>

collapse is a native <details>: the trigger works with the mouse and the keyboard and the browser owns open; when the server changes open, the server wins. LedgerUI.open/close/toggle("id") open and close it too. on_open / on_close run on every toggle (an event name pushes %{"id" => id} to the LiveView or target; a %JS{} is run as is). The LedgerUI.Collapse hook (priv/static/ledger_ui/hooks/collapse.js) provides the events and the chevron's turn.

variant is the design canvas section by default; classic (or nil) leaves the trigger to its class; framed, flat and section are the other ready-made looks.

Summary

Functions

A text clamped to lines lines, with a link under it that shows the rest and hides it again. Works in the browser (no event to the server); the link has aria-expanded and aria-controls.

Functions

collapse(assigns)

Attributes

  • id (:string) (required)
  • open (:boolean) - Defaults to false.
  • on_open (:any) - Defaults to nil.
  • on_close (:any) - Defaults to nil.
  • target (:any) - Defaults to nil.
  • chevron (:string) - Defaults to nil.Must be one of nil, "", "down", or "right".
  • variant (:string) - Defaults to "canvas". Must be one of nil, "", "classic", "framed", "flat", "section", or "canvas".
  • panel_class (:any) - Defaults to nil.
  • chevron_class (:any) - Defaults to nil.
  • class (:any) - Defaults to nil.
  • Global attributes are accepted.

Slots

  • inner_block (required)
  • trigger (required) - Accepts attributes:
    • class (:any)
    • style (:string)

collapse_text(assigns)

A text clamped to lines lines, with a link under it that shows the rest and hides it again. Works in the browser (no event to the server); the link has aria-expanded and aria-controls.

Attributes

  • id (:string) (required)
  • lines (:integer) - Defaults to 2.
  • open (:boolean) - Defaults to false.
  • more (:string) - Defaults to "Show more".
  • less (:string) - Defaults to "Show less".
  • class (:any) - Defaults to nil.
  • text_class (:any) - Defaults to nil.
  • Global attributes are accepted.

Slots

  • inner_block (required)