Sha256: de285cd26046758bea1d72ac2ab28f371462071e40e38f0d08779d50072f7833

Contents?: true

Size: 1.26 KB

Versions: 34

Compression:

Stored size: 1.26 KB

Contents

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

        wraps_component :button do |args|
          Coco::App::Elements::Button.new(icon: :image_plus, **args)
        end

        renders_one :text, Coco::Content

        renders_one :picker, ->(picker = nil, **kwargs, &block) do
          if picker.is_a?(Coco::App::Elements::ImagePicker)
            picker
          else
            picker&.to_s.presence || Coco::App::Elements::ImagePicker.new(
              size: @size,
              resize: @resize,
              src: @src,
              **kwargs
            )
          end
        end

        before_render do
          with_picker(src: @src) unless picker?
        end

        attr_reader :src

        def initialize(src: nil, **kwargs)
          @src = src

          @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 button_text
          text || content
        end
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

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