DevactionUI.FilterMenu (devaction_ui v0.2.3)

Copy Markdown View Source

A button that opens a menu of filter groups; a group opens a submenu of ticks, checkboxes or radios. Ticking does not close the menu. The menu is a form: it sends on Apply (phx-submit), or on every tick with phx-change, as %{"filters" => %{"status" => ["progress"], "who" => ["CA"]}}. A count on each group and on the button follows the ticks, except for an option marked default, which is what the filter already means.

A group is %{key: "status", label: "Status", type: :checkbox, options: [...]}; type is :checkbox or :radio and anything else raises. An option is %{value: "progress", label: "In progress", count: 2, checked: true, default: false, avatar: "CA"}; count, checked, default and avatar are optional, and the option_icon slot draws an icon or a color dot before the label of each option.

The count on the button is the number of filters that were applied: the ones sent by the last Apply (or, when the form has phx-change, every tick). The counts on the groups follow the ticks, and the Apply button shows how many changes it would send. Applying gives the focus back to the button; the menu also closes when the focus leaves it. Arrows move, → opens a submenu, ← and Esc go back, Enter and Space tick. Words are attributes and icons are slots.

Clear (reset_label) unticks every option, back to the default ones. With reset_submits it then submits the form, so the server hears the empty filters at once; without it, it only unticks, and Apply (or phx-change) sends them. The count on the button is only for what was applied, so it drops when Clear submits.

align is the side of the button the panel lines up with; the submenus open to the right of the panel for :start and to the left for :end, and turn to the other side when there is no room on the screen. class goes to the root; phx-submit, phx-change, phx-target and the other global attributes go to the form.

Summary

Functions

filter_menu(assigns)

@spec filter_menu(map()) :: Phoenix.LiveView.Rendered.t()

Attributes

  • id (:string) (required)
  • label (:string) (required) - the button's text and the menu's name.
  • groups (:list) (required)
  • apply_label (:string) (required)
  • reset_label (:string) (required)
  • close_label (:string) (required)
  • align (:atom) - Defaults to :start. Must be one of :start, or :end.
  • reset_submits (:boolean) - Clear also submits the form, which sends the empty filters and applies them; false only unticks (and sends phx-change, if the form has it). Defaults to false.
  • class (:any) - Defaults to nil.
  • Global attributes are accepted. Supports all globals plus: ["phx-submit", "phx-change", "phx-target"].

Slots

  • trigger_icon - the icon of the button.
  • group_icon - the icon of a group's row; gets the group.
  • chevron_icon - the arrow at the end of a group's row.
  • check_icon - the mark of a ticked option.
  • close_icon - the icon of the close button.
  • option_icon - an icon or a color dot before an option; gets %{group: key, option: option}.