Module: Vident::Component
- Extended by:
- ActiveSupport::Concern
- Includes:
- ChildElementHelper, ComponentAttributeResolver, ComponentClassLists, StimulusComponent, StimulusHelper, Tailwind
- Defined in:
- lib/vident/component.rb
Instance Method Summary collapse
-
#after_component_initialize ⇒ Object
Override this method to perform any initialisation after attributes are set.
-
#clone(overrides = {}) ⇒ Object
Create a new component instance with optional overrides for properties.
-
#id ⇒ Object
Generate a unique ID for a component, can be overridden as required.
- #inspect(klass_name = "Component") ⇒ Object
-
#prop_names ⇒ Object
Return the names of the properties defined in the component class.
-
#root_element_attributes ⇒ Object
Properties/attributes passed to the “root” element of the component.
-
#root_element_classes ⇒ Object
This can be overridden to return an array of extra class names, or a string of class names.
Methods included from StimulusHelper
#resolve_values_from_props, #stimulus_dsl_attributes
Methods included from Tailwind
#tailwind_merge_available?, #tailwind_merger
Methods included from ChildElementHelper
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_initialize ⇒ Object
Override this method to perform any initialisation after attributes are set
35 36 |
# File 'lib/vident/component.rb', line 35 def after_component_initialize end |
#clone(overrides = {}) ⇒ Object
Create a new component instance with optional overrides for properties.
49 |
# File 'lib/vident/component.rb', line 49 def clone(overrides = {}) = self.class.new(**to_h.merge(**overrides)) |
#id ⇒ Object
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
58 |
# File 'lib/vident/component.rb', line 58 def id = @id.presence || random_id |
#inspect(klass_name = "Component") ⇒ Object
51 52 53 54 |
# File 'lib/vident/component.rb', line 51 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 |
#prop_names ⇒ Object
Return the names of the properties defined in the component class.
62 63 64 |
# File 'lib/vident/component.rb', line 62 def prop_names self.class.prop_names end |
#root_element_attributes ⇒ Object
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.
44 45 46 |
# File 'lib/vident/component.rb', line 44 def root_element_attributes {} end |
#root_element_classes ⇒ Object
This can be overridden to return an array of extra class names, or a string of class names.
39 40 |
# File 'lib/vident/component.rb', line 39 def root_element_classes end |