Class: Ariadne::UI::ClipboardCopy::Component

Inherits:
Button::Component show all
Defined in:
app/components/ariadne/ui/clipboard_copy/component.rb

Overview

Use ‘ClipboardCopy` to copy element text content or input values to the clipboard.

Examples:

Default

<%= render(Ariadne::UI::ClipboardCopy::Component.new(value: "Text to copy", aria_label: "Copy text to the system clipboard" )) %>

With text instead of icons

<%= render(Ariadne::UI::ClipboardCopy::Component.new(value: "Text to copy", aria_label: "Copy text to the system clipboard" )) do %>
  Click to copy!
<% end %>

Copying from an element

<%= render(Ariadne::UI::ClipboardCopy::Component.new(for_id: "blob-path", aria_label: "Copy text to the system clipboard" )) %>
<div id="blob-path">src/index.js</div>

Constant Summary

Constants inherited from BaseComponent

BaseComponent::ACCEPT_ANYTHING

Constants included from ViewHelper

ViewHelper::HELPERS

Constants included from AttributesHelper

AttributesHelper::PLURAL_ARIA_ATTRIBUTES, AttributesHelper::PLURAL_DATA_ATTRIBUTES

Instance Attribute Summary

Attributes inherited from Button::Component

#icon_only

Instance Method Summary collapse

Methods inherited from Button::Component

#as_icon, #icon_or_svg

Methods included from Behaviors::Tooltipable

#with_tooltip

Methods included from Behaviors::Captionable

#with_caption

Methods inherited from BaseComponent

#class_for, #component, component_id, #component_id, component_name, #html_attributes, i18n_scope, #in_turbo_frame, #in_turbo_stream, #options, stimulus_name, #styles, translate, #validate_aria_label!

Methods included from ViewHelper

generate_id

Methods included from AttributesHelper

#aria, #data, #merge_aria, #merge_data, #merge_prefixed_attribute_hashes, #prepend_action, #prepend_controller, #prepend_data_attribute

Methods included from ViewComponent::StyleVariants

#merged_styles

Constructor Details

#initialize(**options) ⇒ Component

Returns a new instance of Component.



29
30
31
32
# File 'app/components/ariadne/ui/clipboard_copy/component.rb', line 29

def initialize(**options)
  super
  validate!
end

Instance Method Details

#before_renderObject



48
49
50
# File 'app/components/ariadne/ui/clipboard_copy/component.rb', line 48

def before_render
  validate_aria_label!(html_attrs) if content.blank?
end

#classesObject



57
58
59
# File 'app/components/ariadne/ui/clipboard_copy/component.rb', line 57

def classes
  style(:button, size:) + style(:size)
end