Class: ShadcnPhlexcomponents::RadioGroupItem

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

Returns a new instance of RadioGroupItem.



110
111
112
113
114
115
# File 'lib/shadcn_phlexcomponents/components/radio_group.rb', line 110

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

Instance Method Details

#default_attributes ⇒ Object



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/shadcn_phlexcomponents/components/radio_group.rb', line 136

def default_attributes
  {
    type: "button",
    tabindex: -1,
    role: "radio",
    aria: {
      checked: @checked.to_s,
    },
    data: {
      checked: @checked.to_s,
      value: @value,
      radio_group_target: "item",
      action: "        click->radio-group#select\n        keydown.right->radio-group#selectItem:prevent\n        keydown.down->radio-group#selectItem:prevent\n        keydown.up->radio-group#selectItem:prevent\n        keydown.left->radio-group#selectItem:prevent\n        keydown.enter->radio-group#preventDefault\n      HEREDOC\n    },\n  }\nend\n",

#view_template ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/shadcn_phlexcomponents/components/radio_group.rb', line 117

def view_template(&)
  button(**@attributes) do
    RadioGroupItemIndicator()

    input(
      type: "radio",
      value: @value,
      class: "-translate-x-full pointer-events-none absolute top-0 left-0 size-4 opacity-0",
      name: @name,
      tabindex: -1,
      checked: @checked,
      aria: { hidden: "true" },
      data: {
        radio_group_target: "input",
      },
    )
  end
end