stackchain-dashboard/frontend/mobile-task-dock.js
timmy 51ac802d77
All checks were successful
CI / lint (pull_request) Successful in 23s
CI / build-frontend (pull_request) Successful in 5s
feat: add mobile attention queue (#244)
2026-08-08 00:00:21 +00:00

54 lines
1.6 KiB
JavaScript

(function (root, factory) {
if (typeof module === 'object' && module.exports) module.exports = factory;
else root.createMobileTaskDock = factory;
})(typeof self !== 'undefined' ? self : this, function createMobileTaskDock(options) {
const nav = options.nav;
const buttons = options.buttons;
const overlays = options.overlays || [];
let launcher = null;
let wasHidden = false;
function select(name) {
Object.entries(buttons).forEach(([key, button]) => {
if (key === name) button.setAttribute('aria-current', 'page');
else button.removeAttribute('aria-current');
});
}
function refreshVisibility() {
const hidden = overlays.some(overlay => overlay.classList.contains('open'));
nav.hidden = hidden;
if (wasHidden && !hidden && launcher) launcher.focus();
wasHidden = hidden;
}
function start() {
Object.entries(buttons).forEach(([name, button]) => {
button.addEventListener('click', event => {
launcher = event.currentTarget;
select(name);
options.actions[name]();
});
});
options.observe(refreshVisibility, overlays);
refreshVisibility();
}
function updateAttention(count) {
const total = Math.max(0, Number(count) || 0);
const badge = options.attentionBadge;
if (badge) {
badge.textContent = String(total);
badge.hidden = total === 0;
}
if (buttons.work) {
buttons.work.setAttribute(
'aria-label',
total ? 'Work, ' + total + ' items need attention' : 'Work'
);
}
}
return {start, refreshVisibility, updateAttention};
});