Class: HakumiComponents::Tour::Component
- Inherits:
-
BaseComponent
- Object
- ViewComponent::Base
- BaseComponent
- HakumiComponents::Tour::Component
show all
- Extended by:
- T::Sig
- Defined in:
- app/components/hakumi_components/tour/component.rb
Constant Summary
collapse
- Size =
T.type_alias { T.any(Symbol, String) }
- Type =
T.type_alias { T.any(Symbol, String) }
- Placement =
T.type_alias { T.any(Symbol, String) }
- TYPES =
T.let(%i[default primary].freeze, T::Array[Symbol])
- PLACEMENTS =
T.let(%i[
top top_left top_right
bottom bottom_left bottom_right
left left_top left_bottom
right right_top right_bottom
].freeze, T::Array[Symbol])
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 Method Summary
collapse
-
#body_id ⇒ Object
-
#component_html_attributes ⇒ Object
-
#current_step_body ⇒ Object
-
#current_step_title ⇒ Object
-
#first_step? ⇒ Boolean
-
#initialize(steps: [], open: false, current: 0, size: :default, type: :default, placement: :bottom, mask: true, mask_closable: true, closable: true, show_progress: true, **html_options) ⇒ Component
constructor
A new instance of Component.
-
#last_step? ⇒ Boolean
-
#progress_label ⇒ Object
-
#title_id ⇒ Object
#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(steps: [], open: false, current: 0, size: :default, type: :default, placement: :bottom, mask: true, mask_closable: true, closable: true, show_progress: true, **html_options) ⇒ Component
Returns a new instance of Component.
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/tour/component.rb', line 36
def initialize(
steps: [],
open: false,
current: 0,
size: :default,
type: :default,
placement: :bottom,
mask: true,
mask_closable: true,
closable: true,
show_progress: true,
**html_options
)
@steps = T.let(steps, T::Array[HakumiComponents::Tour::Step::Source])
@open = T.let(open, T::Boolean)
@current = T.let(current, Integer)
@size = T.let(size.to_sym, Symbol)
@type = T.let(type.to_sym, Symbol)
@placement = T.let(placement.to_sym, Symbol)
@mask = T.let(mask, T::Boolean)
@mask_closable = T.let(mask_closable, T::Boolean)
@closable = T.let(closable, T::Boolean)
@show_progress = T.let(show_progress, T::Boolean)
@html_options = T.let(html_options, HakumiComponents::Types::HtmlAttributes)
raw_id = @html_options[:id]
@component_id = T.let(raw_id.nil? ? generate_id("hakumi-tour", length: 6) : raw_id.to_s, String)
validate_props!
end
|
Instance Method Details
#body_id ⇒ Object
94
95
96
|
# File 'app/components/hakumi_components/tour/component.rb', line 94
def body_id
"#{@component_id}-body"
end
|
#component_html_attributes ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'app/components/hakumi_components/tour/component.rb', line 67
def component_html_attributes
merge_attributes(
{
id: @component_id,
class: component_html_class,
data: {
controller: "hakumi--tour",
hakumi__tour_open_value: @open,
hakumi__tour_current_value: @current,
hakumi__tour_steps_value: steps_json,
hakumi__tour_placement_value: @placement.to_s.tr("_", "-"),
hakumi__tour_mask_value: @mask,
hakumi__tour_mask_closable_value: @mask_closable,
hakumi__tour_closable_value: @closable,
hakumi__tour_show_progress_value: @show_progress
}
},
@html_options
)
end
|
#current_step_body ⇒ Object
104
105
106
|
# File 'app/components/hakumi_components/tour/component.rb', line 104
def current_step_body
current_step.body
end
|
#current_step_title ⇒ Object
99
100
101
|
# File 'app/components/hakumi_components/tour/component.rb', line 99
def current_step_title
current_step.title
end
|
#first_step? ⇒ Boolean
117
118
119
|
# File 'app/components/hakumi_components/tour/component.rb', line 117
def first_step?
current_index.zero?
end
|
#last_step? ⇒ Boolean
122
123
124
|
# File 'app/components/hakumi_components/tour/component.rb', line 122
def last_step?
normalized_steps.any? && current_index == normalized_steps.length - 1
end
|
#progress_label ⇒ Object
109
110
111
112
113
114
|
# File 'app/components/hakumi_components/tour/component.rb', line 109
def progress_label
return nil unless @show_progress
return "0 / 0" if normalized_steps.empty?
"#{current_index + 1} / #{normalized_steps.length}"
end
|
#title_id ⇒ Object
89
90
91
|
# File 'app/components/hakumi_components/tour/component.rb', line 89
def title_id
"#{@component_id}-title"
end
|