Sha256: b3987df921b9d414789ed5922027644bd7ea2a1ff2c25f72264bd45f16b6e6cd

Contents?: true

Size: 1.3 KB

Versions: 25

Compression:

Stored size: 1.3 KB

Contents

module Coco
  class ColorPickerButton < Coco::Component
    include Concerns::WithDropdownOptions
    include Concerns::WrapsComponent

    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::ColorPicker)
        picker
      else
        picker&.to_s.presence || Coco::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

Version data entries

25 entries across 25 versions & 1 rubygems

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