Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

feat[#50212]: Add `OpenProject::Common::ClipboardCopyComponent`

Kabiru Mwenja4629956cf0ae
diff --git a/app/components/open_project/common/clipboard_copy_component.html.erb b/app/components/open_project/common/clipboard_copy_component.html.erb
new file mode 100644
index 00000000000..75eb37c576a
--- /dev/null
+++ b/app/components/open_project/common/clipboard_copy_component.html.erb
@@ -0,0 +1,6 @@
+<%=
+ render(Primer::Beta::Text.new(tag: :div, flex_items: :center, display: :flex)) do
+ concat(render(Primer::Alpha::TextField.new(**text_field_options)))
+ concat(render(Primer::Beta::ClipboardCopy.new(**clipboard_copy_options)))
+ end
+%>
diff --git a/modules/storages/app/forms/storages/admin/clipboard_copy_input_form.rb b/app/components/open_project/common/clipboard_copy_component.rb
similarity index 53%
rename from modules/storages/app/forms/storages/admin/clipboard_copy_input_form.rb
rename to app/components/open_project/common/clipboard_copy_component.rb
index 54ecda7cd7d..9c713bcba81 100644
--- a/modules/storages/app/forms/storages/admin/clipboard_copy_input_form.rb
+++ b/app/components/open_project/common/clipboard_copy_component.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2012-2023 the OpenProject GmbH
@@ -25,23 +27,46 @@
#
# See COPYRIGHT and LICENSE files for more details.
#++
+#
+module OpenProject::Common
+ class ClipboardCopyComponent < ApplicationComponent
+ include OpPrimer::ComponentHelpers
+
+ options visually_hide_label: false,
+ readonly: true,
+ required: false
+
+ def text_field_options
+ { name: @options[:name],
+ label: @options[:label],
+ classes: "rounded-right-0",
+ visually_hide_label:,
+ value: value_to_copy,
+ inset: true,
+ readonly:,
+ required: }
+ end
+
+ def clipboard_copy_options
+ { value: value_to_copy,
+ aria: { label: clipboard_copy_aria_label },
+ classes: clipboard_copy_classes }
+ end
+
+ private
+
+ def clipboard_copy_classes
+ %w[Button Button--iconOnly Button--secondary Button--medium rounded-left-0 border-left-0].tap do |classes|
+ classes << "mt-4" unless visually_hide_label
+ end
+ end
+
+ def clipboard_copy_aria_label
+ @options[:clipboard_copy_aria_label] || I18n.t('button_copy_to_clipboard')
+ end
-module Storages::Admin
- class ClipboardCopyInputForm < ApplicationForm
- # attr_reader :attribute_name
-
- # def initialize(builder, name:, **options)
- # super(builder, **options)
- # @attribute_name = name
- # end
-
- form do |input_form|
- input_form.text_field(
- name: :host,
- label: I18n.t('activerecord.attributes.storages/storage.host'),
- readonly: true,
- required: true
- )
+ def value_to_copy
+ @options[:value_to_copy]
end
end
end