Sha256: bd8f0c9e91a06cb2919e72f927cac67b18c2627832a196d603369d52bd4fc4e8

Contents?: true

Size: 1.13 KB

Versions: 33

Compression:

Stored size: 1.13 KB

Contents

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

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

        renders_many :layouts, ->(name:, thumbnail:, **layout_options) do
          @layout_options << {name: name, thumbnail: thumbnail, **layout_options}
        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::App::Elements::Button::SIZE_ALIASES.keys) && !kwargs.key?(:resize)
            @size, @resize = Coco::App::Elements::Button::SIZE_ALIASES.fetch(@size)
          end
        end

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

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
coveragebook_components-0.10.0 app/components/coco/app/elements/layout_picker_button/layout_picker_button.rb
coveragebook_components-0.9.1 app/components/coco/app/elements/layout_picker_button/layout_picker_button.rb
coveragebook_components-0.9.0 app/components/coco/app/elements/layout_picker_button/layout_picker_button.rb
coveragebook_components-0.8.9 app/components/coco/app/elements/layout_picker_button/layout_picker_button.rb
coveragebook_components-0.8.8 app/components/coco/app/elements/layout_picker_button/layout_picker_button.rb
coveragebook_components-0.8.7 app/components/coco/app/elements/layout_picker_button/layout_picker_button.rb
coveragebook_components-0.8.6 app/components/coco/app/elements/layout_picker_button/layout_picker_button.rb
coveragebook_components-0.8.5 app/components/coco/app/elements/layout_picker_button/layout_picker_button.rb
coveragebook_components-0.8.4 app/components/coco/app/elements/layout_picker_button/layout_picker_button.rb
coveragebook_components-0.8.3 app/components/coco/app/elements/layout_picker_button/layout_picker_button.rb
coveragebook_components-0.8.2 app/components/coco/app/elements/layout_picker_button/layout_picker_button.rb
coveragebook_components-0.8.1 app/components/coco/app/elements/layout_picker_button/layout_picker_button.rb
coveragebook_components-0.8.0 app/components/coco/app/elements/layout_picker_button/layout_picker_button.rb
coveragebook_components-0.8.0.beta.3 app/components/coco/app/elements/layout_picker_button/layout_picker_button.rb
coveragebook_components-0.8.0.beta.2 app/components/coco/app/elements/layout_picker_button/layout_picker_button.rb
coveragebook_components-0.8.0.beta.1 app/components/coco/app/elements/layout_picker_button/layout_picker_button.rb
coveragebook_components-0.7.10 app/components/coco/app/elements/layout_picker_button/layout_picker_button.rb
coveragebook_components-0.7.9 app/components/coco/app/elements/layout_picker_button/layout_picker_button.rb
coveragebook_components-0.7.8 app/components/coco/app/elements/layout_picker_button/layout_picker_button.rb
coveragebook_components-0.7.7 app/components/coco/app/elements/layout_picker_button/layout_picker_button.rb