المكوّنات · شريط جانبي بمبدّل مساحات
شريط جانبي بمبدّل مساحات
تبديل العميل يغيّر بنود التنقّل كلها
13 تصاميم من هذه العائلة
<div class="sb sbws">
<nav aria-label="التنقّل الرئيسي">
<div class="sb-head">
<button class="ws" aria-expanded="false" aria-haspopup="listbox">
<span class="dot" aria-hidden="true"></span>
<span class="wsn">مشروع الرياض</span>
<span class="arw" aria-hidden="true">⌄</span></button>
<ul class="wsl" role="listbox" hidden>
<li role="option" aria-selected="true" data-ws="0">مشروع الرياض</li>
<li role="option" aria-selected="false" data-ws="1">متجر لمسة</li>
<li role="option" aria-selected="false" data-ws="2">مقهى ضوء</li>
</ul>
</div>
<ul class="nv"></ul>
</nav>
<div class="body">
<h4 data-ar="استوديو تصميم" data-en="Design studio">استوديو تصميم</h4>
<p data-ar="اضغط أي بند لتراه ينشط. التنقّل بالكيبورد يعمل بالأسهم." data-en="Click any item to activate it. Arrow keys navigate.">اضغط أي بند لتراه ينشط. التنقّل بالكيبورد يعمل بالأسهم.</p>
</div>
<p class="live" aria-live="polite"></p>
</div>
/* pt-scoped */
/* sidebar-workspace — استوديو تصميم */
.sbws{display:flex;height:100%;width:100%;font-size:10px;
color:var(--pt-text-secondary);overflow:hidden;position:relative}
.sbws nav{flex:none;display:flex;flex-direction:column;min-width:0}
.sbws ul{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;
overflow-y:auto;flex:1}
.sbws li{margin:0}
.sbws .item{display:flex;align-items:center;width:100%;border:0;background:transparent;
color:inherit;font:inherit;font-size:10px;cursor:pointer;text-align:start;
white-space:nowrap;overflow:hidden;position:relative}
.sbws .ic{flex:none;text-align:center;line-height:1}
.sbws .lbl{flex:1;overflow:hidden;text-overflow:ellipsis}
.sbws .body{flex:1;padding:12px;display:flex;flex-direction:column;gap:7px;min-width:0}
.sbws .body h4{margin:0;font-size:11px;color:var(--pt-text-primary)}
.sbws .body p{margin:0;font-size:9px;color:var(--pt-text-muted);line-height:1.8}
.sbws .item:focus-visible{outline:2px solid var(--pt-focus-ring);outline-offset:-2px}
/* شخصية: مبدّل كبسولي أعلى، بنود مسطّحة، انحناء كبير للحاوية */
.sbws{border:1px solid var(--pt-border-subtle);border-radius:var(--pt-radius-xl);
background:var(--pt-surface)}
.sbws nav{width:210px;background:var(--pt-bg-inset);
border-inline-end:1px solid var(--pt-border-subtle)}
.sbws .sb-head{position:relative;padding:7px}
.sbws .ws{display:flex;align-items:center;gap:7px;width:100%;padding:7px 9px;
border:1px solid var(--pt-border-default);border-radius:var(--pt-radius-full);
background:var(--pt-surface);color:var(--pt-text-primary);font:inherit;font-size:9.5px;
cursor:pointer;text-align:start}
.sbws .ws:hover{border-color:var(--pt-accent)}
.sbws .ws:focus-visible{outline:2px solid var(--pt-focus-ring);outline-offset:1px}
.sbws .dot{flex:none;width:7px;height:7px;border-radius:50%;background:var(--pt-accent)}
.sbws .wsn{flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.sbws .arw{font-size:8px;color:var(--pt-text-muted)}
.sbws .wsl{position:absolute;inset-inline:7px;inset-block-start:calc(100% - 2px);z-index:6;
margin:0;padding:4px;list-style:none;display:flex;flex-direction:column;gap:1px;
border-radius:var(--pt-radius-md);background:var(--pt-bg-overlay);
border:1px solid var(--pt-border-default);box-shadow:var(--pt-shadow-4)}
.sbws .wsl li{padding:6px 9px;border-radius:var(--pt-radius-sm);font-size:9.5px;
cursor:pointer;color:var(--pt-text-secondary)}
.sbws .wsl li:hover{background:var(--pt-surface-hover);color:var(--pt-text-primary)}
.sbws .wsl li[aria-selected="true"]{color:var(--pt-accent)}
.sbws ul.nv{padding:4px 7px;gap:2px}
.sbws .item{gap:8px;padding:6px 9px;border-radius:var(--pt-radius-sm)}
.sbws .ic{width:13px;font-size:10px}
.sbws .item:hover{background:var(--pt-surface-hover);color:var(--pt-text-primary)}
.sbws .item[aria-current="page"]{background:var(--pt-surface);color:var(--pt-accent);
box-shadow:inset 0 0 0 1px color-mix(in srgb,var(--pt-accent) 40%,transparent)}
.sbws .live{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%)}
/* يعمل داخل إطار معزول — لا يعتمد على شيء خارجه */
/* pt-remount — يعاد التركيب عند تبديل اللغة */
(function () {
var host = document.querySelector('.sbws');
if (!host) return;
var snapshot = host.innerHTML;
var timers = [];
var ac = null;
/* الجسم كما كتبه المولِّد. يستقبل بدائل مظلَّلة لـ root وdocument
والمؤقّتات، فينظّف نفسه دون أن يعرف أنه قابل لإعادة التركيب. */
function run(root, document, setTimeout, setInterval) {
var nav = root.querySelector('nav ul');
if (nav) {
var items = [].slice.call(nav.querySelectorAll('[data-nav]'));
items.forEach(function (b) {
b.tabIndex = b.getAttribute('aria-current') === 'page' ? 0 : -1;
b.addEventListener('click', function () { activate(b); });
});
function activate(b) {
items.forEach(function (x) {
var on = x === b;
if (on) x.setAttribute('aria-current', 'page'); else x.removeAttribute('aria-current');
x.tabIndex = on ? 0 : -1;
});
b.focus();
}
nav.addEventListener('keydown', function (e) {
var i = items.indexOf(document.activeElement);
if (i === -1) return;
var j = null;
if (e.key === 'ArrowDown') j = (i + 1) % items.length;
else if (e.key === 'ArrowUp') j = (i - 1 + items.length) % items.length;
else if (e.key === 'Home') j = 0;
else if (e.key === 'End') j = items.length - 1;
if (j === null) return;
e.preventDefault();
items[j].focus();
});
}
var SPACES = [
{ name: 'مشروع الرياض', items: ['الملخّص', 'الشاشات', 'المكتبة', 'التسليم'] },
{ name: 'متجر لمسة', items: ['الملخّص', 'الهوية', 'المتجر', 'الحملة'] },
{ name: 'مقهى ضوء', items: ['الملخّص', 'القائمة', 'التغليف', 'اللافتات'] }
];
var btn = root.querySelector('.ws');
var list = root.querySelector('.wsl');
var nameEl = root.querySelector('.wsn');
var nv = root.querySelector('ul.nv');
var live = root.querySelector('.live');
function build(i) {
var sp = SPACES[i];
nameEl.textContent = sp.name;
nv.innerHTML = '';
sp.items.forEach(function (t, k) {
var li = document.createElement('li');
var b = document.createElement('button');
b.className = 'item';
b.innerHTML = '<span class="ic" aria-hidden="true">◇</span><span class="lbl">' + t + '</span>';
if (k === 0) b.setAttribute('aria-current', 'page');
b.addEventListener('click', function () {
nv.querySelectorAll('.item').forEach(function (x) { x.removeAttribute('aria-current'); });
b.setAttribute('aria-current', 'page');
});
li.appendChild(b); nv.appendChild(li);
});
// التبديل يُعلَن: بدونه يعمل المستخدم على بيانات عميل آخر دون أن يدري
live.textContent = 'مساحة العمل الآن: ' + sp.name;
}
function open(v) { list.hidden = !v; btn.setAttribute('aria-expanded', String(v)); }
btn.addEventListener('click', function (e) { e.stopPropagation(); open(list.hidden); });
document.addEventListener('click', function () { if (!list.hidden) open(false); });
document.addEventListener('keydown', function (e) {
if (e.key === 'Escape' && !list.hidden) { open(false); btn.focus(); }
});
list.addEventListener('click', function (e) {
var li = e.target.closest('[data-ws]');
if (!li) return;
e.stopPropagation();
list.querySelectorAll('li').forEach(function (x) { x.setAttribute('aria-selected', String(x === li)); });
build(+li.dataset.ws);
open(false);
});
build(0);
}
function mount() {
ac = new AbortController();
var real = window.document;
/* وسيط يمرّر كل شيء إلى المستند الحقيقي، ويعلّق كل مستمع بإشارة
تُقطع عند إعادة التركيب — فلا يبقى مستمع من نسخة ماتت. */
var doc = new Proxy(real, {
get: function (t, k) {
if (k === 'addEventListener') {
return function (type, fn, opts) {
var o = (opts && typeof opts === 'object') ? Object.assign({}, opts)
: { capture: !!opts };
o.signal = ac.signal;
return t.addEventListener(type, fn, o);
};
}
var v = t[k];
return typeof v === 'function' ? v.bind(t) : v;
}
});
function track(fn) {
return function (f, ms) { var id = fn(f, ms); timers.push(id); return id; };
}
run(host, doc, track(window.setTimeout.bind(window)),
track(window.setInterval.bind(window)));
}
function unmount() {
if (ac) ac.abort();
// المعرّفان يتشاركان فضاءً واحدًا في المتصفّح، فالإلغاء المزدوج آمن
timers.forEach(function (id) { window.clearTimeout(id); window.clearInterval(id); });
timers = [];
host.innerHTML = snapshot;
}
mount();
addEventListener('pt-lang', function () { unmount(); mount(); });
})();
# Sidebar with Workspace Switcher
**Role:** You are an Arabic-first UI designer and front-end engineer. Read the whole
specification before writing a single line, then follow it literally. If two requirements
conflict, favour usability over visual effect.
**Goal:** Sidebar with Workspace Switcher — Switching the client swaps the whole navigation
**Why this component matters:** Agencies work across clients. Switching workspace must rebuild the nav, reset the active item and announce the change — otherwise the user acts on the previous client’s data.
**Direction:** Genuine RTL — not a mirrored Latin layout. Use logical properties
(`margin-inline-start`, `padding-inline`, `inset-inline-start`, `text-align: start`),
never physical ones (`margin-left`, `left`). The layout must flip with `dir` on its own,
with no duplicated rules.
**Typography:** Cairo for Arabic, IBM Plex Sans for Latin. Arabic line-height must be
`0.18` higher than the Latin equivalent — dots, hamzas and maddas need more vertical room.
Arabic font-size runs `1.06×` the Latin size at the same optical weight.
**Numerals:** Western digits in both languages (`1,234.50`). Only the currency changes:
`ر.س` **after** the number in Arabic, `$` **before** it in English. Jordanian dinar
uses **three** decimal places, not two.
**Colors:** Dark mode — background `#0D142B` · surfaces `#211F54` · borders `#545C91` · text `#918FC2`.
Accent `#ADA9E8` must never exceed 8% of the screen area.
**Language:** Bilingual — every string carries both Arabic and English, and the layout
flips with `dir` automatically.
**States:** `default` · `hover` · `focus` · `active` · `disabled` · `loading` · `error`.
Do not design the resting state alone.
**Accessibility:** Contrast ratio at least `4.5:1`, complete keyboard navigation,
visible focus rings, and honour `prefers-reduced-motion`.
**Output:** Clean HTML and CSS in two separate files. No frameworks, no libraries,
no external dependencies.