5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/lcp_ruby/display/renderers/copy_code.rb', line 5
def render(value, options = {}, record: nil, view_context: nil)
return "" if value.blank?
text = value.to_s
button_label = options["button_label"] ||
I18n.t("lcp_ruby.actions.copy", default: "Copy")
view_context.content_tag(
:div,
class: "lcp-copy-code",
data: { controller: "clipboard" }
) do
code = view_context.content_tag(:code, text, class: "lcp-copy-code__value")
button = view_context.button_tag(
button_label,
type: "button",
class: "lcp-copy-code__btn",
data: {
action: "clipboard#copy",
clipboard_text_value: text
}
)
view_context.safe_join([ code, button ])
end
end
|