Class: Railsboot::CopyToClipboardComponent
- Inherits:
-
Component
- Object
- Component
- Railsboot::CopyToClipboardComponent
- Defined in:
- app/components/railsboot/copy_to_clipboard_component.rb
Overview
ViewComponent: renders the copy to clipboard block.
Instance Method Summary collapse
-
#default_button ⇒ String
Renders the default copy-to-clipboard button with a copy icon.
-
#initialize(**html_attributes) ⇒ CopyToClipboardComponent
constructor
A new instance of CopyToClipboardComponent.
-
#render? ⇒ Boolean
Whether the component should render.
Constructor Details
#initialize(**html_attributes) ⇒ CopyToClipboardComponent
Returns a new instance of CopyToClipboardComponent.
6 7 8 9 10 11 12 13 14 15 |
# File 'app/components/railsboot/copy_to_clipboard_component.rb', line 6 def initialize(**html_attributes) @html_attributes = html_attributes # Set default class and merge with provided classes default_class = 'd-inline-block' provided_class = @html_attributes.delete(:class) @html_attributes[:class] = provided_class ? "#{default_class} #{provided_class}" : default_class @html_attributes['data-controller'] = 'copy-to-clipboard' end |
Instance Method Details
#default_button ⇒ String
Renders the default copy-to-clipboard button with a copy icon.
26 27 28 29 30 31 32 33 |
# File 'app/components/railsboot/copy_to_clipboard_component.rb', line 26 def content_tag :button, type: 'button', class: 'btn btn-sm btn-outline-secondary', data: { action: 'copy-to-clipboard#copy' }, title: 'Copy URL to clipboard' do content_tag :i, nil, class: 'fas fa-copy' end end |
#render? ⇒ Boolean
Whether the component should render. When a block is given, renders only
if the block produced content; otherwise always renders.
20 21 22 |
# File 'app/components/railsboot/copy_to_clipboard_component.rb', line 20 def render? block_given? ? content.present? : true end |