forked from primer/view_components
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfeedback_message.rb
More file actions
55 lines (45 loc) · 1.92 KB
/
Copy pathfeedback_message.rb
File metadata and controls
55 lines (45 loc) · 1.92 KB
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
55
# frozen_string_literal: true
module Primer
module OpenProject
# A view component for messages, inspired by the Primer Blankslate,
# which serves a different use-case (messages for when data is missing).
# We decided to wrap the Blankslate, because we don't want to have to adapt
# lots of different usages if Primer decides to change the Blankslate
# in a way that does not go well with our "misuse".
class FeedbackMessage < Primer::Component
status :open_project
# @param icon_arguments [Hash] special arguments for the icon
# @param loading [Boolean] Show a loading spinner instead of an icon
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
def initialize(icon_arguments: {}, loading: false, **system_arguments)
@system_arguments = system_arguments
@icon_arguments = icon_arguments
@system_arguments[:classes] = class_names(
system_arguments[:classes],
"FeedbackMessage"
)
@icon_arguments[:icon] ||= :"check-circle"
@icon_arguments[:color] ||= :success
@loading = loading
@blankslate = Primer::Beta::Blankslate.new(**@system_arguments)
end
delegate :description?, :description, :with_description, :with_description_content,
:heading?, :heading, :with_heading, :with_heading_content,
:primary_action?, :primary_action, :with_primary_action, :with_primary_action_content,
:secondary_action?, :secondary_action, :with_secondary_action, :with_secondary_action_content,
to: :@blankslate
private
def before_render
if @loading
@blankslate.with_visual_spinner(size: :large)
elsif @icon_arguments[:icon] != :none
@blankslate.with_visual_icon(size: :medium, **@icon_arguments)
end
content
end
def render?
heading.present?
end
end
end
end