المكوّنات · حذف بالضغط المطوّل
حذف بالضغط المطوّل
يكتمل الحذف بعد ضغط متّصل، ويُلغى بالإفلات
12 تصاميم من هذه العائلة
<div class="bt bth">
<button class="hold"><i class="fill" aria-hidden="true"></i>
<span class="tx" data-ar="اضغط مطوّلًا للحذف" data-en="Hold to delete">اضغط مطوّلًا للحذف</span></button>
<div class="log" role="status" aria-live="polite"></div>
<p class="lbl" data-ar="يعمل بالفأرة وباللمس وبمفتاح المسافة" data-en="Works with mouse, touch and the Space key">يعمل بالفأرة وباللمس وبمفتاح المسافة</p>
</div>
/* pt-scoped */
/* button-hold — لوحة تحكّم */
.bth{width:100%;height:100%;display:flex;flex-direction:column;
align-items:center;justify-content:center;gap:9px;padding:10px;
font-size:10px;color:var(--pt-text-secondary);overflow:hidden}
.bth .lbl{font-size:8px;color:var(--pt-text-muted);text-align:center}
.bth button{font:inherit;cursor:pointer;display:inline-flex;align-items:center;
justify-content:center;gap:5px;white-space:nowrap;
transition:background var(--pt-motion-duration-fast) var(--pt-motion-easing-standard),
border-color var(--pt-motion-duration-fast) var(--pt-motion-easing-standard),
color var(--pt-motion-duration-fast) var(--pt-motion-easing-standard),
transform var(--pt-motion-duration-fast) var(--pt-motion-easing-standard),
box-shadow var(--pt-motion-duration-fast) var(--pt-motion-easing-standard)}
.bth button:disabled{cursor:not-allowed}
.bth button:focus-visible{outline:2px solid var(--pt-focus-ring);outline-offset:2px}
/* أي زرّ ينزل بمقدار بكسل عند الضغط — تأكيد لمسيّ قبل وصول الردّ */
.bth button:not(:disabled):active{transform:translateY(1px)}
@media(prefers-reduced-motion:reduce){.bth button{transition:none}
.bth button:not(:disabled):active{transform:none}
}
/* هدف اللمس 44 بكسلًا على الشاشات اللمسية دون تضخيم سطح المكتب */
@media(pointer:coarse){.bth button{min-height:44px;min-width:44px}
}
/* شكل: محدَّد بالخطر، تعبئة تزحف من الحافّة، انحناء كبير */
.bth .hold{position:relative;overflow:hidden;min-width:160px;padding:10px 18px;
border-radius:var(--pt-radius-xl);background:transparent;font-size:9.5px;font-weight:600;
color:var(--pt-color-danger-400);
border:1px solid color-mix(in srgb,var(--pt-color-danger-400) 55%,transparent)}
.bth .fill{position:absolute;inset-block:0;inset-inline-start:0;width:0;
background:color-mix(in srgb,var(--pt-color-danger-500) 82%,transparent)}
.bth .tx{position:relative;z-index:1}
.bth .hold.armed .tx{color:#fff}
.bth .hold.done{border-color:var(--pt-border-subtle);color:var(--pt-text-muted)}
.bth .log{min-height:14px;font-size:8px;color:var(--pt-text-muted)}
/* يعمل داخل إطار معزول — لا يعتمد على شيء خارجه */
/* pt-remount — يعاد التركيب عند تبديل اللغة */
(function () {
var host = document.querySelector('.bth');
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 n = function (v) { return Number(v).toLocaleString('en-US'); };
var btn = root.querySelector('.hold'), fill = root.querySelector('.fill');
var tx = root.querySelector('.tx'), log = root.querySelector('.log');
var MS = 1200, start = 0, raf = 0, running = false;
function tick() {
var p = Math.min(1, (performance.now() - start) / MS);
fill.style.width = (p * 100) + '%';
if (p >= 1) { finish(); return; }
raf = requestAnimationFrame(tick);
}
function begin() {
if (running) return;
running = true; start = performance.now();
btn.classList.add('armed');
tx.textContent = ar ? 'استمرّ…' : 'Keep holding…';
raf = requestAnimationFrame(tick);
}
function abort() {
if (!running) return;
running = false; cancelAnimationFrame(raf);
fill.style.width = '0';
btn.classList.remove('armed');
tx.textContent = ar ? 'اضغط مطوّلًا للحذف' : 'Hold to delete';
log.textContent = ar ? 'أُلغي — أفلتَّ قبل الاكتمال' : 'Aborted — released too early';
}
function finish() {
running = false; cancelAnimationFrame(raf);
btn.classList.remove('armed'); btn.classList.add('done');
btn.disabled = true;
tx.textContent = ar ? '✓ حُذف' : '✓ Deleted';
log.textContent = ar ? 'اكتمل الضغط — نُفّذ الحذف' : 'Hold completed — delete executed';
setTimeout(function () {
btn.disabled = false; btn.classList.remove('done');
fill.style.width = '0';
tx.textContent = ar ? 'اضغط مطوّلًا للحذف' : 'Hold to delete';
log.textContent = '';
}, 1800);
}
btn.addEventListener('pointerdown', function (e) { e.preventDefault(); btn.focus(); begin(); });
['pointerup', 'pointerleave', 'pointercancel'].forEach(function (ev) {
btn.addEventListener(ev, abort);
});
/* لوحة المفاتيح تُعامَل كالمؤشّر: ضغط متّصل ثم إفلات — وإلّا فالإجراء
غير قابل للتنفيذ لمن لا يستخدم فأرة. */
btn.addEventListener('keydown', function (e) {
if (e.key === ' ' || e.key === 'Enter') { e.preventDefault(); begin(); }
});
btn.addEventListener('keyup', function (e) {
if (e.key === ' ' || e.key === 'Enter') abort();
});
btn.addEventListener('blur', abort);
}
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(); });
})();
# Hold-to-Delete
**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:** Hold-to-Delete — The delete completes after a sustained press and aborts on release
**Why this component matters:** Hold-to-confirm replaces a modal for irreversible actions, but it must be reachable by keyboard: bind Space and Enter to the same press-and-release cycle as the pointer.
**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.