Class: HakumiComponents::Steps::Component

Inherits:
BaseComponent
  • Object
show all
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

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(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,
  **html_options
)
  @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(html_options, Types::HtmlAttributes)

  validate_props!
end

Instance Attribute Details

#clickableObject (readonly)

Returns the value of attribute clickable.



103
104
105
# File 'app/components/hakumi_components/steps/component.rb', line 103

def clickable
  @clickable
end

#currentObject (readonly)

Returns the value of attribute current.



91
92
93
# File 'app/components/hakumi_components/steps/component.rb', line 91

def current
  @current
end

#directionObject (readonly)

Returns the value of attribute direction.



94
95
96
# File 'app/components/hakumi_components/steps/component.rb', line 94

def direction
  @direction
end

#initialObject (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_placementObject (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

#percentObject (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_dotObject (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

#responsiveObject (readonly)

Returns the value of attribute responsive.



103
104
105
# File 'app/components/hakumi_components/steps/component.rb', line 103

def responsive
  @responsive
end

#sizeObject (readonly)

Returns the value of attribute size.



94
95
96
# File 'app/components/hakumi_components/steps/component.rb', line 94

def size
  @size
end

#statusObject (readonly)

Returns the value of attribute status.



94
95
96
# File 'app/components/hakumi_components/steps/component.rb', line 94

def status
  @status
end

#typeObject (readonly)

Returns the value of attribute type.



94
95
96
# File 'app/components/hakumi_components/steps/component.rb', line 94

def type
  @type
end

#variantObject (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_placementObject



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

Returns:

  • (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_classesObject



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_attributesObject



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