Class: HakumiComponents::FloatButton::ItemSpec

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
app/components/hakumi_components/float_button/item_spec.rb

Constant Summary collapse

IconValue =
T.type_alias { T.nilable(T.any(String, Symbol, ViewComponent::Base, ViewComponent::Slot, ActiveSupport::SafeBuffer)) }
InputValue =
T.type_alias do
  T.nilable(T.any(
    String,
    Symbol,
    T::Boolean,
    Numeric,
    ViewComponent::Base,
    ViewComponent::Slot,
    ActiveSupport::SafeBuffer,
    Types::HtmlAttributes
  ))
end
InputAttributes =
T.type_alias { T::Hash[Symbol, InputValue] }

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(icon:, description: nil, tooltip: nil, href: nil, target: nil, type: :default, danger: false, html_options: {}) ⇒ ItemSpec

Returns a new instance of ItemSpec.



36
37
38
39
40
41
42
43
44
45
# File 'app/components/hakumi_components/float_button/item_spec.rb', line 36

def initialize(icon:, description: nil, tooltip: nil, href: nil, target: nil, type: :default, danger: false, html_options: {})
  @icon = T.let(icon, IconValue)
  @description = T.let(description, T.nilable(String))
  @tooltip = T.let(tooltip, T.nilable(String))
  @href = T.let(href, T.nilable(String))
  @target = T.let(target, T.nilable(String))
  @type = T.let(type, Symbol)
  @danger = T.let(danger, T::Boolean)
  @html_options = T.let(html_options, Types::HtmlAttributes)
end

Instance Attribute Details

#dangerObject (readonly)

Returns the value of attribute danger.



57
58
59
# File 'app/components/hakumi_components/float_button/item_spec.rb', line 57

def danger
  @danger
end

#descriptionObject (readonly)

Returns the value of attribute description.



51
52
53
# File 'app/components/hakumi_components/float_button/item_spec.rb', line 51

def description
  @description
end

#hrefObject (readonly)

Returns the value of attribute href.



51
52
53
# File 'app/components/hakumi_components/float_button/item_spec.rb', line 51

def href
  @href
end

#html_optionsObject (readonly)

Returns the value of attribute html_options.



60
61
62
# File 'app/components/hakumi_components/float_button/item_spec.rb', line 60

def html_options
  @html_options
end

#iconObject (readonly)

Returns the value of attribute icon.



48
49
50
# File 'app/components/hakumi_components/float_button/item_spec.rb', line 48

def icon
  @icon
end

#targetObject (readonly)

Returns the value of attribute target.



51
52
53
# File 'app/components/hakumi_components/float_button/item_spec.rb', line 51

def target
  @target
end

#tooltipObject (readonly)

Returns the value of attribute tooltip.



51
52
53
# File 'app/components/hakumi_components/float_button/item_spec.rb', line 51

def tooltip
  @tooltip
end

#typeObject (readonly)

Returns the value of attribute type.



54
55
56
# File 'app/components/hakumi_components/float_button/item_spec.rb', line 54

def type
  @type
end

Class Method Details

.coerce(item) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'app/components/hakumi_components/float_button/item_spec.rb', line 68

def self.coerce(item)
  return item if item.is_a?(HakumiComponents::FloatButton::ItemSpec)

  new(
    icon: coerce_icon(item[:icon]),
    description: coerce_string(item[:description]),
    tooltip: coerce_string(item[:tooltip]),
    href: coerce_string(item[:href]),
    target: coerce_string(item[:target]),
    type: coerce_symbol(item[:type]) || :default,
    danger: item[:danger] == true,
    html_options: coerce_html_attributes(item[:html_options])
  )
end

.coerce_all(items) ⇒ Object



63
64
65
# File 'app/components/hakumi_components/float_button/item_spec.rb', line 63

def self.coerce_all(items)
  items.map { |item| coerce(item) }
end