Class: Shadcn::ToggleGroupComponent

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

Overview

Toggle Group component for grouping related toggles Matches shadcn/ui ToggleGroup component

Examples:

Single selection

<%= render Shadcn::ToggleGroupComponent.new(type: :single, name: "alignment") do |group| %>
  <% group.with_item(value: "left", aria_label: "Align left") { icon_left } %>
  <% group.with_item(value: "center", aria_label: "Align center") { icon_center } %>
  <% group.with_item(value: "right", aria_label: "Align right") { icon_right } %>
<% end %>

Multiple selection with outline variant

<%= render Shadcn::ToggleGroupComponent.new(type: :multiple, variant: :outline) do |group| %>
  <% group.with_item(value: "bold") { "B" } %>
  <% group.with_item(value: "italic") { "I" } %>
  <% group.with_item(value: "underline") { "U" } %>
<% end %>

Constant Summary collapse

BASE_CLASSES =
"inline-flex items-center justify-center gap-1 rounded-lg"

Instance Attribute Summary

Attributes inherited from BaseComponent

#class_name, #data, #html_options

Instance Method Summary collapse

Methods inherited from BaseComponent

#content

Methods included from Rails::Helpers::ClassNameHelper

#cn

Constructor Details

#initialize(type: :single, variant: :default, size: :default, value: nil, name: nil, **options) ⇒ ToggleGroupComponent

Returns a new instance of ToggleGroupComponent.

Parameters:

  • type (Symbol) (defaults to: :single)

    :single or :multiple selection mode

  • variant (Symbol) (defaults to: :default)

    :default or :outline

  • size (Symbol) (defaults to: :default)

    :sm, :default, or :lg

  • value (String, Array) (defaults to: nil)

    Currently selected value(s)

  • name (String) (defaults to: nil)

    Form field name



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/components/shadcn/toggle_group_component.rb', line 43

def initialize(
  type: :single,
  variant: :default,
  size: :default,
  value: nil,
  name: nil,
  **options
)
  super(**options)
  @type = type
  @variant = variant
  @size = size
  @value = value
  @name = name
end