Class: Shadcn::RadioGroup::Component

Inherits:
ApplicationViewComponent show all
Includes:
Concerns::SubmitsValue
Defined in:
app/components/shadcn/radio_group/component.rb

Overview

Port of registry/new-york-v4/ui/radio-group.tsx

Constant Summary

Constants inherited from ApplicationViewComponent

ApplicationViewComponent::CONTENTS_STYLE, ApplicationViewComponent::VOID_TAGS

Instance Attribute Summary collapse

Attributes inherited from ApplicationViewComponent

#attributes

Instance Method Summary collapse

Methods included from Concerns::SubmitsValue

included

Methods inherited from ApplicationViewComponent

#css_classes, default_tag, #merged_style, #render_element, #shadcn_t, slot_name, #style_variants, #tag_name

Constructor Details

#initialize(name: nil, value: nil, disabled: false, **attributes) ⇒ Component

Returns a new instance of Component.



18
19
20
21
22
23
# File 'app/components/shadcn/radio_group/component.rb', line 18

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

Instance Attribute Details

#disabledObject (readonly)

Returns the value of attribute disabled.



16
17
18
# File 'app/components/shadcn/radio_group/component.rb', line 16

def disabled
  @disabled
end

#nameObject (readonly)

Returns the value of attribute name.



16
17
18
# File 'app/components/shadcn/radio_group/component.rb', line 16

def name
  @name
end

#valueObject (readonly)

Returns the value of attribute value.



16
17
18
# File 'app/components/shadcn/radio_group/component.rb', line 16

def value
  @value
end

Instance Method Details

#callObject



36
37
38
# File 'app/components/shadcn/radio_group/component.rb', line 36

def call
  render_element(body: safe_join([ items, content, hidden_input ].flatten.compact))
end

#element_attributes(**defaults) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'app/components/shadcn/radio_group/component.rb', line 25

def element_attributes(**defaults)
  super(**{
    role: "radiogroup",
    "aria-required" => nil,
    "data-disabled" => (true if disabled),
    "data-controller" => "shadcn--radio-group",
    "data-shadcn--radio-group-value-value" => value,
    "data-shadcn--radio-group-disabled-value" => disabled
  }.merge(defaults))
end