Class: HakumiComponents::Card::Component

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

Constant Summary collapse

SIZES =
T.let(%i[default small].freeze, T::Array[Symbol])
TYPES =
T.let([ :inner ].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::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(bordered: true, hoverable: false, loading: false, size: :default, type: nil, href: nil, target: nil, **html_options) ⇒ Component

Returns a new instance of Component.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/components/hakumi_components/card/component.rb', line 30

def initialize(
  bordered: true,
  hoverable: false,
  loading: false,
  size: :default,
  type: nil,
  href: nil,
  target: nil,
  **html_options
)
  @bordered = T.let(cast_boolean(bordered) != false, T::Boolean)
  @hoverable = T.let(cast_boolean(hoverable) ? true : false, T::Boolean)
  @loading = T.let(cast_boolean(loading) ? true : false, T::Boolean)
  @size = T.let(size.to_sym, Symbol)
  @type = T.let(type&.to_sym, T.nilable(Symbol))
  @href = T.let(href, T.nilable(String))
  @target = T.let(target, T.nilable(String))
  @html_options = T.let(html_options, Types::HtmlAttributes)

  validate_props!
end

Instance Method Details

#action_widthObject



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

def action_width
  count = actions.length
  return "100%" if count.zero?

  "#{100.0 / count}%"
end

#body_contentObject



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

def body_content
  body? ? body : content
end

#loading?Boolean

Returns:

  • (Boolean)


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

def loading?
  @loading
end

#render_header?Boolean

Returns:

  • (Boolean)


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

def render_header?
  header? || extra?
end

#wrapper_attributesObject



53
54
55
56
57
58
59
60
61
# File 'app/components/hakumi_components/card/component.rb', line 53

def wrapper_attributes
  attrs = T.let({ class: classes }, Types::HtmlAttributes)
  if link_card?
    attrs[:href] = @href
    attrs[:target] = @target if @target
  end

  merge_attributes(attrs, @html_options.except(:class))
end

#wrapper_tagObject



64
65
66
# File 'app/components/hakumi_components/card/component.rb', line 64

def wrapper_tag
  link_card? ? :a : :div
end