2021-04-15 13:01:58 +01:00
|
|
|
import ClipboardJS from "clipboard";
|
2021-04-29 10:38:42 +01:00
|
|
|
import { addClipboardNotifications } from "../pageUtils.js";
|
2021-04-15 13:01:58 +01:00
|
|
|
import { makeFormIcon, makeElement } from "../htmlUtils.js";
|
|
|
|
import { MarginInline } from "./MarginInline.js";
|
|
|
|
|
|
|
|
export function CopyableInputBox(text, copyable = true) {
|
|
|
|
let inputBoxDiv = makeElement({ tag: "div" });
|
|
|
|
let inputBoxCopyButton = null;
|
|
|
|
if (copyable) {
|
|
|
|
inputBoxCopyButton = makeFormIcon("copy");
|
|
|
|
let clipboard = new ClipboardJS(inputBoxCopyButton);
|
2021-04-29 10:38:42 +01:00
|
|
|
addClipboardNotifications(clipboard, 600);
|
2021-04-15 13:01:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
let inputBoxInput = makeElement({
|
|
|
|
tag: "input",
|
|
|
|
class: ["uk-input"],
|
|
|
|
attributes: { "readonly": true, "type": "text" },
|
|
|
|
});
|
|
|
|
|
|
|
|
let inputBoxInner = MarginInline([
|
|
|
|
inputBoxCopyButton,
|
|
|
|
inputBoxInput
|
|
|
|
]);
|
|
|
|
inputBoxDiv.appendChild(inputBoxInner);
|
|
|
|
|
|
|
|
inputBoxDiv.setText = function (text) {
|
|
|
|
inputBoxInput.value = `${text}`;
|
|
|
|
if (copyable) {
|
|
|
|
inputBoxCopyButton.dataset.clipboardText = `${text}`;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
inputBoxDiv.setText(text);
|
|
|
|
|
|
|
|
|
|
|
|
return inputBoxDiv;
|
|
|
|
}
|