LedgerUI.Components.ContextMenu (LedgerUI v0.2.0)

Copy Markdown View Source

A menu that opens under the pointer on a right click.

<.context_menu id="file-menu">
  <div class="lu-panel">Right click here</div>
  <:item phx-click="rename" icon="edit" kbd="F2">Rename</:item>
  <:item phx-click="copy">Copy</:item>
  <:item phx-click="delete" tone="danger" divider icon="trash">Delete</:item>
</.context_menu>

The hook LedgerUI.ContextMenu (priv/static/ledger_ui/hooks/context_menu.js) opens the menu at the pointer (kept inside the window, in the top layer), moves the focus to the first item and closes it on a click outside, Escape, a scroll and when an item is chosen. The arrows, Home, End and letters move between the items.

Besides the README attrs the :item slot takes icon (a name) and kbd (a shortcut shown as text).

Summary

Functions

context_menu(assigns)

Attributes

  • id (:string) (required)
  • label (:string) - Accessible name of the menu. Defaults to "Actions".
  • class (:any) - Defaults to nil.
  • placement (:string) - Where the menu sits against the pointer (bottom-start: below, from the pointer to the right). Defaults to "bottom-start". Must be one of "bottom-start", "bottom-end", "top-start", or "top-end".
  • Global attributes are accepted.

Slots

  • inner_block (required) - The area that answers to the right click.
  • trigger - The area that answers to the right click, in place of the inner block (the vitrine's form).
  • item - Accepts attributes:
    • tone (:string)
    • divider (:boolean)
    • disabled (:boolean)
    • icon (:string)
    • kbd (:string)
    • phx-click (:any)
    • phx-value-id (:any)
    • phx-target (:any)