Class: Railsboot::CopyToClipboardComponent
- Inherits:
-
Component
- Object
- Component
- Railsboot::CopyToClipboardComponent
- Defined in:
- app/components/railsboot/copy_to_clipboard_component.rb
Instance Method Summary collapse
- #default_button ⇒ Object
-
#initialize(**html_attributes) ⇒ CopyToClipboardComponent
constructor
A new instance of CopyToClipboardComponent.
- #render? ⇒ Boolean
Constructor Details
#initialize(**html_attributes) ⇒ CopyToClipboardComponent
Returns a new instance of CopyToClipboardComponent.
2 3 4 5 6 7 8 9 10 11 |
# File 'app/components/railsboot/copy_to_clipboard_component.rb', line 2 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 ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'app/components/railsboot/copy_to_clipboard_component.rb', line 17 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
13 14 15 |
# File 'app/components/railsboot/copy_to_clipboard_component.rb', line 13 def render? block_given? ? content.present? : true end |