Sha256: 244077ebc507f4990e78e05455e93ddf8e71a9d2a34beccc657c2e8dda3364ce

Contents?: true

Size: 1.45 KB

Versions: 37

Compression:

Stored size: 1.45 KB

Contents

# frozen_string_literal: true

module Primer
  module Beta
    # Use `ClipboardCopy` to copy element text content or input values to the clipboard.
    #
    # This component by itself is not styled as a button, and can therefore only be used in limited circumstances.
    # If you're looking for a button, consider using <%= link_to_component(Primer::Beta::ClipboardCopyButton) %>
    # instead.
    #
    # @accessibility
    #   Always set an accessible label to help the user interact with the component.
    class ClipboardCopy < Primer::Component
      status :beta

      # @param aria-label [String] String that will be read to screenreaders when the component is focused
      # @param value [String] Text to copy into the users clipboard when they click the component.
      # @param for [String] Element id from where to get the copied value.
      # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
      def initialize(value: nil, **system_arguments)
        @system_arguments = deny_tag_argument(**system_arguments)
        @value = value

        validate!

        @system_arguments[:tag] = "clipboard-copy"
        @system_arguments[:value] = value if value.present?
      end

      # :nodoc:
      def before_render
        validate_aria_label if content.blank?
      end

      private

      def validate!
        raise ArgumentError, "Must provide either `value` or `for`" if @value.nil? && @system_arguments[:for].nil?
      end
    end
  end
end

Version data entries

37 entries across 37 versions & 2 rubygems

Version Path
openproject-primer_view_components-0.32.1 app/components/primer/beta/clipboard_copy.rb
openproject-primer_view_components-0.32.0 app/components/primer/beta/clipboard_copy.rb
openproject-primer_view_components-0.29.1 app/components/primer/beta/clipboard_copy.rb
openproject-primer_view_components-0.29.0 app/components/primer/beta/clipboard_copy.rb
primer_view_components-0.23.0 app/components/primer/beta/clipboard_copy.rb
openproject-primer_view_components-0.28.1 app/components/primer/beta/clipboard_copy.rb
openproject-primer_view_components-0.28.0 app/components/primer/beta/clipboard_copy.rb
openproject-primer_view_components-0.27.0 app/components/primer/beta/clipboard_copy.rb
openproject-primer_view_components-0.26.0 app/components/primer/beta/clipboard_copy.rb
openproject-primer_view_components-0.25.1 app/components/primer/beta/clipboard_copy.rb
primer_view_components-0.22.0 app/components/primer/beta/clipboard_copy.rb
primer_view_components-0.21.1 app/components/primer/beta/clipboard_copy.rb
openproject-primer_view_components-0.25.0 app/components/primer/beta/clipboard_copy.rb
openproject-primer_view_components-0.24.0 app/components/primer/beta/clipboard_copy.rb
primer_view_components-0.21.0 app/components/primer/beta/clipboard_copy.rb
primer_view_components-0.20.1 app/components/primer/beta/clipboard_copy.rb
primer_view_components-0.20.0 app/components/primer/beta/clipboard_copy.rb
openproject-primer_view_components-0.23.0 app/components/primer/beta/clipboard_copy.rb
primer_view_components-0.19.0 app/components/primer/beta/clipboard_copy.rb
openproject-primer_view_components-0.22.2 app/components/primer/beta/clipboard_copy.rb