المكوّنات · درج جانبي للجوّال
درج جانبي للجوّال
ينزلق من جهة البداية، ويحبس التركيز داخله
13 تصاميم من هذه العائلة
<div class="sb sbd">
<div class="body">
<button class="opn" aria-expanded="false" aria-controls="dr">☰ <span data-ar="القائمة" data-en="Menu">القائمة</span></button>
<h4 data-ar="تطبيق توصيل" data-en="Delivery app">تطبيق توصيل</h4>
<p data-ar="التركيز يبقى داخل الدرج، ويعود لمكانه عند الإغلاق." data-en="Focus stays inside the drawer and returns on close.">التركيز يبقى داخل الدرج، ويعود لمكانه عند الإغلاق.</p>
</div>
<div class="scrim" hidden></div>
<nav id="dr" aria-label="التنقّل الرئيسي" aria-hidden="true">
<div class="sb-head">
<b data-ar="سريع" data-en="Saree">سريع</b>
<button class="cls" aria-label="إغلاق">✕</button></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="Trips">الرحلات</span>
</button></li>
<li><button class="item" data-nav>
<span class="ic" aria-hidden="true">◆</span>
<span class="lbl" data-ar="السائقون" data-en="Drivers">السائقون</span>
</button></li>
<li><button class="item" data-nav>
<span class="ic" aria-hidden="true">◈</span>
<span class="lbl" data-ar="المناطق" data-en="Zones">المناطق</span>
</button></li>
<li><button class="item" data-nav>
<span class="ic" aria-hidden="true">◉</span>
<span class="lbl" data-ar="الشكاوى" data-en="Complaints">الشكاوى</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>
/* pt-scoped */
/* sidebar-drawer — تطبيق توصيل */
.sbd{display:flex;height:100%;width:100%;font-size:10px;
color:var(--pt-text-secondary);overflow:hidden;position:relative}
.sbd nav{flex:none;display:flex;flex-direction:column;min-width:0}
.sbd ul{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;
overflow-y:auto;flex:1}
.sbd li{margin:0}
.sbd .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}
.sbd .ic{flex:none;text-align:center;line-height:1}
.sbd .lbl{flex:1;overflow:hidden;text-overflow:ellipsis}
.sbd .body{flex:1;padding:12px;display:flex;flex-direction:column;gap:7px;min-width:0}
.sbd .body h4{margin:0;font-size:11px;color:var(--pt-text-primary)}
.sbd .body p{margin:0;font-size:9px;color:var(--pt-text-muted);line-height:1.8}
.sbd .item:focus-visible{outline:2px solid var(--pt-focus-ring);outline-offset:-2px}
/* شخصية: كبيرة الانحناء وواسعة اللمس — النشط تعبئة كاملة */
.sbd{border:1px solid var(--pt-border-subtle);border-radius:var(--pt-radius-2xl);
background:var(--pt-surface)}
.sbd nav{position:absolute;inset-block:0;inset-inline-start:0;z-index:4;width:215px;
background:var(--pt-bg-inset);
border-start-end-radius:var(--pt-radius-2xl);border-end-end-radius:var(--pt-radius-2xl);
transform:translateX(calc(var(--sb-dir,1) * -100%));
transition:transform var(--pt-motion-duration-normal) var(--pt-motion-easing-decelerate);
box-shadow:var(--pt-shadow-5)}
[dir=rtl] .sbd nav{--sb-dir:-1}
.sbd.open nav{transform:translateX(0)}
.sbd .sb-head{display:flex;align-items:center;gap:6px;padding:11px 12px;
border-bottom:1px solid var(--pt-border-subtle)}
.sbd .sb-head b{font-size:10.5px;color:var(--pt-text-primary)}
.sbd ul{padding:8px;gap:4px}
.sbd .item{gap:9px;padding:9px 11px;border-radius:var(--pt-radius-lg)}
.sbd .ic{width:15px;font-size:12px}
.sbd .item:hover{background:var(--pt-surface-hover);color:var(--pt-text-primary)}
.sbd .item[aria-current="page"]{background:var(--pt-accent);color:var(--pt-color-ink-900)}
.sbd .opn{align-self:flex-start;display:inline-flex;align-items:center;gap:6px;
padding:7px 12px;border-radius:var(--pt-radius-full);
border:1px solid var(--pt-border-default);background:var(--pt-bg-raised);
color:var(--pt-text-secondary);font:inherit;font-size:9.5px;cursor:pointer}
.sbd .opn:hover{border-color:var(--pt-accent);color:var(--pt-accent)}
.sbd .opn:focus-visible{outline:2px solid var(--pt-focus-ring);outline-offset:1px}
.sbd .scrim{position:absolute;inset:0;z-index:3;border-radius:inherit;
background:rgba(5,9,26,.55);backdrop-filter:blur(1px)}
.sbd .cls{margin-inline-start:auto;width:22px;height:22px;display:grid;place-items:center;
border:0;border-radius:var(--pt-radius-full);background:transparent;
color:var(--pt-text-muted);font-size:10px;cursor:pointer}
.sbd .cls:hover{background:var(--pt-surface-hover);color:var(--pt-text-primary)}
.sbd .cls:focus-visible{outline:2px solid var(--pt-focus-ring);outline-offset:1px}
@media(prefers-reduced-motion:reduce){.sbd nav{transition:none}
}
/* يعمل داخل إطار معزول — لا يعتمد على شيء خارجه */
/* pt-remount — يعاد التركيب عند تبديل اللغة */
(function () {
var host = document.querySelector('.sbd');
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 opn = root.querySelector('.opn');
var cls = root.querySelector('.cls');
var drawer = root.querySelector('nav');
var scrim = root.querySelector('.scrim');
var last = null;
function set(v) {
root.classList.toggle('open', v);
scrim.hidden = !v;
drawer.setAttribute('aria-hidden', String(!v));
opn.setAttribute('aria-expanded', String(v));
if (v) { last = document.activeElement; cls.focus(); }
else if (last) last.focus();
}
opn.addEventListener('click', function () { set(true); });
cls.addEventListener('click', function () { set(false); });
scrim.addEventListener('click', function () { set(false); });
document.addEventListener('keydown', function (e) {
if (!root.classList.contains('open')) return;
if (e.key === 'Escape') { set(false); return; }
if (e.key !== 'Tab') return;
var f = drawer.querySelectorAll('button');
var first = f[0], lastEl = f[f.length - 1];
if (e.shiftKey && document.activeElement === first) { e.preventDefault(); lastEl.focus(); }
else if (!e.shiftKey && document.activeElement === lastEl) { e.preventDefault(); first.focus(); }
});
}
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(); });
})();
# Mobile Drawer
**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:** Mobile Drawer — Slides from the start edge and traps focus inside
**Why this component matters:** A drawer that leaves focus behind lets keyboard users tab into hidden content. Trapping focus and restoring it on close is what separates a drawer from a div that slides.
**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.