المكوّنات · بحث بسجلّ سابق
بحث بسجلّ سابق
يحفظ آخر عمليات البحث محلّيًّا ويقترحها قبل الكتابة
12 تصاميم من هذه العائلة
<div class="sr srh">
<div class="fld">
<span aria-hidden="true">🔍</span>
<input type="search" aria-label="ابحث عن عقار" placeholder="حيّ، مدينة، أو رقم إعلان…">
<button class="clr" hidden aria-label="مسح">✕</button>
</div>
<div class="panel">
<div class="hist">
<div class="hh"><span data-ar="عمليات بحث سابقة" data-en="Recent searches">عمليات بحث سابقة</span>
<button class="wipe" data-ar="مسح الكل" data-en="Clear all">مسح الكل</button></div>
<ul class="hl"></ul>
</div>
<div class="res" hidden><div class="cnt"></div><ul class="rl"></ul>
<p class="empty" hidden data-ar="لا نتائج" data-en="No results">لا نتائج</p></div>
</div>
</div>
/* pt-scoped */
/* search-recent — منصّة عقارية */
.srh{width:100%;height:100%;display:flex;flex-direction:column;gap:7px;
font-size:10px;color:var(--pt-text-secondary);overflow:hidden;position:relative}
.srh .fld{display:flex;align-items:center;gap:6px;width:100%}
.srh input[type=search], .srh input[type=text]{flex:1;min-width:0;border:0;background:transparent;
color:var(--pt-text-primary);font:inherit;font-size:10px;outline:none}
.srh input::placeholder{color:var(--pt-text-muted)}
.srh ul{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:2px;
overflow-y:auto}
.srh li[hidden]{display:none}
.srh mark{background:color-mix(in srgb,var(--pt-accent) 30%,transparent);
color:inherit;border-radius:2px;padding:0 1px}
.srh .empty{margin:0;padding:9px;text-align:center;font-size:9px;color:var(--pt-text-muted)}
.srh .cnt{font-size:8.5px;color:var(--pt-text-muted);font-variant-numeric:tabular-nums;
white-space:nowrap}
.srh{padding:9px;gap:7px}
.srh .fld{padding:6px 9px;border-radius:var(--pt-radius-full);
border:1px solid var(--pt-border-default);background:var(--pt-bg-inset);
color:var(--pt-text-muted);font-size:10px}
.srh .fld:focus-within{border-color:var(--pt-accent)}
.srh .clr{width:16px;height:16px;border:0;border-radius:50%;background:var(--pt-surface-hover);
color:var(--pt-text-muted);font-size:8px;cursor:pointer}
.srh .panel{flex:1;min-height:0;display:flex;flex-direction:column}
.srh .hh{display:flex;align-items:center;justify-content:space-between;gap:8px;
padding:0 2px 4px;font-size:8px;color:var(--pt-text-muted)}
.srh .wipe{border:0;background:transparent;color:var(--pt-accent);font-size:8px;
cursor:pointer;padding:0}
.srh .hl li{display:flex;align-items:center;justify-content:space-between;gap:6px;
padding:5px 8px;border-radius:var(--pt-radius-sm);font-size:9px;cursor:pointer;
color:var(--pt-text-secondary)}
.srh .hl li:hover{background:var(--pt-surface-hover);color:var(--pt-text-primary)}
.srh .hl .x{border:0;background:transparent;color:var(--pt-text-muted);font-size:8px;
cursor:pointer;padding:0 2px}
.srh .rl{flex:1;gap:3px}
.srh .rl li{padding:6px 8px;border-radius:var(--pt-radius-sm);background:var(--pt-surface);
border:1px solid var(--pt-border-subtle);font-size:9px;
display:flex;justify-content:space-between;gap:8px}
.srh .rl .p{color:var(--pt-accent);font-weight:700;font-variant-numeric:tabular-nums}
/* يعمل داخل إطار معزول — لا يعتمد على شيء خارجه */
/* pt-remount — يعاد التركيب عند تبديل اللغة */
(function () {
var host = document.querySelector('.srh');
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 HOMES = [
{ t: 'شقّة 3 غرف · حيّ الملقا', c: 'الرياض', p: 780000 },
{ t: 'فيلا دورين · حيّ الياسمين', c: 'الرياض', p: 1850000 },
{ t: 'دور أرضي · حيّ الشاطئ', c: 'جدّة', p: 1120000 },
{ t: 'استوديو مفروش · الكورنيش', c: 'الخبر', p: 420000 },
{ t: 'أرض سكنية · حيّ النرجس', c: 'الرياض', p: 990000 },
{ t: 'شقّة مطلّة · حيّ السلامة', c: 'جدّة', p: 640000 }
];
var ar = document.documentElement.lang !== 'en';
var KEY = 'sr-recent';
var input = root.querySelector('input'), clr = root.querySelector('.clr');
var hist = root.querySelector('.hist'), res = root.querySelector('.res');
var hl = root.querySelector('.hl'), rl = root.querySelector('.rl');
var empty = root.querySelector('.empty'), cnt = root.querySelector('.cnt');
function load() {
try { return JSON.parse(localStorage.getItem(KEY)) || ['حيّ الملقا', 'جدّة']; }
catch (e) { return ['حيّ الملقا', 'جدّة']; }
}
function save(v) { try { localStorage.setItem(KEY, JSON.stringify(v)); } catch (e) {} }
var recent = load();
function drawHist() {
hl.innerHTML = recent.length
? recent.map(function (q, i) {
return '<li data-q="' + q + '"><span>↺ ' + q +
'</span><button class="x" data-i="' + i + '" aria-label="احذف">✕</button></li>';
}).join('')
: '<li style="cursor:default;color:var(--pt-text-muted)">' +
(ar ? 'لا سجلّ بعد' : 'No history yet') + '</li>';
}
rl.innerHTML = HOMES.map(function (h) {
return '<li data-raw="' + h.t + ' ' + h.c + '"><span class="t">' + h.t +
'</span><span class="p">' + (ar ? Math.round(h.p).toLocaleString('en-US') + ' ر.س'
: '$' + Math.round(h.p / 3.75).toLocaleString('en-US')) + '</span></li>';
}).join('');
var lis = [].slice.call(rl.children);
function run(q) {
/* السجل يظهر وقت الفراغ فقط — خلطه بالنتائج يجعل القديم يبدو مطابقًا */
var has = q.trim().length > 0;
hist.hidden = has; res.hidden = !has; clr.hidden = !has;
if (!has) return;
var shown = 0;
lis.forEach(function (li, i) {
var ok = hit(HOMES[i].t + ' ' + HOMES[i].c, q);
li.hidden = !ok;
if (ok) { shown++; mark(li.querySelector('.t'), q); }
});
empty.hidden = shown > 0;
cnt.textContent = shown + (ar ? ' عقارًا' : ' properties');
}
function remember(q) {
q = q.trim();
if (!q) return;
recent = [q].concat(recent.filter(function (x) { return norm(x) !== norm(q); })).slice(0, 5);
save(recent); drawHist();
}
input.addEventListener('input', function () { run(input.value); });
input.addEventListener('change', function () { remember(input.value); });
input.addEventListener('keydown', function (e) { if (e.key === 'Enter') remember(input.value); });
clr.addEventListener('click', function () { input.value = ''; run(''); input.focus(); });
hl.addEventListener('click', function (e) {
var x = e.target.closest('.x');
if (x) { recent.splice(+x.dataset.i, 1); save(recent); drawHist(); return; }
var li = e.target.closest('li[data-q]');
if (li) { input.value = li.dataset.q; run(input.value); input.focus(); }
});
root.querySelector('.wipe').addEventListener('click', function () {
recent = []; save(recent); drawHist();
});
drawHist(); 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(); });
})();
# Search with Recent History
**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:** Search with Recent History — Stores recent searches locally and offers them before you type
**Why this component matters:** Show history only while the field is empty. Once the user types, suggestions must come from the data — mixing history into live results makes stale entries look like matches.
**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.