Sha256: 50e3a588871eca6a2f54a47429e76829ac794cdb6a6af1cfea7a9b501f7027e5

Contents?: true

Size: 1.21 KB

Versions: 22

Compression:

Stored size: 1.21 KB

Contents

module Coco
  module App
    module Elements
      class ColorPicker < Coco::Component
        include Concerns::AcceptsOptions
        include Coco::AppHelper

        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: [: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
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
coveragebook_components-0.7.10 app/components/coco/app/elements/color_picker/color_picker.rb
coveragebook_components-0.7.9 app/components/coco/app/elements/color_picker/color_picker.rb
coveragebook_components-0.7.8 app/components/coco/app/elements/color_picker/color_picker.rb
coveragebook_components-0.7.7 app/components/coco/app/elements/color_picker/color_picker.rb
coveragebook_components-0.7.6 app/components/coco/app/elements/color_picker/color_picker.rb
coveragebook_components-0.7.5 app/components/coco/app/elements/color_picker/color_picker.rb
coveragebook_components-0.7.4 app/components/coco/app/elements/color_picker/color_picker.rb
coveragebook_components-0.7.3 app/components/coco/app/elements/color_picker/color_picker.rb
coveragebook_components-0.7.2 app/components/coco/app/elements/color_picker/color_picker.rb
coveragebook_components-0.7.1 app/components/coco/app/elements/color_picker/color_picker.rb
coveragebook_components-0.7.0 app/components/coco/app/elements/color_picker/color_picker.rb
coveragebook_components-0.6.5 app/components/coco/app/elements/color_picker/color_picker.rb
coveragebook_components-0.6.4 app/components/coco/app/elements/color_picker/color_picker.rb
coveragebook_components-0.6.3 app/components/coco/app/elements/color_picker/color_picker.rb
coveragebook_components-0.6.2 app/components/coco/app/elements/color_picker/color_picker.rb
coveragebook_components-0.6.1 app/components/coco/app/elements/color_picker/color_picker.rb
coveragebook_components-0.6.0 app/components/coco/app/elements/color_picker/color_picker.rb
coveragebook_components-0.5.7 app/components/coco/app/elements/color_picker/color_picker.rb
coveragebook_components-0.5.6 app/components/coco/app/elements/color_picker/color_picker.rb
coveragebook_components-0.5.5 app/components/coco/app/elements/color_picker/color_picker.rb