المكوّنات · شريط جانبي قابل للطيّ
شريط جانبي قابل للطيّ
يطوي نفسه إلى شريط أيقونات، ويتذكّر اختيارك
13 تصاميم من هذه العائلة
<div class="sb sbc">
<nav aria-label="التنقّل الرئيسي">
<div class="sb-head">
<button class="tgl" aria-expanded="true" aria-label="طيّ الشريط">☰</button>
<b data-ar="شركة الأفق" data-en="Ufuq Co.">شركة الأفق</b>
</div>
<ul>
<li><button class="item" data-nav aria-current="page">
<span class="ic" aria-hidden="true">▤</span>
<span class="lbl" data-ar="لوحة المعلومات" data-en="Dashboard">لوحة المعلومات</span>
</button></li>
<li><button class="item" data-nav>
<span class="ic" aria-hidden="true">◔</span>
<span class="lbl" data-ar="الموظفون" data-en="Employees">الموظفون</span>
</button></li>
<li><button class="item" data-nav>
<span class="ic" aria-hidden="true">▦</span>
<span class="lbl" data-ar="الأقسام" data-en="Departments">الأقسام</span>
</button></li>
<li><button class="item" data-nav>
<span class="ic" aria-hidden="true">◫</span>
<span class="lbl" data-ar="الرواتب" data-en="Payroll">الرواتب</span>
</button></li>
<li><button class="item" data-nav>
<span class="ic" aria-hidden="true">◷</span>
<span class="lbl" data-ar="الحضور" data-en="Attendance">الحضور</span>
</button></li>
<li><button class="item" data-nav>
<span class="ic" aria-hidden="true">⚙</span>
<span class="lbl" data-ar="الإعدادات" data-en="Settings">الإعدادات</span>
</button></li>
</ul>
</nav>
<div class="body">
<h4 data-ar="الموارد البشرية" data-en="HR">الموارد البشرية</h4>
<p data-ar="اضغط أي بند لتراه ينشط. التنقّل بالكيبورد يعمل بالأسهم." data-en="Click any item to activate it. Arrow keys navigate.">اضغط أي بند لتراه ينشط. التنقّل بالكيبورد يعمل بالأسهم.</p>
</div>
</div>
/* pt-scoped */
/* sidebar-collapsible — الموارد البشرية */
.sbc{display:flex;height:100%;width:100%;font-size:10px;
color:var(--pt-text-secondary);overflow:hidden;position:relative}
.sbc nav{flex:none;display:flex;flex-direction:column;min-width:0}
.sbc ul{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;
overflow-y:auto;flex:1}
.sbc li{margin:0}
.sbc .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}
.sbc .ic{flex:none;text-align:center;line-height:1}
.sbc .lbl{flex:1;overflow:hidden;text-overflow:ellipsis}
.sbc .body{flex:1;padding:12px;display:flex;flex-direction:column;gap:7px;min-width:0}
.sbc .body h4{margin:0;font-size:11px;color:var(--pt-text-primary)}
.sbc .body p{margin:0;font-size:9px;color:var(--pt-text-muted);line-height:1.8}
.sbc .item:focus-visible{outline:2px solid var(--pt-focus-ring);outline-offset:-2px}
/* شخصية: حادّة وكثيفة — انحناء أدنى، شريط داخلي للنشط */
.sbc{border:1px solid var(--pt-border-subtle);border-radius:var(--pt-radius-xs);
background:var(--pt-surface)}
.sbc nav{width:200px;background:var(--pt-bg-inset);
border-inline-end:1px solid var(--pt-border-subtle);
transition:width var(--pt-motion-duration-normal) var(--pt-motion-easing-standard)}
.sbc .sb-head{display:flex;align-items:center;gap:6px;padding:7px 8px;min-height:32px;
border-bottom:1px solid var(--pt-border-subtle)}
.sbc .sb-head b{font-size:10px;color:var(--pt-text-primary);white-space:nowrap;
overflow:hidden;text-overflow:ellipsis}
.sbc ul{padding:4px;gap:1px}
.sbc .item{gap:7px;padding:5px 8px;border-radius:var(--pt-radius-xs)}
.sbc .ic{width:14px;font-size:11px}
.sbc .item:hover{background:var(--pt-surface-hover);color:var(--pt-text-primary)}
.sbc .item[aria-current="page"]{background:var(--pt-surface);color:var(--pt-accent);
box-shadow:inset 2px 0 0 var(--pt-accent)}
[dir=ltr] .sbc .item[aria-current="page"]{box-shadow:inset -2px 0 0 var(--pt-accent)}
.sbc .tgl{flex:none;width:22px;height:22px;display:grid;place-items:center;border:0;
border-radius:var(--pt-radius-xs);background:transparent;color:var(--pt-text-muted);
cursor:pointer;font-size:11px}
.sbc .tgl:hover{background:var(--pt-surface-hover);color:var(--pt-text-primary)}
.sbc .tgl:focus-visible{outline:2px solid var(--pt-focus-ring);outline-offset:1px}
.sbc.mini nav{width:52px}
.sbc.mini .lbl, .sbc.mini .sb-head b{display:none}
.sbc.mini .item{justify-content:center;padding-inline:0}
/* يعمل داخل إطار معزول — لا يعتمد على شيء خارجه */
/* pt-remount — يعاد التركيب عند تبديل اللغة */
(function () {
var host = document.querySelector('.sbc');
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 tgl = root.querySelector('.tgl');
var KEY = 'sb-collapsed';
function paint(mini) {
root.classList.toggle('mini', mini);
tgl.setAttribute('aria-expanded', String(!mini));
tgl.setAttribute('aria-label', mini ? 'فتح الشريط' : 'طيّ الشريط');
try { localStorage.setItem(KEY, mini ? '1' : '0'); } catch (e) {}
}
tgl.addEventListener('click', function () { paint(!root.classList.contains('mini')); });
try { paint(localStorage.getItem(KEY) === '1'); } catch (e) {}
}
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(); });
})();
# Collapsible Sidebar
**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:** Collapsible Sidebar — Folds into an icon rail and remembers your choice
**Why this component matters:** On narrow screens a 200px sidebar eats a third of the viewport. Folding it to a rail keeps navigation reachable — and the state must persist, or the user re-folds it on every page.
**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.