Class: Crm::ClipboardButtonComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- Crm::ClipboardButtonComponent
- Defined in:
- app/components/crm/clipboard_button_component.rb
Overview
Unified clipboard copy button component.
Supports icon mode (copy button) and text mode (clickable text that copies).
Includes visual feedback on click via CSS class.
Link behavior:
- If url: is provided → automatically copies as rich HTML link
- Plain text always copies the display text (not the URL)
- With include_url_in_text: true → plain text includes URL: "Text "
Constant Summary collapse
- RICH_LINK_STYLE =
Default styling for rich text links
'color:#307e6b;text-decoration-style:double'
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(text:, mode: :icon, url: nil, link_text: nil, copy_value: nil, include_url_in_text: false, button_class: nil, title: nil) ⇒ ClipboardButtonComponent
constructor
A new instance of ClipboardButtonComponent.
Constructor Details
#initialize(text:, mode: :icon, url: nil, link_text: nil, copy_value: nil, include_url_in_text: false, button_class: nil, title: nil) ⇒ ClipboardButtonComponent
Returns a new instance of ClipboardButtonComponent.
33 34 35 36 37 38 39 40 41 42 |
# File 'app/components/crm/clipboard_button_component.rb', line 33 def initialize(text:, mode: :icon, url: nil, link_text: nil, copy_value: nil, include_url_in_text: false, button_class: nil, title: nil) @text = text @mode = mode @url = url @link_text = link_text || text @copy_value = copy_value @include_url_in_text = include_url_in_text @button_class = || @title = title || 'Copy to clipboard' end |
Instance Method Details
#call ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'app/components/crm/clipboard_button_component.rb', line 44 def call tag.( type: 'button', class: combined_classes, data: controller_data, title: @title ) do content.presence || end end |