Class: HakumiComponents::Progress::Component
- Inherits:
-
BaseComponent
- Object
- ViewComponent::Base
- BaseComponent
- HakumiComponents::Progress::Component
- Extended by:
- T::Sig
- Defined in:
- app/components/hakumi_components/progress/component.rb
Constant Summary collapse
- ProgressValue =
T.type_alias { Numeric }
- ProgressOption =
T.type_alias { Types::HtmlKey }
- InfoTooltipInput =
T.type_alias { T.nilable(T.any(Types::HtmlKey, T::Boolean)) }
- DisplaySize =
T.type_alias { T.nilable(BaseComponent::SizeValue) }
- StrokeGradient =
T.type_alias { T::Hash[String, String] }
- StrokeColorInput =
T.type_alias { T.nilable(T.any(String, Types::DataAttributes, StrokeGradient)) }
- StrokeColor =
T.type_alias { T.nilable(T.any(String, StrokeGradient)) }
- FormatProc =
T.type_alias do T.proc.params( percent: ProgressValue, success_percent: T.nilable(ProgressValue) ).returns(String) end
- FormatValue =
T.type_alias { T.nilable(T.any(Types::Renderable, FormatProc)) }
- TooltipMode =
T.type_alias { T.nilable(Symbol) }
- TooltipOptionsMap =
T.type_alias { T::Hash[Types::HtmlKey, Types::HtmlPrimitive] }
- StepStateValue =
T.type_alias { Types::HtmlPrimitive }
- StepState =
T.type_alias { T::Hash[Symbol, StepStateValue] }
- SizeInput =
T.type_alias { DisplaySize }
- TYPES =
T.let(%i[line circle dashboard].freeze, T::Array[Symbol])
- STATUSES =
T.let(%i[normal success exception active].freeze, T::Array[Symbol])
- LINE_SIZES =
T.let(%i[small default].freeze, T::Array[Symbol])
- LINECAPS =
T.let(%i[round square butt].freeze, T::Array[Symbol])
Constants inherited from BaseComponent
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
- #circle? ⇒ Boolean
- #dashboard? ⇒ Boolean
- #data_attributes ⇒ Object
- #formatted_info ⇒ Object
- #info_tooltip_threshold_value ⇒ Object
-
#initialize(percent: 0, success_percent: nil, type: :line, status: nil, show_info: true, size: nil, stroke_width: nil, stroke_color: nil, trail_color: nil, stroke_linecap: :round, steps: nil, gap_degree: nil, gap_position: nil, format: nil, info_tooltip: :auto, info_tooltip_threshold: 20, info_tooltip_options: nil, **html_options) ⇒ Component
constructor
A new instance of Component.
- #inline_info? ⇒ Boolean
- #line? ⇒ Boolean
- #show_info? ⇒ Boolean
- #status ⇒ Object
- #steps? ⇒ Boolean
- #success_segment? ⇒ Boolean
- #tooltip_component_options ⇒ Object
- #tooltip_enabled? ⇒ Boolean
- #tooltip_label ⇒ Object
- #wrap_with_tooltip? ⇒ Boolean
- #wrapper_attributes ⇒ Object
Methods inherited from BaseComponent
#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(percent: 0, success_percent: nil, type: :line, status: nil, show_info: true, size: nil, stroke_width: nil, stroke_color: nil, trail_color: nil, stroke_linecap: :round, steps: nil, gap_degree: nil, gap_position: nil, format: nil, info_tooltip: :auto, info_tooltip_threshold: 20, info_tooltip_options: nil, **html_options) ⇒ Component
Returns a new instance of Component.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'app/components/hakumi_components/progress/component.rb', line 64 def initialize( percent: 0, success_percent: nil, type: :line, status: nil, show_info: true, size: nil, stroke_width: nil, stroke_color: nil, trail_color: nil, stroke_linecap: :round, steps: nil, gap_degree: nil, gap_position: nil, format: nil, info_tooltip: :auto, info_tooltip_threshold: 20, info_tooltip_options: nil, ** ) @type = T.let(type.to_sym, Symbol) @status = T.let(status&.to_sym, T.nilable(Symbol)) @show_info = T.let(cast_boolean(show_info) != false, T::Boolean) @size = T.let(normalize_size(size), DisplaySize) @stroke_width = T.let(stroke_width&.to_f, T.nilable(Float)) @stroke_color = T.let(normalize_stroke_color(stroke_color), StrokeColor) @trail_color = T.let(trail_color&.strip&.presence, T.nilable(String)) @stroke_linecap = T.let(stroke_linecap.to_sym, Symbol) @steps = T.let(steps, T.nilable(Integer)) @gap_degree = T.let(gap_degree&.to_f, T.nilable(Float)) @gap_position = T.let(gap_position&.to_sym, T.nilable(Symbol)) @format = T.let(format, FormatValue) @html_options = T.let(, Types::HtmlAttributes) @info_tooltip_mode = T.let(normalize_info_tooltip(info_tooltip), TooltipMode) @info_tooltip_threshold = T.let(info_tooltip_threshold.to_f, Float) @info_tooltip_options = T.let((), Types::HtmlAttributes) @percent = T.let(clamp_percent(percent), ProgressValue) @success_percent = T.let(success_percent.nil? ? nil : clamp_percent(success_percent), T.nilable(ProgressValue)) @info_tooltip_policy = T.let(nil, T.nilable(Progress::InfoTooltipPolicy)) @status_state = T.let(nil, T.nilable(Progress::StatusState)) @attribute_renderer = T.let(nil, T.nilable(Progress::AttributeRenderer)) validate_props! end |
Class Method Details
.extract_controller_locals(params) ⇒ Object
38 39 40 |
# File 'app/components/hakumi_components/progress/component.rb', line 38 def self.extract_controller_locals(params) ControllerLocalsParser.call(params) end |
Instance Method Details
#circle? ⇒ Boolean
175 176 177 |
# File 'app/components/hakumi_components/progress/component.rb', line 175 def circle? @type == :circle end |
#dashboard? ⇒ Boolean
180 181 182 |
# File 'app/components/hakumi_components/progress/component.rb', line 180 def dashboard? @type == :dashboard end |
#data_attributes ⇒ Object
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'app/components/hakumi_components/progress/component.rb', line 195 def data_attributes { controller: "hakumi--progress", "hakumi--progress-type-value": @type, "hakumi--progress-percent-value": @percent, "hakumi--progress-success-percent-value": @success_percent, "hakumi--progress-status-value": status, "hakumi--progress-status-explicit-value": status_state.explicit?, "hakumi--progress-steps-value": @steps, "hakumi--progress-gap-degree-value": @gap_degree, "hakumi--progress-gap-position-value": attribute_renderer.circle_gap_position, "hakumi--progress-stroke-width-value": attribute_renderer.stroke_width_value, "hakumi--progress-show-info-value": show_info?, "hakumi--progress-custom-info-value": custom_info? }.compact end |
#formatted_info ⇒ Object
126 127 128 129 130 |
# File 'app/components/hakumi_components/progress/component.rb', line 126 def formatted_info return nil unless show_info? info_text end |
#info_tooltip_threshold_value ⇒ Object
155 156 157 |
# File 'app/components/hakumi_components/progress/component.rb', line 155 def info_tooltip_threshold_value @info_tooltip_threshold.to_i end |
#inline_info? ⇒ Boolean
138 139 140 |
# File 'app/components/hakumi_components/progress/component.rb', line 138 def inline_info? show_info? && !wrap_with_tooltip? end |
#line? ⇒ Boolean
170 171 172 |
# File 'app/components/hakumi_components/progress/component.rb', line 170 def line? @type == :line end |
#show_info? ⇒ Boolean
133 134 135 |
# File 'app/components/hakumi_components/progress/component.rb', line 133 def show_info? @show_info end |
#status ⇒ Object
190 191 192 |
# File 'app/components/hakumi_components/progress/component.rb', line 190 def status status_state.value end |
#steps? ⇒ Boolean
185 186 187 |
# File 'app/components/hakumi_components/progress/component.rb', line 185 def steps? !@steps.nil? && @steps.positive? end |
#success_segment? ⇒ Boolean
213 214 215 216 |
# File 'app/components/hakumi_components/progress/component.rb', line 213 def success_segment? success = @success_percent !success.nil? && success.positive? end |
#tooltip_component_options ⇒ Object
148 149 150 151 152 |
# File 'app/components/hakumi_components/progress/component.rb', line 148 def = T.let(@info_tooltip_options.dup, Types::HtmlAttributes) [:title] = tooltip_label unless .key?(:title) end |
#tooltip_enabled? ⇒ Boolean
165 166 167 |
# File 'app/components/hakumi_components/progress/component.rb', line 165 def tooltip_enabled? info_tooltip_policy.enabled? end |
#tooltip_label ⇒ Object
160 161 162 |
# File 'app/components/hakumi_components/progress/component.rb', line 160 def tooltip_label info_value.tooltip_label end |
#wrap_with_tooltip? ⇒ Boolean
143 144 145 |
# File 'app/components/hakumi_components/progress/component.rb', line 143 def wrap_with_tooltip? info_tooltip_policy.wrap? end |
#wrapper_attributes ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'app/components/hakumi_components/progress/component.rb', line 110 def wrapper_attributes merge_attributes( { class: wrapper_classes, role: "progressbar", "aria-valuenow": @percent, "aria-valuemin": 0, "aria-valuemax": 100, "aria-label": accessibility_label, data: data_attributes }, @html_options ) end |