// NCSpinner - shared circular loading spinner component // Served at /shared/js/ui/spinner.js by applySharedBase. // // API: // NCSpinner.create([opts]) -> returns wrapper element (not inserted into DOM) // NCSpinner.show(container, [opts]) -> inserts full-area overlay spinner; returns element // NCSpinner.hide(el) -> removes element from DOM safely // // opts: // size : 'sm'|'md'|'lg'|'xl' - maps to CSS utility class pairs in index.css (default 'lg') // color : CSS text-color utility class from index.css (default 'text-slate-400') // label : accessible label string (default 'Loading...') // text : visible text string displayed below the spinner (default none) // id : optional id attribute on the wrapper // overlay : bool - if true (default), wrapper fills its positioned parent absolutely (function (global) { 'use strict'; var SIZES = { sm: 'h-8 w-8', md: 'h-10 w-10', lg: 'h-12 w-12', xl: 'h-16 w-16' }; var SVG_NS = 'http://www.w3.org/2000/svg'; function makeSvg(sizeClass, color) { var svg = document.createElementNS(SVG_NS, 'svg'); svg.setAttribute('class', 'animate-spin ' + sizeClass + ' ' + color); svg.setAttribute('fill', 'none'); svg.setAttribute('viewBox', '0 0 24 24'); svg.setAttribute('aria-hidden', 'true'); var circle = document.createElementNS(SVG_NS, 'circle'); circle.setAttribute('class', 'opacity-25'); circle.setAttribute('cx', '12'); circle.setAttribute('cy', '12'); circle.setAttribute('r', '10'); circle.setAttribute('stroke', 'currentColor'); circle.setAttribute('stroke-width', '4'); svg.appendChild(circle); var path = document.createElementNS(SVG_NS, 'path'); path.setAttribute('class', 'opacity-75'); path.setAttribute('fill', 'currentColor'); path.setAttribute('d', 'M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z'); svg.appendChild(path); return svg; } /** * Create a spinner wrapper element without inserting it. * @param {object} [opts] * @returns {HTMLElement} */ function create(opts) { opts = opts || {}; var size = opts.size || 'md'; var color = opts.color || 'text-slate-400'; var label = opts.label || 'Loading\u2026'; var text = opts.text || ''; var extraCls = opts.wrapClass || ''; var sizeClass = SIZES[size] || size; var wrap = document.createElement('div'); var flexDir = text ? 'flex-col gap-3 ' : ''; wrap.className = ( 'pointer-events-none flex ' + flexDir + 'items-center justify-center ' + extraCls ).trim(); wrap.setAttribute('role', 'status'); wrap.setAttribute('aria-label', label); wrap.appendChild(makeSvg(sizeClass, color)); if (text) { var textEl = document.createElement('div'); textEl.className = 'text-xs font-semibold uppercase tracking-[0.5px] text-[var(--color-text-dim)]'; textEl.textContent = text; wrap.appendChild(textEl); } return wrap; } /** * Insert an overlay spinner as a child of `container` (defaults to document.body). * @param {Element|null} container * @param {object} [opts] * @returns {HTMLElement} the inserted element */ function show(container, opts) { opts = opts || {}; var overlay = opts.overlay !== false; var wrapClass = overlay ? 'absolute inset-0 z-10' : ''; var el = create({ size: opts.size || 'lg', color: opts.color || 'text-slate-400', label: opts.label || 'Loading\u2026', text: opts.text || '', wrapClass: wrapClass, }); if (opts.id) el.id = opts.id; (container || document.body).appendChild(el); return el; } /** * Remove a spinner element previously returned by show(). * @param {Element|null} el */ function hide(el) { try { if (el && el.parentNode) el.parentNode.removeChild(el); // eslint-disable-next-line no-empty } catch {} } global.NCSpinner = { create: create, show: show, hide: hide }; })(window);