The views of a collection (List, Board, Table...) as a segmented control (lu-seg), with an
optional "+ View" menu to add one and a menu of saved views.
<.view_switcher
id="invoice-views"
value={@view}
on_change="set_view"
on_add="add_view"
views={[%{label: "List", value: "list", icon: "list"}, %{label: "Board", value: "board", icon: "kanban"}]}
options={[%{label: "Table", value: "table", icon: "table", description: "Table view"}]}
/>views are maps with :label, :value and optionally :icon, :count, :disabled,
:patch/:navigate/:href (a link, aria-current="page" when chosen); plain strings
stand for %{label: s, value: s}. A tab sends on_change with %{"view" => value}.
options are the views the menu offers (:label, :value, :icon, :description, :added,
:disabled); choosing one sends on_add with %{"view" => value}. The menu is a
dropdown/1 with id "#{id}-add". saved (same shape) adds a menu of saved views
(on_saved, saved_value, saved_label).
Without options and saved the root is the lu-seg itself; otherwise a lu-row wraps it.
Link views carry aria-current="page" when chosen, button views aria-pressed; the menu
triggers carry aria-haspopup/aria-expanded/aria-controls (rendered by dropdown/1).
data-lu-single is set on the control when a value is chosen.
Summary
Functions
Attributes
id(:string) (required)value(:any) - Defaults tonil.current(:any) - Alias ofvalue. Defaults tonil.views(:list) - Defaults to[].options(:list) - Defaults to[].saved(:list) - Defaults to[].saved_value(:any) - Defaults tonil.saved_label(:string) - Defaults to"Saved views".on_change(:any) - Defaults tonil.on_add(:any) - Defaults tonil.on_saved(:any) - Defaults tonil.target(:any) - Defaults tonil.add_label(:string) - Defaults to"View".menu_title(:string) - Defaults to"Add a new view".columns(:integer) - Defaults to2. Must be one of1, or2.placement(:string) - Defaults to"bottom-start".class(:any) - Defaults tonil.- Global attributes are accepted.