SaaS — App Shell
A polished, fully responsive SaaS application shell with a collapsible left sidebar, workspace switcher, and a topbar carrying search, notifications, theme toggle, and an avatar menu. Built in vanilla HTML, CSS, and JavaScript, it ships persisted sidebar collapse, a working light and dark theme, mobile off-canvas navigation, dropdown menus, and a Command-K palette stub over a sample dashboard with breadcrumb, stat cards, an inline SVG chart, and task list.
MCP
Code
/* ===== Tokens ===== */
:root {
--bg: #f7f8fb;
--surface: #ffffff;
--surface-2: #f2f3f8;
--ink: #0f1222;
--muted: #646b85;
--brand: #6366f1;
--brand-d: #4f46e5;
--ok: #16a34a;
--warn: #d97706;
--danger: #dc2626;
--line: rgba(15, 18, 34, .1);
--line-2: rgba(15, 18, 34, .06);
--ring: rgba(99, 102, 241, .45);
--shadow: 0 1px 2px rgba(15, 18, 34, .06), 0 8px 24px rgba(15, 18, 34, .08);
--shadow-sm: 0 1px 2px rgba(15, 18, 34, .07);
--sb-w: 264px;
--tb-h: 60px;
--radius: 14px;
}
[data-theme="dark"] {
--bg: #0b0d16;
--surface: #14172180;
--surface: #141721;
--surface-2: #1b1f2c;
--ink: #eef0f7;
--muted: #9aa1bd;
--brand: #818cf8;
--brand-d: #6366f1;
--line: rgba(255, 255, 255, .1);
--line-2: rgba(255, 255, 255, .06);
--ring: rgba(129, 140, 248, .5);
--shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 12px 30px rgba(0, 0, 0, .45);
--shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
margin: 0;
font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
background: var(--bg);
color: var(--ink);
line-height: 1.5;
-webkit-font-smoothing: antialiased;
text-rendering: optimizeLegibility;
}
a { color: inherit; }
button { font-family: inherit; }
.skip-link {
position: fixed; top: 8px; left: 8px; z-index: 200;
background: var(--brand); color: #fff; padding: 8px 14px; border-radius: 8px;
transform: translateY(-150%); transition: transform .18s; text-decoration: none; font-weight: 600;
}
.skip-link:focus { transform: translateY(0); }
:focus-visible {
outline: 2px solid var(--brand);
outline-offset: 2px;
border-radius: 8px;
}
/* ===== Layout ===== */
.app {
display: grid;
grid-template-columns: var(--sb-w) 1fr;
min-height: 100vh;
transition: grid-template-columns .22s ease;
}
.app.is-collapsed { --sb-w: 76px; }
/* ===== Sidebar ===== */
.sidebar {
grid-row: 1 / -1;
display: flex;
flex-direction: column;
background: var(--surface);
border-right: 1px solid var(--line);
position: sticky; top: 0; height: 100vh;
overflow: hidden;
z-index: 60;
}
.sidebar__top { padding: 14px 12px 8px; }
.ws { position: relative; }
.ws__btn {
display: flex; align-items: center; gap: 10px; width: 100%;
padding: 8px; border: 1px solid var(--line-2); border-radius: 12px;
background: var(--surface-2); cursor: pointer; color: var(--ink);
transition: background .15s, border-color .15s;
}
.ws__btn:hover { border-color: var(--line); }
.ws__logo {
flex: none; width: 34px; height: 34px; display: grid; place-items: center;
border-radius: 9px; background: linear-gradient(135deg, var(--brand), var(--brand-d));
color: #fff; font-size: 16px;
}
.ws__logo--sm { width: 24px; height: 24px; font-size: 12px; border-radius: 7px; }
.ws__logo--b { background: linear-gradient(135deg, #0ea5e9, #2563eb); }
.ws__logo--g { background: linear-gradient(135deg, #10b981, #059669); }
.ws__meta { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; text-align: left; }
.ws__name { font-weight: 700; font-size: 14px; white-space: nowrap; }
.ws__plan { font-size: 11.5px; color: var(--muted); }
.ws__chev { width: 16px; height: 16px; margin-left: auto; color: var(--muted); flex: none; }
/* ===== Nav ===== */
.nav { flex: 1; overflow-y: auto; padding: 4px 12px; }
.nav__label {
font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
color: var(--muted); margin: 16px 8px 6px; white-space: nowrap;
}
.nav__item {
display: flex; align-items: center; gap: 12px;
padding: 9px 10px; border-radius: 10px; text-decoration: none;
color: var(--muted); font-size: 14px; font-weight: 500;
transition: background .14s, color .14s;
}
.nav__item svg { width: 20px; height: 20px; flex: none; }
.nav__item span:not(.nav__badge) { white-space: nowrap; }
.nav__item:hover { background: var(--surface-2); color: var(--ink); }
.nav__item.is-active { background: color-mix(in srgb, var(--brand) 14%, transparent); color: var(--brand-d); }
[data-theme="dark"] .nav__item.is-active { color: var(--brand); }
.nav__badge {
margin-left: auto; font-size: 11px; font-weight: 700;
background: var(--surface-2); color: var(--muted);
padding: 1px 8px; border-radius: 999px;
}
.nav__item.is-active .nav__badge { background: var(--brand); color: #fff; }
/* ===== Sidebar bottom ===== */
.sidebar__bottom { padding: 12px; border-top: 1px solid var(--line-2); }
.usage {
background: var(--surface-2); border: 1px solid var(--line-2);
border-radius: 12px; padding: 12px; margin-bottom: 10px;
}
.usage__head { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-bottom: 8px; white-space: nowrap; }
.usage__bar { height: 7px; border-radius: 999px; background: var(--line); overflow: hidden; }
.usage__bar > span { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--brand), var(--brand-d)); }
.usage__cta {
margin-top: 10px; width: 100%; border: 0; border-radius: 9px; cursor: pointer;
padding: 8px; font-size: 13px; font-weight: 600; color: #fff;
background: linear-gradient(135deg, var(--brand), var(--brand-d));
transition: filter .15s;
}
.usage__cta:hover { filter: brightness(1.06); }
.collapse {
display: flex; align-items: center; gap: 10px; width: 100%;
border: 1px solid var(--line-2); background: transparent; cursor: pointer;
padding: 8px 10px; border-radius: 10px; color: var(--muted); font-size: 13px; font-weight: 500;
transition: background .14s, color .14s;
}
.collapse:hover { background: var(--surface-2); color: var(--ink); }
.collapse svg { width: 16px; height: 16px; transition: transform .22s; }
/* ===== Collapsed state ===== */
.app.is-collapsed .ws__meta,
.app.is-collapsed .ws__chev,
.app.is-collapsed .nav__label,
.app.is-collapsed .nav__item span:not(.nav__badge),
.app.is-collapsed .nav__badge,
.app.is-collapsed .usage,
.app.is-collapsed .collapse__txt { display: none; }
.app.is-collapsed .ws__btn { justify-content: center; padding: 8px; }
.app.is-collapsed .nav__item { justify-content: center; padding: 9px; }
.app.is-collapsed .collapse { justify-content: center; }
.app.is-collapsed .collapse svg { transform: rotate(180deg); }
/* ===== Main column ===== */
.col { display: flex; flex-direction: column; min-width: 0; }
/* ===== Topbar ===== */
.topbar {
position: sticky; top: 0; z-index: 50;
height: var(--tb-h); display: flex; align-items: center; gap: 12px;
padding: 0 18px; background: color-mix(in srgb, var(--surface) 86%, transparent);
backdrop-filter: saturate(1.4) blur(10px);
border-bottom: 1px solid var(--line);
}
.topbar__burger { display: none; }
.search {
display: flex; align-items: center; gap: 10px;
width: min(420px, 46vw); padding: 8px 12px; cursor: text;
border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2);
color: var(--muted); transition: border-color .15s, box-shadow .15s;
}
.search:hover { border-color: var(--brand); }
.search svg { width: 16px; height: 16px; flex: none; }
.search__txt { font-size: 13.5px; flex: 1; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search__kbd, kbd {
font: 600 11px/1 "Inter", sans-serif; color: var(--muted);
background: var(--surface); border: 1px solid var(--line); border-bottom-width: 2px;
padding: 3px 6px; border-radius: 6px;
}
.topbar__actions { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.icon-btn {
position: relative; width: 38px; height: 38px; display: grid; place-items: center;
border: 1px solid transparent; border-radius: 10px; background: transparent; cursor: pointer;
color: var(--muted); transition: background .14s, color .14s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn svg { width: 20px; height: 20px; }
.dot {
position: absolute; top: 4px; right: 4px; min-width: 16px; height: 16px;
display: grid; place-items: center; padding: 0 4px;
font-size: 10px; font-weight: 700; color: #fff; background: var(--danger);
border-radius: 999px; border: 2px solid var(--surface);
}
.ic-moon { display: none; }
[data-theme="dark"] .ic-sun { display: none; }
[data-theme="dark"] .ic-moon { display: block; }
.avatar-btn {
display: flex; align-items: center; gap: 8px; cursor: pointer;
border: 1px solid var(--line-2); border-radius: 999px; padding: 4px 10px 4px 4px;
background: var(--surface-2); color: var(--ink); transition: border-color .15s;
}
.avatar-btn:hover { border-color: var(--line); }
.avatar-btn__name { font-size: 13.5px; font-weight: 600; white-space: nowrap; }
.avatar-btn .ws__chev { margin-left: 0; }
.avatar {
width: 30px; height: 30px; flex: none; border-radius: 999px; display: grid; place-items: center;
font-size: 12px; font-weight: 700; color: #fff;
background: linear-gradient(135deg, #f97316, #db2777);
}
.avatar--lg { width: 42px; height: 42px; font-size: 15px; }
/* ===== Dropdown menus ===== */
.dd, [data-menu] { position: relative; }
.menu {
position: absolute; z-index: 90; min-width: 240px;
background: var(--surface); border: 1px solid var(--line);
border-radius: 14px; box-shadow: var(--shadow); padding: 6px;
animation: pop .14s ease;
}
@keyframes pop { from { opacity: 0; transform: translateY(-6px) scale(.98); } }
.menu--ws { left: 0; top: calc(100% + 6px); right: 0; }
.menu--notif, .menu--user { right: 0; top: calc(100% + 8px); }
.menu--notif { width: 320px; }
.menu--user { width: 250px; }
.menu__label { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; padding: 8px 10px 4px; }
.menu__item {
display: flex; align-items: center; gap: 10px; width: 100%;
padding: 9px 10px; border: 0; border-radius: 9px; background: transparent; cursor: pointer;
color: var(--ink); font-size: 13.5px; font-weight: 500; text-align: left;
}
.menu__item:hover { background: var(--surface-2); }
.menu__item.is-active { background: color-mix(in srgb, var(--brand) 12%, transparent); }
.menu__item .check { margin-left: auto; color: var(--brand); font-weight: 800; }
.menu__item--muted { color: var(--muted); }
.menu__item--danger { color: var(--danger); }
.menu__item--danger:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); }
.menu__sep { height: 1px; background: var(--line-2); margin: 6px 4px; }
.menu__bar { display: flex; align-items: center; justify-content: space-between; padding: 8px 10px 6px; }
.menu__title { font-size: 14px; font-weight: 700; margin: 0; }
.menu__clear { border: 0; background: transparent; color: var(--brand); font-size: 12.5px; font-weight: 600; cursor: pointer; }
.menu__clear:hover { text-decoration: underline; }
.menu__user { display: flex; align-items: center; gap: 10px; padding: 10px; }
.menu__user strong { display: block; font-size: 14px; }
.menu__user small { color: var(--muted); font-size: 12px; }
.menu__foot { display: block; text-align: center; padding: 9px; margin-top: 4px; font-size: 13px; font-weight: 600; color: var(--brand); text-decoration: none; border-top: 1px solid var(--line-2); }
.menu__foot:hover { background: var(--surface-2); border-radius: 0 0 10px 10px; }
.notif { max-height: 300px; overflow-y: auto; }
.notif__item { display: flex; gap: 10px; width: 100%; text-align: left; padding: 10px; border: 0; border-radius: 10px; background: transparent; cursor: pointer; position: relative; }
.notif__item:hover { background: var(--surface-2); }
.notif__item.is-unread::before { content: ""; position: absolute; left: 2px; top: 16px; width: 6px; height: 6px; border-radius: 999px; background: var(--brand); }
.notif__ico { flex: none; width: 32px; height: 32px; display: grid; place-items: center; border-radius: 9px; font-weight: 700; font-size: 14px; }
.nf-a { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.nf-b { background: color-mix(in srgb, var(--brand) 16%, transparent); color: var(--brand-d); }
.nf-c { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.nf-d { background: var(--surface-2); color: var(--muted); }
[data-theme="dark"] .nf-b { color: var(--brand); }
.notif__b { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.notif__b strong { font-size: 13.5px; }
.notif__b span { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.notif__b time { font-size: 11px; color: var(--muted); margin-top: 2px; }
/* ===== Main content ===== */
.main { padding: 24px clamp(18px, 4vw, 36px) 56px; max-width: 1180px; width: 100%; }
.crumbs ol { list-style: none; display: flex; gap: 8px; align-items: center; padding: 0; margin: 0 0 14px; flex-wrap: wrap; }
.crumbs a { text-decoration: none; color: var(--muted); font-size: 13px; }
.crumbs a:hover { color: var(--ink); }
.crumbs li[aria-hidden] { color: var(--line); }
.crumbs [aria-current] { font-size: 13px; font-weight: 600; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head h1 { font-size: clamp(22px, 3vw, 28px); margin: 0 0 4px; letter-spacing: -.02em; }
.page-head__sub { color: var(--muted); margin: 0; font-size: 14.5px; }
.page-head__act { display: flex; gap: 10px; }
.btn {
border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer;
padding: 9px 15px; border-radius: 10px; font-size: 13.5px; font-weight: 600;
transition: background .14s, border-color .14s, filter .14s; box-shadow: var(--shadow-sm);
}
.btn--ghost:hover { background: var(--surface-2); }
.btn--primary { color: #fff; border-color: transparent; background: linear-gradient(135deg, var(--brand), var(--brand-d)); }
.btn--primary:hover { filter: brightness(1.07); }
/* ===== Stats ===== */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow-sm); }
.stat__label { margin: 0 0 6px; font-size: 13px; color: var(--muted); }
.stat__value { margin: 0 0 6px; font-size: 26px; font-weight: 700; letter-spacing: -.02em; }
.stat__delta { margin: 0; font-size: 12.5px; font-weight: 600; }
.stat__delta span { color: var(--muted); font-weight: 500; }
.is-up { color: var(--ok); }
.is-down { color: var(--ok); }
.is-flat { color: var(--muted); }
/* ===== Cards ===== */
.cards { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 14px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow-sm); }
.card__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 10px; }
.card__head h2 { font-size: 15px; margin: 0; }
.pill { font-size: 11.5px; font-weight: 600; color: var(--muted); background: var(--surface-2); padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.link { color: var(--brand); font-size: 12.5px; font-weight: 600; text-decoration: none; }
.link:hover { text-decoration: underline; }
.card--chart { display: flex; flex-direction: column; }
.chart { width: 100%; height: 120px; flex: 1; }
.chart__legend { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 4px; }
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.list__row { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line-2); font-size: 13.5px; }
.list__row:last-child { border-bottom: 0; }
.list__name { flex: 1; font-weight: 500; }
.dotmark { width: 9px; height: 9px; border-radius: 999px; flex: none; }
.dm-1 { background: #6366f1; } .dm-2 { background: #f59e0b; } .dm-3 { background: #10b981; } .dm-4 { background: #94a3b8; }
.tag { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.tag--ok { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.tag--warn { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }
.todo { list-style: none; margin: 0; padding: 0; }
.check-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; font-size: 13.5px; cursor: pointer; }
.check-row input { width: 17px; height: 17px; accent-color: var(--brand); cursor: pointer; }
.check-row:has(input:checked) { color: var(--muted); text-decoration: line-through; }
/* ===== Scrim (mobile) ===== */
.scrim { position: fixed; inset: 0; background: rgba(15, 18, 34, .5); z-index: 55; border: 0; }
/* ===== Command palette ===== */
.cmdk { position: fixed; inset: 0; z-index: 150; background: rgba(15, 18, 34, .42); backdrop-filter: blur(3px); display: grid; place-items: start center; padding-top: 12vh; animation: fade .14s; }
@keyframes fade { from { opacity: 0; } }
.cmdk__panel { width: min(560px, 92vw); background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); overflow: hidden; animation: pop .16s ease; }
.cmdk__search { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line-2); }
.cmdk__search svg { width: 18px; height: 18px; color: var(--muted); flex: none; }
.cmdk__search input { flex: 1; border: 0; outline: 0; background: transparent; color: var(--ink); font-size: 15px; }
.cmdk__list { list-style: none; margin: 0; padding: 8px; max-height: 320px; overflow-y: auto; }
.cmdk__item { display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 10px; cursor: pointer; font-size: 14px; }
.cmdk__item .ci-ico { width: 28px; height: 28px; display: grid; place-items: center; border-radius: 8px; background: var(--surface-2); font-size: 14px; flex: none; }
.cmdk__item .ci-hint { margin-left: auto; font-size: 11px; color: var(--muted); }
.cmdk__item.is-sel, .cmdk__item:hover { background: var(--surface-2); }
.cmdk__empty { padding: 28px 12px; text-align: center; color: var(--muted); font-size: 13.5px; }
/* ===== Toast ===== */
.toast {
position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 140%);
background: var(--ink); color: var(--bg); padding: 11px 18px; border-radius: 10px;
font-size: 13.5px; font-weight: 500; box-shadow: var(--shadow); z-index: 250;
transition: transform .3s cubic-bezier(.16,1,.3,1); max-width: 90vw;
}
.toast.is-show { transform: translate(-50%, 0); }
/* ===== Responsive ===== */
@media (max-width: 1080px) {
.cards { grid-template-columns: 1fr 1fr; }
.card--chart { grid-column: 1 / -1; }
}
@media (max-width: 860px) {
.app { grid-template-columns: 1fr; }
.app.is-collapsed { --sb-w: 264px; }
.sidebar {
position: fixed; top: 0; left: 0; width: 264px; height: 100vh;
transform: translateX(-100%); transition: transform .24s ease; box-shadow: var(--shadow);
}
.app.nav-open .sidebar { transform: translateX(0); }
.topbar__burger { display: grid; }
.avatar-btn__name { display: none; }
.search__txt { display: none; }
.search { width: auto; }
.search__kbd { display: none; }
}
@media (max-width: 620px) {
.stats { grid-template-columns: 1fr 1fr; }
.cards { grid-template-columns: 1fr; }
.page-head__act { width: 100%; }
.page-head__act .btn { flex: 1; }
}
@media (max-width: 400px) {
.stats { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}(function () {
"use strict";
var $ = function (s, r) { return (r || document).querySelector(s); };
var $$ = function (s, r) { return Array.prototype.slice.call((r || document).querySelectorAll(s)); };
var app = $("#app");
var STORE = "saas-shell";
/* ---------- Toast ---------- */
var toastEl = $("#toast"), toastT;
function toast(msg) {
toastEl.textContent = msg;
toastEl.classList.add("is-show");
clearTimeout(toastT);
toastT = setTimeout(function () { toastEl.classList.remove("is-show"); }, 2400);
}
/* ---------- Persisted prefs ---------- */
function load() { try { return JSON.parse(localStorage.getItem(STORE)) || {}; } catch (e) { return {}; } }
function save(p) { try { localStorage.setItem(STORE, JSON.stringify(p)); } catch (e) {} }
var prefs = load();
/* ---------- Theme ---------- */
function applyTheme(t) {
document.documentElement.setAttribute("data-theme", t);
prefs.theme = t; save(prefs);
}
applyTheme(prefs.theme || (window.matchMedia && matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light"));
$("#themeBtn").addEventListener("click", function () {
var next = document.documentElement.getAttribute("data-theme") === "dark" ? "light" : "dark";
applyTheme(next);
toast(next === "dark" ? "Dark theme on" : "Light theme on");
});
/* ---------- Sidebar collapse (persisted, desktop) ---------- */
if (prefs.collapsed) app.classList.add("is-collapsed");
$("#collapseBtn").addEventListener("click", function () {
var c = app.classList.toggle("is-collapsed");
prefs.collapsed = c; save(prefs);
this.setAttribute("aria-label", c ? "Expand sidebar" : "Collapse sidebar");
});
/* ---------- Mobile off-canvas ---------- */
var burger = $("#burger"), scrim = $("#scrim");
function openNav() { app.classList.add("nav-open"); scrim.hidden = false; burger.setAttribute("aria-expanded", "true"); }
function closeNav() { app.classList.remove("nav-open"); scrim.hidden = true; burger.setAttribute("aria-expanded", "false"); }
burger.addEventListener("click", function () { app.classList.contains("nav-open") ? closeNav() : openNav(); });
scrim.addEventListener("click", closeNav);
/* ---------- Nav active state ---------- */
$$(".nav__item").forEach(function (item) {
item.addEventListener("click", function (e) {
e.preventDefault();
$$(".nav__item").forEach(function (n) { n.classList.remove("is-active"); n.removeAttribute("aria-current"); });
item.classList.add("is-active");
item.setAttribute("aria-current", "page");
toast(item.dataset.nav + " — page would load here.");
if (window.innerWidth <= 860) closeNav();
});
});
/* ---------- Dropdown menus (workspace, notifications, avatar) ---------- */
var openMenu = null;
function shutMenu() {
if (!openMenu) return;
openMenu.menu.hidden = true;
openMenu.btn.setAttribute("aria-expanded", "false");
openMenu = null;
}
$$("[data-menu]").forEach(function (wrap) {
var btn = $("button[aria-haspopup]", wrap);
var menu = $(".menu", wrap);
if (!btn || !menu) return;
btn.addEventListener("click", function (e) {
e.stopPropagation();
var isOpen = !menu.hidden;
shutMenu();
if (!isOpen) {
menu.hidden = false;
btn.setAttribute("aria-expanded", "true");
openMenu = { btn: btn, menu: menu };
var first = $(".menu__item, .notif__item", menu);
if (first) first.focus();
}
});
menu.addEventListener("click", function (e) { e.stopPropagation(); });
});
document.addEventListener("click", shutMenu);
document.addEventListener("keydown", function (e) {
if (e.key === "Escape" && openMenu) { var b = openMenu.btn; shutMenu(); b.focus(); }
});
/* ---------- Workspace switcher ---------- */
$$('#wsMenu [role="menuitemradio"]').forEach(function (it) {
it.addEventListener("click", function () {
$$('#wsMenu [role="menuitemradio"]').forEach(function (x) {
x.classList.remove("is-active"); x.setAttribute("aria-checked", "false");
var c = $(".check", x); if (c) c.remove();
});
it.classList.add("is-active"); it.setAttribute("aria-checked", "true");
if (!$(".check", it)) {
var c = document.createElement("span");
c.className = "check"; c.setAttribute("aria-hidden", "true"); c.textContent = "✓";
it.appendChild(c);
}
var name = it.textContent.replace("✓", "").trim();
$(".ws__name").textContent = name;
shutMenu();
toast("Switched to " + name);
});
});
$('#wsMenu .menu__item--muted').addEventListener("click", function () { shutMenu(); toast("Create workspace dialog would open."); });
/* ---------- Notifications ---------- */
function updateBadge() {
var unread = $$("#notifList .is-unread").length;
var dot = $("#notifBtn .dot");
var btn = $("#notifBtn");
if (unread) { dot.textContent = unread; dot.style.display = ""; btn.setAttribute("aria-label", "Notifications, " + unread + " unread"); }
else { dot.style.display = "none"; btn.setAttribute("aria-label", "Notifications, none unread"); }
}
$$("#notifList .notif__item").forEach(function (n) {
n.addEventListener("click", function () { n.classList.remove("is-unread"); updateBadge(); });
});
$("#clearNotif").addEventListener("click", function () {
$$("#notifList .is-unread").forEach(function (n) { n.classList.remove("is-unread"); });
updateBadge(); toast("All notifications marked read.");
});
/* ---------- Avatar / user menu actions ---------- */
$$("#avatarMenu .menu__item").forEach(function (it) {
it.addEventListener("click", function () { shutMenu(); toast(it.textContent.trim() + " — coming soon."); });
});
/* ---------- Misc CTAs ---------- */
$$("[data-toast]").forEach(function (b) { b.addEventListener("click", function () { toast(b.dataset.toast); }); });
$("[data-upgrade]").addEventListener("click", function () { toast("Upgrade flow would open here."); });
/* ---------- Command palette (⌘K) ---------- */
var COMMANDS = [
{ icon: "🏠", label: "Go to Dashboard", hint: "G then D", run: function () { goto("Dashboard"); } },
{ icon: "📁", label: "Go to Projects", hint: "G then P", run: function () { goto("Projects"); } },
{ icon: "+", label: "Create new project", hint: "C", run: function () { toast("New project draft created."); } },
{ icon: "👥", label: "Invite teammate", hint: "I", run: function () { toast("Invite dialog would open."); } },
{ icon: "🌓", label: "Toggle theme", hint: "T", run: function () { $("#themeBtn").click(); } },
{ icon: "💳", label: "Open billing", hint: "", run: function () { goto("Billing"); } },
{ icon: "⚙", label: "Open settings", hint: "", run: function () { goto("Settings"); } }
];
function goto(name) {
var t = $$(".nav__item").filter(function (n) { return n.dataset.nav === name; })[0];
if (t) t.click(); else toast("Opening " + name);
}
var cmdk = $("#cmdk"), cmdkInput = $("#cmdkInput"), cmdkList = $("#cmdkList"), sel = 0, lastFocus = null;
function renderCmd(q) {
q = (q || "").toLowerCase().trim();
var items = COMMANDS.filter(function (c) { return c.label.toLowerCase().indexOf(q) > -1; });
cmdkList.innerHTML = "";
if (!items.length) { cmdkList.innerHTML = '<li class="cmdk__empty">No commands match “' + q + '”.</li>'; return; }
sel = Math.min(sel, items.length - 1);
items.forEach(function (c, i) {
var li = document.createElement("li");
li.className = "cmdk__item" + (i === sel ? " is-sel" : "");
li.setAttribute("role", "option");
li.setAttribute("aria-selected", i === sel ? "true" : "false");
li.innerHTML = '<span class="ci-ico">' + c.icon + '</span><span>' + c.label + '</span>' + (c.hint ? '<span class="ci-hint">' + c.hint + '</span>' : "");
li.addEventListener("click", function () { closeCmdk(); c.run(); });
li.addEventListener("mousemove", function () { sel = i; mark(); });
cmdkList.appendChild(li);
});
}
function mark() {
$$(".cmdk__item", cmdkList).forEach(function (el, i) {
var on = i === sel; el.classList.toggle("is-sel", on); el.setAttribute("aria-selected", on ? "true" : "false");
});
}
function currentItems() { return COMMANDS.filter(function (c) { return c.label.toLowerCase().indexOf(cmdkInput.value.toLowerCase().trim()) > -1; }); }
function openCmdk() {
lastFocus = document.activeElement;
cmdk.hidden = false; sel = 0; cmdkInput.value = ""; renderCmd("");
cmdkInput.focus();
}
function closeCmdk() { cmdk.hidden = true; if (lastFocus) lastFocus.focus(); }
$("#searchBtn").addEventListener("click", openCmdk);
cmdk.addEventListener("click", function (e) { if (e.target === cmdk) closeCmdk(); });
cmdkInput.addEventListener("input", function () { sel = 0; renderCmd(cmdkInput.value); });
cmdkInput.addEventListener("keydown", function (e) {
var items = currentItems();
if (e.key === "ArrowDown") { e.preventDefault(); sel = (sel + 1) % Math.max(items.length, 1); mark(); }
else if (e.key === "ArrowUp") { e.preventDefault(); sel = (sel - 1 + items.length) % Math.max(items.length, 1); mark(); }
else if (e.key === "Enter") { e.preventDefault(); if (items[sel]) { closeCmdk(); items[sel].run(); } }
else if (e.key === "Escape") { e.preventDefault(); closeCmdk(); }
});
document.addEventListener("keydown", function (e) {
if ((e.metaKey || e.ctrlKey) && (e.key === "k" || e.key === "K")) {
e.preventDefault();
cmdk.hidden ? openCmdk() : closeCmdk();
}
});
})();<!doctype html>
<html lang="en" data-theme="light">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Northwind — App Shell</title>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet" />
<link rel="stylesheet" href="style.css" />
</head>
<body>
<a class="skip-link" href="#main">Skip to content</a>
<div class="app" id="app">
<!-- ===== Sidebar ===== -->
<aside class="sidebar" id="sidebar" aria-label="Primary navigation">
<div class="sidebar__top">
<!-- Workspace switcher -->
<div class="ws" data-menu>
<button class="ws__btn" id="wsBtn" aria-haspopup="true" aria-expanded="false" aria-controls="wsMenu">
<span class="ws__logo" aria-hidden="true">◣</span>
<span class="ws__meta">
<span class="ws__name">Northwind</span>
<span class="ws__plan">Growth plan</span>
</span>
<svg class="ws__chev" viewBox="0 0 16 16" aria-hidden="true"><path d="M4 6l4 4 4-4" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg>
</button>
<div class="menu menu--ws" id="wsMenu" role="menu" aria-label="Switch workspace" hidden>
<p class="menu__label">Workspaces</p>
<button class="menu__item is-active" role="menuitemradio" aria-checked="true"><span class="ws__logo ws__logo--sm">◣</span> Northwind <span class="check" aria-hidden="true">✓</span></button>
<button class="menu__item" role="menuitemradio" aria-checked="false"><span class="ws__logo ws__logo--sm ws__logo--b">◆</span> Blue Harbor</button>
<button class="menu__item" role="menuitemradio" aria-checked="false"><span class="ws__logo ws__logo--sm ws__logo--g">▲</span> Greenfield Co</button>
<div class="menu__sep" role="separator"></div>
<button class="menu__item menu__item--muted" role="menuitem">+ Create workspace</button>
</div>
</div>
</div>
<nav class="nav" aria-label="Sections">
<p class="nav__label">Workspace</p>
<a class="nav__item is-active" href="#" aria-current="page" data-nav="Dashboard">
<svg viewBox="0 0 20 20" aria-hidden="true"><path d="M3 10.5 10 4l7 6.5M5 9v7h4v-4h2v4h4V9" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"/></svg>
<span>Dashboard</span>
</a>
<a class="nav__item" href="#" data-nav="Projects">
<svg viewBox="0 0 20 20" aria-hidden="true"><path d="M3 6h5l1.5 2H17v8H3z" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linejoin="round"/></svg>
<span>Projects</span>
<span class="nav__badge">8</span>
</a>
<a class="nav__item" href="#" data-nav="Analytics">
<svg viewBox="0 0 20 20" aria-hidden="true"><path d="M4 16V9m4 7V5m4 11v-4m4 4V8" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"/></svg>
<span>Analytics</span>
</a>
<a class="nav__item" href="#" data-nav="Customers">
<svg viewBox="0 0 20 20" aria-hidden="true"><circle cx="7" cy="7" r="2.6" fill="none" stroke="currentColor" stroke-width="1.6"/><path d="M3 16c0-2.4 1.8-4 4-4s4 1.6 4 4M13 8.5a2 2 0 1 0-.01-4M17 16c0-2-1.2-3.4-3-3.8" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"/></svg>
<span>Customers</span>
</a>
<p class="nav__label">Account</p>
<a class="nav__item" href="#" data-nav="Billing">
<svg viewBox="0 0 20 20" aria-hidden="true"><rect x="3" y="5" width="14" height="10" rx="2" fill="none" stroke="currentColor" stroke-width="1.6"/><path d="M3 8.5h14" stroke="currentColor" stroke-width="1.6"/></svg>
<span>Billing</span>
</a>
<a class="nav__item" href="#" data-nav="Settings">
<svg viewBox="0 0 20 20" aria-hidden="true"><circle cx="10" cy="10" r="2.4" fill="none" stroke="currentColor" stroke-width="1.6"/><path d="M10 3v2m0 10v2m7-7h-2M5 10H3m11.9-4.9-1.4 1.4M6.5 13.5l-1.4 1.4m9.8 0-1.4-1.4M6.5 6.5 5.1 5.1" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"/></svg>
<span>Settings</span>
</a>
</nav>
<div class="sidebar__bottom">
<div class="usage">
<div class="usage__head"><span>Seats used</span><span>9 / 12</span></div>
<div class="usage__bar" role="progressbar" aria-valuenow="9" aria-valuemin="0" aria-valuemax="12" aria-label="Seats used"><span style="width:75%"></span></div>
<button class="usage__cta" data-upgrade>Upgrade plan</button>
</div>
<button class="collapse" id="collapseBtn" aria-label="Collapse sidebar" title="Collapse sidebar">
<svg viewBox="0 0 16 16" aria-hidden="true"><path d="M10 4 6 8l4 4" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"/></svg>
<span class="collapse__txt">Collapse</span>
</button>
</div>
</aside>
<div class="scrim" id="scrim" hidden></div>
<!-- ===== Main column ===== -->
<div class="col">
<!-- Topbar -->
<header class="topbar" role="banner">
<button class="icon-btn topbar__burger" id="burger" aria-label="Open menu" aria-controls="sidebar" aria-expanded="false">
<svg viewBox="0 0 20 20" aria-hidden="true"><path d="M3 6h14M3 10h14M3 14h14" stroke="currentColor" stroke-width="1.7" stroke-linecap="round"/></svg>
</button>
<button class="search" id="searchBtn" aria-label="Search (Command K)">
<svg viewBox="0 0 18 18" aria-hidden="true"><circle cx="8" cy="8" r="5" fill="none" stroke="currentColor" stroke-width="1.6"/><path d="M12 12l3 3" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"/></svg>
<span class="search__txt">Search projects, people…</span>
<kbd class="search__kbd">⌘K</kbd>
</button>
<div class="topbar__actions">
<button class="icon-btn" id="themeBtn" aria-label="Toggle theme" title="Toggle theme">
<svg class="ic-sun" viewBox="0 0 20 20" aria-hidden="true"><circle cx="10" cy="10" r="3.6" fill="none" stroke="currentColor" stroke-width="1.6"/><path d="M10 2v2m0 12v2m8-8h-2M4 10H2m13.7-5.7-1.4 1.4M5.7 14.3l-1.4 1.4m11.4 0-1.4-1.4M5.7 5.7 4.3 4.3" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"/></svg>
<svg class="ic-moon" viewBox="0 0 20 20" aria-hidden="true"><path d="M16 11.5A6.5 6.5 0 0 1 8.5 4a6.5 6.5 0 1 0 7.5 7.5z" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linejoin="round"/></svg>
</button>
<div class="dd" data-menu>
<button class="icon-btn icon-btn--dot" id="notifBtn" aria-haspopup="true" aria-expanded="false" aria-controls="notifMenu" aria-label="Notifications, 3 unread">
<svg viewBox="0 0 20 20" aria-hidden="true"><path d="M10 3a4 4 0 0 0-4 4c0 4-1.5 5-1.5 5h11S14 11 14 7a4 4 0 0 0-4-4zM8 16a2 2 0 0 0 4 0" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"/></svg>
<span class="dot" aria-hidden="true">3</span>
</button>
<div class="menu menu--notif" id="notifMenu" role="menu" aria-label="Notifications" hidden>
<div class="menu__bar"><p class="menu__title">Notifications</p><button class="menu__clear" id="clearNotif">Mark all read</button></div>
<div class="notif" id="notifList">
<button class="notif__item is-unread" role="menuitem"><span class="notif__ico nf-a">↑</span><span class="notif__b"><strong>Deploy succeeded</strong><span>Production build #482 is live.</span><time>2m ago</time></span></button>
<button class="notif__item is-unread" role="menuitem"><span class="notif__ico nf-b">@</span><span class="notif__b"><strong>Mara mentioned you</strong><span>“Can you review the pricing copy?”</span><time>18m ago</time></span></button>
<button class="notif__item is-unread" role="menuitem"><span class="notif__ico nf-c">$</span><span class="notif__b"><strong>Invoice paid</strong><span>Acme Corp — $4,200.00</span><time>1h ago</time></span></button>
<button class="notif__item" role="menuitem"><span class="notif__ico nf-d">⚑</span><span class="notif__b"><strong>Weekly report ready</strong><span>Your team summary is available.</span><time>Yesterday</time></span></button>
</div>
<a class="menu__foot" href="#">View all activity</a>
</div>
</div>
<div class="dd" data-menu>
<button class="avatar-btn" id="avatarBtn" aria-haspopup="true" aria-expanded="false" aria-controls="avatarMenu">
<span class="avatar" aria-hidden="true">JR</span>
<span class="avatar-btn__name">Jordan Reyes</span>
<svg class="ws__chev" viewBox="0 0 16 16" aria-hidden="true"><path d="M4 6l4 4 4-4" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg>
</button>
<div class="menu menu--user" id="avatarMenu" role="menu" aria-label="Account" hidden>
<div class="menu__user"><span class="avatar avatar--lg" aria-hidden="true">JR</span><span><strong>Jordan Reyes</strong><small>[email protected]</small></span></div>
<div class="menu__sep" role="separator"></div>
<button class="menu__item" role="menuitem"><span aria-hidden="true">👤</span> Profile</button>
<button class="menu__item" role="menuitem"><span aria-hidden="true">⚙</span> Account settings</button>
<button class="menu__item" role="menuitem"><span aria-hidden="true">⌨</span> Keyboard shortcuts</button>
<div class="menu__sep" role="separator"></div>
<button class="menu__item menu__item--danger" role="menuitem"><span aria-hidden="true">⎋</span> Sign out</button>
</div>
</div>
</div>
</header>
<!-- Content -->
<main class="main" id="main" tabindex="-1">
<nav class="crumbs" aria-label="Breadcrumb">
<ol>
<li><a href="#">Workspace</a></li>
<li aria-hidden="true">/</li>
<li><a href="#">Projects</a></li>
<li aria-hidden="true">/</li>
<li aria-current="page">Overview</li>
</ol>
</nav>
<div class="page-head">
<div>
<h1>Dashboard</h1>
<p class="page-head__sub">Welcome back, Jordan. Here's how Northwind is doing this week.</p>
</div>
<div class="page-head__act">
<button class="btn btn--ghost" data-toast="Filters panel would open here.">Filters</button>
<button class="btn btn--primary" data-toast="New project draft created.">+ New project</button>
</div>
</div>
<section class="stats" aria-label="Key metrics">
<article class="stat">
<p class="stat__label">Active users</p>
<p class="stat__value">12,840</p>
<p class="stat__delta is-up">▲ 8.2% <span>vs last week</span></p>
</article>
<article class="stat">
<p class="stat__label">MRR</p>
<p class="stat__value">$48.6k</p>
<p class="stat__delta is-up">▲ 3.1% <span>vs last week</span></p>
</article>
<article class="stat">
<p class="stat__label">Churn</p>
<p class="stat__value">1.9%</p>
<p class="stat__delta is-down">▼ 0.4% <span>vs last week</span></p>
</article>
<article class="stat">
<p class="stat__label">Open tickets</p>
<p class="stat__value">37</p>
<p class="stat__delta is-flat">— steady <span>vs last week</span></p>
</article>
</section>
<section class="cards">
<article class="card card--chart">
<div class="card__head"><h2>Revenue trend</h2><span class="pill">Last 8 weeks</span></div>
<svg class="chart" viewBox="0 0 320 120" preserveAspectRatio="none" role="img" aria-label="Revenue trending upward over eight weeks">
<defs><linearGradient id="g" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stop-color="var(--brand)" stop-opacity=".26"/><stop offset="1" stop-color="var(--brand)" stop-opacity="0"/></linearGradient></defs>
<path d="M0 92 L46 80 L91 84 L137 60 L183 64 L229 40 L274 46 L320 22 L320 120 L0 120 Z" fill="url(#g)"/>
<path d="M0 92 L46 80 L91 84 L137 60 L183 64 L229 40 L274 46 L320 22" fill="none" stroke="var(--brand)" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
<div class="chart__legend"><span>W1</span><span>W4</span><span>W8</span></div>
</article>
<article class="card">
<div class="card__head"><h2>Recent projects</h2><a class="link" href="#">View all</a></div>
<ul class="list">
<li class="list__row"><span class="dotmark dm-1"></span><span class="list__name">Atlas redesign</span><span class="tag tag--ok">On track</span></li>
<li class="list__row"><span class="dotmark dm-2"></span><span class="list__name">Billing v2</span><span class="tag tag--warn">At risk</span></li>
<li class="list__row"><span class="dotmark dm-3"></span><span class="list__name">Mobile onboarding</span><span class="tag tag--ok">On track</span></li>
<li class="list__row"><span class="dotmark dm-4"></span><span class="list__name">API rate limits</span><span class="tag">Paused</span></li>
</ul>
</article>
<article class="card">
<div class="card__head"><h2>Your tasks</h2><span class="pill">3 due today</span></div>
<ul class="todo" id="todo">
<li><label class="check-row"><input type="checkbox" /> Review pricing copy</label></li>
<li><label class="check-row"><input type="checkbox" checked /> Approve Q3 roadmap</label></li>
<li><label class="check-row"><input type="checkbox" /> Sync with design on Atlas</label></li>
<li><label class="check-row"><input type="checkbox" /> Triage support backlog</label></li>
</ul>
</article>
</section>
</main>
</div>
</div>
<!-- ===== Command palette stub ===== -->
<div class="cmdk" id="cmdk" role="dialog" aria-modal="true" aria-label="Command palette" hidden>
<div class="cmdk__panel">
<div class="cmdk__search">
<svg viewBox="0 0 18 18" aria-hidden="true"><circle cx="8" cy="8" r="5" fill="none" stroke="currentColor" stroke-width="1.6"/><path d="M12 12l3 3" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"/></svg>
<input id="cmdkInput" type="text" placeholder="Type a command or search…" autocomplete="off" aria-label="Command input" />
<kbd>esc</kbd>
</div>
<ul class="cmdk__list" id="cmdkList" role="listbox" aria-label="Commands"></ul>
</div>
</div>
<div class="toast" id="toast" role="status" aria-live="polite"></div>
<script src="script.js"></script>
</body>
</html>App Shell
The structural backbone for a SaaS product. A collapsible left sidebar pairs a workspace switcher with grouped navigation, a live seat-usage meter, and an upgrade call to action. The sticky topbar offers a search field with a ⌘K hint, a notification bell with an unread badge, a theme toggle, and an avatar menu — each opening an accessible dropdown. The content area renders a sample dashboard: breadcrumb, page header with actions, four stat cards, an inline SVG revenue chart, a recent-projects list, and an interactive task checklist.
Every interaction actually works. Sidebar collapse and the chosen theme persist to localStorage, dropdowns close on outside-click or Escape, and the navigation tracks the active section. Pressing ⌘K (or clicking search) opens a command-palette stub you can filter and drive entirely from the keyboard with arrow keys and Enter.
On narrow screens the sidebar becomes an off-canvas drawer behind a scrim, the search collapses to an icon, and the grids reflow down to a single column. Landmark roles, aria attributes, visible focus rings, and WCAG AA contrast in both themes keep it keyboard-friendly and screen-reader aware.
Illustrative SaaS UI only — fictional product, metrics, and billing. No real backend.