المكوّنات · شبكة إحصاءات
شبكة إحصاءات
أربعة أرقام في نظرة، وكل فرق محسوب لا مكتوب
12 تصاميم من هذه العائلة
<div class="st stg">
<div class="cards">
<div class="c" data-now="248" data-prev="221">
<span class="k" data-ar="الموظفون" data-en="Employees">الموظفون</span>
<b class="v"></b><span class="d"></span>
</div>
<div class="c" data-now="184300" data-prev="196800" data-money="1">
<span class="k" data-ar="الرواتب" data-en="Payroll">الرواتب</span>
<b class="v"></b><span class="d"></span>
</div>
<div class="c" data-now="96.4" data-prev="94.1" data-dec="1" data-unit="%">
<span class="k" data-ar="الحضور" data-en="Attendance">الحضور</span>
<b class="v"></b><span class="d"></span>
</div>
<div class="c" data-now="12" data-prev="19">
<span class="k" data-ar="طلبات معلّقة" data-en="Pending requests">طلبات معلّقة</span>
<b class="v"></b><span class="d"></span>
</div>
</div>
</div>
/* pt-scoped */
/* stats-grid */
.stg{width:100%;height:100%;display:flex;flex-direction:column;
font-size:10px;color:var(--pt-text-secondary);overflow:hidden}
.stg .k{font-size:8.5px;color:var(--pt-text-muted);white-space:nowrap;
overflow:hidden;text-overflow:ellipsis}
.stg .v{font-variant-numeric:tabular-nums;color:var(--pt-text-primary);
letter-spacing:-.01em;line-height:1.15}
.stg .d{font-size:8px;font-variant-numeric:tabular-nums;white-space:nowrap}
.stg .up{color:var(--pt-accent)}
.stg .dn{color:var(--pt-color-danger-400)}
/* شخصية: شبكة مربّعة حادّة الحواف، حدود رفيعة، كثافة عالية */
.stg{padding:2px}
.stg .cards{display:grid;grid-template-columns:1fr 1fr;gap:1px;flex:1;
background:var(--pt-border-subtle);border:1px solid var(--pt-border-subtle);
border-radius:var(--pt-radius-xs);overflow:hidden}
.stg .c{background:var(--pt-surface);padding:9px 10px;
display:flex;flex-direction:column;gap:3px;justify-content:center}
.stg .v{font-size:16px;font-weight:700}
.stg .d{margin-top:1px}
/* يعمل داخل إطار معزول — لا يعتمد على شيء خارجه */
/* pt-remount — يعاد التركيب عند تبديل اللغة */
(function () {
var host = document.querySelector('.stg');
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) + '%'; }
root.querySelectorAll('.c').forEach(function (c) {
var now = parseFloat(c.dataset.now), prev = parseFloat(c.dataset.prev);
var dec = parseInt(c.dataset.dec || '0', 10);
var v = c.querySelector('.v'), d = c.querySelector('.d');
v.textContent = c.dataset.money ? money(now) : nf(now, dec) + (c.dataset.unit || '');
var p = pct(now, prev);
d.textContent = sign(p);
d.className = 'd ' + (p >= 0 ? 'up' : 'dn');
});
}
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(); });
})();
# Stats Grid
**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:** Stats Grid — Four numbers at a glance — every delta computed, not typed
**Why this component matters:** The most common stat block. Its trap is hardcoded deltas: the moment the data changes the percentage lies. Compute it from the current and previous values so it can never drift.
**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.