المكوّنات · شريط جانبي بتثبيت البنود
شريط جانبي بتثبيت البنود
ثبّت ما تستخدمه يوميًّا في الأعلى، ويبقى محفوظًا
13 تصاميم من هذه العائلة
<div class="sb sbpn">
<nav aria-label="التنقّل الرئيسي">
<div class="sb-head"><b data-ar="البيك الذهبي" data-en="Golden Bite">البيك الذهبي</b></div>
<p class="pl" data-ar="المثبَّتة" data-en="Pinned">المثبَّتة</p>
<ul class="pins"></ul>
<p class="pl" data-ar="الكل" data-en="All">الكل</p>
<ul class="all">
<li data-id="0"><button class="item" data-nav aria-current="page">
<span class="ic" aria-hidden="true">◍</span>
<span class="lbl" data-ar="الطلبات المباشرة" data-en="Live orders">الطلبات المباشرة</span>
<span class="pin" role="button" tabindex="0" aria-label="تثبيت الطلبات المباشرة">☆</span>
</button></li>
<li data-id="1"><button class="item" data-nav>
<span class="ic" aria-hidden="true">◎</span>
<span class="lbl" data-ar="قائمة الطعام" data-en="Menu">قائمة الطعام</span>
<span class="pin" role="button" tabindex="0" aria-label="تثبيت قائمة الطعام">☆</span>
</button></li>
<li data-id="2"><button class="item" data-nav>
<span class="ic" aria-hidden="true">◌</span>
<span class="lbl" data-ar="الفروع" data-en="Branches">الفروع</span>
<span class="pin" role="button" tabindex="0" aria-label="تثبيت الفروع">☆</span>
</button></li>
<li data-id="3"><button class="item" data-nav>
<span class="ic" aria-hidden="true">◉</span>
<span class="lbl" data-ar="المخزون" data-en="Stock">المخزون</span>
<span class="pin" role="button" tabindex="0" aria-label="تثبيت المخزون">☆</span>
</button></li>
<li data-id="4"><button class="item" data-nav>
<span class="ic" aria-hidden="true">◐</span>
<span class="lbl" data-ar="الموردون" data-en="Suppliers">الموردون</span>
<span class="pin" role="button" tabindex="0" aria-label="تثبيت الموردون">☆</span>
</button></li>
<li data-id="5"><button class="item" data-nav>
<span class="ic" aria-hidden="true">◑</span>
<span class="lbl" data-ar="التقارير" data-en="Reports">التقارير</span>
<span class="pin" role="button" tabindex="0" aria-label="تثبيت التقارير">☆</span>
</button></li>
</ul>
</nav>
<div class="body">
<h4 data-ar="سلسلة مطاعم" data-en="Restaurant chain">سلسلة مطاعم</h4>
<p data-ar="اضغط أي بند لتراه ينشط. التنقّل بالكيبورد يعمل بالأسهم." data-en="Click any item to activate it. Arrow keys navigate.">اضغط أي بند لتراه ينشط. التنقّل بالكيبورد يعمل بالأسهم.</p>
</div>
</div>
/* pt-scoped */
/* sidebar-pinned — سلسلة مطاعم */
.sbpn{display:flex;height:100%;width:100%;font-size:10px;
color:var(--pt-text-secondary);overflow:hidden;position:relative}
.sbpn nav{flex:none;display:flex;flex-direction:column;min-width:0}
.sbpn ul{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;
overflow-y:auto;flex:1}
.sbpn li{margin:0}
.sbpn .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}
.sbpn .ic{flex:none;text-align:center;line-height:1}
.sbpn .lbl{flex:1;overflow:hidden;text-overflow:ellipsis}
.sbpn .body{flex:1;padding:12px;display:flex;flex-direction:column;gap:7px;min-width:0}
.sbpn .body h4{margin:0;font-size:11px;color:var(--pt-text-primary)}
.sbpn .body p{margin:0;font-size:9px;color:var(--pt-text-muted);line-height:1.8}
.sbpn .item:focus-visible{outline:2px solid var(--pt-focus-ring);outline-offset:-2px}
/* شخصية: قائمة مسطّحة بانحناء صغير، قسم مثبَّت أعلى، نجمة تتبدّل */
.sbpn{border:1px solid var(--pt-border-subtle);border-radius:var(--pt-radius-md);
background:var(--pt-surface)}
.sbpn nav{width:212px;background:var(--pt-bg-inset);
border-inline-end:1px solid var(--pt-border-subtle)}
.sbpn .sb-head{padding:9px 10px 6px}
.sbpn .sb-head b{font-size:10px;color:var(--pt-text-primary)}
.sbpn .pl{margin:0;padding:6px 11px 3px;font-size:8px;font-weight:700;
color:var(--pt-text-muted);letter-spacing:.06em}
.sbpn ul{padding:0 6px;gap:1px;flex:none}
.sbpn ul.all{flex:1}
.sbpn .item{gap:7px;padding:6px 8px;border-radius:var(--pt-radius-sm)}
.sbpn .ic{width:13px;font-size:10px}
.sbpn .item:hover{background:var(--pt-surface-hover);color:var(--pt-text-primary)}
.sbpn .item[aria-current="page"]{background:var(--pt-surface);color:var(--pt-accent)}
.sbpn .pin{flex:none;width:15px;text-align:center;font-size:10px;
color:var(--pt-text-muted);opacity:0;cursor:pointer;border-radius:var(--pt-radius-xs)}
.sbpn .item:hover .pin, .sbpn .pin:focus-visible, .sbpn li.on .pin{opacity:1}
.sbpn li.on .pin{color:var(--pt-accent)}
.sbpn .pin:focus-visible{outline:2px solid var(--pt-focus-ring);outline-offset:1px}
/* يعمل داخل إطار معزول — لا يعتمد على شيء خارجه */
/* pt-remount — يعاد التركيب عند تبديل اللغة */
(function () {
var host = document.querySelector('.sbpn');
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 all = root.querySelector('ul.all');
var pins = root.querySelector('ul.pins');
var KEY = 'sb-pins';
function saved() {
try { return JSON.parse(localStorage.getItem(KEY) || '[]'); } catch (e) { return []; }
}
function store(list) { try { localStorage.setItem(KEY, JSON.stringify(list)); } catch (e) {} }
function paint() {
var list = saved();
[].slice.call(root.querySelectorAll('nav li[data-id]')).forEach(function (li) {
var on = list.indexOf(li.dataset.id) !== -1;
li.classList.toggle('on', on);
var star = li.querySelector('.pin');
star.textContent = on ? '★' : '☆';
star.setAttribute('aria-pressed', String(on));
(on ? pins : all).appendChild(li);
});
}
root.addEventListener('click', function (e) {
var star = e.target.closest('.pin');
if (!star) return;
e.preventDefault(); e.stopPropagation();
var li = star.closest('li');
var list = saved();
var i = list.indexOf(li.dataset.id);
if (i === -1) list.push(li.dataset.id); else list.splice(i, 1);
store(list); paint();
});
root.addEventListener('keydown', function (e) {
if ((e.key === 'Enter' || e.key === ' ') && e.target.classList.contains('pin')) {
e.preventDefault(); e.target.click();
}
});
paint();
}
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 Pinned Items
**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 Pinned Items — Pin what you use daily to the top — and it stays pinned
**Why this component matters:** In a long menu the same three items get used every day. Letting the user pin them removes a daily scan; persisting the choice is what makes it worth doing at all.
**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.