Class: Keystone::Ui::CopyButtonComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/keystone/ui/copy_button_component.rb

Constant Summary collapse

BUTTON_CLASSES =
"inline-flex items-center gap-1.5 rounded-md border border-gray-300 bg-white px-3 py-1.5 text-sm font-medium text-gray-700 transition hover:bg-gray-50 dark:border-zinc-600 dark:bg-zinc-800 dark:text-gray-300 dark:hover:bg-zinc-700"
COPY_ICON =
<<~SVG.freeze
  <svg class="h-4 w-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z" /></svg>
SVG

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text:, label: "Copy", success_message: "Copied!", error_message: "Failed!") ⇒ CopyButtonComponent

Returns a new instance of CopyButtonComponent.



14
15
16
17
18
19
# File 'app/components/keystone/ui/copy_button_component.rb', line 14

def initialize(text:, label: "Copy", success_message: "Copied!", error_message: "Failed!")
  @text = text
  @label = label
  @success_message = success_message
  @error_message = error_message
end

Instance Attribute Details

#error_messageObject (readonly)

Returns the value of attribute error_message.



12
13
14
# File 'app/components/keystone/ui/copy_button_component.rb', line 12

def error_message
  @error_message
end

#labelObject (readonly)

Returns the value of attribute label.



12
13
14
# File 'app/components/keystone/ui/copy_button_component.rb', line 12

def label
  @label
end

#success_messageObject (readonly)

Returns the value of attribute success_message.



12
13
14
# File 'app/components/keystone/ui/copy_button_component.rb', line 12

def success_message
  @success_message
end

#textObject (readonly)

Returns the value of attribute text.



12
13
14
# File 'app/components/keystone/ui/copy_button_component.rb', line 12

def text
  @text
end

Instance Method Details

#classesObject



21
22
23
# File 'app/components/keystone/ui/copy_button_component.rb', line 21

def classes
  BUTTON_CLASSES
end

#copy_iconObject



25
26
27
# File 'app/components/keystone/ui/copy_button_component.rb', line 25

def copy_icon
  COPY_ICON
end

#wrapper_dataObject



29
30
31
32
33
34
35
36
# File 'app/components/keystone/ui/copy_button_component.rb', line 29

def wrapper_data
  {
    controller: "clipboard",
    "clipboard-text": @text,
    "clipboard-success-message-value": @success_message,
    "clipboard-error-message-value": @error_message
  }
end