Module: ClipboardHelper
- Defined in:
- app/helpers/clipboard_helper.rb
Overview
Unified clipboard copy functionality.
Provides consistent copy-to-clipboard behavior across the application.
All modes include visual feedback on click via CSS animation.
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 "
Usage:
<%# Icon button (default) - copies plain text %>
<%= clipboard_copy(@text) %>
<%# Text button - shows text, copies plain text %>
<%= clipboard_copy(@reference_number, mode: :text) %>
<%# Text button with rich link (plain text = "TTK51040", rich = link) %>
<%= clipboard_copy(@reference_number, mode: :text, url: order_url(@order)) %>
<%# Include URL in plain text copy ("TTK51040 https://...") %>
<%= clipboard_copy(@reference_number, mode: :text, url: order_url(@order), include_url_in_text: true) %>
<%# Display label but copy different value %>
<%= clipboard_copy('Copy Link', mode: :text, copy_value: @url) %>
<%# Custom button class %>
<%= clipboard_copy(@text, button_class: 'btn btn-primary') %>
Instance Method Summary collapse
-
#clipboard_copy(text, mode: :icon, url: nil, link_text: nil, copy_value: nil, include_url_in_text: false, button_class: nil, title: nil) ⇒ String
Renders a clipboard copy button with visual feedback.
Instance Method Details
#clipboard_copy(text, mode: :icon, url: nil, link_text: nil, copy_value: nil, include_url_in_text: false, button_class: nil, title: nil) ⇒ String
Renders a clipboard copy button with visual feedback.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/helpers/clipboard_helper.rb', line 45 def clipboard_copy(text, mode: :icon, url: nil, link_text: nil, copy_value: nil, include_url_in_text: false, button_class: nil, title: nil) return nil if text.blank? render Crm::ClipboardButtonComponent.new( text: text, mode: mode, url: url, link_text: link_text, copy_value: copy_value, include_url_in_text: include_url_in_text, button_class: , title: title ) end |