2021-05-03 09:25:42 +01:00
|
|
|
import { MarginInline } from "./MarginInline.js";
|
2021-04-29 10:38:42 +01:00
|
|
|
import { addClipboardNotifications } from "../pageUtils.js";
|
2021-04-29 11:12:17 +01:00
|
|
|
import { makeElement } from "../htmlUtils.js";
|
2021-05-03 09:25:42 +01:00
|
|
|
import ClipboardJS from "clipboard";
|
2021-04-29 11:12:17 +01:00
|
|
|
import i18next from "i18next";
|
2021-04-15 13:01:58 +01:00
|
|
|
|
|
|
|
export function CopyableInputBox(text, copyable = true) {
|
|
|
|
let inputBoxDiv = makeElement({ tag: "div" });
|
|
|
|
let inputBoxCopyButton = null;
|
|
|
|
if (copyable) {
|
2021-04-29 11:12:17 +01:00
|
|
|
inputBoxCopyButton = makeElement({
|
|
|
|
tag: "a",
|
|
|
|
class: "uk-form-icon",
|
|
|
|
attributes: {
|
|
|
|
"uk-icon": "icon: copy",
|
|
|
|
"role": "img",
|
|
|
|
"aria-label": i18next.t("copy_input_box_copy_icon_text")
|
2021-05-07 12:07:51 +01:00
|
|
|
},
|
|
|
|
thenRun: (e) => {
|
|
|
|
let clipboard = new ClipboardJS(e);
|
|
|
|
addClipboardNotifications(clipboard, 600);
|
2021-04-29 11:12:17 +01:00
|
|
|
}
|
|
|
|
});
|
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;
|
|
|
|
}
|