Class: HakumiComponents::Descriptions::Component

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

Constant Summary collapse

LAYOUTS =
T.let(%i[horizontal vertical].freeze, T::Array[Symbol])
COLUMN_BREAKPOINTS =
T.let(%i[xs sm md lg xl xxl].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::SIZES, BaseComponent::SizeValue, BaseComponent::SymbolInput

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(title: nil, extra: nil, bordered: false, size: :default, layout: :horizontal, column: 3, colon: true, **html_options) ⇒ Component

Returns a new instance of Component.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/components/hakumi_components/descriptions/component.rb', line 46

def initialize(
  title: nil,
  extra: nil,
  bordered: false,
  size: :default,
  layout: :horizontal,
  column: 3,
  colon: true,
  **html_options
)
  @title = T.let(title, Types::Renderable)
  @extra = T.let(extra, Types::Renderable)
  @bordered = T.let(cast_boolean(bordered) ? true : false, T::Boolean)
  @size = T.let(size.to_sym, Symbol)
  @layout = T.let(layout.to_sym, Symbol)
  @column = T.let(normalize_column(column), T.any(Integer, T::Hash[Symbol, Integer]))
  @colon = T.let(cast_boolean(colon) != false, T::Boolean)
  @html_options = T.let(html_options, Types::HtmlAttributes)

  validate_props!
end

Instance Method Details

#extra_contentObject



91
92
93
94
95
# File 'app/components/hakumi_components/descriptions/component.rb', line 91

def extra_content
  return render_value(extra) if extra?

  render_value(@extra)
end

#header?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'app/components/hakumi_components/descriptions/component.rb', line 74

def header?
  title_content.present? || extra_content.present?
end

#title_contentObject



84
85
86
87
88
# File 'app/components/hakumi_components/descriptions/component.rb', line 84

def title_content
  return render_value(title) if title?

  render_value(@title)
end

#vertical_layout?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'app/components/hakumi_components/descriptions/component.rb', line 79

def vertical_layout?
  @layout == :vertical
end

#wrapper_attributesObject



69
70
71
# File 'app/components/hakumi_components/descriptions/component.rb', line 69

def wrapper_attributes
  merge_attributes({ class: wrapper_classes }, @html_options)
end