Sha256: 979a9d74c7c95025649ab1187174c8ede4fa32929a7d71798201d14fd9c8a339

Contents?: true

Size: 1.69 KB

Versions: 7

Compression:

Stored size: 1.69 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::FormButton.new(**button_kwargs(kwargs, :form_button))
            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)) },
          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_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.5.6 app/components/coco/concerns/acts_as_button_group.rb
coveragebook_components-0.5.5 app/components/coco/concerns/acts_as_button_group.rb
coveragebook_components-0.5.4 app/components/coco/concerns/acts_as_button_group.rb
coveragebook_components-0.5.3 app/components/coco/concerns/acts_as_button_group.rb
coveragebook_components-0.5.2 app/components/coco/concerns/acts_as_button_group.rb
coveragebook_components-0.5.1 app/components/coco/concerns/acts_as_button_group.rb
coveragebook_components-0.5.0 app/components/coco/concerns/acts_as_button_group.rb