Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Added universal clipboard component (#12860)
Damian Legawiecc07400bc38fd
diff --git a/admin/app/assets/stylesheets/spree/admin/components/_buttons.scss b/admin/app/assets/stylesheets/spree/admin/components/_buttons.scssindex 7ac129dd73..1bb65e23d6 100644--- a/admin/app/assets/stylesheets/spree/admin/components/_buttons.scss+++ b/admin/app/assets/stylesheets/spree/admin/components/_buttons.scss@@ -174,6 +174,16 @@ button[disabled] .show-when-enabled { display: none; }}}+.btn-clipboard {+ @extend .btn-light;+ @extend .px-1;+ @extend .ml-2;+ @extend .font-size-sm;++ min-width: 24px;+ height: 24px;+}+.page-link {@extend .btn;@extend .btn-sm;diff --git a/admin/app/helpers/spree/admin/base_helper.rb b/admin/app/helpers/spree/admin/base_helper.rbindex 95ff61c718..2aedd2ec84 100644--- a/admin/app/helpers/spree/admin/base_helper.rb+++ b/admin/app/helpers/spree/admin/base_helper.rb@@ -243,6 +243,44 @@ module Spreecontent_tag(:span, ' *', class: 'required font-weight-bold text-danger')end+ # renders a clipboard button+ # @param options [Hash] the options for the button+ # @option options [String] :class the CSS class(es) of the button+ # @option options [Hash] :data the data attributes for the button+ # @option options [String] :title the title of the button+ # @return [String] the button+ def clipboard_button(options = {})+ options[:class] ||= 'btn btn-clipboard with-tip'+ options[:type] ||= 'button'+ options[:data] ||= {}+ options[:data][:action] = 'clipboard#copy'+ options[:data][:clipboard_target] = 'button'+ options[:data][:title] = Spree.t('admin.copy_to_clipboard')+ options[:aria_label] ||= Spree.t('admin.copy_to_clipboard') # screen-reader label++ content_tag(:button, options) do+ icon('copy', class: 'mr-0 font-size-sm')+ end+ end++ # renders a clipboard component+ # @param text [String] the text to copy+ # @param options [Hash] the options for the component+ # @option options [String] :class the CSS class(es) of the component+ # @option options [Hash] :data the data attributes for the component+ # @option options [String] :title the title of the component+ # @return [String] the component+ def clipboard_component(text, options = {})+ options[:data] ||= {}+ options[:data][:controller] = 'clipboard'+ options[:data][:clipboard_success_content_value] ||= raw(icon('check', class: 'mr-0 font-size-sm'))++ content_tag(:span, data: options[:data]) do+ hidden_field_tag(:clipboard_source, text, data: { clipboard_target: 'source' }) ++ clipboard_button+ end+ end+# returns the allowed file types for upload, according to the active storage configuration# @return [Array<String>] the allowed file types for upload, eg. ['image/png', 'image/jpeg', 'image/gif', 'image/webp']def allowed_file_types_for_uploaddiff --git a/admin/app/views/spree/admin/coupon_codes/_coupon_code.html.erb b/admin/app/views/spree/admin/coupon_codes/_coupon_code.html.erbindex 9822600023..3475122021 100644--- a/admin/app/views/spree/admin/coupon_codes/_coupon_code.html.erb+++ b/admin/app/views/spree/admin/coupon_codes/_coupon_code.html.erb@@ -1,11 +1,7 @@<tr id="spree_coupon_code_<%= coupon_code[0] %>"><td class="w-50">- <div data-controller="clipboard">- <code data-clipboard-target="source"><%= coupon_code[1].upcase %></code>- <button type="button" class="btn btn-light p-1 ml-2 with-tip" data-action="clipboard#copy" title="<%= Spree.t('admin.copy_to_clipboard') %>">- <%= icon('copy-check', class: 'mr-0 font-size-sm') %>- </button>- </div>+ <code><%= coupon_code[1].upcase %></code>+ <%= clipboard_component(coupon_code[1].upcase) %></td><td class="w-25 font-size-sm"><%= active_badge(coupon_code[2] == 'used') %></td><td class="w-25 font-size-sm"><%= local_time(coupon_code[3]) %></td>diff --git a/admin/app/views/spree/admin/dashboard/_store_preview.html.erb b/admin/app/views/spree/admin/dashboard/_store_preview.html.erbindex e0d7c26305..fd17b8e8cf 100644--- a/admin/app/views/spree/admin/dashboard/_store_preview.html.erb+++ b/admin/app/views/spree/admin/dashboard/_store_preview.html.erb@@ -12,15 +12,9 @@<% end %><div class="card-body px-2 pt-0 pb-2">- <div class="flex my-2 p-1 w-100 rounded border" data-controller="clipboard" data-clipboard-success-content-value="Copied!">- <% if current_store.default_custom_domain&.active? %>- <%= text_field_tag :custom_domain, current_store.default_custom_domain.url, readonly: true, class: 'form-control-plaintext py-0', data: { clipboard_target: 'source' } %>- <% else %>- <%= text_field_tag :domain, current_store.url, readonly: true, class: 'form-control-plaintext py-0', data: { clipboard_target: 'source' } %>- <% end %>- <button data-action="clipboard#copy" data-clipboard-target="button" class="btn btn-sm py-1 hover-gray">- Copy- </button>+ <div class="flex my-2 p-1 w-100 rounded border">+ <%= text_field_tag :domain, current_store.url_or_custom_domain, readonly: true, class: 'form-control-plaintext py-0' %>+ <%= clipboard_component(current_store.url_or_custom_domain) %></div><div class="d-flex">diff --git a/admin/app/views/spree/admin/orders/_customer.html.erb b/admin/app/views/spree/admin/orders/_customer.html.erbindex 375afb0ab9..d369aa443a 100644--- a/admin/app/views/spree/admin/orders/_customer.html.erb+++ b/admin/app/views/spree/admin/orders/_customer.html.erb@@ -37,7 +37,10 @@<%= render 'spree/admin/shared/user', user: @order.user %><%= render 'spree/admin/orders/user_overview', user: @order.user %><% elsif @order.email.present? %>- <%= mail_to truncate(@order.email, length: 35), class: 'text-dark with-tip', title: @order.email %>+ <div class="d-flex align-items-center w-100">+ <%= mail_to @order.email, @order.email, class: 'text-blue' %>+ <%= clipboard_component(@order.email) %>+ </div><% else %><span class="text-muted"><%= Spree.t(:no_email_provided) %>diff --git a/admin/app/views/spree/admin/promotions/_sidebar.html.erb b/admin/app/views/spree/admin/promotions/_sidebar.html.erbindex 60d26428ec..c2f62b12d7 100644--- a/admin/app/views/spree/admin/promotions/_sidebar.html.erb+++ b/admin/app/views/spree/admin/promotions/_sidebar.html.erb@@ -75,16 +75,11 @@</li><% if @promotion.code.present? %>- <li class="list-group-item d-flex justify-content-between align-items-center py-2" data-controller="clipboard" data-clipboard-success-content="Copied!">+ <li class="list-group-item d-flex justify-content-between align-items-center py-2"><span class="text-muted"><%= Spree.t(:coupon_code) %></span><div class="d-flex align-items-center gap-1">- <span class="form-control form-control-sm">- <span data-clipboard-target="source"><%= @promotion.code.upcase %></span>- </span>-- <button type="button" class="btn btn-light btn-sm with-tip p-1" data-action="clipboard#copy" title="<%= Spree.t(:copy) %>">- <%= icon 'copy', class: 'mr-0' %>- </button>+ <code><%= @promotion.code.upcase %></code>+ <%= clipboard_component(@promotion.code.upcase) %></div></li><% end %>diff --git a/admin/app/views/spree/admin/shared/_user.html.erb b/admin/app/views/spree/admin/shared/_user.html.erbindex 4c5c3b837f..023dd5aa82 100644--- a/admin/app/views/spree/admin/shared/_user.html.erb+++ b/admin/app/views/spree/admin/shared/_user.html.erb@@ -1,4 +1,4 @@-<%= link_to spree.admin_user_path(user), class: 'rounded hover-light p-2 d-flex justify-content-start align-items-center', data: {turbo_frame: :_top, row_link_target: :link} do %>+<%= link_to spree.admin_user_path(user), class: 'rounded p-2 d-flex justify-content-start align-items-center', data: {turbo_frame: :_top, row_link_target: :link} do %><% if user.name.present? %><%= render_avatar(user, width: 48, height: 48, class: 'mr-3 avatar') %><% else %>@@ -13,12 +13,7 @@<span class="text-muted with-tip" title="<%= user.email %>"><%= user.email %></span>- <span data-controller="clipboard">- <%= hidden_field_tag :user_email, user.email, data: { clipboard_target: 'source' } %>- <button data-action="clipboard#copy" class="btn btn-sm text-muted with-tip mx-1" title="Copy email">- <%= icon 'files', class: 'mr-0' %>- </button>- </span>+ <%= clipboard_component(user.email) %><% end %></div><% end %>diff --git a/admin/app/views/spree/admin/users/_details.html.erb b/admin/app/views/spree/admin/users/_details.html.erbindex fe2a812897..5123feba14 100644--- a/admin/app/views/spree/admin/users/_details.html.erb+++ b/admin/app/views/spree/admin/users/_details.html.erb@@ -12,6 +12,7 @@<%= Spree.t(:email) %><span><%= @user.email %>+ <%= clipboard_component(@user.email) %></span></li><li class="list-group-item d-flex justify-content-between align-items-center">