Class: Anchor::Component

Inherits:
ViewComponent::Base
  • Object
show all
Includes:
FetchOrFallbackHelper, ViewHelper
Defined in:
app/components/anchor/component.rb

Constant Summary

Constants included from ViewHelper

ViewHelper::ANCHOR_HELPERS

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ViewHelper

#anchor_form_with, #anchor_svg, #deep_blank?, #merge_options, #popover_trigger_attributes

Methods included from FetchOrFallbackHelper

#fetch_or_fallback

Constructor Details

#initialize(**kwargs) ⇒ Component

Returns a new instance of Component.



10
11
12
13
14
15
16
17
18
19
20
# File 'app/components/anchor/component.rb', line 10

def initialize(**kwargs)
  classes = add_variant_classes_if_available(
    classes: [*kwargs.delete(:classes), *kwargs.delete(:class)],
    variant: kwargs.delete(:variant)
  )
  @wrapper_options = kwargs
    .merge(class: classes)
    .reject { |_, v| deep_blank?(v) }

  super # rubocop:disable Anchor/AvoidImplicitSuper
end

Class Method Details

.generate_id(base_name: name.demodulize.underscore.dasherize) ⇒ Object



6
7
8
# File 'app/components/anchor/component.rb', line 6

def self.generate_id(base_name: name.demodulize.underscore.dasherize)
  "#{base_name}-#{SecureRandom.uuid}"
end