Files
Life-OS/public/system-navigation.js
T

44 lines
7.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/* Windows-inspired categories around the existing settings controls. */
(() => {
const tabs = ['home', 'appearance', 'notifications', 'language', 'data', 'about'];
const symbols = { home: '⌂', appearance: '◈', notifications: '♧', language: '文', data: '▤', about: 'ⓘ' };
const t = (key, values) => LifeI18n.t(`systemNav.${key}`, values);
let active = 'home';
const navigationButton = (id, compact = false) => `<button type="button" class="system-nav-item ${active === id ? 'selected' : ''} ${compact ? 'system-home-link' : ''}" data-category="${id}" ${active === id ? 'aria-current="page"' : ''}><span class="system-nav-symbol" aria-hidden="true">${symbols[id]}</span><span>${t(id)}</span>${compact ? '<span class="system-chevron" aria-hidden="true">›</span>' : ''}</button>`;
window.setSystemCategory = id => {
if (!tabs.includes(id)) return;
active = id;
const container = document.querySelector('#content-system');
if (!container) return;
window.systemApp(container);
container.querySelector('.system-settings-main h1')?.focus({ preventScroll: true });
};
const previous = window.systemApp;
window.systemApp = container => {
previous(container);
const panel = container.querySelector('.settings');
if (!panel?.querySelectorAll || !container.replaceChildren) return;
const sections = [...panel.querySelectorAll(':scope > section[data-settings-group]')];
const shell = document.createElement('div');
shell.className = 'system-settings-shell';
shell.innerHTML = `<aside class="system-settings-sidebar"><div class="system-settings-brand">LIFE OS <span>/ ${t('settings')}</span></div><nav class="system-settings-nav" aria-label="${t('navigation')}">${tabs.map(id => navigationButton(id)).join('')}</nav></aside><main class="system-settings-main"><header class="system-settings-header"><div class="eyebrow">${t('settings')}</div><h1 tabindex="-1">${t(active)}</h1>${active === 'home' ? `<p class="sub">${t('homeHint')}</p>` : ''}</header><div class="system-settings-view"></div></main>`;
const view = shell.querySelector('.system-settings-view');
if (active === 'home') {
view.innerHTML = `<div class="system-home-status"><div class="system-device-mark" aria-hidden="true">◫</div><div><strong>${t('device')}</strong><p>${t('deviceHint')}</p></div><span>${t('version', { version: window.LifeOSVersion || '1.16.0' })}</span></div><div class="system-home-heading">${t('quickSettings')}</div><div class="system-home-grid">${['appearance', 'notifications', 'language', 'data'].map(id => `<div class="system-home-card">${navigationButton(id, true)}<p>${t(`${id}Hint`)}</p></div>`).join('')}</div>`;
} else {
const group = document.createElement('div');
group.className = 'settings system-settings-group';
sections.filter(section => section.dataset.settingsGroup === active).forEach(section => group.append(section));
view.append(group);
}
container.replaceChildren(shell);
shell.querySelectorAll('[data-category]').forEach(button => button.addEventListener('click', () => window.setSystemCategory(button.dataset.category)));
};
const style = document.createElement('style');
style.textContent = `.window[data-id="system"]{width:min(900px,calc(100vw - 100px));height:min(650px,calc(100vh - 120px))}#content-system{padding:0!important;height:100%;min-height:0}.system-settings-shell{display:grid;grid-template-columns:210px minmax(0,1fr);min-height:100%;background:var(--panel)}.system-settings-sidebar{padding:22px 10px;background:color-mix(in srgb,var(--panel2) 78%,var(--panel));border-right:1px solid var(--line)}.system-settings-brand{padding:0 13px 22px;color:var(--ink);font:600 12px 'DM Mono',monospace;letter-spacing:.09em}.system-settings-brand span{color:var(--muted);font-weight:400}.system-settings-nav{display:grid;gap:3px}.system-nav-item{position:relative;display:flex;align-items:center;gap:12px;width:100%;min-height:43px;padding:8px 13px;border:0;border-radius:8px;background:transparent;color:var(--ink);text-align:left;font:500 13px Manrope,system-ui;cursor:pointer}.system-nav-item:hover,.system-nav-item:focus-visible{background:var(--panel2)}.system-nav-item.selected{background:color-mix(in srgb,var(--accent) 12%,var(--panel2))}.system-nav-item.selected:before{content:'';position:absolute;left:0;top:11px;bottom:11px;width:3px;border-radius:3px;background:var(--accent)}.system-nav-symbol{width:22px;flex:none;text-align:center;color:var(--accent);font-size:19px;line-height:1}.system-settings-main{min-width:0;padding:28px clamp(22px,4vw,42px) 45px}.system-settings-header{margin-bottom:22px}.system-settings-header h1{font-size:clamp(25px,3vw,34px);margin:7px 0 0}.system-settings-header h1:focus{outline:none}.system-settings-header .sub{margin:8px 0 0}.system-settings-group{display:block}.system-settings-group>section{padding:18px 20px!important;margin-bottom:12px;border:1px solid var(--line)!important;border-radius:12px;background:var(--panel2)}.system-settings-group>section:first-child{border-top:1px solid var(--line)}.system-settings-group .notification-row{background:var(--panel)}.system-settings-group .notification-list{grid-template-columns:repeat(2,minmax(0,1fr))}.system-home-status{display:flex;align-items:center;gap:16px;padding:18px 20px;margin-bottom:24px;border:1px solid var(--line);border-radius:13px;background:var(--panel2)}.system-device-mark{display:grid;place-items:center;width:58px;height:58px;flex:none;border-radius:10px;background:var(--bg);color:var(--accent);font-size:30px}.system-home-status strong{font-size:15px}.system-home-status p{margin:4px 0 0;color:var(--muted);font-size:12px}.system-home-status>span{margin-left:auto;white-space:nowrap;color:var(--muted);font:11px 'DM Mono',monospace}.system-home-heading{margin-bottom:12px;font-size:17px;font-weight:600}.system-home-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:12px}.system-home-card{border:1px solid var(--line);border-radius:12px;background:var(--panel2);padding:9px 10px 12px}.system-home-card:hover{border-color:var(--accent)}.system-home-link{font-size:14px;font-weight:600}.system-home-link:before{display:none}.system-chevron{margin-left:auto;color:var(--muted);font-size:20px}.system-home-card p{padding:0 13px 0 47px;margin:0;color:var(--muted);font-size:12px;line-height:1.5}@media(max-width:760px){.system-settings-shell{grid-template-columns:1fr}.system-settings-sidebar{padding:12px 14px 7px;border-right:0;border-bottom:1px solid var(--line)}.system-settings-brand{padding:3px 4px 10px}.system-settings-nav{display:flex;overflow-x:auto;gap:5px;scrollbar-width:thin}.system-settings-nav .system-nav-item{width:auto;white-space:nowrap;flex:none;padding:9px 12px}.system-settings-nav .system-nav-item.selected:before{left:12px;right:12px;top:auto;bottom:0;width:auto;height:2px}.system-settings-main{padding:23px 18px 90px}.system-home-grid{grid-template-columns:1fr}.system-settings-group .notification-list{grid-template-columns:1fr}.system-home-status{flex-wrap:wrap}.system-home-status>span{margin-left:74px}}@media(max-width:650px){.window[data-id="system"]{width:100%;height:100%}}`;
document.head.append(style);
})();