Class: PhlexKit::ButtonGroup

Inherits:
BaseComponent show all
Defined in:
app/components/phlex_kit/button_group/button_group.rb

Overview

Joined row (or column) of buttons, ported from shadcn/ui's ButtonGroup: children lose their inner corners/double borders and read as one segmented control. orientation: :vertical stacks. Nest groups to separate segments with a gap; add ButtonGroupText for static labels and ButtonGroupSeparator between same-fill buttons. .pk-button-group (button_group.css).

Constant Summary collapse

ORIENTATIONS =
{ horizontal: nil, vertical: "vertical" }.freeze

Instance Method Summary collapse

Methods inherited from BaseComponent

#on

Constructor Details

#initialize(orientation: :horizontal, **attrs) ⇒ ButtonGroup

Returns a new instance of ButtonGroup.



10
11
12
13
# File 'app/components/phlex_kit/button_group/button_group.rb', line 10

def initialize(orientation: :horizontal, **attrs)
  @orientation = orientation.to_sym
  @attrs = attrs
end

Instance Method Details

#view_templateObject



15
16
17
18
# File 'app/components/phlex_kit/button_group/button_group.rb', line 15

def view_template(&)
  classes = [ "pk-button-group", fetch_option(ORIENTATIONS, @orientation, :orientation) ].compact.join(" ")
  div(**mix({ class: classes, role: "group" }, @attrs), &)
end