app/components/lookbook/base_component.rb in lookbook-1.0.0.beta.4 vs app/components/lookbook/base_component.rb in lookbook-1.0.0.beta.5
- old
+ new
@@ -8,15 +8,17 @@
@html_attrs[:class] = {"#{@html_attrs[:class]}": true} if @html_attrs[:class].is_a? String
end
def render_component_tag(tag = :div, **attrs, &block)
merged_classes = class_names(attrs[:class], @html_attrs[:class])
- merge_attrs = @html_attrs.except(:class).deep_merge(attrs.except(:class))
+ merged_attrs = @html_attrs.except(:class).deep_merge(attrs.except(:class))
+
+
render Lookbook::TagComponent.new(tag: tag,
name: component_name,
- **merge_attrs,
- x_data: prepare_alpine_data(attrs[:x_data]),
+ **merged_attrs,
+ "x-data": prepare_alpine_data(merged_attrs[:"x-data"]),
class: merged_classes), &block
end
def component_name
self.class.name.chomp("::Component").delete_prefix("Lookbook::").underscore.tr("/", "_").tr("_", "-")
@@ -29,10 +31,10 @@
def alpine_component
nil
end
def prepare_alpine_data(x_data = nil)
- alpine_component_name = x_data || @html_attrs&.dig(:x_data) || alpine_component
+ alpine_component_name = x_data || @html_attrs&.dig(:"x-data") || alpine_component
if alpine_component_name.present?
args = Array.wrap(alpine_data)
args.any? ? "#{alpine_component_name}(#{safe_join(args).gsub(""", "'").tr("\"", "'")})" : alpine_component_name
end
end