module StimulusAttrs::DefaultIdentifier extend ActiveSupport::Concern module ClassMethods def identifier_for_stimulus_attrs # Convert things like 'Admin::UserAvatarComponent' to 'admin--user-avatar' @identifier_for_stimulus_attrs ||= name.gsub('::Component', '').gsub(/Component$/, '') .underscore.gsub('/', '--').gsub('_', '-') end end def identifier_for_stimulus_attrs self.class.identifier_for_stimulus_attrs end ViewComponent::Base.include(self) if defined?(ViewComponent::Base) Phlex::HTML.include(self) if defined?(Phlex::HTML) end