Class: Plutonium::UI::TabList
- Inherits:
-
Component::Base
- Object
- Component::Base
- Plutonium::UI::TabList
- Defined in:
- lib/plutonium/ui/tab_list.rb
Defined Under Namespace
Classes: TabDefinition
Constant Summary collapse
- BASE_BUTTON_CLASSES =
"inline-block px-5 py-3 border-b-2 rounded-t-lg transition-colors"- ACTIVE_CLASSES =
"focus:outline-none text-primary-600 border-primary-600 dark:text-primary-400 dark:border-primary-400"- INACTIVE_CLASSES =
"text-[var(--pu-text-muted)] hover:text-[var(--pu-text)] border-transparent hover:border-[var(--pu-border-strong)]"
Instance Method Summary collapse
-
#initialize ⇒ TabList
constructor
A new instance of TabList.
- #render? ⇒ Boolean
- #view_template ⇒ Object
- #with_tab(identifier:, title:, &block) ⇒ 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 ⇒ TabList
Returns a new instance of TabList.
11 12 13 14 15 |
# File 'lib/plutonium/ui/tab_list.rb', line 11 def initialize(...) super @tabs = [] 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
21 22 23 |
# File 'lib/plutonium/ui/tab_list.rb', line 21 def render? @tabs.present? end |
#view_template ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/plutonium/ui/tab_list.rb', line 25 def view_template default_identifier = @tabs.first&.dig(:identifier) div( data_controller: "resource-tab-list", data_resource_tab_list_active_classes_value: ACTIVE_CLASSES, data_resource_tab_list_in_active_classes_value: INACTIVE_CLASSES ) do div(class: "relative mb-6 border-b border-[var(--pu-border)]") do ul( class: "flex flex-nowrap overflow-x-auto whitespace-nowrap -mb-px text-base font-semibold gap-1 " \ "[scrollbar-width:none] [&::-webkit-scrollbar]:hidden", role: "tablist" ) do @tabs.each do |tab| active = tab[:identifier] == default_identifier li(role: "presentation") do ( class: (active), id: "#{tab[:identifier]}-tab", type: "button", role: "tab", aria_controls: "#{tab[:identifier]}-tabpanel", aria_selected: active.to_s, tabindex: active ? "0" : "-1", data_resource_tab_list_target: "btn", data_target: "#{tab[:identifier]}-tabpanel", data_action: "click->resource-tab-list#select" ) do phlexi_render tab[:title] do |val| plain val end end end end end div( class: "pointer-events-none absolute right-0 top-0 bottom-0 w-8 " \ "bg-gradient-to-l from-[var(--pu-body)] to-transparent", aria_hidden: "true" ) end div do @tabs.each do |tab| active = tab[:identifier] == default_identifier div( hidden: !active, id: "#{tab[:identifier]}-tabpanel", role: "tabpanel", aria_labelledby: "#{tab[:identifier]}-tab", aria_hidden: (!active).to_s, data_resource_tab_list_target: "tab" ) do phlexi_render tab[:block] do |val| raise NotImplementedError, "this should NEVER be triggered" end end end end end end |
#with_tab(identifier:, title:, &block) ⇒ Object
17 18 19 |
# File 'lib/plutonium/ui/tab_list.rb', line 17 def with_tab(identifier:, title:, &block) @tabs << {identifier:, title:, block:} end |