2022-03-31 11:08:32 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Renders a GlAlert root element
|
|
|
|
module Pajamas
|
|
|
|
class AlertComponent < Pajamas::Component
|
|
|
|
# @param [String] title
|
|
|
|
# @param [Symbol] variant
|
|
|
|
# @param [Boolean] dismissible
|
2022-04-27 08:08:19 -04:00
|
|
|
# @param [Boolean] show_icon
|
2022-06-14 11:08:43 -04:00
|
|
|
# @param [Hash] alert_options
|
|
|
|
# @param [Hash] close_button_options
|
2022-03-31 11:08:32 -04:00
|
|
|
def initialize(
|
2022-04-27 08:08:19 -04:00
|
|
|
title: nil, variant: :info, dismissible: true, show_icon: true,
|
2022-06-14 11:08:43 -04:00
|
|
|
alert_options: {}, close_button_options: {})
|
2022-03-31 11:08:32 -04:00
|
|
|
@title = title
|
|
|
|
@variant = variant
|
|
|
|
@dismissible = dismissible
|
2022-04-27 08:08:19 -04:00
|
|
|
@show_icon = show_icon
|
2022-06-10 08:09:36 -04:00
|
|
|
@alert_options = alert_options
|
2022-06-14 11:08:43 -04:00
|
|
|
@close_button_options = close_button_options
|
2022-03-31 11:08:32 -04:00
|
|
|
end
|
|
|
|
|
2022-04-27 08:08:19 -04:00
|
|
|
def base_class
|
|
|
|
classes = ["gl-alert-#{@variant}"]
|
|
|
|
classes.push('gl-alert-not-dismissible') unless @dismissible
|
|
|
|
classes.push('gl-alert-no-icon') unless @show_icon
|
|
|
|
|
|
|
|
classes.join(' ')
|
|
|
|
end
|
|
|
|
|
2022-03-31 11:08:32 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
delegate :sprite_icon, to: :helpers
|
|
|
|
|
2022-05-05 20:07:56 -04:00
|
|
|
renders_one :body
|
|
|
|
renders_one :actions
|
|
|
|
|
2022-03-31 11:08:32 -04:00
|
|
|
ICONS = {
|
|
|
|
info: 'information-o',
|
|
|
|
warning: 'warning',
|
|
|
|
success: 'check-circle',
|
|
|
|
danger: 'error',
|
|
|
|
tip: 'bulb'
|
|
|
|
}.freeze
|
|
|
|
|
|
|
|
def icon
|
|
|
|
ICONS[@variant]
|
|
|
|
end
|
|
|
|
|
|
|
|
def icon_classes
|
|
|
|
"gl-alert-icon#{' gl-alert-icon-no-title' if @title.nil?}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|