Sha256: ec3e88f86932a1e09083eeb5a8ea03a046aab0407531bcfa99df212c6253f736

Contents?: true

Size: 1018 Bytes

Versions: 25

Compression:

Stored size: 1018 Bytes

Contents

module Coco
  class ColorPicker < Coco::Component
    include Concerns::AcceptsOptions

    DEFAULT_SWATCHES = [
      {color: "#111827"},
      {color: "#F3F4F6"},
      {color: "#FFFFFF"},
      {color: "#FEC878"},
      {color: "#FC5C0E"},
      {color: "#D50201"},
      {color: "#1A8871"},
      {color: "#C1DAA9"},
      {color: "#F5EEE6"},
      {color: "#91C7E1"},
      {color: "#0164FF"},
      {color: "#3A2D86"}
    ]

    accepts_option :size, from: [:xs, :sm, :md, nil], default: :sm

    before_render do
      content unless content_evaluated?

      if @swatches.empty?
        @swatches = DEFAULT_SWATCHES
      end

      args[:resize]&.each { set_tag_data_attr("size-#{_1}", _2) }
    end

    renders_many :swatches,
      ->(color, name = nil) do
        @swatches << {name: name, color: color}
      end

    attr_reader :selected

    def initialize(selected: "FFFFFF", **kwargs)
      @selected = selected
      @swatches = []
    end

    def color_swatches
      @swatches
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

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