Class: Shadcn::RadioGroupComponent

Inherits:
BaseComponent
  • Object
show all
Defined in:
app/components/shadcn/radio_group_component.rb

Overview

Radio Group component for selecting one option from a set Uses native elements styled with CSS Works without JavaScript for progressive enhancement

Examples:

Data-driven usage (Tier 1)

<%= render Shadcn::RadioGroupComponent.new(
  name: "plan",
  value: "pro",
  items: [
    { value: "free", label: "Free" },
    { value: "pro", label: "Pro" },
    { value: "enterprise", label: "Enterprise", disabled: true }
  ]
) %>

Simple DSL with labels (Tier 2)

<%= render Shadcn::RadioGroupComponent.new(name: "plan") do |group| %>
  <%= group.with_item(value: "free", label: "Free") %>
  <%= group.with_item(value: "pro", label: "Pro") %>
<% end %>

With separate labels (backward compatible)

<%= render Shadcn::RadioGroupComponent.new(name: "plan") do |group| %>
  <div class="flex items-center space-x-2">
    <%= group.with_item(value: "free", id: "free") %>
    <%= render Shadcn::LabelComponent.new(for: "free") { "Free" } %>
  </div>
<% end %>

Constant Summary collapse

BASE_CLASSES =
"grid gap-3"

Instance Attribute Summary

Attributes inherited from BaseComponent

#class_name, #data, #html_options

Instance Method Summary collapse

Methods inherited from BaseComponent

#content

Methods included from Shadcn::Rails::Helpers::ClassNameHelper

#cn

Constructor Details

#initialize(name:, value: nil, items: [], disabled: false, required: false, orientation: :vertical, **options) ⇒ RadioGroupComponent



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/components/shadcn/radio_group_component.rb', line 55

def initialize(
  name:,
  value: nil,
  items: [],
  disabled: false,
  required: false,
  orientation: :vertical,
  **options
)
  super(**options)
  @name = name
  @value = value
  @items_data = items
  @disabled = disabled
  @required = required
  @orientation = orientation
end