UNPKG

gentelella

Version:

Gentelella v4 — free admin template. 60 pages, 20 chart variants, fully interactive inbox & kanban, live theme generator, component playground, PWA-ready. Vite 8, vanilla JS, no Bootstrap, no jQuery.

1 lines 2.65 kB
var e=null,t=null,n=null,o='button:not([disabled]), [href], input:not([disabled]):not([type="hidden"]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';function l({skipHook:o=!1}={}){if(!e)return;const l=e;l.classList.remove("show"),document.body.classList.remove("modal-open");const a=()=>{l.isConnected&&l.remove()};l.addEventListener("transitionend",a,{once:!0}),setTimeout(a,280);const d=n,s=t;e=null,n=null,t=null,s&&"function"==typeof s.focus&&s.focus(),o||"function"!=typeof d||d()}function a({title:a,body:d="",actions:s=[],size:c="md",onClose:i}={}){l({skipHook:!0});const r=document.createElement("div");r.className="modal-backdrop";const u=document.createElement("div");u.className=`modal-dialog modal-${c}`,u.setAttribute("role","dialog"),u.setAttribute("aria-modal","true"),a&&u.setAttribute("aria-label",a);const m=document.createElement("div");m.className="modal-header",m.innerHTML=`\n <h2 class="modal-title">${a||""}</h2>\n <button type="button" class="modal-close" aria-label="Close">\n <svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="currentColor" stroke-width="1.5" aria-hidden="true"><path d="M3 3l8 8M11 3l-8 8"/></svg>\n </button>\n `;const p=document.createElement("div");p.className="modal-body",d instanceof HTMLElement?p.appendChild(d):p.innerHTML=d,u.appendChild(m),u.appendChild(p);let b=null;s.length&&(b=document.createElement("div"),b.className="modal-footer",s.forEach(e=>{const t=document.createElement("button");t.type="button",t.className=`btn btn-${e.variant||"outline"}`,t.textContent=e.label,t.addEventListener("click",()=>{!1!==("function"==typeof e.action?e.action({dialog:u,body:p,close:()=>l()}):null)&&!1!==e.closeOnAction&&l()}),b.appendChild(t)}),u.appendChild(b)),r.appendChild(u),document.body.appendChild(r),document.body.classList.add("modal-open"),requestAnimationFrame(()=>r.classList.add("show")),m.querySelector(".modal-close").addEventListener("click",()=>l()),r.addEventListener("click",e=>{e.target===r&&l()}),u.addEventListener("keydown",e=>{if("Tab"!==e.key)return;const t=u.querySelectorAll(o);if(!t.length)return;const n=t[0],l=t[t.length-1];e.shiftKey&&document.activeElement===n?(e.preventDefault(),l.focus()):e.shiftKey||document.activeElement!==l||(e.preventDefault(),n.focus())}),t=document.activeElement,e=r,n=i;const f=p.querySelector(o);return f?f.focus():b&&b.querySelector(".btn-primary")?b.querySelector(".btn-primary").focus():m.querySelector(".modal-close").focus(),{dialog:u,body:p,close:()=>l()}}document.addEventListener("keydown",t=>{"Escape"===t.key&&e&&(t.stopPropagation(),l())});export{a as n,l as t};