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

Methods included from LocoMotion::Concerns::InspectableComponent

#build_inspect_string

Constructor Details

#initialize(**kws) ⇒ DockSectionComponent

Creates a new dock section.

Parameters:

  • kws (Hash)

    The keyword arguments for the component.

Options Hash (**kws):

  • icon (String)

    The icon to display, as a qualified [library:]name[/variant] token (e.g. "home", "home/solid").

  • 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.

  • target (String)

    The HTML target attribute for the section's <a> tag (e.g. "_blank"). Only applied when href is also provided.

  • action (String)

    A Stimulus action wired to the section via its data-action attribute. Stimulus infers the click event, so action: "my-controller#handle" is shorthand for action: "click->my-controller#handle".

  • turbo_frame (String)

    The Turbo Frame to target, rendered as data-turbo-frame.

  • turbo_action (String, Symbol)

    How Turbo Drive updates the browser history for the visit, rendered as data-turbo-action (e.g. :advance or :replace).

  • turbo_method (String, Symbol)

    The HTTP method Turbo should use for the request, rendered as data-turbo-method (e.g. :delete).

  • turbo_confirm (String)

    A confirmation prompt Turbo shows before submitting, rendered as data-turbo-confirm.

  • 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-[#449944]


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

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

  @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.



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

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.

Returns:

  • (String)

    The rendered HTML for the dock section.



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

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