Class: ShadcnPhlexcomponents::Toggle

Inherits:
Base
  • Object
show all
Defined in:
lib/shadcn_phlexcomponents/components/toggle.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(variant: :default, size: :default, on: false, **attributes) ⇒ Toggle

Returns a new instance of Toggle.



36
37
38
39
40
# File 'lib/shadcn_phlexcomponents/components/toggle.rb', line 36

def initialize(variant: :default, size: :default, on: false, **attributes)
  @class_variants = { variant: variant, size: size }
  @on = on
  super(**attributes)
end

Instance Method Details

#default_attributes ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/shadcn_phlexcomponents/components/toggle.rb', line 42

def default_attributes
  {
    aria: {
      pressed: @on.to_s,
    },
    data: {
      controller: "toggle",
      toggle_is_on_value: @on.to_s,
      action: "click->toggle#toggle",
    },
  }
end

#view_template ⇒ Object



55
56
57
# File 'lib/shadcn_phlexcomponents/components/toggle.rb', line 55

def view_template(&)
  button(**@attributes, &)
end