Class: HakumiComponents::Steps::Component
- Inherits:
-
BaseComponent
- Object
- ViewComponent::Base
- BaseComponent
- HakumiComponents::Steps::Component
- Extended by:
- T::Sig
- Defined in:
- app/components/hakumi_components/steps/component.rb
Constant Summary collapse
- DIRECTIONS =
T.let(%i[horizontal vertical].freeze, T::Array[Symbol])
- TYPES =
T.let(%i[default navigation inline].freeze, T::Array[Symbol])
- SIZES =
T.let(%i[default small].freeze, T::Array[Symbol])
- STATUSES =
T.let(%i[wait process finish error].freeze, T::Array[Symbol])
- LABEL_PLACEMENTS =
T.let(%i[horizontal vertical].freeze, T::Array[Symbol])
- VARIANTS =
T.let(%i[filled outlined].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::SizeValue, BaseComponent::SymbolInput
Instance Attribute Summary collapse
-
#clickable ⇒ Object
readonly
Returns the value of attribute clickable.
-
#current ⇒ Object
readonly
Returns the value of attribute current.
-
#direction ⇒ Object
readonly
Returns the value of attribute direction.
-
#initial ⇒ Object
readonly
Returns the value of attribute initial.
-
#label_placement ⇒ Object
readonly
Returns the value of attribute label_placement.
-
#percent ⇒ Object
readonly
Returns the value of attribute percent.
-
#progress_dot ⇒ Object
readonly
Returns the value of attribute progress_dot.
-
#responsive ⇒ Object
readonly
Returns the value of attribute responsive.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#variant ⇒ Object
readonly
Returns the value of attribute variant.
Instance Method Summary collapse
- #effective_label_placement ⇒ Object
-
#initialize(current: 0, direction: :horizontal, type: :default, size: :default, status: :process, label_placement: nil, percent: nil, progress_dot: false, responsive: true, initial: 0, clickable: false, variant: :filled, **html_options) ⇒ Component
constructor
A new instance of Component.
- #item_clickable?(index) ⇒ Boolean
- #item_status(index) ⇒ Object
- #steps_classes ⇒ 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(current: 0, direction: :horizontal, type: :default, size: :default, status: :process, label_placement: nil, percent: nil, progress_dot: false, responsive: true, initial: 0, clickable: false, variant: :filled, **html_options) ⇒ Component
Returns a new instance of Component.
58 59 60 61 62 63 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 |
# File 'app/components/hakumi_components/steps/component.rb', line 58 def initialize( current: 0, direction: :horizontal, type: :default, size: :default, status: :process, label_placement: nil, percent: nil, progress_dot: false, responsive: true, initial: 0, clickable: false, variant: :filled, ** ) @current = T.let(current, Integer) @direction = T.let(direction, Symbol) @type = T.let(type, Symbol) @size = T.let(size, Symbol) @status = T.let(status, Symbol) @label_placement = T.let(label_placement, T.nilable(Symbol)) @percent = T.let(percent, T.nilable(Numeric)) @progress_dot = T.let(progress_dot, T::Boolean) @responsive = T.let(responsive, T::Boolean) @initial = T.let(initial, Integer) @clickable = T.let(clickable, T::Boolean) @variant = T.let(variant, Symbol) @html_options = T.let(, Types::HtmlAttributes) validate_props! end |
Instance Attribute Details
#clickable ⇒ Object (readonly)
Returns the value of attribute clickable.
103 104 105 |
# File 'app/components/hakumi_components/steps/component.rb', line 103 def clickable @clickable end |
#current ⇒ Object (readonly)
Returns the value of attribute current.
91 92 93 |
# File 'app/components/hakumi_components/steps/component.rb', line 91 def current @current end |
#direction ⇒ Object (readonly)
Returns the value of attribute direction.
94 95 96 |
# File 'app/components/hakumi_components/steps/component.rb', line 94 def direction @direction end |
#initial ⇒ Object (readonly)
Returns the value of attribute initial.
91 92 93 |
# File 'app/components/hakumi_components/steps/component.rb', line 91 def initial @initial end |
#label_placement ⇒ Object (readonly)
Returns the value of attribute label_placement.
97 98 99 |
# File 'app/components/hakumi_components/steps/component.rb', line 97 def label_placement @label_placement end |
#percent ⇒ Object (readonly)
Returns the value of attribute percent.
100 101 102 |
# File 'app/components/hakumi_components/steps/component.rb', line 100 def percent @percent end |
#progress_dot ⇒ Object (readonly)
Returns the value of attribute progress_dot.
103 104 105 |
# File 'app/components/hakumi_components/steps/component.rb', line 103 def progress_dot @progress_dot end |
#responsive ⇒ Object (readonly)
Returns the value of attribute responsive.
103 104 105 |
# File 'app/components/hakumi_components/steps/component.rb', line 103 def responsive @responsive end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
94 95 96 |
# File 'app/components/hakumi_components/steps/component.rb', line 94 def size @size end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
94 95 96 |
# File 'app/components/hakumi_components/steps/component.rb', line 94 def status @status end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
94 95 96 |
# File 'app/components/hakumi_components/steps/component.rb', line 94 def type @type end |
#variant ⇒ Object (readonly)
Returns the value of attribute variant.
94 95 96 |
# File 'app/components/hakumi_components/steps/component.rb', line 94 def variant @variant end |
Instance Method Details
#effective_label_placement ⇒ Object
122 123 124 125 126 |
# File 'app/components/hakumi_components/steps/component.rb', line 122 def effective_label_placement return :vertical if @progress_dot && @direction == :horizontal @label_placement || :horizontal end |
#item_clickable?(index) ⇒ Boolean
155 156 157 158 159 160 161 162 |
# File 'app/components/hakumi_components/steps/component.rb', line 155 def item_clickable?(index) return false unless @clickable raw_item = items[index] return false unless raw_item && raw_item.respond_to?(:disabled) !raw_item.disabled end |
#item_status(index) ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'app/components/hakumi_components/steps/component.rb', line 138 def item_status(index) raw_item = items[index] if raw_item && raw_item.respond_to?(:status) s = raw_item.status return s if s end if index < @current :finish elsif index == @current @status else :wait end end |
#steps_classes ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'app/components/hakumi_components/steps/component.rb', line 106 def steps_classes modifiers = T.let({ direction => true, type => @type != :default, small: @size == :small, "label-#{effective_label_placement}": @direction == :horizontal && @type == :default, "with-progress": @percent.present?, dot: @progress_dot, navigation: @type == :navigation, inline: @type == :inline, variant => @variant != :filled }, Types::ClassModifiers) component_classes("steps", modifiers, @html_options) end |
#wrapper_attributes ⇒ Object
129 130 131 132 133 134 135 |
# File 'app/components/hakumi_components/steps/component.rb', line 129 def wrapper_attributes data = stimulus_attrs("hakumi--steps", T.let({ current: @current, clickable: @clickable }, Types::StimulusValues)) merge_attributes({ class: steps_classes, data: data }, @html_options.except(:class)) end |