Class: Components::CopyableText

Inherits:
Base
  • Object
show all
Defined in:
app/components/copyable_text.rb

Instance Method Summary collapse

Constructor Details

#initialize(text:, label: nil, obfuscated: false) ⇒ CopyableText

Returns a new instance of CopyableText.



2
3
4
5
6
# File 'app/components/copyable_text.rb', line 2

def initialize(text:, label: nil, obfuscated: false)
  @text = text
  @label = label
  @obfuscated = obfuscated
end

Instance Method Details

#before_template ⇒ Object



8
9
10
# File 'app/components/copyable_text.rb', line 8

def before_template
  @label ||= t("components.copy_button.copy")
end

#view_template ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/components/copyable_text.rb', line 12

def view_template
  div(data: {controller: "obfuscated-text"}) do
    span(class: @obfuscated ? "obfuscated" : nil) { @text }
    whitespace
    if @obfuscated
      button class: "btn btn-sm btn-outline-secondary", title: t("components.copyable_text.reveal"), data: {action: "click->obfuscated-text#toggle:prevent"} do
        Icon icon: "eye"
      end
    end
    whitespace
    button class: "btn btn-sm btn-outline-secondary", title: @label, data: {controller: "copy-text", action: "click->copy-text#copy:prevent", copy_text_text_value: @text} do
      Icon icon: "clipboard-plus"
    end
  end
end