Class: HakumiComponents::Affix::Component

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

Constant Summary

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

Class Method 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(body: nil, offset_top: nil, offset_bottom: nil, target_selector: nil, z_index: nil, on_change: nil, **html_options) ⇒ Component

Returns a new instance of Component.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/components/hakumi_components/affix/component.rb', line 35

def initialize(
  body: nil,
  offset_top: nil,
  offset_bottom: nil,
  target_selector: nil,
  z_index: nil,
  on_change: nil,
  **html_options
)
  @body = T.let(body, T.nilable(String))
  @offset_top = T.let(normalize_offset(offset_top), T.nilable(Float))
  @offset_bottom = T.let(normalize_offset(offset_bottom), T.nilable(Float))
  @target_selector = T.let(target_selector, T.nilable(String))
  @z_index = T.let(z_index, T.nilable(Integer))
  @on_change = T.let(on_change, T.nilable(String))
  @html_options = T.let(html_options, Types::HtmlAttributes)

  normalize_offsets!
  validate_props!
end

Class Method Details

.extract_controller_locals(params) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'app/components/hakumi_components/affix/component.rb', line 13

def self.extract_controller_locals(params)
  {
    body: string_html_param(html_param(params, :body)),
    offset_top: float_html_param(html_param(params, :offset_top)),
    offset_bottom: float_html_param(html_param(params, :offset_bottom)),
    target_selector: string_html_param(html_param(params, :target_selector)),
    z_index: integer_html_param(html_param(params, :z_index)),
    on_change: string_html_param(html_param(params, :on_change))
  }.compact
end

Instance Method Details

#content_valueObject



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

def content_value
  content.presence || @body
end

#root_attributesObject



57
58
59
# File 'app/components/hakumi_components/affix/component.rb', line 57

def root_attributes
  merge_attributes({ class: class_names("affix"), data: data_attributes }, @html_options)
end