Class: Daisy::Navigation::DockSectionComponent

Inherits:
LocoMotion::BaseComponent show all
Includes:
LocoMotion::Concerns::IconableComponent, LocoMotion::Concerns::LinkableComponent
Defined in:
app/components/daisy/navigation/dock_component.rb

Overview

A section within a Dock component.

Constant Summary

Constants inherited from LocoMotion::BaseComponent

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

Instance Attribute Summary

Attributes inherited from LocoMotion::BaseComponent

#config, #loco_parent

Instance Method Summary collapse

Methods included from LocoMotion::Concerns::IconableComponent

#has_icons?, #left_icon_html, #render_left_icon, #render_right_icon, #right_icon_html

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(**kws) ⇒ DockSectionComponent

Creates a new dock section.

Options Hash (**kws):

  • icon (String)

    The name of the icon to display.

  • icon_variant (Symbol)

    The variant of the icon to use (default: :outline).

  • icon_css (String)

    Additional CSS classes for the icon.

  • title (String)

    Optional text to display below the icon.

  • href (String)

    Optional URL to make the section a link.

  • active (Boolean)

    Whether this section is currently active (default: false).

  • css (String)

    Additional CSS classes for styling. Common options include:

    • Text color: ‘text-primary`, `text-secondary`, `text-accent`

    • Custom colors: ‘text-`



74
75
76
77
78
79
80
# File 'app/components/daisy/navigation/dock_component.rb', line 74

def initialize(**kws)
  super(**kws)

  @icon_variant = config_option(:icon_variant, :outline)
  @title = config_option(:title)
  @active = config_option(:active, false)
end

Instance Method Details

#before_renderObject

Configure the component before rendering.

Adds the dock-active class if this section is active and configures the title with appropriate styling.



86
87
88
89
90
91
92
93
94
# File 'app/components/daisy/navigation/dock_component.rb', line 86

def before_render
  super

  set_tag_name(:component, "button") unless @href
  add_css(:component, "dock-active") if @active

  set_tag_name(:title, :span)
  add_css(:title, "dock-label")
end

#callString

Render the dock section component with icon, title, and content.



99
100
101
102
103
104
105
# File 'app/components/daisy/navigation/dock_component.rb', line 99

def call
  part(:component) do
    concat(render_icon)
    concat(part(:title) { @title }) if @title
    concat(content)
  end
end