1
0
mirror of https://github.com/mastodon/mastodon synced 2024-12-21 18:18:13 +09:00
mastodon/app/helpers/react_component_helper.rb

24 lines
540 B
Ruby
Raw Normal View History

2023-04-27 01:21:32 +09:00
# 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(props) }
2023-04-27 01:21:32 +09:00
div_tag_with_data(data)
end
private
def div_tag_with_data(data)
content_tag(:div, nil, data: data)
end
end