المكوّنات · شريط جانبي بملفّ المستخدم
شريط جانبي بملفّ المستخدم
قائمة منسدلة تُغلق بالضغط خارجها وبمفتاح الهروب
13 تصاميم من هذه العائلة
<div class="sb sbp">
<nav aria-label="التنقّل الرئيسي">
<div class="sb-head"><b data-ar="وكالة مدى" data-en="Mada Agency">وكالة مدى</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="Campaigns">الحملات</span>
</button></li>
<li><button class="item" data-nav>
<span class="ic" aria-hidden="true">◒</span>
<span class="lbl" data-ar="المحتوى" data-en="Content">المحتوى</span>
</button></li>
<li><button class="item" data-nav>
<span class="ic" aria-hidden="true">◓</span>
<span class="lbl" data-ar="التقارير" data-en="Reports">التقارير</span>
</button></li>
<li><button class="item" data-nav>
<span class="ic" aria-hidden="true">◉</span>
<span class="lbl" data-ar="العملاء" data-en="Clients">العملاء</span>
</button></li>
</ul>
<div class="sb-foot">
<button class="usr" aria-expanded="false" aria-haspopup="menu">
<span class="av" aria-hidden="true">ر</span>
<span class="who"><b data-ar="ريم القحطاني" data-en="R. Alqahtani">ريم القحطاني</b>
<i data-ar="مديرة الحسابات" data-en="Account Director">مديرة الحسابات</i></span>
<span class="arw" aria-hidden="true">⌃</span></button>
<ul class="menu" role="menu" hidden>
<li role="none"><button role="menuitem" data-ar="الملف الشخصي" data-en="Profile">الملف الشخصي</button></li>
<li role="none"><button role="menuitem" data-ar="تبديل الوكالة" data-en="Switch agency">تبديل الوكالة</button></li>
<li role="none"><button role="menuitem" class="out" data-ar="تسجيل الخروج" data-en="Sign out">تسجيل الخروج</button></li>
</ul>
</div>
</nav>
<div class="body">
<h4 data-ar="وكالة تسويق" data-en="Marketing agency">وكالة تسويق</h4>
<p data-ar="اضغط أي بند لتراه ينشط. التنقّل بالكيبورد يعمل بالأسهم." data-en="Click any item to activate it. Arrow keys navigate.">اضغط أي بند لتراه ينشط. التنقّل بالكيبورد يعمل بالأسهم.</p>
</div>
</div>
/* pt-scoped */
/* sidebar-profile — وكالة تسويق */
.sbp{display:flex;height:100%;width:100%;font-size:10px;
color:var(--pt-text-secondary);overflow:hidden;position:relative}
.sbp nav{flex:none;display:flex;flex-direction:column;min-width:0}
.sbp ul{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;
overflow-y:auto;flex:1}
.sbp li{margin:0}
.sbp .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}
.sbp .ic{flex:none;text-align:center;line-height:1}
.sbp .lbl{flex:1;overflow:hidden;text-overflow:ellipsis}
.sbp .body{flex:1;padding:12px;display:flex;flex-direction:column;gap:7px;min-width:0}
.sbp .body h4{margin:0;font-size:11px;color:var(--pt-text-primary)}
.sbp .body p{margin:0;font-size:9px;color:var(--pt-text-muted);line-height:1.8}
.sbp .item:focus-visible{outline:2px solid var(--pt-focus-ring);outline-offset:-2px}
/* شخصية: بطاقات مرتفعة — كل بند بطاقة، والنشط يرتفع بظلّ وحلقة */
.sbp{border:1px solid var(--pt-border-subtle);border-radius:var(--pt-radius-xl);
background:var(--pt-bg-base)}
.sbp nav{width:205px;background:var(--pt-bg-inset);padding:8px;
border-inline-end:1px solid var(--pt-border-subtle)}
.sbp .sb-head{padding:2px 4px 9px}
.sbp .sb-head b{font-size:10px;color:var(--pt-text-primary)}
.sbp ul{padding:0;gap:5px}
.sbp .item{gap:8px;padding:7px 9px;border-radius:var(--pt-radius-md);
background:var(--pt-surface);
transition:transform var(--pt-motion-duration-fast) var(--pt-motion-easing-standard),
box-shadow var(--pt-motion-duration-fast) var(--pt-motion-easing-standard)}
.sbp .ic{width:14px;font-size:11px}
.sbp .item:hover{transform:translateY(-1px);box-shadow:var(--pt-shadow-2)}
.sbp .item[aria-current="page"]{color:var(--pt-accent);box-shadow:var(--pt-shadow-3),
inset 0 0 0 1px color-mix(in srgb,var(--pt-accent) 45%,transparent)}
.sbp .sb-foot{position:relative;padding-top:8px;margin-top:auto;
border-top:1px solid var(--pt-border-subtle)}
.sbp .usr{display:flex;align-items:center;gap:7px;width:100%;padding:6px;border:0;
border-radius:var(--pt-radius-md);background:var(--pt-surface);color:inherit;
font:inherit;cursor:pointer;text-align:start}
.sbp .usr:hover{box-shadow:var(--pt-shadow-2)}
.sbp .usr:focus-visible{outline:2px solid var(--pt-focus-ring);outline-offset:1px}
.sbp .av{flex:none;width:22px;height:22px;border-radius:var(--pt-radius-md);
display:grid;place-items:center;background:var(--pt-accent-muted);
color:var(--pt-accent);font-size:9px}
.sbp .who{flex:1;min-width:0;display:flex;flex-direction:column}
.sbp .who b{font-size:9.5px;color:var(--pt-text-primary);white-space:nowrap;
overflow:hidden;text-overflow:ellipsis}
.sbp .who i{font-style:normal;font-size:8px;color:var(--pt-text-muted)}
.sbp .arw{font-size:8px;color:var(--pt-text-muted)}
.sbp .menu{position:absolute;inset-inline:0;inset-block-end:calc(100% + 3px);z-index:5;
margin:0;padding:4px;list-style:none;display:flex;flex-direction:column;gap:2px;
border-radius:var(--pt-radius-md);background:var(--pt-bg-overlay);
border:1px solid var(--pt-border-default);box-shadow:var(--pt-shadow-4)}
.sbp .menu button{width:100%;padding:6px 8px;border:0;border-radius:var(--pt-radius-sm);
background:transparent;color:var(--pt-text-secondary);font:inherit;font-size:9.5px;
cursor:pointer;text-align:start}
.sbp .menu button:hover{background:var(--pt-surface-hover);color:var(--pt-text-primary)}
.sbp .menu button:focus-visible{outline:2px solid var(--pt-focus-ring);outline-offset:-2px}
.sbp .menu .out{color:var(--pt-color-danger-400)}
/* يعمل داخل إطار معزول — لا يعتمد على شيء خارجه */
/* pt-remount — يعاد التركيب عند تبديل اللغة */
(function () {
var host = document.querySelector('.sbp');
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 btn = root.querySelector('.usr');
var menu = root.querySelector('.menu');
function open(v) {
menu.hidden = !v;
btn.setAttribute('aria-expanded', String(v));
if (v) menu.querySelector('button').focus();
}
btn.addEventListener('click', function (e) { e.stopPropagation(); open(menu.hidden); });
document.addEventListener('click', function () { if (!menu.hidden) open(false); });
menu.addEventListener('click', function (e) { e.stopPropagation(); });
document.addEventListener('keydown', function (e) {
if (e.key === 'Escape' && !menu.hidden) { open(false); btn.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(); });
})();
# Sidebar with User Menu
**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 User Menu — A menu that closes on outside click and on Escape
**Why this component matters:** A dropdown that only closes by clicking its trigger again traps the user. Escape and outside-click are not extras — they are what makes a menu a menu.
**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.