المكوّنات · جدول يتحوّل إلى بطاقات
جدول يتحوّل إلى بطاقات
على الشاشة الضيّقة يصير بطاقات، ويحمل كل حقل عنوانه
12 تصاميم من هذه العائلة
<div class="tb tbr">
<div class="head"><h4 data-ar="فواتير العملاء" data-en="Client invoices">فواتير العملاء</h4>
<button class="mode" data-ar="اعرض كبطاقات" data-en="Show as cards">اعرض كبطاقات</button>
<span class="cnt"></span></div>
<div class="wrap"><table>
<thead><tr>
<th scope="col" data-ar="الفاتورة" data-en="Invoice">الفاتورة</th>
<th scope="col" data-ar="العميل" data-en="Client">العميل</th>
<th scope="col" data-ar="الاستحقاق" data-en="Due">الاستحقاق</th>
<th scope="col" data-ar="الحالة" data-en="Status">الحالة</th>
<th scope="col" class="e" data-ar="المبلغ" data-en="Amount">المبلغ</th>
</tr></thead>
<tbody></tbody>
</table></div>
</div>
/* pt-scoped */
/* table-responsive — فواتير */
.tbr{width:100%;height:100%;display:flex;flex-direction:column;gap:6px;
font-size:10px;color:var(--pt-text-secondary);overflow:hidden;padding:9px 10px}
.tbr .wrap{flex:1;min-height:0;overflow:auto;border-radius:var(--pt-radius-sm);
border:1px solid var(--pt-border-subtle)}
.tbr table{width:100%;border-collapse:collapse;font-size:8.5px}
.tbr th, .tbr td{padding:5px 7px;text-align:start;white-space:nowrap}
.tbr thead th{position:sticky;inset-block-start:0;z-index:2;background:var(--pt-bg-inset);
color:var(--pt-text-muted);font-weight:500;font-size:8px;
border-bottom:1px solid var(--pt-border-default)}
.tbr tbody tr{border-bottom:1px solid var(--pt-border-subtle)}
.tbr tbody tr:last-child{border-bottom:0}
.tbr tbody tr:hover{background:var(--pt-surface-hover)}
.tbr tbody td{color:var(--pt-text-secondary)}
.tbr .e{text-align:end;font-variant-numeric:tabular-nums}
.tbr .head{display:flex;align-items:center;gap:7px;flex-wrap:wrap}
.tbr .head h4{margin:0;font-size:10px;color:var(--pt-text-primary);font-weight:600}
.tbr .cnt{font-size:8px;color:var(--pt-text-muted);font-variant-numeric:tabular-nums;
margin-inline-start:auto}
.tbr button{font:inherit;cursor:pointer}
.tbr button:focus-visible, .tbr input:focus-visible, .tbr select:focus-visible, .tbr th:focus-visible{outline:2px solid var(--pt-focus-ring);outline-offset:-2px}
.tbr .empty{padding:12px;text-align:center;font-size:9px;color:var(--pt-text-muted)}
/* شخصية: يتحوّل من صفوف إلى بطاقات، انحناء متوسّط */
.tbr .mode{padding:3px 9px;border-radius:var(--pt-radius-md);
border:1px solid var(--pt-border-default);background:transparent;
color:var(--pt-text-secondary);font-size:8px}
.tbr .mode:hover{border-color:var(--pt-accent);color:var(--pt-accent)}
.tbr .st{padding:1px 6px;border-radius:var(--pt-radius-full);font-size:7.5px}
.tbr .pd{background:var(--pt-accent-muted);color:var(--pt-accent)}
.tbr .du{background:color-mix(in srgb,var(--pt-color-warn-400) 20%,transparent);
color:var(--pt-color-warn-400)}
.tbr .ov{background:color-mix(in srgb,var(--pt-color-danger-400) 18%,transparent);
color:var(--pt-color-danger-400)}
/* وضع البطاقات: كل خلية تحمل عنوان عمودها، وإلّا صارت رقمًا بلا معنى */
.tbr.cards thead{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%)}
.tbr.cards table, .tbr.cards tbody, .tbr.cards tr, .tbr.cards td{display:block;width:100%}
.tbr.cards tbody tr{margin-bottom:5px;padding:7px 9px;border:1px solid var(--pt-border-subtle);
border-radius:var(--pt-radius-md);background:var(--pt-surface)}
.tbr.cards tbody tr:hover{background:var(--pt-surface-hover)}
.tbr.cards td{display:flex;align-items:baseline;justify-content:space-between;gap:10px;
padding:2px 0;white-space:normal;text-align:start}
.tbr.cards td::before{content:attr(data-l);color:var(--pt-text-muted);font-size:7.5px;
flex:none}
.tbr.cards td.e{text-align:start}
/* يعمل داخل إطار معزول — لا يعتمد على شيء خارجه */
/* pt-remount — يعاد التركيب عند تبديل اللغة */
(function () {
var host = document.querySelector('.tbr');
if (!host) return;
var snapshot = host.innerHTML;
var timers = [];
var ac = null;
/* الجسم كما كتبه المولِّد. يستقبل بدائل مظلَّلة لـ root وdocument
والمؤقّتات، فينظّف نفسه دون أن يعرف أنه قابل لإعادة التركيب. */
function run(root, document, setTimeout, setInterval) {
var ar = document.documentElement.lang !== 'en';
/* العملة: $ ($) — سوق عالمي.
الأرقام مخزَّنة بـالريال وتُحوَّل، فتبقى
المبالغ معقولة في كل سوق. والتحويل لا التبديل: «18,500» راتبًا بالريال
معقول، وبالدينار الأردني ثروة.
وخانتان عشريتان — الوحدة تُقسَّم إلى مئة. */
var money = (function () {
var RATE = 1, DEC = 2;
return function (v, d) {
var out = (Number(v) / 3.75) * RATE;
var places = d === undefined ? DEC : d;
var s = out.toLocaleString('en-US', {
minimumFractionDigits: places, maximumFractionDigits: places });
return ar ? '$' + s : '$' + s;
};
})();
var ROWS = [
{ no: 'INV-2481', cl: 'شركة الأفق', due: 4, amt: 42000 },
{ no: 'INV-2482', cl: 'مؤسّسة النسيم', due: -3, amt: 18500 },
{ no: 'INV-2483', cl: 'مجموعة نماء', due: 12, amt: 96400 },
{ no: 'INV-2484', cl: 'دار العمران', due: 0, amt: 27300 }
];
var L = ar
? { no: 'الفاتورة', cl: 'العميل', due: 'الاستحقاق', st: 'الحالة', amt: 'المبلغ' }
: { no: 'Invoice', cl: 'Client', due: 'Due', st: 'Status', amt: 'Amount' };
function state(d) {
if (d < 0) return { c: 'ov', t: ar ? 'متأخّرة ' + (-d) + ' يومًا' : (-d) + 'd overdue' };
if (d === 0) return { c: 'du', t: ar ? 'تستحقّ اليوم' : 'Due today' };
return { c: 'pd', t: ar ? 'خلال ' + d + ' أيّام' : 'In ' + d + 'd' };
}
function fmt(d) {
var x = new Date(); x.setDate(x.getDate() + d);
return x.toLocaleDateString(ar ? 'ar-SA-u-nu-latn' : 'en-GB',
{ day: 'numeric', month: 'short' });
}
root.querySelector('tbody').innerHTML = ROWS.map(function (r) {
var s = state(r.due);
return '<tr><td data-l="' + L.no + '">' + r.no + '</td>' +
'<td data-l="' + L.cl + '">' + r.cl + '</td>' +
'<td data-l="' + L.due + '">' + fmt(r.due) + '</td>' +
'<td data-l="' + L.st + '"><span class="st ' + s.c + '">' + s.t + '</span></td>' +
'<td class="e" data-l="' + L.amt + '">' + money(r.amt, 0) + '</td></tr>';
}).join('');
var late = ROWS.filter(function (r) { return r.due < 0; }).length;
root.querySelector('.cnt').textContent = ROWS.length + (ar ? ' فواتير · ' : ' invoices · ') +
late + (ar ? ' متأخّرة' : ' overdue');
var btn = root.querySelector('.mode');
btn.addEventListener('click', function () {
var on = root.classList.toggle('cards');
btn.textContent = on ? (ar ? 'اعرض كجدول' : 'Show as table')
: (ar ? 'اعرض كبطاقات' : 'Show as cards');
});
}
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(); });
})();
# Table that Becomes Cards
**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:** Table that Becomes Cards — On narrow screens it becomes cards, each field carrying its own label
**Why this component matters:** When a table reflows into cards, each value must carry its column label — usually via a data attribute rendered with ::before. Without it the numbers become unlabelled and the card is unreadable.
**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.