# frozen_string_literal: true module Ariadne # Use `ClipboardCopyComponent` to copy element text content or input values to the clipboard. # # @accessibility # Always set an accessible label to help the user interact with the component. class ClipboardCopyComponent < Ariadne::Component DEFAULT_TAG = :"clipboard-copy" DEFAULT_CLASSES = LinkComponent::DEFAULT_ACTIONABLE_CLASSES DATA_CONTROLLER = "clipboard-copy-component" DATA_ACTION = "click->clipboard-copy-component#copy" # `Tooltip` that appears on mouse hover or keyboard focus over the button. Use tooltips sparingly and as a last resort. # **Important:** This tooltip defaults to `type: :description`. In a few scenarios, `type: :label` may be more appropriate. # Consult the <%= link_to_component(Ariadne::TooltipComponent) %> documentation for more information. # # @param tag [Symbol, String] The rendered tag name # @param text [String] The text content of the tooltip. This should be brief and no longer than a sentence. # @param direction [Symbol] <%= one_of(Ariadne::TooltipComponent::VALID_PLACEMENTS) %> # @param classes [String] <%= link_to_classes_docs %> # @param attributes [Hash] Same arguments as <%= link_to_component(Ariadne::TooltipComponent) %>. renders_one :tooltip, lambda { |tag: Ariadne::TooltipComponent::DEFAULT_TAG, text:, direction: Ariadne::TooltipComponent::DEFAULT_PLACEMENT, type: Ariadne::TooltipComponent::TYPE_DEFAULT, classes: "", attributes: {}| raise ArgumentError, "CopyClipboardComponents with a tooltip must have a unique `id` set on the `CopyClipboardComponent`." if @id.blank? @data_tooltip_direction = { "data-tooltip-component-direction": direction } Ariadne::TooltipComponent.new(tag: tag, for_id: @id, text: text, direction: direction, type: type, classes: classes, attributes: attributes) } # @example Default # <%= render(Ariadne::ClipboardCopyComponent.new(value: "Text to copy", aria_label: "Copy text to the system clipboard" )) %> # # @example With text instead of icons # <%= render(Ariadne::ClipboardCopyComponent.new(value: "Text to copy", aria_label: "Copy text to the system clipboard" )) do %> # Click to copy! # <% end %> # # @example Copying from an element # <%= render(Ariadne::ClipboardCopyComponent.new(for_id: "blob-path", aria_label: "Copy text to the system clipboard" )) %> #