Class: Daisy::Navigation::TabsComponent

Inherits:
LocoMotion::BaseComponent show all
Defined in:
app/components/daisy/navigation/tabs_component.rb

Overview

Note:

When using radio button tabs, the titles must be simple strings and cannot contain HTML elements or icons.

Creates a tabbed navigation component that can be used either as links or radio buttons with associated content.

Defined Under Namespace

Classes: TabComponent

Constant Summary

Constants inherited from LocoMotion::BaseComponent

LocoMotion::BaseComponent::EMPTY_PART_IGNORED_TAGS, LocoMotion::BaseComponent::SELF_CLOSING_TAGS

Instance Attribute Summary collapse

Attributes inherited from LocoMotion::BaseComponent

#config, #loco_parent

Instance Method Summary collapse

Methods inherited from LocoMotion::BaseComponent

build, #component_ref, #config_option, #cssify, define_modifier, define_modifiers, define_part, define_parts, define_size, define_sizes, #empty_part_content, #inspect, #part, register_component_initializer, register_component_setup, #rendered_css, #rendered_data, #rendered_html, #rendered_stimulus_controllers, #rendered_tag_name, renders_many, renders_one, set_component_name, #set_loco_parent, #strip_spaces

Constructor Details

#initialize(*args, **kws, &block) ⇒ TabsComponent

Create a new instance of the TabsComponent.

Parameters:

  • args (Array)

    Not used.

  • kws (Hash)

    The keyword arguments for the component.

Options Hash (**kws):

  • name (String)

    The name attribute for radio button tabs (default: auto-generated UUID).

  • radio (Boolean)

    Whether to use radio buttons instead of links (default: false).

  • css (String)

    Additional CSS classes for styling. Common options include:

    • Style: ‘tabs-border`, `tabs-lift`

    • Size: ‘tabs-xl`, `tabs-lg`, `tabs-md` (default), `tabs-sm`, `tabs-xs`

    • Width: ‘w-full`, `w-`



204
205
206
207
208
209
# File 'app/components/daisy/navigation/tabs_component.rb', line 204

def initialize(*args, **kws, &block)
  super

  @name = config_option(:name, "tabs-#{SecureRandom.uuid}")
  @radio = config_option(:radio, false)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



184
185
186
# File 'app/components/daisy/navigation/tabs_component.rb', line 184

def name
  @name
end

#radioObject (readonly)

Returns the value of attribute radio.



184
185
186
# File 'app/components/daisy/navigation/tabs_component.rb', line 184

def radio
  @radio
end

Instance Method Details

#before_renderObject



211
212
213
214
# File 'app/components/daisy/navigation/tabs_component.rb', line 211

def before_render
  add_css(:component, "tabs")
  add_html(:component, { role: "tablist" })
end

#radio?Boolean

Returns:

  • (Boolean)


216
217
218
# File 'app/components/daisy/navigation/tabs_component.rb', line 216

def radio?
  radio
end