المكوّنات · جدول بتجميع ومجاميع فرعية
جدول بتجميع ومجاميع فرعية
المجاميع الفرعية والكلّية محسوبة من الصفوف لا مكتوبة
12 تصاميم من هذه العائلة
<div class="tb tbg">
<div class="head"><h4 data-ar="القيود حسب المركز" data-en="Entries by cost centre">القيود حسب المركز</h4>
<button class="tog" data-ar="اطوِ الكل" data-en="Collapse all">اطوِ الكل</button>
<span class="cnt"></span></div>
<div class="wrap"><table>
<thead><tr>
<th scope="col" data-ar="البند" data-en="Item">البند</th>
<th scope="col" data-ar="التاريخ" data-en="Date">التاريخ</th>
<th scope="col" class="e" data-ar="المبلغ" data-en="Amount">المبلغ</th>
</tr></thead>
<tbody></tbody>
<tfoot><tr><td colspan="2" data-ar="الإجمالي العام" data-en="Grand total">الإجمالي العام</td>
<td class="e all"></td></tr></tfoot>
</table></div>
</div>
/* pt-scoped */
/* table-group — نظام محاسبة */
.tbg{width:100%;height:100%;display:flex;flex-direction:column;gap:6px;
font-size:10px;color:var(--pt-text-secondary);overflow:hidden;padding:9px 10px}
.tbg .wrap{flex:1;min-height:0;overflow:auto;border-radius:var(--pt-radius-sm);
border:1px solid var(--pt-border-subtle)}
.tbg table{width:100%;border-collapse:collapse;font-size:8.5px}
.tbg th, .tbg td{padding:5px 7px;text-align:start;white-space:nowrap}
.tbg 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)}
.tbg tbody tr{border-bottom:1px solid var(--pt-border-subtle)}
.tbg tbody tr:last-child{border-bottom:0}
.tbg tbody tr:hover{background:var(--pt-surface-hover)}
.tbg tbody td{color:var(--pt-text-secondary)}
.tbg .e{text-align:end;font-variant-numeric:tabular-nums}
.tbg .head{display:flex;align-items:center;gap:7px;flex-wrap:wrap}
.tbg .head h4{margin:0;font-size:10px;color:var(--pt-text-primary);font-weight:600}
.tbg .cnt{font-size:8px;color:var(--pt-text-muted);font-variant-numeric:tabular-nums;
margin-inline-start:auto}
.tbg button{font:inherit;cursor:pointer}
.tbg button:focus-visible, .tbg input:focus-visible, .tbg select:focus-visible, .tbg th:focus-visible{outline:2px solid var(--pt-focus-ring);outline-offset:-2px}
.tbg .empty{padding:12px;text-align:center;font-size:9px;color:var(--pt-text-muted)}
/* شخصية: صفوف مجموعات بخلفية، مجاميع فرعية بارزة، انحناء صغير */
.tbg .tog{padding:3px 9px;border-radius:var(--pt-radius-xs);
border:1px solid var(--pt-border-default);background:transparent;
color:var(--pt-text-secondary);font-size:8px}
.tbg .tog:hover{border-color:var(--pt-accent);color:var(--pt-accent)}
.tbg tr.grp{background:var(--pt-bg-inset);cursor:pointer}
.tbg tr.grp td{font-size:8.5px;color:var(--pt-text-primary);font-weight:600;
border-block:1px solid var(--pt-border-subtle)}
.tbg tr.grp .ar::before{content:'▾';margin-inline-end:5px;color:var(--pt-text-muted);
display:inline-block;font-size:8px}
.tbg tr.grp.closed .ar::before{transform:rotate(90deg)}
[dir=rtl] .tbg tr.grp.closed .ar::before{transform:rotate(-90deg)}
.tbg tr.grp .sub{color:var(--pt-accent);font-variant-numeric:tabular-nums}
.tbg tr.item td:first-child{padding-inline-start:20px;color:var(--pt-text-muted)}
.tbg tfoot td{padding-top:6px;border-top:2px solid var(--pt-border-default);
color:var(--pt-text-primary);font-weight:600;font-size:9px}
.tbg tfoot .all{color:var(--pt-accent);font-weight:700;font-size:11px;
font-variant-numeric:tabular-nums}
/* يعمل داخل إطار معزول — لا يعتمد على شيء خارجه */
/* pt-remount — يعاد التركيب عند تبديل اللغة */
(function () {
var host = document.querySelector('.tbg');
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';
/* العملة: د.ك (KWD) — سوق الكويت.
الأرقام مخزَّنة بـالريال وتُحوَّل، فتبقى
المبالغ معقولة في كل سوق. والتحويل لا التبديل: «18,500» راتبًا بالريال
معقول، وبالدينار الأردني ثروة.
وثلاث خانات عشرية — الدينار يُقسَّم إلى ألف فلس. */
var money = (function () {
var RATE = 0.307, DEC = 3;
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 + ' د.ك' : 'KWD ' + s;
};
})();
/* المدن: سوق الكويت — تتبع العملة */
var TOWN = ar ? ['حولي', 'السالمية', 'الفروانية', 'مدينة الكويت']
: ['Hawalli', 'Salmiya', 'Farwaniya', 'Kuwait City'];
var GROUPS = [
{ g: (ar ? 'مركز ' : 'DC ') + TOWN[0], rows: [
['إيجار مكتب', '01-08', 42000], ['كهرباء وماء', '03-08', 3800],
['صيانة تكييف', '11-08', 6300] ] },
{ g: 'مركز جدّة', rows: [
['إيجار معرض', '01-08', 28500], ['دعاية محلّية', '07-08', 12400] ] },
{ g: 'المقرّ الرئيسي', rows: [
['رواتب إدارية', '25-08', 186000], ['اشتراكات برمجيات', '02-08', 18500],
['تأمين طبّي', '15-08', 76400] ] }
];
var tb = root.querySelector('tbody');
var closed = {};
function draw() {
var html = '', grand = 0;
GROUPS.forEach(function (G, gi) {
/* المجموع الفرعي من صفوف المجموعة، والعامّ من المجاميع الفرعية —
كتابة أيّهما تضمن اختلافهما مع أوّل تعديل صفّ. */
var sub = G.rows.reduce(function (a, r) { return a + r[2]; }, 0);
grand += sub;
var isClosed = !!closed[gi];
html += '<tr class="grp ' + (isClosed ? 'closed' : '') + '" data-g="' + gi +
'" tabindex="0" aria-expanded="' + (!isClosed) + '">' +
'<td class="ar">' + G.g + '</td>' +
'<td>' + G.rows.length + (ar ? ' قيود' : ' entries') + '</td>' +
'<td class="e sub">' + money(sub, 0) + '</td></tr>';
if (!isClosed) {
html += G.rows.map(function (r) {
return '<tr class="item"><td>' + r[0] + '</td><td>' + r[1] + '</td>' +
'<td class="e">' + money(r[2], 0) + '</td></tr>';
}).join('');
}
});
tb.innerHTML = html;
root.querySelector('.all').textContent = money(grand, 0);
var open = GROUPS.filter(function (_, i) { return !closed[i]; }).length;
root.querySelector('.cnt').textContent = open + ' / ' + GROUPS.length +
(ar ? ' مفتوحة' : ' open');
root.querySelector('.tog').textContent = open
? (ar ? 'اطوِ الكل' : 'Collapse all') : (ar ? 'افتح الكل' : 'Expand all');
}
function toggle(gi) { closed[gi] = !closed[gi]; draw(); }
tb.addEventListener('click', function (e) {
var tr = e.target.closest('.grp'); if (tr) toggle(+tr.dataset.g);
});
tb.addEventListener('keydown', function (e) {
var tr = e.target.closest('.grp');
if (tr && (e.key === 'Enter' || e.key === ' ')) { e.preventDefault(); toggle(+tr.dataset.g); }
});
root.querySelector('.tog').addEventListener('click', function () {
var anyOpen = GROUPS.some(function (_, i) { return !closed[i]; });
GROUPS.forEach(function (_, i) { closed[i] = anyOpen; });
draw();
});
draw();
}
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(); });
})();
# Grouped Table with Subtotals
**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:** Grouped Table with Subtotals — Subtotals and the grand total computed from the rows, never typed
**Why this component matters:** Compute subtotals from the rows in each group and derive the grand total from the subtotals — typing either one guarantees they disagree the first time a row changes.
**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.