Class: HakumiComponents::Anchor::Component
- Inherits:
-
BaseComponent
- Object
- ViewComponent::Base
- BaseComponent
- HakumiComponents::Anchor::Component
show all
- Extended by:
- T::Sig
- Defined in:
- app/components/hakumi_components/anchor/component.rb
Constant Summary
collapse
- DIRECTIONS =
T.let(%i[vertical horizontal].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
#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(affix: true, bounds: 5, offset_top: 0, target_offset: nil, direction: :vertical, replace: false, **html_options) ⇒ Component
Returns a new instance of Component.
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'app/components/hakumi_components/anchor/component.rb', line 24
def initialize(
affix: true,
bounds: 5,
offset_top: 0,
target_offset: nil,
direction: :vertical,
replace: false,
**html_options
)
@affix = T.let(affix, T::Boolean)
@bounds = T.let(bounds, Numeric)
@offset_top = T.let(offset_top, Numeric)
@target_offset = T.let(target_offset, T.nilable(Numeric))
@direction = T.let(direction, Symbol)
@replace = T.let(replace, T::Boolean)
@html_options = T.let(html_options, Types::HtmlAttributes)
validate_props!
end
|
Instance Method Details
#anchor_classes ⇒ Object
50
51
52
|
# File 'app/components/hakumi_components/anchor/component.rb', line 50
def anchor_classes
class_names("anchor", { fixed: @affix })
end
|
#horizontal? ⇒ Boolean
76
77
78
|
# File 'app/components/hakumi_components/anchor/component.rb', line 76
def horizontal?
@direction == :horizontal
end
|
#stimulus_controller ⇒ Object
55
56
57
|
# File 'app/components/hakumi_components/anchor/component.rb', line 55
def stimulus_controller
"hakumi--anchor"
end
|
#wrapper_attributes ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'app/components/hakumi_components/anchor/component.rb', line 60
def wrapper_attributes
values = T.let({
offset_top: @offset_top,
target_offset: @target_offset || @offset_top,
bounds: @bounds,
replace: @replace,
direction: @direction.to_s
}, Types::StimulusValues)
merge_attributes(
{ class: wrapper_classes, data: stimulus_attrs(stimulus_controller, values) },
@html_options
)
end
|
#wrapper_classes ⇒ Object
45
46
47
|
# File 'app/components/hakumi_components/anchor/component.rb', line 45
def wrapper_classes
class_names("anchor-wrapper", { fixed: @affix, horizontal: horizontal? })
end
|