import {EmojiButton} from "@joeattardi/emoji-button"; // eslint-disable-next-line require-jsdoc export default function addInputEmoji() { const containers = document.querySelectorAll("[data-input-emoji]"); if (containers.length) { containers.forEach((elem) => { const picker = new EmojiButton({ position: "bottom-end", rootElement: elem.closest("form")?.parentElement || document.body, zIndex: 2000 }); // if the selector is inside a modal window // this allows shows the emoji menu uncut const reveal = elem.closest("[data-reveal]") if (reveal) { reveal.style.overflowY = "unset" } const wrapper = document.createElement("div"); wrapper.className = "emoji__container" const btnContainer = document.createElement("div"); btnContainer.className = "emoji__trigger" const btn = document.createElement("div"); btn.className = "emoji__button" btn.innerHTML = '' const parent = elem.parentNode; parent.insertBefore(wrapper, elem); wrapper.appendChild(elem); wrapper.appendChild(btnContainer); btnContainer.appendChild(btn); // The form errors need to be in the same container with the field they // belong to for Foundation Abide to show them automatically. parent.querySelectorAll(".form-error").forEach((el) => wrapper.appendChild(el)); let handlerPicker = function () { picker.togglePicker(btnContainer); } btnContainer.addEventListener("click", handlerPicker); elem.addEventListener("characterCounter", (event) => { if (event.detail.remaining >= 4) { btnContainer.addEventListener("click", handlerPicker); btnContainer.removeAttribute("style"); } else { btnContainer.removeEventListener("click", handlerPicker); btnContainer.setAttribute("style", "color:lightgrey"); } }); picker.on("emoji", ({emoji}) => { elem.value += ` ${emoji} ` const event = new Event("emoji.added"); elem.dispatchEvent(event); }); }) } };