0
0
Fork 0

React component helper specs (#24072)

This commit is contained in:
Matt Jankowski 2023-04-26 12:21:32 -04:00 committed by GitHub
parent 3029aeb838
commit 91a8cd21d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 266 additions and 83 deletions

View file

@ -0,0 +1,23 @@
# frozen_string_literal: true
module ReactComponentHelper
def react_component(name, props = {}, &block)
data = { component: name.to_s.camelcase, props: Oj.dump(props) }
if block.nil?
div_tag_with_data(data)
else
content_tag(:div, data: data, &block)
end
end
def react_admin_component(name, props = {})
data = { 'admin-component': name.to_s.camelcase, props: Oj.dump({ locale: I18n.locale }.merge(props)) }
div_tag_with_data(data)
end
private
def div_tag_with_data(data)
content_tag(:div, nil, data: data)
end
end