Sha256: cbf1c9170926835a5cd8ddbf603376e576530cfa48812f4c54a049e6c460b079

Contents?: true

Size: 807 Bytes

Versions: 57

Compression:

Stored size: 807 Bytes

Contents

# frozen_string_literal: true

class Avo::Fields::Common::BadgeViewerComponent < ViewComponent::Base
  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

57 entries across 57 versions & 1 rubygems

Version Path
avo-3.9.2 app/components/avo/fields/common/badge_viewer_component.rb
avo-3.9.1 app/components/avo/fields/common/badge_viewer_component.rb
avo-3.8.2 app/components/avo/fields/common/badge_viewer_component.rb
avo-3.9.0 app/components/avo/fields/common/badge_viewer_component.rb
avo-3.8.1 app/components/avo/fields/common/badge_viewer_component.rb
avo-3.8.0 app/components/avo/fields/common/badge_viewer_component.rb
avo-3.6.4 app/components/avo/fields/common/badge_viewer_component.rb
avo-3.6.3 app/components/avo/fields/common/badge_viewer_component.rb
avo-3.6.2 app/components/avo/fields/common/badge_viewer_component.rb
avo-3.6.1 app/components/avo/fields/common/badge_viewer_component.rb
avo-3.6.0 app/components/avo/fields/common/badge_viewer_component.rb
avo-3.5.8 app/components/avo/fields/common/badge_viewer_component.rb
avo-3.5.7 app/components/avo/fields/common/badge_viewer_component.rb
avo-3.5.6 app/components/avo/fields/common/badge_viewer_component.rb
avo-3.5.6.beta1 app/components/avo/fields/common/badge_viewer_component.rb
avo-3.5.5 app/components/avo/fields/common/badge_viewer_component.rb
avo-3.5.4 app/components/avo/fields/common/badge_viewer_component.rb
avo-3.5.3 app/components/avo/fields/common/badge_viewer_component.rb
avo-3.5.2 app/components/avo/fields/common/badge_viewer_component.rb
avo-3.5.1 app/components/avo/fields/common/badge_viewer_component.rb