From f89cc67fdaaa9c1fdba485dd95e642745c441de6 Mon Sep 17 00:00:00 2001 From: Andrew Dryga Date: Mon, 14 Oct 2024 14:05:14 -0600 Subject: [PATCH] fix(portal): Fix copy-paste buttons (#7033) - Added semi-transparent shadow to the button so that it's more visible when text is overlapping it. Padding did not look well because it required scrollbar to be moved inside the parent container and it looked very ugly - Replaced custom phx hook with a new native Tailwind component Closes #5973 --- elixir/apps/web/assets/js/hooks.js | 35 ------------ .../web/lib/web/components/core_components.ex | 54 ++++++++++++------- 2 files changed, 35 insertions(+), 54 deletions(-) diff --git a/elixir/apps/web/assets/js/hooks.js b/elixir/apps/web/assets/js/hooks.js index da622d65d..e5121b4d8 100644 --- a/elixir/apps/web/assets/js/hooks.js +++ b/elixir/apps/web/assets/js/hooks.js @@ -64,41 +64,6 @@ Hooks.Refocus = { }, }; -Hooks.Copy = { - mounted() { - this.el.addEventListener("click", (ev) => { - ev.preventDefault(); - - let inner_html = ev.currentTarget - .querySelector("[data-copy]") - .innerHTML.trim(); - let doc = new DOMParser().parseFromString(inner_html, "text/html"); - let text = doc.documentElement.textContent; - - let content = ev.currentTarget.querySelector("[data-content]"); - let icon_cl = ev.currentTarget.querySelector("[data-icon]").classList; - - navigator.clipboard.writeText(text).then(() => { - icon_cl.add("hero-clipboard-document-check"); - icon_cl.add("hover:text-accent-500"); - icon_cl.remove("hero-clipboard-document"); - if (content) { - content.innerHTML = "Copied"; - } - }); - - setTimeout(() => { - icon_cl.remove("hero-clipboard-document-check"); - icon_cl.remove("hover:text-accent-500"); - icon_cl.add("hero-clipboard-document"); - if (content) { - content.innerHTML = "Copy"; - } - }, 2000); - }); - }, -}; - /* The phx-disable-with attribute on submit buttons only applies to liveview forms. * However, we need to disable the submit button for regular forms as well to prevent * double submissions and cases where the submit handler is slow (e.g. constant-time auth). diff --git a/elixir/apps/web/lib/web/components/core_components.ex b/elixir/apps/web/lib/web/components/core_components.ex index 475f2f893..1b0a9f106 100644 --- a/elixir/apps/web/lib/web/components/core_components.ex +++ b/elixir/apps/web/lib/web/components/core_components.ex @@ -69,7 +69,7 @@ defmodule Web.CoreComponents do def code_block(assigns) do ~H""" -
+
- <%= render_slot(@inner_block) %> + <%= render_slot(@inner_block) %>
- +
""" end @@ -114,11 +123,18 @@ defmodule Web.CoreComponents do def copy(assigns) do ~H""" -
- <%= render_slot(@inner_block) %> - +
+ <%= render_slot(@inner_block) %> +
""" end