Class: Shadcn::RadioGroup::Item::Component
- Inherits:
-
ApplicationViewComponent
- Object
- ViewComponent::Base
- ApplicationViewComponent
- Shadcn::RadioGroup::Item::Component
- Defined in:
- app/components/shadcn/radio_group/item/component.rb
Overview
RadioGroupItem
Constant Summary collapse
- INDICATOR_CLASSES =
"relative flex items-center justify-center"- DOT_CLASSES =
"absolute top-1/2 left-1/2 size-2 -translate-x-1/2 -translate-y-1/2 " \ "fill-primary"
Constants inherited from ApplicationViewComponent
ApplicationViewComponent::CONTENTS_STYLE, ApplicationViewComponent::VOID_TAGS
Instance Attribute Summary collapse
-
#checked ⇒ Object
readonly
Returns the value of attribute checked.
-
#disabled ⇒ Object
readonly
Returns the value of attribute disabled.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Attributes inherited from ApplicationViewComponent
Instance Method Summary collapse
- #call ⇒ Object
- #element_attributes(**defaults) ⇒ Object
-
#initialize(value:, checked: false, disabled: false, **attributes) ⇒ Component
constructor
A new instance of Component.
- #state ⇒ Object
Methods inherited from ApplicationViewComponent
#css_classes, default_tag, #merged_style, #render_element, #shadcn_t, slot_name, #style_variants, #tag_name
Constructor Details
#initialize(value:, checked: false, disabled: false, **attributes) ⇒ Component
Returns a new instance of Component.
28 29 30 31 32 33 |
# File 'app/components/shadcn/radio_group/item/component.rb', line 28 def initialize(value:, checked: false, disabled: false, **attributes) @value = value.to_s @checked = checked @disabled = disabled super(**attributes) end |
Instance Attribute Details
#checked ⇒ Object (readonly)
Returns the value of attribute checked.
26 27 28 |
# File 'app/components/shadcn/radio_group/item/component.rb', line 26 def checked @checked end |
#disabled ⇒ Object (readonly)
Returns the value of attribute disabled.
26 27 28 |
# File 'app/components/shadcn/radio_group/item/component.rb', line 26 def disabled @disabled end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
26 27 28 |
# File 'app/components/shadcn/radio_group/item/component.rb', line 26 def value @value end |
Instance Method Details
#call ⇒ Object
56 57 58 |
# File 'app/components/shadcn/radio_group/item/component.rb', line 56 def call render_element(body: indicator) end |
#element_attributes(**defaults) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/components/shadcn/radio_group/item/component.rb', line 39 def element_attributes(**defaults) super(**{ type: "button", role: "radio", value: value, disabled: (true if disabled), tabindex: (checked ? "0" : "-1"), "aria-checked" => checked.to_s, "data-state" => state, "data-value" => value, "data-disabled" => (true if disabled), "data-shadcn--radio-group-target" => "item", "data-action" => "click->shadcn--radio-group#select " \ "keydown->shadcn--radio-group#keydown" }.merge(defaults)) end |
#state ⇒ Object
35 36 37 |
# File 'app/components/shadcn/radio_group/item/component.rb', line 35 def state checked ? "checked" : "unchecked" end |