Yassine Doghri c0e66d5f70 feat: enhance ui using javascript in admin area
- bundle js using parcel
- add markdown editor, html editor, dropdown and tooltip features using third-party packages
- integrate optimized inline svg icons from RemixIcon using svgo and a php helper
- add scripts in package.json to bundle icons, images, css and js
- update tailwind config to add purgecss lookups and typography plugin
- refactor views to add missing pages in user journey
- update admin's holy grail layout using css grid
2020-10-15 14:41:09 +00:00

57 lines
1.5 KiB
JavaScript

import { createPopper } from "@popperjs/core";
const Dropdown = () => {
const dropdownContainers = document.querySelectorAll(
"[data-toggle='dropdown']"
);
for (let i = 0; i < dropdownContainers.length; i++) {
const dropdownContainer = dropdownContainers[i];
const button = dropdownContainer.querySelector("[data-popper='button']");
const menu = dropdownContainer.querySelector("[data-popper='menu']");
const popper = createPopper(button, menu, {
placement: menu.dataset.popperPlacement,
modifiers: [
{
name: "offset",
options: {
offset: [menu.dataset.popperOffsetX, menu.dataset.popperOffsetY],
},
},
],
});
const dropdownToggle = () => {
const isExpanded = !menu.classList.contains("hidden");
if (isExpanded) {
menu.classList.add("hidden");
menu.classList.remove("flex");
} else {
menu.classList.add("flex");
menu.classList.remove("hidden");
}
button.setAttribute("aria-expanded", isExpanded);
popper.update();
};
// Toggle dropdown menu on button click event
button.addEventListener("click", dropdownToggle);
// Toggle off when clicking outside of dropdown
document.addEventListener("click", function (event) {
const isExpanded = !menu.classList.contains("hidden");
const isClickOutside = !dropdownContainer.contains(event.target);
if (isExpanded && isClickOutside) {
dropdownToggle();
}
});
}
};
export default Dropdown;