Class: LightningUiKit::AlertComponent

Inherits:
BaseComponent
  • Object
show all
Defined in:
app/components/lightning_ui_kit/alert_component.rb

Instance Method Summary collapse

Methods inherited from BaseComponent

#merge_classes

Methods included from HeroiconHelper

#heroicon

Constructor Details

#initialize(title: nil, type: :info, **options) ⇒ AlertComponent

Returns a new instance of AlertComponent.



4
5
6
7
8
# File 'app/components/lightning_ui_kit/alert_component.rb', line 4

def initialize(title: nil, type: :info, **options)
  @title = title
  @type = type
  @options = options
end

Instance Method Details

#classesObject



10
11
12
# File 'app/components/lightning_ui_kit/alert_component.rb', line 10

def classes
  merge_classes([base_classes, type_classes, @options[:class]].compact.join(" "))
end

#iconObject



14
15
16
17
18
19
20
21
# File 'app/components/lightning_ui_kit/alert_component.rb', line 14

def icon
  case @type
  when :error then "exclamation-triangle"
  when :success then "check-circle"
  when :warning then "exclamation-triangle"
  else "information-circle"
  end
end

#icon_classesObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/components/lightning_ui_kit/alert_component.rb', line 23

def icon_classes
  base = if @title
    "lui:absolute lui:left-4 lui:top-4 lui:size-4"
  else
    "lui:size-4 lui:me-3 lui:shrink-0"
  end

  case @type
  when :error then "#{base} lui:text-destructive-text"
  when :success then "#{base} lui:text-success-text"
  when :warning then "#{base} lui:text-warning-text"
  else "#{base} lui:text-foreground"
  end
end

#title_classesObject



38
39
40
41
42
43
44
45
46
# File 'app/components/lightning_ui_kit/alert_component.rb', line 38

def title_classes
  base = "lui:mb-1 lui:font-medium lui:leading-none lui:tracking-tight"
  case @type
  when :error then "#{base} lui:text-destructive-text"
  when :success then "#{base} lui:text-success-text"
  when :warning then "#{base} lui:text-warning-text"
  else base
  end
end