Sha256: 2d0e40db94bdd22b9b4f0c868ce3377ecf80d353d07fdfd7dc88c332a640e4b7

Contents?: true

Size: 964 Bytes

Versions: 20

Compression:

Stored size: 964 Bytes

Contents

module Coco
  class LayoutPickerButton < Coco::Component
    include Concerns::AcceptsOptions
    include Concerns::WithDropdownOptions
    include Concerns::WrapsComponent

    wraps_component :button do |args|
      args[:class] = [args[:class], "layout-picker-trigger"]
      Coco::Button.new(**args)
    end

    renders_many :layouts, ->(name:, thumbnail: nil, **layout_options, &block) do
      @layout_options << {name: name, thumbnail: thumbnail, **layout_options, icon: block&.call}
    end

    attr_reader :layout_options, :size, :resize

    def initialize(selected: nil, **kwargs)
      @selected = selected
      @layout_options = []
      @resize = {}

      @size = kwargs.fetch(:size, :default)&.to_sym
      if @size.in?(Coco::Button::SIZE_ALIASES.keys) && !kwargs.key?(:resize)
        @size, @resize = Coco::Button::SIZE_ALIASES.fetch(@size)
      end
    end

    def selected
      @selected || @layout_options.first[:name]
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
coveragebook_components-0.19.8 app/components/coco/buttons/layout_picker_button/layout_picker_button.rb
coveragebook_components-0.19.7 app/components/coco/buttons/layout_picker_button/layout_picker_button.rb
coveragebook_components-0.19.6 app/components/coco/buttons/layout_picker_button/layout_picker_button.rb
coveragebook_components-0.19.5 app/components/coco/buttons/layout_picker_button/layout_picker_button.rb
coveragebook_components-0.19.4 app/components/coco/buttons/layout_picker_button/layout_picker_button.rb
coveragebook_components-0.19.3 app/components/coco/buttons/layout_picker_button/layout_picker_button.rb
coveragebook_components-0.19.2 app/components/coco/buttons/layout_picker_button/layout_picker_button.rb
coveragebook_components-0.19.1 app/components/coco/buttons/layout_picker_button/layout_picker_button.rb
coveragebook_components-0.19.0 app/components/coco/buttons/layout_picker_button/layout_picker_button.rb
coveragebook_components-0.18.8 app/components/coco/buttons/layout_picker_button/layout_picker_button.rb
coveragebook_components-0.18.7 app/components/coco/buttons/layout_picker_button/layout_picker_button.rb
coveragebook_components-0.18.0 app/components/coco/buttons/layout_picker_button/layout_picker_button.rb
coveragebook_components-0.17.7 app/components/coco/buttons/layout_picker_button/layout_picker_button.rb
coveragebook_components-0.17.6 app/components/coco/buttons/layout_picker_button/layout_picker_button.rb
coveragebook_components-0.17.5 app/components/coco/buttons/layout_picker_button/layout_picker_button.rb
coveragebook_components-0.17.4 app/components/coco/buttons/layout_picker_button/layout_picker_button.rb
coveragebook_components-0.17.3 app/components/coco/buttons/layout_picker_button/layout_picker_button.rb
coveragebook_components-0.17.2 app/components/coco/buttons/layout_picker_button/layout_picker_button.rb
coveragebook_components-0.17.1 app/components/coco/buttons/layout_picker_button/layout_picker_button.rb
coveragebook_components-0.17.0 app/components/coco/buttons/layout_picker_button/layout_picker_button.rb