Sha256: 064b87a4f8535a78f99457f5327bc8bbe8e4c30f3cfa8e11569937343c46e9e1

Contents?: true

Size: 1.57 KB

Versions: 7

Compression:

Stored size: 1.57 KB

Contents

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

        wraps_component :button do |args|
          Coco::Button.new(**args)
        end

        renders_one :text, Coco::Content

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

        renders_one :icon, ->(&block) do
          tag.span class: "picker-icon", style: "color: #{@selected}", ":style": "{color: selectedColor}", &block
        end

        before_render do
          with_picker(selected: @selected) unless picker?
          unless icon?
            with_icon do
              tag.span class: "picker-button-color", ":style": "{backgroundColor: selectedColor}"
            end
          end
        end

        attr_reader :selected

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

          @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/color_picker_button/color_picker_button.rb
coveragebook_components-0.12.1 app/components/coco/app/elements/color_picker_button/color_picker_button.rb
coveragebook_components-0.12.0 app/components/coco/app/elements/color_picker_button/color_picker_button.rb
coveragebook_components-0.11.0 app/components/coco/app/elements/color_picker_button/color_picker_button.rb
coveragebook_components-0.10.1.beta.2 app/components/coco/app/elements/color_picker_button/color_picker_button.rb
coveragebook_components-0.10.1.beta.1 app/components/coco/app/elements/color_picker_button/color_picker_button.rb
coveragebook_components-0.10.1.beta.0 app/components/coco/app/elements/color_picker_button/color_picker_button.rb