Class: ShadcnPhlexcomponents::SwitchThumb

Inherits:
Base
  • Object
show all
Defined in:
lib/shadcn_phlexcomponents/components/switch.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(checked: false, **attributes) ⇒ SwitchThumb

Returns a new instance of SwitchThumb.



85
86
87
88
# File 'lib/shadcn_phlexcomponents/components/switch.rb', line 85

def initialize(checked: false, **attributes)
  @checked = checked
  super(**attributes)
end

Instance Method Details

#default_attributes ⇒ Object



90
91
92
93
94
95
96
97
# File 'lib/shadcn_phlexcomponents/components/switch.rb', line 90

def default_attributes
  {
    data: {
      switch_target: "thumb",
      state: @checked ? "checked" : "unchecked",
    },
  }
end

#view_template ⇒ Object



99
100
101
# File 'lib/shadcn_phlexcomponents/components/switch.rb', line 99

def view_template
  span(**@attributes)
end