Class: Shadcn::ButtonGroup::Component

Inherits:
ApplicationViewComponent show all
Defined in:
app/components/shadcn/button_group/component.rb

Overview

Port of registry/new-york-v4/ui/button-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 inherited from ApplicationViewComponent

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

Constructor Details

#initialize(orientation: nil, **attributes) ⇒ Component

Left nil rather than defaulted, because upstream destructures orientation with no default: the classes fall back to horizontal via cva's defaultVariants, but data-orientation is only emitted when the caller actually passed one.



39
40
41
42
# File 'app/components/shadcn/button_group/component.rb', line 39

def initialize(orientation: nil, **attributes)
  @orientation = orientation&.to_sym
  super(**attributes)
end

Instance Attribute Details

#orientationObject (readonly)

Returns the value of attribute orientation.



33
34
35
# File 'app/components/shadcn/button_group/component.rb', line 33

def orientation
  @orientation
end

Instance Method Details

#element_attributes(**defaults) ⇒ Object



48
49
50
# File 'app/components/shadcn/button_group/component.rb', line 48

def element_attributes(**defaults)
  super(**{ role: "group", "data-orientation" => orientation }.merge(defaults))
end

#style_variantsObject



44
45
46
# File 'app/components/shadcn/button_group/component.rb', line 44

def style_variants
  { orientation: orientation || :horizontal }
end