Sha256: bea28283b05d2e9b226723d43ed187fc902d8b5397a0f6b9462acbc52d5b3266

Contents?: true

Size: 1.22 KB

Versions: 7

Compression:

Stored size: 1.22 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::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::Button::SIZE_ALIASES.keys) && !kwargs.key?(:resize)
            @size, @resize = Coco::Button::SIZE_ALIASES.fetch(@size)
          end
        end

        def button_text
          text || content
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
coveragebook_components-0.12.2 app/components/coco/app/elements/image_picker_button/image_picker_button.rb
coveragebook_components-0.12.1 app/components/coco/app/elements/image_picker_button/image_picker_button.rb
coveragebook_components-0.12.0 app/components/coco/app/elements/image_picker_button/image_picker_button.rb
coveragebook_components-0.11.0 app/components/coco/app/elements/image_picker_button/image_picker_button.rb
coveragebook_components-0.10.1.beta.2 app/components/coco/app/elements/image_picker_button/image_picker_button.rb
coveragebook_components-0.10.1.beta.1 app/components/coco/app/elements/image_picker_button/image_picker_button.rb
coveragebook_components-0.10.1.beta.0 app/components/coco/app/elements/image_picker_button/image_picker_button.rb