المكوّنات · جدول بتحديد وإجراءات جماعية
جدول بتحديد وإجراءات جماعية
مربّع «الكلّ» ثلاثيّ الحالة، والإجراءات تعرف عددها
12 تصاميم من هذه العائلة
<div class="tb tbl">
<div class="head"><h4 data-ar="المستخدمون" data-en="Users">المستخدمون</h4>
<span class="cnt"></span></div>
<div class="acts" hidden role="toolbar" aria-label="إجراءات جماعية">
<span class="pick num"></span>
<button class="ex" data-ar="تصدير" data-en="Export">تصدير</button>
<button class="sp" data-ar="تعليق" data-en="Suspend">تعليق</button>
<button class="cl" data-ar="إلغاء التحديد" data-en="Clear">إلغاء التحديد</button>
</div>
<div class="wrap"><table>
<thead><tr>
<th scope="col" class="ck"><input type="checkbox" class="all" aria-label="تحديد الكل"></th>
<th scope="col" data-ar="المستخدم" data-en="User">المستخدم</th>
<th scope="col" data-ar="البريد" data-en="Email">البريد</th>
<th scope="col" data-ar="الدور" data-en="Role">الدور</th>
</tr></thead>
<tbody></tbody>
</table></div>
<p class="out" role="status"></p>
</div>
/* pt-scoped */
/* table-select — إدارة مستخدمين */
.tbl{width:100%;height:100%;display:flex;flex-direction:column;gap:6px;
font-size:10px;color:var(--pt-text-secondary);overflow:hidden;padding:9px 10px}
.tbl .wrap{flex:1;min-height:0;overflow:auto;border-radius:var(--pt-radius-sm);
border:1px solid var(--pt-border-subtle)}
.tbl table{width:100%;border-collapse:collapse;font-size:8.5px}
.tbl th, .tbl td{padding:5px 7px;text-align:start;white-space:nowrap}
.tbl 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)}
.tbl tbody tr{border-bottom:1px solid var(--pt-border-subtle)}
.tbl tbody tr:last-child{border-bottom:0}
.tbl tbody tr:hover{background:var(--pt-surface-hover)}
.tbl tbody td{color:var(--pt-text-secondary)}
.tbl .e{text-align:end;font-variant-numeric:tabular-nums}
.tbl .head{display:flex;align-items:center;gap:7px;flex-wrap:wrap}
.tbl .head h4{margin:0;font-size:10px;color:var(--pt-text-primary);font-weight:600}
.tbl .cnt{font-size:8px;color:var(--pt-text-muted);font-variant-numeric:tabular-nums;
margin-inline-start:auto}
.tbl button{font:inherit;cursor:pointer}
.tbl button:focus-visible, .tbl input:focus-visible, .tbl select:focus-visible, .tbl th:focus-visible{outline:2px solid var(--pt-focus-ring);outline-offset:-2px}
.tbl .empty{padding:12px;text-align:center;font-size:9px;color:var(--pt-text-muted)}
/* شخصية: عمود تحديد، شريط إجراءات ينزلق، انحناء صغير */
.tbl .ck{width:26px}
.tbl input[type=checkbox]{width:12px;height:12px;accent-color:var(--pt-accent);cursor:pointer;
vertical-align:middle}
.tbl tbody tr.sel{background:var(--pt-accent-muted)}
.tbl .acts{display:flex;align-items:center;gap:5px;padding:5px 8px;
border-radius:var(--pt-radius-sm);background:var(--pt-accent-muted);
animation:tbslide var(--pt-motion-duration-fast) var(--pt-motion-easing-emphasized)}
@keyframes tbslide{from{opacity:0;transform:translateY(-3px)}to{opacity:1;transform:none}}
@media(prefers-reduced-motion:reduce){.tbl .acts{animation:none}
}
.tbl .pick{flex:1;font-size:8.5px;color:var(--pt-accent);font-weight:600}
.tbl .acts button{padding:3px 9px;border-radius:var(--pt-radius-xs);
border:1px solid color-mix(in srgb,var(--pt-accent) 40%,transparent);
background:transparent;color:var(--pt-accent);font-size:8px}
.tbl .acts button:hover{background:var(--pt-surface)}
.tbl .sp{border-color:color-mix(in srgb,var(--pt-color-danger-400) 40%,transparent);
color:var(--pt-color-danger-400)}
.tbl .out{font-size:8px;min-height:10px;color:var(--pt-text-muted)}
/* يعمل داخل إطار معزول — لا يعتمد على شيء خارجه */
/* pt-remount — يعاد التركيب عند تبديل اللغة */
(function () {
var host = document.querySelector('.tbl');
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';
var ROWS = [
{ nm: 'حسام', em: '[email protected]', rl: 'مدير' },
{ nm: 'هند', em: '[email protected]', rl: 'محرّر' },
{ nm: 'سامي', em: '[email protected]', rl: 'مشاهد' },
{ nm: 'هبة', em: '[email protected]', rl: 'محرّر' },
{ nm: 'طارق', em: '[email protected]', rl: 'مشاهد' },
{ nm: 'دينا', em: '[email protected]', rl: 'مدير' }
];
var sel = ROWS.map(function () { return false; });
var tb = root.querySelector('tbody'), all = root.querySelector('.all');
var acts = root.querySelector('.acts'), out = root.querySelector('.out');
tb.innerHTML = ROWS.map(function (r, i) {
return '<tr><td class="ck"><input type="checkbox" data-i="' + i +
'" aria-label="تحديد ' + r.nm + '"></td>' +
'<td>' + r.nm + '</td><td dir="ltr">' + r.em + '</td><td>' + r.rl + '</td></tr>';
}).join('');
var boxes = [].slice.call(tb.querySelectorAll('input'));
function refresh() {
var on = sel.filter(Boolean).length;
/* ثلاث حالات لا حالتان: محدَّد، وفارغ، وغير محسوم حين يُحدَّد بعضها.
إسقاط الثالثة يجعل المربّع يكذب على المستخدم. */
all.checked = on === ROWS.length;
all.indeterminate = on > 0 && on < ROWS.length;
boxes.forEach(function (b, i) {
b.checked = sel[i];
b.closest('tr').classList.toggle('sel', sel[i]);
});
acts.hidden = on === 0;
root.querySelector('.pick').textContent = on + (ar ? ' محدَّدًا' : ' selected');
root.querySelector('.cnt').textContent = ROWS.length + (ar ? ' مستخدمًا' : ' users');
}
all.addEventListener('change', function () {
sel = sel.map(function () { return all.checked; }); refresh();
});
tb.addEventListener('change', function (e) {
if (e.target.dataset.i === undefined) return;
sel[+e.target.dataset.i] = e.target.checked; refresh();
});
root.querySelector('.cl').addEventListener('click', function () {
sel = sel.map(function () { return false; }); refresh();
});
root.querySelector('.ex').addEventListener('click', function () {
out.textContent = (ar ? 'صُدّر ' : 'Exported ') + sel.filter(Boolean).length +
(ar ? ' سجلًّا' : ' records');
});
root.querySelector('.sp').addEventListener('click', function () {
out.textContent = (ar ? 'عُلّق ' : 'Suspended ') + sel.filter(Boolean).length +
(ar ? ' مستخدمًا' : ' users');
});
refresh();
}
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 Bulk Selection
**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 Bulk Selection — A genuinely tri-state “select all”, with actions that state their count
**Why this component matters:** The header checkbox has three states, not two — checked, unchecked and indeterminate. Skipping the third makes it lie whenever a subset is selected.
**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.