Class: ShadcnPhlexcomponents::AccordionTrigger

Inherits:
Base
  • Object
show all
Defined in:
lib/shadcn_phlexcomponents/components/accordion.rb

Constant Summary

Constants inherited from Base

Base::SANITIZER_ALLOWED_ATTRIBUTES, Base::SANITIZER_ALLOWED_TAGS, Base::TAILWIND_MERGER

Instance Method Summary collapse

Methods inherited from Base

#before_template, #convert_collection_hash_to_struct, #find_as_child, #icon, #item_disabled?, #merge_default_attributes, #merged_as_child_attributes, #nokogiri_attributes_to_hash, #overlay, #sanitize_as_child

Constructor Details

#initialize(aria_id: nil, **attributes) ⇒ AccordionTrigger

Returns a new instance of AccordionTrigger.



82
83
84
85
# File 'lib/shadcn_phlexcomponents/components/accordion.rb', line 82

def initialize(aria_id: nil, **attributes)
  @aria_id = aria_id
  super(**attributes)
end

Instance Method Details

#default_attributes ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/shadcn_phlexcomponents/components/accordion.rb', line 87

def default_attributes
  {
    type: "button",
    id: "#{@aria_id}-trigger",
    aria: {
      controls: "#{@aria_id}-content",
      expanded: "false",
    },
    data: {
      state: "closed",
      accordion_target: "trigger",
      action: "        click->accordion#toggle\n        keydown.up->accordion#focusTrigger:prevent\n        keydown.down->accordion#focusTrigger:prevent\n      HEREDOC\n    },\n  }\nend\n",

#view_template ⇒ Object



107
108
109
110
111
112
113
114
115
# File 'lib/shadcn_phlexcomponents/components/accordion.rb', line 107

def view_template(&)
  h3(class: "flex") do
    button(**@attributes) do
      yield

      icon("chevron-down", class: "text-muted-foreground pointer-events-none size-4 shrink-0 translate-y-0.5 transition-transform duration-200")
    end
  end
end