Class: HakumiComponents::Result::Component
- Inherits:
-
BaseComponent
- Object
- ViewComponent::Base
- BaseComponent
- HakumiComponents::Result::Component
show all
- Extended by:
- T::Sig
- Defined in:
- app/components/hakumi_components/result/component.rb
Constant Summary
collapse
- Status =
T.type_alias { T.any(Symbol, String) }
- IconOverride =
T.type_alias { T.any(FalseClass, HakumiComponents::Types::Renderable) }
- STATUSES =
T.let(%i[success info warning error].freeze, T::Array[Symbol])
- DEFAULT_TITLES =
T.let({
success: "Success",
info: "Information",
warning: "Warning",
error: "Error"
}.freeze, T::Hash[Symbol, String])
- DEFAULT_ICON_NAME =
T.let("result_success", String)
- STATUS_ICON_MAP =
T.let({
success: [ "check-circle", :filled, "var(--color-success)" ],
info: [ "info-circle", :filled, "var(--color-primary)" ],
warning: [ "exclamation-circle", :filled, "var(--color-warning)" ],
error: [ "close-circle", :filled, "var(--color-error)" ]
}.freeze, T::Hash[Symbol, [ String, Symbol, String ]])
- STATUS_ICON_SIZE =
T.let(72, Integer)
BaseComponent::ControllerOptions, BaseComponent::DateInput, BaseComponent::DateLikeValue, BaseComponent::DimensionInput, BaseComponent::HtmlPayloadInput, BaseComponent::I18nOptionValue, BaseComponent::PresenceArray, BaseComponent::PresenceScalar, BaseComponent::PresenceValue, BaseComponent::RawHtmlInput, BaseComponent::SIZES, BaseComponent::SizeValue, BaseComponent::SymbolInput
Class Method Summary
collapse
Instance Method Summary
collapse
#append_data_token, boolean_html_param, #build_inline_style, cast_boolean, #cast_boolean, #class_names, #component_classes, #data_attributes_from, #dimension_to_css, #ensure_dom_id!, float_html_param, #generate_id, #html_classes, html_param, html_primitive_param, #html_style, #i18n_scope, integer_html_param, #merge_attributes, #render_value, #size_to_pixels, #stimulus_attrs, string_html_param, string_or_symbol_array_html_param, symbol_html_param, #t_default, #translate_with_default, #validate_inclusion!, #validate_required!, #value_present?
Constructor Details
#initialize(status: :info, title: nil, sub_title: nil, icon: nil, extra: nil, **html_options) ⇒ Component
Returns a new instance of Component.
63
64
65
66
67
68
69
70
71
72
|
# File 'app/components/hakumi_components/result/component.rb', line 63
def initialize(status: :info, title: nil, sub_title: nil, icon: nil, extra: nil, **html_options)
@status = T.let(status.to_sym, Symbol)
@title = T.let(title || DEFAULT_TITLES[@status], HakumiComponents::Types::Renderable)
@sub_title = T.let(sub_title, HakumiComponents::Types::Renderable)
@icon = T.let(icon, T.nilable(IconOverride))
@extra = T.let(, HakumiComponents::Types::Renderable)
@html_options = T.let(html_options, HakumiComponents::Types::HtmlAttributes)
validate_props!
end
|
Class Method Details
38
39
40
41
42
43
44
45
46
|
# File 'app/components/hakumi_components/result/component.rb', line 38
def self.(params)
{
status: symbol_html_param(html_param(params, :status)),
title: html_primitive_param(html_param(params, :title)),
sub_title: html_primitive_param(html_param(params, :sub_title)),
icon: icon_html_param(html_param(params, :icon)),
extra: html_primitive_param(html_param(params, :extra))
}
end
|
.icon_html_param(value) ⇒ Object
49
50
51
|
# File 'app/components/hakumi_components/result/component.rb', line 49
def self.icon_html_param(value)
boolean_html_param(value) == false ? false : nil
end
|
Instance Method Details
#content_present? ⇒ Boolean
120
121
122
|
# File 'app/components/hakumi_components/result/component.rb', line 120
def content_present?
content.present?
end
|
113
114
115
116
117
|
# File 'app/components/hakumi_components/result/component.rb', line 113
def
return render_value() if
render_value(@extra)
end
|
125
126
127
|
# File 'app/components/hakumi_components/result/component.rb', line 125
def
|| @extra.present?
end
|
#icon_content ⇒ Object
92
93
94
95
96
|
# File 'app/components/hakumi_components/result/component.rb', line 92
def icon_content
return nil unless icon_present?
render_value(@icon || status_icon_component || default_icon)
end
|
#icon_present? ⇒ Boolean
87
88
89
|
# File 'app/components/hakumi_components/result/component.rb', line 87
def icon_present?
@icon != false
end
|
#sub_title_content ⇒ Object
106
107
108
109
110
|
# File 'app/components/hakumi_components/result/component.rb', line 106
def sub_title_content
return render_value(sub_title) if sub_title?
render_value(@sub_title)
end
|
#sub_title_present? ⇒ Boolean
135
136
137
|
# File 'app/components/hakumi_components/result/component.rb', line 135
def sub_title_present?
sub_title? || @sub_title.present?
end
|
#title_content ⇒ Object
99
100
101
102
103
|
# File 'app/components/hakumi_components/result/component.rb', line 99
def title_content
return render_value(title) if title?
render_value(@title)
end
|
#title_present? ⇒ Boolean
130
131
132
|
# File 'app/components/hakumi_components/result/component.rb', line 130
def title_present?
title? || @title.present?
end
|
#wrapper_attributes ⇒ Object
75
76
77
78
79
80
81
82
83
84
|
# File 'app/components/hakumi_components/result/component.rb', line 75
def wrapper_attributes
merge_attributes(
{
class: wrapper_classes,
role: "status",
"aria-live": "polite"
},
@html_options.except(:class)
)
end
|