Class: HakumiComponents::Steps::Item::Component

Inherits:
BaseComponent
  • Object
show all
Extended by:
T::Sig
Defined in:
app/components/hakumi_components/steps/item/component.rb

Constant Summary collapse

STATUSES =
T.let(%i[wait process finish error].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

Instance Method Summary collapse

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, subtitle: nil, description: nil, tooltip: nil, icon: nil, icon_spin: false, status: nil, disabled: false, parent: nil, **html_options) ⇒ Component

Returns a new instance of Component.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/components/hakumi_components/steps/item/component.rb', line 26

def initialize(
  title: nil,
  subtitle: nil,
  description: nil,
  tooltip: nil,
  icon: nil,
  icon_spin: false,
  status: nil,
  disabled: false,
  parent: nil,
  **html_options
)
  @title = T.let(title, T.nilable(Types::Renderable))
  @subtitle = T.let(subtitle, T.nilable(String))
  @description = T.let(description, T.nilable(Types::Renderable))
  @tooltip = T.let(tooltip, T.nilable(String))
  @icon = T.let(icon, T.nilable(T.any(Symbol, ViewComponent::Base)))
  @icon_spin = T.let(icon_spin, T::Boolean)
  @status = T.let(status, T.nilable(Symbol))
  @disabled = T.let(disabled, T::Boolean)
  @parent = T.let(parent, T.nilable(HakumiComponents::Steps::Component))
  @html_options = T.let(html_options, Types::HtmlAttributes)

  validate_props!
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



53
54
55
# File 'app/components/hakumi_components/steps/item/component.rb', line 53

def description
  @description
end

#disabledObject (readonly)

Returns the value of attribute disabled.



62
63
64
# File 'app/components/hakumi_components/steps/item/component.rb', line 62

def disabled
  @disabled
end

#iconObject (readonly)

Returns the value of attribute icon.



59
60
61
# File 'app/components/hakumi_components/steps/item/component.rb', line 59

def icon
  @icon
end

#icon_spinObject (readonly)

Returns the value of attribute icon_spin.



62
63
64
# File 'app/components/hakumi_components/steps/item/component.rb', line 62

def icon_spin
  @icon_spin
end

#statusObject (readonly)

Returns the value of attribute status.



65
66
67
# File 'app/components/hakumi_components/steps/item/component.rb', line 65

def status
  @status
end

#subtitleObject (readonly)

Returns the value of attribute subtitle.



56
57
58
# File 'app/components/hakumi_components/steps/item/component.rb', line 56

def subtitle
  @subtitle
end

#titleObject (readonly)

Returns the value of attribute title.



53
54
55
# File 'app/components/hakumi_components/steps/item/component.rb', line 53

def title
  @title
end

#tooltipObject (readonly)

Returns the value of attribute tooltip.



56
57
58
# File 'app/components/hakumi_components/steps/item/component.rb', line 56

def tooltip
  @tooltip
end

Instance Method Details

#icon_content(computed_status, index, progress_dot, percent) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'app/components/hakumi_components/steps/item/component.rb', line 99

def icon_content(computed_status, index, progress_dot, percent)
  return nil if progress_dot

  if @icon
    @icon
  else
    case computed_status
    when :finish
      :check
    when :error
      :close
    end
  end
end

#item_classes(computed_status, clickable) ⇒ Object



68
69
70
71
72
73
74
75
# File 'app/components/hakumi_components/steps/item/component.rb', line 68

def item_classes(computed_status, clickable)
  classes = T.let([ "hakumi-steps-item" ], T::Array[String])
  classes << "hakumi-steps-item-#{computed_status}"
  classes << "hakumi-steps-item-disabled" if @disabled
  classes << "hakumi-steps-item-clickable" if clickable && !@disabled
  classes << "hakumi-steps-item-custom" if @icon
  classes.join(" ")
end

#show_number?(computed_status) ⇒ Boolean

Returns:

  • (Boolean)


115
116
117
118
119
# File 'app/components/hakumi_components/steps/item/component.rb', line 115

def show_number?(computed_status)
  return false if @icon

  %i[wait process].include?(computed_status)
end

#wrapper_attributes(index, computed_status, clickable) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
# File 'app/components/hakumi_components/steps/item/component.rb', line 78

def wrapper_attributes(index, computed_status, clickable)
  base_attrs = T.let({ class: item_classes(computed_status, clickable) }, Types::HtmlAttributes)

  if clickable && !@disabled
    base_attrs[:data] = T.let({
      action: "click->hakumi--steps#selectStep",
      "step-index" => index
    }, Types::DataAttributes)
  end

  merge_attributes(base_attrs, @html_options)
end