المكوّنات · أشرطة ترتيب
أشرطة ترتيب
يرتّب نفسه ويقيس أشرطته نسبةً إلى الأكبر
12 تصاميم من هذه العائلة
<div class="st stb">
<span class="k" data-ar="الموظفون حسب القسم" data-en="Employees by department">الموظفون حسب القسم</span>
<ul class="list">
<li data-v="64"><span data-ar="التقنية" data-en="Tech">التقنية</span></li>
<li data-v="31"><span data-ar="المالية" data-en="Finance">المالية</span></li>
<li data-v="88"><span data-ar="العمليات" data-en="Operations">العمليات</span></li>
<li data-v="22"><span data-ar="الموارد" data-en="HR">الموارد</span></li>
<li data-v="43"><span data-ar="المبيعات" data-en="Sales">المبيعات</span></li>
</ul>
</div>
/* pt-scoped */
/* stats-bars */
.stb{width:100%;height:100%;display:flex;flex-direction:column;
font-size:10px;color:var(--pt-text-secondary);overflow:hidden}
.stb .k{font-size:8.5px;color:var(--pt-text-muted);white-space:nowrap;
overflow:hidden;text-overflow:ellipsis}
.stb .v{font-variant-numeric:tabular-nums;color:var(--pt-text-primary);
letter-spacing:-.01em;line-height:1.15}
.stb .d{font-size:8px;font-variant-numeric:tabular-nums;white-space:nowrap}
.stb .up{color:var(--pt-accent)}
.stb .dn{color:var(--pt-color-danger-400)}
/* شخصية: أشرطة كبسولية، بلا حاوية مرئية، كثافة مريحة */
.stb{padding:10px 12px;gap:8px;justify-content:center}
.stb .list{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:6px}
.stb li{display:grid;grid-template-columns:58px 1fr auto;align-items:center;gap:8px;
font-size:9px}
.stb li > span:first-child{color:var(--pt-text-secondary);white-space:nowrap;
overflow:hidden;text-overflow:ellipsis}
.stb .track{height:7px;border-radius:var(--pt-radius-full);
background:var(--pt-border-subtle);overflow:hidden}
.stb .fill{height:100%;border-radius:var(--pt-radius-full);background:var(--pt-accent);
width:0;transition:width var(--pt-motion-duration-slow) var(--pt-motion-easing-decelerate)}
.stb li:nth-child(n+2) .fill{background:color-mix(in srgb,var(--pt-accent) 62%,transparent)}
.stb .n{font-size:9px;font-variant-numeric:tabular-nums;color:var(--pt-text-primary);
min-width:20px;text-align:end}
/* يعمل داخل إطار معزول — لا يعتمد على شيء خارجه */
/* pt-remount — يعاد التركيب عند تبديل اللغة */
(function () {
var host = document.querySelector('.stb');
if (!host) return;
var snapshot = host.innerHTML;
var timers = [];
var ac = null;
/* الجسم كما كتبه المولِّد. يستقبل بدائل مظلَّلة لـ root وdocument
والمؤقّتات، فينظّف نفسه دون أن يعرف أنه قابل لإعادة التركيب. */
function run(root, document, setTimeout, setInterval) {
function nf(n, dec) {
return Number(n).toLocaleString('en-US',
{ minimumFractionDigits: dec || 0, maximumFractionDigits: dec || 0 });
}
function money(n) {
var ar = document.documentElement.lang !== 'en';
// ق١ب: الرمز يلي الرقم عربيًّا ويسبقه إنجليزيًّا · التثبيت 3.75
return ar ? nf(Math.round(n * 3.75)) + ' ر.س' : '$' + nf(n);
}
function pct(a, b) { return b === 0 ? 0 : ((a - b) / b) * 100; }
function sign(x) { return (x >= 0 ? '+' : '−') + nf(Math.abs(x), 1) + '%'; }
var list = root.querySelector('.list');
var items = [].slice.call(list.children);
// الترتيب في الكود لا في الترميز: بيانات جديدة = ترتيب صحيح تلقائيًّا
items.sort(function (a, b) { return b.dataset.v - a.dataset.v; });
var max = Math.max.apply(null, items.map(function (li) { return +li.dataset.v; }));
items.forEach(function (li) {
var v = +li.dataset.v;
var track = document.createElement('span'); track.className = 'track';
var fill = document.createElement('span'); fill.className = 'fill';
track.appendChild(fill);
var n = document.createElement('span'); n.className = 'n'; n.textContent = nf(v);
li.appendChild(track); li.appendChild(n);
list.appendChild(li);
requestAnimationFrame(function () { fill.style.width = (v / max * 100) + '%'; });
});
}
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(); });
})();
# Ranked Bars
**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:** Ranked Bars — Sorts itself and scales each bar against the largest
**Why this component matters:** Ranked lists must sort in code, not in the markup. Hardcoding the order means a data change silently produces a wrong ranking that still looks plausible.
**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.