Class: HakumiComponents::Progress::AttributeRenderer
- Inherits:
-
Object
- Object
- HakumiComponents::Progress::AttributeRenderer
- Extended by:
- T::Sig
- Defined in:
- app/components/hakumi_components/progress/attribute_renderer.rb
Constant Summary collapse
- ProgressValue =
T.type_alias { Numeric }
- StrokeGradient =
T.type_alias { T::Hash[String, String] }
- StrokeColor =
T.type_alias { T.nilable(T.any(String, StrokeGradient)) }
- DisplaySize =
T.type_alias { T.nilable(BaseComponent::SizeValue) }
- StepStateValue =
T.type_alias { Types::HtmlPrimitive }
- StepState =
T.type_alias { T::Hash[Symbol, StepStateValue] }
- StyleBuilder =
T.type_alias { T.proc.params(styles: T.nilable(Types::StyleValue)).returns(T.nilable(String)) }
Instance Attribute Summary collapse
-
#gradient_id ⇒ Object
readonly
Returns the value of attribute gradient_id.
Instance Method Summary collapse
- #circle_gap_position ⇒ Object
- #circle_geometry ⇒ Object
- #circle_gradient_attributes ⇒ Object
- #circle_inner_style ⇒ Object
- #circle_path_attributes ⇒ Object
- #circle_radius ⇒ Object
- #circle_size ⇒ Object
- #circle_step_style(step) ⇒ Object
- #circle_steps ⇒ Object
- #circle_steps? ⇒ Boolean
- #circle_stroke_width ⇒ Object
- #circle_trail_attributes ⇒ Object
- #circle_trail_style ⇒ Object
- #circle_transform ⇒ Object
- #gradient? ⇒ Boolean
- #gradient_css ⇒ Object
- #gradient_svg_direction ⇒ Object
-
#initialize(type:, percent:, success_percent:, size:, stroke_width:, stroke_color:, trail_color:, stroke_linecap:, steps:, gap_degree:, gap_position:, gradient_id:, style_builder:) ⇒ AttributeRenderer
constructor
A new instance of AttributeRenderer.
- #line_bar_style ⇒ Object
- #line_steps ⇒ Object
- #line_style ⇒ Object
- #line_success_style ⇒ Object
- #stroke_width_value ⇒ Object
Constructor Details
#initialize(type:, percent:, success_percent:, size:, stroke_width:, stroke_color:, trail_color:, stroke_linecap:, steps:, gap_degree:, gap_position:, gradient_id:, style_builder:) ⇒ AttributeRenderer
Returns a new instance of AttributeRenderer.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/components/hakumi_components/progress/attribute_renderer.rb', line 34 def initialize( type:, percent:, success_percent:, size:, stroke_width:, stroke_color:, trail_color:, stroke_linecap:, steps:, gap_degree:, gap_position:, gradient_id:, style_builder: ) @type = T.let(type, Symbol) @percent = T.let(percent, ProgressValue) @success_percent = T.let(success_percent, T.nilable(ProgressValue)) @size = T.let(size, DisplaySize) @stroke_width = T.let(stroke_width, T.nilable(Float)) @stroke_color = T.let(stroke_color, StrokeColor) @trail_color = T.let(trail_color, T.nilable(String)) @stroke_linecap = T.let(stroke_linecap, Symbol) @steps = T.let(steps, T.nilable(Integer)) @gap_degree = T.let(gap_degree, T.nilable(Float)) @gap_position = T.let(gap_position, T.nilable(Symbol)) @gradient_id = T.let(gradient_id, String) @style_builder = T.let(style_builder, StyleBuilder) @circle_geometry = T.let(nil, T.nilable(Progress::CircleGeometry)) @stroke_gradient = T.let(nil, T.nilable(Progress::StrokeGradientValue)) end |
Instance Attribute Details
#gradient_id ⇒ Object (readonly)
Returns the value of attribute gradient_id.
170 171 172 |
# File 'app/components/hakumi_components/progress/attribute_renderer.rb', line 170 def gradient_id @gradient_id end |
Instance Method Details
#circle_gap_position ⇒ Object
228 229 230 231 232 |
# File 'app/components/hakumi_components/progress/attribute_renderer.rb', line 228 def circle_gap_position return @gap_position unless @gap_position.nil? dashboard? ? :bottom : :top end |
#circle_geometry ⇒ Object
245 246 247 248 249 250 251 252 253 254 255 |
# File 'app/components/hakumi_components/progress/attribute_renderer.rb', line 245 def circle_geometry geometry = @circle_geometry return geometry unless geometry.nil? geometry = Progress::CircleGeometry.new( stroke_width: circle_stroke_width, gap_degree: circle_gap_degree, gap_position: circle_gap_position ) @circle_geometry = geometry end |
#circle_gradient_attributes ⇒ Object
162 163 164 165 166 167 |
# File 'app/components/hakumi_components/progress/attribute_renderer.rb', line 162 def circle_gradient_attributes gradient = gradient_value return [] if gradient.nil? gradient.stop_pairs end |
#circle_inner_style ⇒ Object
106 107 108 109 110 111 |
# File 'app/components/hakumi_components/progress/attribute_renderer.rb', line 106 def circle_inner_style style( "width" => "#{circle_size}px", "height" => "#{circle_size}px" ) end |
#circle_path_attributes ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'app/components/hakumi_components/progress/attribute_renderer.rb', line 132 def circle_path_attributes return {} if circle_steps? attrs = T.let( { class: "hakumi-progress-circle-path", cx: 50, cy: 50, r: circle_radius, fill: "none", "stroke-linecap": @stroke_linecap, "stroke-width": circle_stroke_width, "stroke-dasharray": circle_path_dasharray, "stroke-dashoffset": circle_dashoffset, transform: circle_transform }, Types::HtmlAttributes ) stroke = circle_stroke attrs[:style] = style("stroke" => stroke) if stroke attrs end |
#circle_radius ⇒ Object
199 200 201 |
# File 'app/components/hakumi_components/progress/attribute_renderer.rb', line 199 def circle_radius circle_geometry.radius end |
#circle_size ⇒ Object
99 100 101 102 103 |
# File 'app/components/hakumi_components/progress/attribute_renderer.rb', line 99 def circle_size return @size if @size.is_a?(Integer) 120 end |
#circle_step_style(step) ⇒ Object
222 223 224 225 |
# File 'app/components/hakumi_components/progress/attribute_renderer.rb', line 222 def circle_step_style(step) stroke = step[:stroke] style("stroke" => stroke&.to_s) end |
#circle_steps ⇒ Object
214 215 216 217 218 219 |
# File 'app/components/hakumi_components/progress/attribute_renderer.rb', line 214 def circle_steps steps_renderer( circle_geometry: circle_geometry, gradient_id: gradient? ? gradient_id : nil ).circle_steps end |
#circle_steps? ⇒ Boolean
209 210 211 |
# File 'app/components/hakumi_components/progress/attribute_renderer.rb', line 209 def circle_steps? steps_renderer.circle_steps? end |
#circle_stroke_width ⇒ Object
194 195 196 |
# File 'app/components/hakumi_components/progress/attribute_renderer.rb', line 194 def circle_stroke_width stroke_width_value.to_f end |
#circle_trail_attributes ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'app/components/hakumi_components/progress/attribute_renderer.rb', line 114 def circle_trail_attributes return {} if circle_steps? { class: "hakumi-progress-circle-trail", cx: 50, cy: 50, r: circle_radius, fill: "none", stroke: "var(--hakumi-progress-trail-color, var(--color-border-secondary))", "stroke-width": circle_stroke_width, "stroke-dasharray": circle_trail_dasharray, "stroke-dashoffset": circle_dashoffset, transform: circle_transform } end |
#circle_trail_style ⇒ Object
157 158 159 |
# File 'app/components/hakumi_components/progress/attribute_renderer.rb', line 157 def circle_trail_style style("--hakumi-progress-trail-color" => @trail_color) end |
#circle_transform ⇒ Object
204 205 206 |
# File 'app/components/hakumi_components/progress/attribute_renderer.rb', line 204 def circle_transform circle_geometry.transform end |
#gradient? ⇒ Boolean
181 182 183 |
# File 'app/components/hakumi_components/progress/attribute_renderer.rb', line 181 def gradient? @stroke_color.is_a?(Hash) end |
#gradient_css ⇒ Object
186 187 188 189 190 191 |
# File 'app/components/hakumi_components/progress/attribute_renderer.rb', line 186 def gradient_css gradient = gradient_value return nil if gradient.nil? gradient.css end |
#gradient_svg_direction ⇒ Object
173 174 175 176 177 178 |
# File 'app/components/hakumi_components/progress/attribute_renderer.rb', line 173 def gradient_svg_direction gradient = gradient_value return Progress::StrokeGradientValue.default_svg_direction if gradient.nil? gradient.svg_direction end |
#line_bar_style ⇒ Object
75 76 77 78 79 80 81 82 83 |
# File 'app/components/hakumi_components/progress/attribute_renderer.rb', line 75 def styles = T.let({ "width" => "#{@percent}%" }, Types::StyleMap) if gradient? styles["background"] = gradient_css elsif @stroke_color.is_a?(String) styles["background-color"] = @stroke_color end style(styles) end |
#line_steps ⇒ Object
94 95 96 |
# File 'app/components/hakumi_components/progress/attribute_renderer.rb', line 94 def line_steps steps_renderer.line_steps end |
#line_style ⇒ Object
67 68 69 70 71 72 |
# File 'app/components/hakumi_components/progress/attribute_renderer.rb', line 67 def line_style style( "--hakumi-progress-stroke-width" => "#{line_stroke_width}px", "--hakumi-progress-trail-color" => @trail_color ) end |
#line_success_style ⇒ Object
86 87 88 89 90 91 |
# File 'app/components/hakumi_components/progress/attribute_renderer.rb', line 86 def line_success_style success = @success_percent return nil if success.nil? style("width" => "#{success}%") end |
#stroke_width_value ⇒ Object
235 236 237 238 239 240 241 242 |
# File 'app/components/hakumi_components/progress/attribute_renderer.rb', line 235 def stroke_width_value return whole_number?(@stroke_width) ? @stroke_width.to_i : @stroke_width unless @stroke_width.nil? return 6 if circle? || dashboard? width = line_stroke_width whole_number?(width) ? width.to_i : width end |