Class: RubyUI::ToggleGroupItem

Inherits:
Toggle
  • Object
show all
Defined in:
lib/ruby_ui/toggle_group/toggle_group_item.rb

Constant Summary collapse

JOIN_BASE =
"w-auto min-w-0 shrink-0 px-3 focus:z-10 focus-visible:z-10"

Constants inherited from Toggle

RubyUI::Toggle::BASE_CLASSES, RubyUI::Toggle::SIZE_CLASSES, RubyUI::Toggle::VARIANT_CLASSES

Constants inherited from Base

Base::TAILWIND_MERGER

Instance Attribute Summary

Attributes inherited from Base

#attrs

Instance Method Summary collapse

Methods inherited from Toggle

classes_for

Constructor Details

#initialize(value:, group_context:, variant: nil, size: nil, **attrs) ⇒ ToggleGroupItem

Returns a new instance of ToggleGroupItem.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/ruby_ui/toggle_group/toggle_group_item.rb', line 7

def initialize(value:, group_context:, variant: nil, size: nil, **attrs)
  @item_value = value.to_s
  @group_context = group_context

  pressed = group_context[:selected_values].include?(@item_value)
  super(
    pressed: pressed,
    name: nil,
    value: @item_value,
    variant: variant || group_context[:variant],
    size: size || group_context[:size],
    disabled: group_context[:disabled],
    **attrs
  )
end

Instance Method Details

#view_template(&block) ⇒ Object



23
24
25
# File 'lib/ruby_ui/toggle_group/toggle_group_item.rb', line 23

def view_template(&block)
  button(**attrs, &block)
end