-
Notifications
You must be signed in to change notification settings - Fork 120
/
Copy pathcountdown_alert_component.rb
54 lines (46 loc) · 1.19 KB
/
countdown_alert_component.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# frozen_string_literal: true
class CountdownAlertComponent < BaseComponent
attr_reader :show_at_remaining, :alert_options, :countdown_options, :tag_options
def initialize(
show_at_remaining: nil,
alert_options: {},
countdown_options: {},
**tag_options
)
@show_at_remaining = show_at_remaining
@alert_options = alert_options
@countdown_options = countdown_options
@tag_options = tag_options
end
def call
content_tag(
:'lg-countdown-alert',
content,
**tag_options,
class: css_class,
'show-at-remaining': show_at_remaining&.in_milliseconds,
)
end
def content
AlertComponent.new(
**alert_options,
type: :info,
class: alert_css_class,
).with_content(alert_content).render_in(view_context)
end
private
def alert_content
t(
'components.countdown_alert.time_remaining_html',
countdown_html: CountdownComponent.new(**countdown_options).render_in(view_context),
)
end
def css_class
classes = [*tag_options[:class]]
classes << 'display-none' if show_at_remaining.present?
classes
end
def alert_css_class
[*alert_options[:class], 'usa-alert--info-time']
end
end