Class: HakumiComponents::Collapse::Panel::Component

Inherits:
BaseComponent
  • Object
show all
Extended by:
T::Sig
Defined in:
app/components/hakumi_components/collapse/panel/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

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(key:, header: nil, extra: nil, disabled: false, show_arrow: true, collapsible: nil, force_render: false, parent: nil, **html_options) ⇒ Component

Returns a new instance of Component.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/components/hakumi_components/collapse/panel/component.rb', line 23

def initialize(
  key:,
  header: nil,
  extra: nil,
  disabled: false,
  show_arrow: true,
  collapsible: nil,
  force_render: false,
  parent: nil,
  **html_options
)
  @key = T.let(key.to_s, String)
  @header = T.let(header, T.nilable(Types::Renderable))
  @extra = T.let(extra, T.nilable(Types::Renderable))
  @disabled = T.let(disabled, T::Boolean)
  @show_arrow = T.let(show_arrow, T::Boolean)
  @collapsible = T.let(collapsible, T.nilable(Symbol))
  @force_render = T.let(force_render, T::Boolean)
  @parent = T.let(parent, T.nilable(HakumiComponents::Collapse::Component))
  @html_options = T.let(html_options, Types::HtmlAttributes)
  @panel_content = T.let(nil, Types::RenderedContent)

  validate_props!
end

Instance Attribute Details

#collapsibleObject (readonly)

Returns the value of attribute collapsible.



58
59
60
# File 'app/components/hakumi_components/collapse/panel/component.rb', line 58

def collapsible
  @collapsible
end

#disabledObject (readonly)

Returns the value of attribute disabled.



55
56
57
# File 'app/components/hakumi_components/collapse/panel/component.rb', line 55

def disabled
  @disabled
end

#extraObject (readonly)

Returns the value of attribute extra.



52
53
54
# File 'app/components/hakumi_components/collapse/panel/component.rb', line 52

def extra
  @extra
end

#force_renderObject (readonly)

Returns the value of attribute force_render.



55
56
57
# File 'app/components/hakumi_components/collapse/panel/component.rb', line 55

def force_render
  @force_render
end

#headerObject (readonly)

Returns the value of attribute header.



52
53
54
# File 'app/components/hakumi_components/collapse/panel/component.rb', line 52

def header
  @header
end

#keyObject (readonly)

Returns the value of attribute key.



49
50
51
# File 'app/components/hakumi_components/collapse/panel/component.rb', line 49

def key
  @key
end

#show_arrowObject (readonly)

Returns the value of attribute show_arrow.



55
56
57
# File 'app/components/hakumi_components/collapse/panel/component.rb', line 55

def show_arrow
  @show_arrow
end

Instance Method Details

#contentObject



61
62
63
# File 'app/components/hakumi_components/collapse/panel/component.rb', line 61

def content
  @panel_content
end

#content=(value) ⇒ Object



66
67
68
# File 'app/components/hakumi_components/collapse/panel/component.rb', line 66

def content=(value)
  @panel_content = value
end

#extra?Boolean

Returns:

  • (Boolean)


95
96
97
# File 'app/components/hakumi_components/collapse/panel/component.rb', line 95

def extra?
  @extra.present?
end

#header_contentObject



90
91
92
# File 'app/components/hakumi_components/collapse/panel/component.rb', line 90

def header_content
  @header || @key
end

#item_attributes(active) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
# File 'app/components/hakumi_components/collapse/panel/component.rb', line 77

def item_attributes(active)
  base = T.let({
    class: item_classes(active),
    data: {
      "hakumi--collapse-target": "item",
      key: @key,
      disabled: @disabled
    }
  }, Types::HtmlAttributes)
  merge_attributes(base, @html_options.except(:class))
end

#item_classes(active) ⇒ Object



71
72
73
74
# File 'app/components/hakumi_components/collapse/panel/component.rb', line 71

def item_classes(active)
  base = component_classes("collapse-item", { active: active, disabled: @disabled }, @html_options)
  @show_arrow ? base : "#{base} hakumi-collapse-no-arrow"
end