Class: Plutonium::UI::Table::Components::ViewSwitcher
- Inherits:
-
Component::Base
- Object
- Component::Base
- Plutonium::UI::Table::Components::ViewSwitcher
- Defined in:
- lib/plutonium/ui/table/components/view_switcher.rb
Overview
Segmented control for switching between index views (Table / Grid). Renders nothing unless at least two views are enabled. Selection is persisted in a per-resource cookie that the server reads on the next request — no ‘?view=` URL pollution so filters / search / clear-x links don’t have to thread it through. The Stimulus controller sets the cookie on click, then reloads.
Constant Summary collapse
- SEGMENT_LABELS =
{ table: {label: "Table", icon: Phlex::TablerIcons::Table}, grid: {label: "Grid", icon: Phlex::TablerIcons::LayoutGrid} }.freeze
Instance Method Summary collapse
-
#initialize(views:, current:, cookie_name:, cookie_path: "/") ⇒ ViewSwitcher
constructor
A new instance of ViewSwitcher.
- #render? ⇒ Boolean
- #view_template ⇒ Object
Methods included from Component::Behaviour
Methods included from Component::Tokens
Methods included from Component::Kit
#BuildActionButton, #BuildActionsDropdown, #BuildBlock, #BuildBreadcrumbs, #BuildBulkActionsToolbar, #BuildColorModeSelector, #BuildDynaFrameContent, #BuildDynaFrameHost, #BuildEmptyCard, #BuildFrameNavigatorPanel, #BuildModalCentered, #BuildModalSlideover, #BuildPageHeader, #BuildPanel, #BuildRowActionsDropdown, #BuildSkeletonTable, #BuildTabList, #BuildTableFilterPills, #BuildTableInfo, #BuildTablePagination, #BuildTableScopesBar, #BuildTableScopesPills, #BuildTableSearchBar, #BuildTableToolbar, #BuildTableViewSwitcher, #method_missing, #respond_to_missing?
Constructor Details
#initialize(views:, current:, cookie_name:, cookie_path: "/") ⇒ ViewSwitcher
Returns a new instance of ViewSwitcher.
20 21 22 23 24 25 |
# File 'lib/plutonium/ui/table/components/view_switcher.rb', line 20 def initialize(views:, current:, cookie_name:, cookie_path: "/") @views = views @current = current @cookie_name = @cookie_path = end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Plutonium::UI::Component::Kit
Instance Method Details
#render? ⇒ Boolean
27 28 29 |
# File 'lib/plutonium/ui/table/components/view_switcher.rb', line 27 def render? @views.size > 1 end |
#view_template ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/plutonium/ui/table/components/view_switcher.rb', line 31 def view_template div( role: "tablist", aria: {label: "View"}, class: "inline-flex h-8 rounded-md border border-[var(--pu-border)] bg-[var(--pu-surface)] overflow-hidden", data: { controller: "view-switcher", view_switcher_cookie_name_value: @cookie_name, view_switcher_cookie_path_value: @cookie_path } ) do @views.each_with_index do |key, i| render_segment(key, last: i == @views.length - 1) end end end |