Sha256: 06f46b07118cde8785cfaad62c8424f74c534a5c88637b786e5deb0543fa4f22

Contents?: true

Size: 1.16 KB

Versions: 37

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

class Avo::AlertComponent < Avo::BaseComponent
  include Avo::ApplicationHelper

  prop :type, kind: :positional
  prop :message, kind: :positional

  def icon
    return "heroicons/solid/exclamation-circle" if is_error?
    return "heroicons/solid/exclamation" if is_warning?
    return "heroicons/solid/exclamation-circle" if is_info?
    return "heroicons/solid/check-circle" if is_success?

    "check-circle"
  end

  def classes
    return "hidden" if is_empty?

    result = "max-w-lg w-full shadow-lg rounded px-4 py-3 rounded relative border text-white pointer-events-auto"

    result += if is_error?
      " bg-red-400 border-red-600"
    elsif is_success?
      " bg-green-500 border-green-600"
    elsif is_warning?
      " bg-orange-400 border-orange-600"
    elsif is_info?
      " bg-blue-400 border-blue-600"
    end

    result
  end

  def is_error?
    @type.to_sym == :error || @type.to_sym == :alert
  end

  def is_success?
    @type.to_sym == :success
  end

  def is_info?
    @type.to_sym == :notice || @type.to_sym == :info
  end

  def is_warning?
    @type.to_sym == :warning
  end

  def is_empty?
    @message.nil?
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
avo-3.18.1 app/components/avo/alert_component.rb
avo-3.18.0 app/components/avo/alert_component.rb
avo-3.17.9.beta2 app/components/avo/alert_component.rb
avo-3.17.9.beta1 app/components/avo/alert_component.rb
avo-3.17.9 app/components/avo/alert_component.rb
avo-3.17.8 app/components/avo/alert_component.rb
avo-3.17.7 app/components/avo/alert_component.rb
avo-3.17.6 app/components/avo/alert_component.rb
avo-3.17.5 app/components/avo/alert_component.rb
avo-3.17.4 app/components/avo/alert_component.rb
avo-3.17.3 app/components/avo/alert_component.rb
avo-3.17.2 app/components/avo/alert_component.rb
avo-3.17.1 app/components/avo/alert_component.rb
avo-3.17.0 app/components/avo/alert_component.rb
avo-3.16.6 app/components/avo/alert_component.rb
avo-3.16.5 app/components/avo/alert_component.rb
avo-3.16.4 app/components/avo/alert_component.rb
avo-3.16.3 app/components/avo/alert_component.rb
avo-3.16.2 app/components/avo/alert_component.rb
avo-3.16.1 app/components/avo/alert_component.rb