Class: HakumiComponents::Timeline::Item::Component
- Inherits:
-
BaseComponent
- Object
- ViewComponent::Base
- BaseComponent
- HakumiComponents::Timeline::Item::Component
- Extended by:
- T::Sig
- Defined in:
- app/components/hakumi_components/timeline/item/component.rb
Constant Summary collapse
- ColorValue =
T.type_alias { Types::HtmlKey }
- ContentBlock =
T.type_alias { T.nilable(T.proc.returns(Types::RenderedContent)) }
- COLORS =
T.let( { blue: "var(--color-primary)", red: "var(--color-error)", green: "var(--color-success)", gray: "var(--color-text-secondary)" }.freeze, T::Hash[Symbol, String] )
- POSITIONS =
T.let(%i[left right].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
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#color ⇒ Object
readonly
Returns the value of attribute color.
-
#dot ⇒ Object
readonly
Returns the value of attribute dot.
-
#loading ⇒ Object
readonly
Returns the value of attribute loading.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#pending ⇒ Object
readonly
Returns the value of attribute pending.
-
#position ⇒ Object
readonly
Returns the value of attribute position.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
- #dot_content ⇒ Object
-
#initialize(title: nil, body: nil, color: :blue, dot: nil, position: nil, loading: false, parent: nil, pending: false, **html_options, &block) ⇒ Component
constructor
A new instance of Component.
- #item_content ⇒ Object
- #last_item? ⇒ Boolean
- #resolved_position ⇒ Object
- #title_content ⇒ Object
- #with_context(index:, total:, position:, reverse: false) ⇒ Object
- #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(title: nil, body: nil, color: :blue, dot: nil, position: nil, loading: false, parent: nil, pending: false, **html_options, &block) ⇒ Component
Returns a new instance of Component.
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 65 |
# File 'app/components/hakumi_components/timeline/item/component.rb', line 38 def initialize( title: nil, body: nil, color: :blue, dot: nil, position: nil, loading: false, parent: nil, pending: false, **, &block ) @title = T.let(title, Types::Renderable) @body = T.let(body, Types::Renderable) @color = T.let(color.is_a?(String) ? color : color.to_sym, ColorValue) @dot = T.let(dot, Types::Renderable) @position = T.let(position, T.nilable(Symbol)) @loading = T.let(cast_boolean(loading) ? true : false, T::Boolean) @parent = T.let(parent, T.nilable(HakumiComponents::Timeline::Component)) @pending = T.let(cast_boolean(pending) ? true : false, T::Boolean) @html_options = T.let(, Types::HtmlAttributes) @content_block = T.let(block, ContentBlock) @index = T.let(nil, T.nilable(Integer)) @total = T.let(nil, T.nilable(Integer)) @resolved_position = T.let(nil, T.nilable(Symbol)) @reverse = T.let(false, T::Boolean) validate_props! end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
68 69 70 |
# File 'app/components/hakumi_components/timeline/item/component.rb', line 68 def body @body end |
#color ⇒ Object (readonly)
Returns the value of attribute color.
71 72 73 |
# File 'app/components/hakumi_components/timeline/item/component.rb', line 71 def color @color end |
#dot ⇒ Object (readonly)
Returns the value of attribute dot.
68 69 70 |
# File 'app/components/hakumi_components/timeline/item/component.rb', line 68 def dot @dot end |
#loading ⇒ Object (readonly)
Returns the value of attribute loading.
77 78 79 |
# File 'app/components/hakumi_components/timeline/item/component.rb', line 77 def loading @loading end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
80 81 82 |
# File 'app/components/hakumi_components/timeline/item/component.rb', line 80 def parent @parent end |
#pending ⇒ Object (readonly)
Returns the value of attribute pending.
77 78 79 |
# File 'app/components/hakumi_components/timeline/item/component.rb', line 77 def pending @pending end |
#position ⇒ Object (readonly)
Returns the value of attribute position.
74 75 76 |
# File 'app/components/hakumi_components/timeline/item/component.rb', line 74 def position @position end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
68 69 70 |
# File 'app/components/hakumi_components/timeline/item/component.rb', line 68 def title @title end |
Instance Method Details
#dot_content ⇒ Object
144 145 146 147 148 149 150 |
# File 'app/components/hakumi_components/timeline/item/component.rb', line 144 def dot_content rendered_dot = render_value(@dot) return rendered_dot if rendered_dot.present? return render(HakumiComponents::Icon::Component.new(name: :loading, spin: true, size: 12)) if loading nil end |
#item_content ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'app/components/hakumi_components/timeline/item/component.rb', line 116 def item_content rendered_body = render_value(@body) return rendered_body if rendered_body.present? return content if content.present? if @content_block && view_context captured = view_context.capture(&@content_block) return captured if captured.present? end nil end |
#last_item? ⇒ Boolean
135 136 137 138 139 140 141 |
# File 'app/components/hakumi_components/timeline/item/component.rb', line 135 def last_item? index = @index total = @total return false if index.nil? || total.nil? @reverse ? index.zero? : index == (total - 1) end |
#resolved_position ⇒ Object
130 131 132 |
# File 'app/components/hakumi_components/timeline/item/component.rb', line 130 def resolved_position @resolved_position || @position || :left end |
#title_content ⇒ Object
111 112 113 |
# File 'app/components/hakumi_components/timeline/item/component.rb', line 111 def title_content render_value(@title) end |
#with_context(index:, total:, position:, reverse: false) ⇒ Object
90 91 92 93 94 95 96 |
# File 'app/components/hakumi_components/timeline/item/component.rb', line 90 def with_context(index:, total:, position:, reverse: false) @index = index @total = total @resolved_position = position @reverse = reverse self end |
#wrapper_attributes ⇒ Object
99 100 101 102 103 104 105 106 107 108 |
# File 'app/components/hakumi_components/timeline/item/component.rb', line 99 def wrapper_attributes merge_attributes( { class: item_classes, data: item_data, style: dot_style }, @html_options ) end |