Sha256: b99a73ebfcdfd05c0f9f8767e7f54519d65040e676448eb82aec5c539b94a86b
Contents?: true
Size: 1.12 KB
Versions: 21
Compression:
Stored size: 1.12 KB
Contents
# frozen_string_literal: true require 'view_component' class Proscenium::ViewComponent < ViewComponent::Base extend ActiveSupport::Autoload autoload :TagBuilder autoload :ReactComponent def render_in(...) cssm.compile_class_names(super(...)) end def before_render side_load_assets unless self.class < ReactComponent end def css_module(name) cssm.class_names!(name).join ' ' end private # Side load any CSS/JS assets for the component. This will side load any `index.{css|js}` in # the component directory. def side_load_assets Proscenium::SideLoad.append asset_path if Rails.application.config.proscenium.side_load end def asset_path @asset_path ||= "app/components#{virtual_path}" end def cssm @cssm ||= Proscenium::CssModule.new(asset_path) end # Overrides ActionView::Helpers::TagHelper::TagBuilder, allowing us to intercept the # `css_module` option from the HTML options argument of the `tag` and `content_tag` helpers, and # prepend it to the HTML `class` attribute. def tag_builder @tag_builder ||= Proscenium::ViewComponent::TagBuilder.new(self) end end
Version data entries
21 entries across 21 versions & 1 rubygems