المكوّنات · جدول بصفوف تتوسّع
جدول بصفوف تتوسّع
التفاصيل تحت الصفّ نفسه، بربط aria صحيح
12 تصاميم من هذه العائلة
<div class="tb tbe">
<div class="head"><h4 data-ar="الطلبات" data-en="Orders">الطلبات</h4><span class="cnt"></span></div>
<div class="wrap"><table>
<thead><tr>
<th scope="col" class="ex"></th>
<th scope="col" data-ar="الطلب" data-en="Order">الطلب</th>
<th scope="col" data-ar="العميل" data-en="Customer">العميل</th>
<th scope="col" data-ar="الحالة" data-en="Status">الحالة</th>
<th scope="col" class="e" data-ar="الإجمالي" data-en="Total">الإجمالي</th>
</tr></thead>
<tbody></tbody>
</table></div>
</div>
/* pt-scoped */
/* table-expand — إدارة طلبات */
.tbe{width:100%;height:100%;display:flex;flex-direction:column;gap:6px;
font-size:10px;color:var(--pt-text-secondary);overflow:hidden;padding:9px 10px}
.tbe .wrap{flex:1;min-height:0;overflow:auto;border-radius:var(--pt-radius-sm);
border:1px solid var(--pt-border-subtle)}
.tbe table{width:100%;border-collapse:collapse;font-size:8.5px}
.tbe th, .tbe td{padding:5px 7px;text-align:start;white-space:nowrap}
.tbe 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)}
.tbe tbody tr{border-bottom:1px solid var(--pt-border-subtle)}
.tbe tbody tr:last-child{border-bottom:0}
.tbe tbody tr:hover{background:var(--pt-surface-hover)}
.tbe tbody td{color:var(--pt-text-secondary)}
.tbe .e{text-align:end;font-variant-numeric:tabular-nums}
.tbe .head{display:flex;align-items:center;gap:7px;flex-wrap:wrap}
.tbe .head h4{margin:0;font-size:10px;color:var(--pt-text-primary);font-weight:600}
.tbe .cnt{font-size:8px;color:var(--pt-text-muted);font-variant-numeric:tabular-nums;
margin-inline-start:auto}
.tbe button{font:inherit;cursor:pointer}
.tbe button:focus-visible, .tbe input:focus-visible, .tbe select:focus-visible, .tbe th:focus-visible{outline:2px solid var(--pt-focus-ring);outline-offset:-2px}
.tbe .empty{padding:12px;text-align:center;font-size:9px;color:var(--pt-text-muted)}
/* شخصية: صفّ تفاصيل مدمج، سهم يدور، انحناء متوسّط */
.tbe .ex{width:22px}
.tbe .tg{width:16px;height:16px;padding:0;border:0;border-radius:var(--pt-radius-xs);
background:transparent;color:var(--pt-text-muted);font-size:9px;line-height:1}
.tbe .tg:hover{background:var(--pt-surface-hover);color:var(--pt-accent)}
.tbe .tg::before{content:'▸';display:inline-block;
transition:transform var(--pt-motion-duration-fast) var(--pt-motion-easing-standard)}
[dir=rtl] .tbe .tg::before{content:'◂'}
.tbe .tg[aria-expanded=true]::before{transform:rotate(-90deg)}
[dir=rtl] .tbe .tg[aria-expanded=true]::before{transform:rotate(90deg)}
@media(prefers-reduced-motion:reduce){.tbe .tg::before{transition:none}
}
.tbe tr.det td{background:var(--pt-bg-inset);padding:7px 10px}
.tbe .items{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:2px}
.tbe .items li{display:grid;grid-template-columns:1fr auto auto;gap:8px;font-size:8px;
color:var(--pt-text-muted)}
.tbe .items .a{color:var(--pt-text-secondary);font-variant-numeric:tabular-nums}
.tbe .addr{margin-top:4px;font-size:7.5px;color:var(--pt-text-muted)}
.tbe .st{padding:1px 6px;border-radius:var(--pt-radius-full);font-size:7.5px}
.tbe .ok{background:var(--pt-accent-muted);color:var(--pt-accent)}
.tbe .wt{background:color-mix(in srgb,var(--pt-color-warn-400) 20%,transparent);
color:var(--pt-color-warn-400)}
/* يعمل داخل إطار معزول — لا يعتمد على شيء خارجه */
/* pt-remount — يعاد التركيب عند تبديل اللغة */
(function () {
var host = document.querySelector('.tbe');
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 SPOT = ar ? ['دبي — الخليج التجاري', 'الدار البيضاء — عين الذئاب', 'بيروت — الحمرا', 'تونس — البحيرة']
: ['Dubai — Business Bay', 'Casablanca — Ain Diab', 'Beirut — Hamra', 'Tunis — Lac'];
var ROWS = [
{ no: '#48210', cu: 'نور', st: 'مكتمل', cls: 'ok',
addr: SPOT[0],
items: [['قميص قطن', 2, 129], ['حزام جلد', 1, 89]] },
{ no: '#48211', cu: 'سامي', st: 'قيد التجهيز', cls: 'wt',
addr: 'جدّة — حيّ السلامة',
items: [['حذاء رياضي', 1, 349], ['جوارب ×3', 2, 45]] },
{ no: '#48212', cu: 'لينا', st: 'مكتمل', cls: 'ok',
addr: 'الدمّام — حيّ الشاطئ',
items: [['عطر 100 مل', 1, 420]] }
];
var tb = root.querySelector('tbody');
tb.innerHTML = ROWS.map(function (r, i) {
var tot = r.items.reduce(function (a, it) { return a + it[1] * it[2]; }, 0);
/* صفّ التفاصيل داخل الجدول نفسه: لوحة عائمة تفقد محاذاة الأعمدة
وسياق الصفّ معًا. */
return '<tr><td class="ex"><button class="tg" aria-expanded="false" ' +
'aria-controls="d' + i + '" aria-label="تفاصيل ' + r.no + '"></button></td>' +
'<td>' + r.no + '</td><td>' + r.cu + '</td>' +
'<td><span class="st ' + r.cls + '">' + r.st + '</span></td>' +
'<td class="e">' + money(tot, 0) + '</td></tr>' +
'<tr class="det" id="d' + i + '" hidden><td colspan="5">' +
'<ul class="items">' + r.items.map(function (it) {
return '<li><span>' + it[0] + '</span><span>×' + it[1] + '</span>' +
'<span class="a">' + money(it[1] * it[2], 0) + '</span></li>';
}).join('') + '</ul>' +
'<div class="addr">' + (ar ? 'التوصيل: ' : 'Ship to: ') + r.addr + '</div></td></tr>';
}).join('');
tb.addEventListener('click', function (e) {
var b = e.target.closest('.tg');
if (!b) return;
var det = root.querySelector('#' + b.getAttribute('aria-controls'));
var open = det.hidden;
det.hidden = !open;
b.setAttribute('aria-expanded', String(open));
});
root.querySelector('.cnt').textContent = ROWS.length + (ar ? ' طلبات' : ' orders');
}
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 with Expandable Rows
**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 with Expandable Rows — Details open under their own row, correctly wired with aria
**Why this component matters:** Bind the toggle to its detail row with aria-controls and aria-expanded, and keep the detail in the same table so the column alignment survives — a floating panel loses the row context entirely.
**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.