Module: Coco::Concerns::ActsAsButtonGroup

Extended by:
ActiveSupport::Concern
Included in:
ButtonGroup, Menu
Defined in:
app/components/coco/concerns/acts_as_button_group.rb

Constant Summary collapse

BUTTON_TYPES =
{
  menu: "Coco::MenuButton",
  color_picker: "Coco::ColorPickerButton",
  layout_picker: "Coco::LayoutPickerButton",
  image_picker: "Coco::ImagePickerButton"
}

Instance Method Summary collapse

Instance Method Details

#init_button_groupObject



36
37
38
# File 'app/components/coco/concerns/acts_as_button_group.rb', line 36

def init_button_group
  with_item_noop
end

#instantiate_button(type, *args, **kwargs, &block) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'app/components/coco/concerns/acts_as_button_group.rb', line 25

def instantiate_button(type, *args, **kwargs, &block)
  href, content = if block
    [args.first, nil]
  else
    (args.size == 1) ? [nil, args.first] : args[0..2].reverse!
  end
  component = BUTTON_TYPES[type].constantize.new(href: href, **button_kwargs(kwargs, type))
  component.with_content(content) if !block && content.present?
  component
end

#with_buttonObject



44
45
46
# File 'app/components/coco/concerns/acts_as_button_group.rb', line 44

def with_button(...)
  with_item_button(...)
end

#with_color_picker_buttonObject



52
53
54
# File 'app/components/coco/concerns/acts_as_button_group.rb', line 52

def with_color_picker_button(...)
  with_item_color_picker_button(...)
end

#with_dividerObject



40
41
42
# File 'app/components/coco/concerns/acts_as_button_group.rb', line 40

def with_divider(...)
  with_item_divider(...)
end

#with_image_picker_buttonObject



56
57
58
# File 'app/components/coco/concerns/acts_as_button_group.rb', line 56

def with_image_picker_button(...)
  with_item_image_picker_button(...)
end

#with_layout_picker_buttonObject



60
61
62
# File 'app/components/coco/concerns/acts_as_button_group.rb', line 60

def with_layout_picker_button(...)
  with_item_layout_picker_button(...)
end

#with_menu_buttonObject



48
49
50
# File 'app/components/coco/concerns/acts_as_button_group.rb', line 48

def with_menu_button(...)
  with_item_menu_button(...)
end