Class: Railsboot::CopyToClipboardComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/railsboot/copy_to_clipboard_component.rb

Instance Method Summary collapse

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_buttonObject



17
18
19
20
21
22
23
24
# File 'app/components/railsboot/copy_to_clipboard_component.rb', line 17

def default_button
   :button, type: 'button',
                      class: 'btn btn-sm btn-outline-secondary',
                      data: { action: 'copy-to-clipboard#copy' },
                      title: 'Copy URL to clipboard' do
     :i, nil, class: 'fas fa-copy'
  end
end

#render?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'app/components/railsboot/copy_to_clipboard_component.rb', line 13

def render?
  block_given? ? content.present? : true
end