Module: Vident::Component

Extended by:
ActiveSupport::Concern
Includes:
ComponentAttributeResolver, ComponentClassLists, StimulusComponent, StimulusDSL, TagHelper, Tailwind
Defined in:
lib/vident/component.rb

Instance Method Summary collapse

Methods included from StimulusDSL

#resolve_values_from_props, #stimulus_dsl_attributes

Methods included from Tailwind

#tailwind_merge_available?, #tailwind_merger

Methods included from TagHelper

#tag

Methods included from ComponentClassLists

#class_list_for_stimulus_classes, #render_classes

Methods included from StimulusComponent

#component_name, #default_controller_path, #outlet_id, #stimulus_identifier, stimulus_identifier_from_path

Methods included from StimulusAttributes

#add_stimulus_actions, #add_stimulus_classes, #add_stimulus_controllers, #add_stimulus_outlets, #add_stimulus_targets, #add_stimulus_values, #stimulus_action, #stimulus_actions, #stimulus_class, #stimulus_classes, #stimulus_controller, #stimulus_controllers, #stimulus_outlet, #stimulus_outlets, #stimulus_scoped_event, #stimulus_scoped_event_on_window, #stimulus_target, #stimulus_targets, #stimulus_value, #stimulus_values

Instance Method Details

#after_component_initializeObject

Override this method to perform any initialisation after attributes are set



28
29
# File 'lib/vident/component.rb', line 28

def after_component_initialize
end

#clone(overrides = {}) ⇒ Object

Create a new component instance with optional overrides for properties.



42
# File 'lib/vident/component.rb', line 42

def clone(overrides = {}) = self.class.new(**to_h.merge(**overrides))

#element_classesObject

This can be overridden to return an array of extra class names, or a string of class names.



32
33
# File 'lib/vident/component.rb', line 32

def element_classes
end

#idObject

Generate a unique ID for a component, can be overridden as required. Makes it easier to setup things like ARIA attributes which require elements to reference by ID. Note this overrides the ‘id` accessor



51
# File 'lib/vident/component.rb', line 51

def id = @id.presence || random_id

#inspect(klass_name = "Component") ⇒ Object



44
45
46
47
# File 'lib/vident/component.rb', line 44

def inspect(klass_name = "Component")
  attr_text = to_h.map { |k, v| "#{k}=#{v.inspect}" }.join(", ")
  "#<#{self.class.name}<Vident::#{klass_name}> #{attr_text}>"
end

#root_element_attributesObject

Properties/attributes passed to the “root” element of the component. You normally override this method to return a hash of attributes that should be applied to the root element of your component.



37
38
39
# File 'lib/vident/component.rb', line 37

def root_element_attributes
  {}
end