Last active
February 1, 2021 15:04
-
-
Save rotaliator/73daca2dc93c586122a0da57189ece13 to your computer and use it in GitHub Desktop.
#clojurescript copy to clipboard by Robert Stuttaford @RobStuttaford
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; https://twitter.com/RobStuttaford/status/1095434901950734337 | |
(defn copy-to-clipboard [val] | |
(let [el (js/document.createElement "textarea")] | |
(set! (.-value el) val) | |
(.appendChild js/document.body el) | |
(.select el) | |
(js/document.execCommand "copy") | |
(.removeChild js/document.body el))) | |
(defn copyable-label [value] | |
[:a.tooltip.is-tooltip-left | |
{:href "javascript:" | |
:data-tooltip "Click to Copy" | |
:on-click #(do (.stopPropagation %) | |
(copy-to-clipboard value))} | |
[:code value]]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You are right, thanks!