المكوّنات · بحث داخل جدول
بحث داخل جدول
يظلّل داخل الخلايا ويعدّ الصفوف ويجمع القيم الظاهرة
12 تصاميم من هذه العائلة
<div class="sr srb">
<div class="fld">
<span aria-hidden="true">🔍</span>
<input type="search" aria-label="ابحث في القيود" placeholder="مورّد، وصف، أو رقم قيد…">
<span class="cnt"></span>
</div>
<div class="wrap"><table>
<thead><tr><th data-ar="القيد" data-en="Ref">القيد</th><th data-ar="الوصف" data-en="Description">الوصف</th>
<th data-ar="المورّد" data-en="Vendor">المورّد</th><th class="e" data-ar="المبلغ" data-en="Amount">المبلغ</th></tr></thead>
<tbody></tbody>
<tfoot><tr><td colspan="3" data-ar="مجموع الظاهر" data-en="Visible total">مجموع الظاهر</td>
<td class="e sum"></td></tr></tfoot>
</table></div>
<p class="empty" hidden data-ar="لا قيد مطابق" data-en="No matching entry">لا قيد مطابق</p>
</div>
/* pt-scoped */
/* search-table — شؤون مالية */
.srb{width:100%;height:100%;display:flex;flex-direction:column;gap:7px;
font-size:10px;color:var(--pt-text-secondary);overflow:hidden;position:relative}
.srb .fld{display:flex;align-items:center;gap:6px;width:100%}
.srb input[type=search], .srb input[type=text]{flex:1;min-width:0;border:0;background:transparent;
color:var(--pt-text-primary);font:inherit;font-size:10px;outline:none}
.srb input::placeholder{color:var(--pt-text-muted)}
.srb ul{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:2px;
overflow-y:auto}
.srb li[hidden]{display:none}
.srb mark{background:color-mix(in srgb,var(--pt-accent) 30%,transparent);
color:inherit;border-radius:2px;padding:0 1px}
.srb .empty{margin:0;padding:9px;text-align:center;font-size:9px;color:var(--pt-text-muted)}
.srb .cnt{font-size:8.5px;color:var(--pt-text-muted);font-variant-numeric:tabular-nums;
white-space:nowrap}
.srb{padding:9px;gap:6px}
.srb .fld{padding:5px 8px;border-radius:var(--pt-radius-sm);
border:1px solid var(--pt-border-default);background:var(--pt-bg-inset);
color:var(--pt-text-muted);font-size:10px}
.srb .fld:focus-within{border-color:var(--pt-accent)}
.srb .wrap{flex:1;min-height:0;overflow:auto;border-radius:var(--pt-radius-sm);
border:1px solid var(--pt-border-subtle)}
.srb table{width:100%;border-collapse:collapse;font-size:8.5px}
.srb th, .srb td{padding:4px 7px;text-align:start;white-space:nowrap}
.srb thead th{position:sticky;inset-block-start:0;background:var(--pt-bg-inset);
color:var(--pt-text-muted);font-weight:500;font-size:8px;
border-bottom:1px solid var(--pt-border-default);z-index:1}
.srb tbody tr{border-bottom:1px solid var(--pt-border-subtle)}
.srb tbody tr:hover{background:var(--pt-surface-hover)}
.srb tbody td{color:var(--pt-text-secondary)}
.srb .e{text-align:end;font-variant-numeric:tabular-nums}
.srb tfoot td{padding-top:5px;border-top:1px solid var(--pt-border-default);
color:var(--pt-text-muted);font-size:8px}
.srb tfoot .sum{color:var(--pt-accent);font-weight:700;font-size:9.5px}
/* يعمل داخل إطار معزول — لا يعتمد على شيء خارجه */
/* pt-remount — يعاد التركيب عند تبديل اللغة */
(function () {
var host = document.querySelector('.srb');
if (!host) return;
var snapshot = host.innerHTML;
var timers = [];
var ac = null;
/* الجسم كما كتبه المولِّد. يستقبل بدائل مظلَّلة لـ root وdocument
والمؤقّتات، فينظّف نفسه دون أن يعرف أنه قابل لإعادة التركيب. */
function run(root, document, setTimeout, setInterval) {
function norm(s) {
return String(s).replace(/[\u064B-\u0652\u0670\u0640]/g, '')
.replace(/[\u0622\u0623\u0625\u0671]/g, '\u0627')
.replace(/\u0629/g, '\u0647').replace(/\u0649/g, '\u064A')
.replace(/\u0624/g, '\u0648').replace(/\u0626/g, '\u064A')
.replace(/[\u0660-\u0669]/g, function (d) { return d.charCodeAt(0) - 0x0660; })
.toLowerCase().replace(/\s+/g, ' ').trim();
}
function stripAl(w) { return w.length > 4 && w.indexOf('\u0627\u0644') === 0 ? w.slice(2) : w; }
function hit(hay, q) {
var terms = norm(q).split(' ').filter(Boolean);
if (!terms.length) return true;
var h = norm(hay);
return terms.every(function (t) { return h.indexOf(t) !== -1 || h.indexOf(stripAl(t)) !== -1; });
}
/* التظليل يعمل على النصّ الأصلي لا المطبَّع: الأطوال تختلف بعد التطبيع،
فالمطابقة على المطبَّع تظلّل الحرف الخطأ. نبحث عن أطول بادئة مطابقة. */
function mark(el, q) {
var raw = el.dataset.raw || el.textContent;
el.dataset.raw = raw;
var t = norm(q).split(' ').filter(Boolean)[0];
if (!t) { el.textContent = raw; return; }
for (var i = 0; i < raw.length; i++) {
for (var j = raw.length; j > i; j--) {
if (norm(raw.slice(i, j)) === t) {
el.innerHTML = '';
el.appendChild(document.createTextNode(raw.slice(0, i)));
var m = document.createElement('mark');
m.textContent = raw.slice(i, j);
el.appendChild(m);
el.appendChild(document.createTextNode(raw.slice(j)));
return;
}
}
}
el.textContent = raw;
}
var ROWS = [
{ r: 'JV-1042', d: 'إيجار مكتب الربع الثالث', v: 'شركة العقارات المتّحدة', a: 42000 },
{ r: 'JV-1043', d: 'اشتراك برمجيات سنوي', v: 'حلول التقنية', a: 18500 },
{ r: 'JV-1044', d: 'صيانة تكييف', v: 'مؤسّسة النسيم', a: 6300 },
{ r: 'JV-1045', d: 'قرطاسية ومطبوعات', v: 'مكتبة الأفق', a: 2150 },
{ r: 'JV-1046', d: 'استضافة خوادم', v: 'حلول التقنية', a: 9800 },
{ r: 'JV-1047', d: 'تأمين طبّي', v: 'التعاونية', a: 76400 },
{ r: 'JV-1048', d: 'ضيافة اجتماعات', v: 'مؤسّسة النسيم', a: 1480 }
];
var ar = document.documentElement.lang !== 'en';
var input = root.querySelector('input'), tb = root.querySelector('tbody');
var cnt = root.querySelector('.cnt'), sum = root.querySelector('.sum');
var empty = root.querySelector('.empty');
var money = function (v) {
return ar ? v.toLocaleString('en-US') + ' ر.س'
: '$' + Math.round(v / 3.75).toLocaleString('en-US');
};
tb.innerHTML = ROWS.map(function (r) {
return '<tr><td data-raw="' + r.r + '">' + r.r + '</td><td data-raw="' + r.d + '">' + r.d +
'</td><td data-raw="' + r.v + '">' + r.v + '</td><td class="e">' + money(r.a) + '</td></tr>';
}).join('');
var trs = [].slice.call(tb.children);
function run(q) {
var shown = 0, total = 0;
trs.forEach(function (tr, i) {
var r = ROWS[i];
var ok = hit(r.r + ' ' + r.d + ' ' + r.v, q);
tr.hidden = !ok;
if (!ok) return;
shown++; total += r.a;
[].slice.call(tr.children, 0, 3).forEach(function (td) { mark(td, q); });
});
// المجموع يُعاد حسابه على الظاهر فقط — وإلّا ناقض الصفوف فوقه
sum.textContent = money(total);
cnt.textContent = shown + ' / ' + ROWS.length;
empty.hidden = shown > 0;
}
input.addEventListener('input', function () { run(input.value); });
run('');
}
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(); });
})();
# In-table Search
**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:** In-table Search — Highlights inside cells, counts rows and sums only what is visible
**Why this component matters:** The footer total must recompute over visible rows only. A total that ignores the filter contradicts the rows above it, and finance users will trust neither.
**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.
**Important:** This component has no equivalent in any global library. Do not imitate a
Latin pattern and translate its labels — build it from Gulf market requirements directly.