المكوّنات · مقارنة فترتين
مقارنة فترتين
الحالي أمام السابق، والفرق محسوب في الاتجاهين
12 تصاميم من هذه العائلة
<div class="st stcm">
<div class="row" data-now="184300" data-prev="196800" data-money="1">
<span class="k" data-ar="الرواتب" data-en="Payroll">الرواتب</span>
<span class="pair"><b class="v"></b><i class="was"></i></span>
<span class="d"></span>
</div>
<div class="row" data-now="248" data-prev="221">
<span class="k" data-ar="الموظفون" data-en="Employees">الموظفون</span>
<span class="pair"><b class="v"></b><i class="was"></i></span>
<span class="d"></span>
</div>
<div class="row" data-now="31" data-prev="44">
<span class="k" data-ar="الاستقالات" data-en="Resignations">الاستقالات</span>
<span class="pair"><b class="v"></b><i class="was"></i></span>
<span class="d"></span>
</div>
<p class="note" data-ar="مقارنة بالربع السابق" data-en="vs. previous quarter">مقارنة بالربع السابق</p>
</div>
/* pt-scoped */
/* stats-compare */
.stcm{width:100%;height:100%;display:flex;flex-direction:column;
font-size:10px;color:var(--pt-text-secondary);overflow:hidden}
.stcm .k{font-size:8.5px;color:var(--pt-text-muted);white-space:nowrap;
overflow:hidden;text-overflow:ellipsis}
.stcm .v{font-variant-numeric:tabular-nums;color:var(--pt-text-primary);
letter-spacing:-.01em;line-height:1.15}
.stcm .d{font-size:8px;font-variant-numeric:tabular-nums;white-space:nowrap}
.stcm .up{color:var(--pt-accent)}
.stcm .dn{color:var(--pt-color-danger-400)}
/* شخصية: صفوف مفصولة بخطوط، بلا بطاقات، انحناء متوسّط للحاوية */
.stcm{padding:4px 12px;gap:0;justify-content:center;
border:1px solid var(--pt-border-subtle);border-radius:var(--pt-radius-md);
background:var(--pt-surface)}
.stcm .row{display:grid;grid-template-columns:1fr auto auto;align-items:center;
gap:10px;padding:9px 0;border-bottom:1px solid var(--pt-border-subtle)}
.stcm .row:last-of-type{border-bottom:0}
.stcm .pair{display:flex;align-items:baseline;gap:6px}
.stcm .v{font-size:13px;font-weight:600}
.stcm .was{font-style:normal;font-size:8.5px;color:var(--pt-text-muted);
font-variant-numeric:tabular-nums;text-decoration:line-through}
.stcm .d{min-width:44px;text-align:end}
.stcm .note{margin:6px 0 0;font-size:8px;color:var(--pt-text-muted)}
/* يعمل داخل إطار معزول — لا يعتمد على شيء خارجه */
/* pt-remount — يعاد التركيب عند تبديل اللغة */
(function () {
var host = document.querySelector('.stcm');
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('.row').forEach(function (r) {
var now = parseFloat(r.dataset.now), prev = parseFloat(r.dataset.prev);
var fmt = r.dataset.money ? money : function (n) { return nf(n); };
r.querySelector('.v').textContent = fmt(now);
r.querySelector('.was').textContent = fmt(prev);
var p = pct(now, prev);
var d = r.querySelector('.d');
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(); });
})();
# Period Comparison
**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:** Period Comparison — Current against previous — the delta computed both ways
**Why this component matters:** A single number answers “how many”, never “is that good”. Showing the previous period beside it, with the gap computed, is what turns a number into information.
**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.