المكوّنات · بحث بوسوم مركّبة
بحث بوسوم مركّبة
كل وسم شرط، والنتيجة تقاطعها لا اتحادها
12 تصاميم من هذه العائلة
<div class="sr srt">
<div class="box">
<span class="chips"></span>
<input type="text" aria-label="أضف وسمًا" placeholder="اكتب ثم Enter…">
</div>
<p class="hint" data-ar="Enter يضيف · Backspace يحذف آخر وسم" data-en="Enter adds · Backspace removes the last tag">Enter يضيف · Backspace يحذف آخر وسم</p>
<div class="cnt"></div>
<ul></ul>
<p class="empty" hidden data-ar="لا قطعة تطابق كل الوسوم" data-en="No part matches every tag">لا قطعة تطابق كل الوسوم</p>
</div>
/* pt-scoped */
/* search-tags — قطع غيار */
.srt{width:100%;height:100%;display:flex;flex-direction:column;gap:7px;
font-size:10px;color:var(--pt-text-secondary);overflow:hidden;position:relative}
.srt .fld{display:flex;align-items:center;gap:6px;width:100%}
.srt input[type=search], .srt input[type=text]{flex:1;min-width:0;border:0;background:transparent;
color:var(--pt-text-primary);font:inherit;font-size:10px;outline:none}
.srt input::placeholder{color:var(--pt-text-muted)}
.srt ul{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:2px;
overflow-y:auto}
.srt li[hidden]{display:none}
.srt mark{background:color-mix(in srgb,var(--pt-accent) 30%,transparent);
color:inherit;border-radius:2px;padding:0 1px}
.srt .empty{margin:0;padding:9px;text-align:center;font-size:9px;color:var(--pt-text-muted)}
.srt .cnt{font-size:8.5px;color:var(--pt-text-muted);font-variant-numeric:tabular-nums;
white-space:nowrap}
.srt{padding:9px;gap:6px}
.srt .box{display:flex;flex-wrap:wrap;align-items:center;gap:4px;padding:5px 7px;
border-radius:var(--pt-radius-md);border:1px solid var(--pt-border-default);
background:var(--pt-bg-inset);min-height:26px}
.srt .box:focus-within{border-color:var(--pt-accent)}
.srt .box input{flex:1;min-width:60px;font-size:9.5px}
.srt .chip{display:inline-flex;align-items:center;gap:4px;padding:2px 4px 2px 7px;
border-radius:var(--pt-radius-full);background:var(--pt-accent-muted);
color:var(--pt-accent);font-size:8px}
.srt .chip button{width:12px;height:12px;border:0;border-radius:50%;background:transparent;
color:inherit;font-size:8px;cursor:pointer;display:grid;place-items:center}
.srt .chip button:hover{background:color-mix(in srgb,var(--pt-accent) 30%,transparent)}
.srt .hint{margin:0;font-size:7.5px;color:var(--pt-text-muted)}
.srt ul{flex:1;gap:3px}
.srt li{display:flex;align-items:center;justify-content:space-between;gap:8px;
padding:5px 8px;border-radius:var(--pt-radius-sm);background:var(--pt-surface);
border:1px solid var(--pt-border-subtle);font-size:9px}
.srt li .t{color:var(--pt-text-primary)}
.srt li .m{font-size:7.5px;color:var(--pt-text-muted)}
.srt li .p{color:var(--pt-accent);font-weight:700;font-variant-numeric:tabular-nums}
/* يعمل داخل إطار معزول — لا يعتمد على شيء خارجه */
/* pt-remount — يعاد التركيب عند تبديل اللغة */
(function () {
var host = document.querySelector('.srt');
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 PARTS = [
{ t: 'فلتر زيت', tags: ['تويوتا', 'محرك', 'أصلي'], p: 45 },
{ t: 'طقم فحمات أمامي', tags: ['هيونداي', 'فرامل', 'تجاري'], p: 180 },
{ t: 'بطارية 70 أمبير', tags: ['كهرباء', 'أصلي'], p: 320 },
{ t: 'مساعد خلفي', tags: ['تويوتا', 'تعليق', 'تجاري'], p: 265 },
{ t: 'فلتر هواء', tags: ['هيونداي', 'محرك', 'أصلي'], p: 60 },
{ t: 'شمعات إشعال', tags: ['تويوتا', 'محرك', 'تجاري'], p: 95 },
{ t: 'طرمبة ماء', tags: ['نيسان', 'تبريد', 'أصلي'], p: 410 }
];
var ar = document.documentElement.lang !== 'en';
var box = root.querySelector('.box'), input = box.querySelector('input');
var chips = root.querySelector('.chips'), list = root.querySelector('ul');
var empty = root.querySelector('.empty'), cnt = root.querySelector('.cnt');
var tags = ['تويوتا'];
list.innerHTML = PARTS.map(function (p) {
return '<li><span class="t">' + p.t + '</span><span class="m">' + p.tags.join(' · ') +
'</span><span class="p">' + (ar ? p.p + ' ر.س' : '$' + Math.round(p.p / 3.75)) +
'</span></li>';
}).join('');
var lis = [].slice.call(list.children);
function render() {
chips.innerHTML = tags.map(function (t, i) {
return '<span class="chip">' + t +
'<button type="button" data-i="' + i + '" aria-label="احذف ' + t + '">✕</button></span>';
}).join('');
/* تقاطع لا اتحاد: إضافة وسم تضيّق البحث — ولو وسّعته لبدا معطوبًا */
var shown = 0;
lis.forEach(function (li, i) {
var ok = tags.every(function (t) {
return PARTS[i].tags.some(function (x) { return hit(x, t); });
});
li.hidden = !ok;
if (ok) shown++;
});
empty.hidden = shown > 0;
cnt.textContent = shown + (ar ? ' قطعة' : ' parts') +
(tags.length ? (ar ? ' · ' + tags.length + ' وسمًا' : ' · ' + tags.length + ' tags') : '');
}
function add(v) {
v = v.trim();
if (!v || tags.some(function (t) { return norm(t) === norm(v); })) return;
tags.push(v); input.value = ''; render();
}
input.addEventListener('keydown', function (e) {
if (e.key === 'Enter') { e.preventDefault(); add(input.value); }
if (e.key === 'Backspace' && !input.value && tags.length) { tags.pop(); render(); }
});
chips.addEventListener('click', function (e) {
var b = e.target.closest('button');
if (!b) return;
tags.splice(+b.dataset.i, 1); render(); input.focus();
});
render();
}
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(); });
})();
# Tag-based 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:** Tag-based Search — Each tag is a condition — results are their intersection, not their union
**Why this component matters:** Tag filters must AND, not OR: a user adding a second tag is narrowing the search, and returning more rows than before feels broken.
**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.