Class: Arara::FabComponent

Inherits:
ActionView::Component::Base
  • Object
show all
Includes:
BaseComponent
Defined in:
app/components/arara/fab_component.rb

Defined Under Namespace

Classes: InvalidVariant

Constant Summary collapse

VALID_VARIANTS =
%w(default mini extended extended_no_icon)

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from BaseComponent

#default_html_tag, #html_class, #html_content, #html_data, #html_tag, included

Constructor Details

#initialize(variant: "default", label:, extended_label: nil, label_before: false, **kw) ⇒ FabComponent

Returns a new instance of FabComponent.

Raises:



14
15
16
17
18
19
20
21
22
# File 'app/components/arara/fab_component.rb', line 14

def initialize(variant: "default", label:, extended_label: nil, label_before: false, **kw)
  raise InvalidVariant.new("`#{variant}' is not a valid variant") unless VALID_VARIANTS.include?(variant.to_s)
  super(tag: "button", variant: variant, **kw)

  @variant = variant
  @label = label
  @extended_label = extended_label
  @label_before = label_before
end

Instance Attribute Details

#extended_labelObject (readonly)

Returns the value of attribute extended_label.



8
9
10
# File 'app/components/arara/fab_component.rb', line 8

def extended_label
  @extended_label
end

#labelObject (readonly)

Returns the value of attribute label.



8
9
10
# File 'app/components/arara/fab_component.rb', line 8

def label
  @label
end

#label_beforeObject (readonly)

Returns the value of attribute label_before.



8
9
10
# File 'app/components/arara/fab_component.rb', line 8

def label_before
  @label_before
end

Instance Method Details

#default_data_controllerObject



38
39
40
# File 'app/components/arara/fab_component.rb', line 38

def default_data_controller
  "mdc-ripple"
end

#default_html_classObject



24
25
26
27
28
29
# File 'app/components/arara/fab_component.rb', line 24

def default_html_class
  return "mdc-fab mdc-fab--mini" if user_variant == "mini"
  return "mdc-fab mdc-fab--extended" if user_variant == "extended"
  return "mdc-fab mdc-fab--extended" if user_variant == "extended_no_icon"
  "mdc-fab"
end

#html_optionsObject



31
32
33
34
35
36
# File 'app/components/arara/fab_component.rb', line 31

def html_options
  opts = super
  opts[:aria] = {} unless opts.has_key?(:aria)
  opts[:aria][:label] = label
  opts
end