Sha256: 1ca9110732ce5515e97416f1d6dc8d42ce342e9d851c40eeb8117b09b1a6b3c5

Contents?: true

Size: 1.91 KB

Versions: 7

Compression:

Stored size: 1.91 KB

Contents

module Coco
  module Concerns
    module ActsAsButtonGroup
      extend ActiveSupport::Concern
      include Coco::AppHelper

      included do
        renders_many :items, types: {
          divider: ->(**kwargs) { tag.div(class: "divider") },
          button: ->(**kwargs) {
            if kwargs.key?(:action) || kwargs.key?(:method) || kwargs.key?(:params)
              App::Elements::ButtonTo.new(**button_kwargs(kwargs, :button_to))
            else
              App::Elements::Button.new(**button_kwargs(kwargs, :button))
            end
          },
          menu_button: ->(**kwargs) { App::Elements::MenuButton.new(**button_kwargs(kwargs, :menu)) },
          color_picker_button: ->(**kwargs) { App::Elements::ColorPickerButton.new(**button_kwargs(kwargs, :color_picker)) },
          layout_picker_button: ->(**kwargs) { App::Elements::LayoutPickerButton.new(**button_kwargs(kwargs, :layout_picker)) },
          image_picker_button: ->(**kwargs) { App::Elements::ImagePickerButton.new(**button_kwargs(kwargs, :image_picker)) },
          dropdown_button: ->(**kwargs) { App::Elements::DropdownButton.new(**button_kwargs(kwargs, :dropdown)) }
        }
      end

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

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

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

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

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

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

      def with_dropdown_button(...)
        with_item_dropdown_button(...)
      end

      private

      def button_kwargs(kwargs, type = nil)
        {
          size: args[:size],
          resize: args[:resize],
          **kwargs
        }
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
coveragebook_components-0.7.9 app/components/coco/concerns/acts_as_button_group.rb
coveragebook_components-0.7.8 app/components/coco/concerns/acts_as_button_group.rb
coveragebook_components-0.7.7 app/components/coco/concerns/acts_as_button_group.rb
coveragebook_components-0.7.6 app/components/coco/concerns/acts_as_button_group.rb
coveragebook_components-0.7.5 app/components/coco/concerns/acts_as_button_group.rb
coveragebook_components-0.7.4 app/components/coco/concerns/acts_as_button_group.rb
coveragebook_components-0.7.3 app/components/coco/concerns/acts_as_button_group.rb