Sha256: 9c0d08148607ced05b6da0c72f04feedc08834cc67137c40f857f2d71e59f181

Contents?: true

Size: 806 Bytes

Versions: 19

Compression:

Stored size: 806 Bytes

Contents

# frozen_string_literal: true

class Avo::Fields::Common::BadgeViewerComponent < Avo::BaseComponent
  def initialize(value:, options:)
    @value = value
    @options = options
    @backgrounds = {
      info: "bg-blue-500",
      success: "bg-green-500",
      danger: "bg-red-500",
      warning: "bg-yellow-500",
      neutral: "bg-gray-500"
    }
  end

  def classes
    background = :info

    @options.invert.each do |values, type|
      if [values].flatten.map { |value| value.to_s }.include? @value.to_s
        background = type.to_sym
        next
      end
    end

    classes = "whitespace-nowrap rounded-md uppercase px-2 py-1 text-xs font-bold block text-center truncate "

    classes += "#{@backgrounds[background]} text-white" if @backgrounds[background].present?

    classes
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
avo-3.11.7 app/components/avo/fields/common/badge_viewer_component.rb
avo-3.11.6 app/components/avo/fields/common/badge_viewer_component.rb
avo-3.11.5 app/components/avo/fields/common/badge_viewer_component.rb
avo-3.11.4 app/components/avo/fields/common/badge_viewer_component.rb
avo-3.11.3 app/components/avo/fields/common/badge_viewer_component.rb
avo-3.11.2 app/components/avo/fields/common/badge_viewer_component.rb
avo-3.11.1 app/components/avo/fields/common/badge_viewer_component.rb
avo-3.11.0 app/components/avo/fields/common/badge_viewer_component.rb
avo-3.10.10 app/components/avo/fields/common/badge_viewer_component.rb
avo-3.10.9 app/components/avo/fields/common/badge_viewer_component.rb
avo-3.10.8 app/components/avo/fields/common/badge_viewer_component.rb
avo-3.10.7 app/components/avo/fields/common/badge_viewer_component.rb
avo-3.10.6 app/components/avo/fields/common/badge_viewer_component.rb
avo-3.10.5 app/components/avo/fields/common/badge_viewer_component.rb
avo-3.10.4 app/components/avo/fields/common/badge_viewer_component.rb
avo-3.10.3 app/components/avo/fields/common/badge_viewer_component.rb
avo-3.10.2 app/components/avo/fields/common/badge_viewer_component.rb
avo-3.10.1 app/components/avo/fields/common/badge_viewer_component.rb
avo-3.10.0 app/components/avo/fields/common/badge_viewer_component.rb