المكوّنات · إدخال رمز التحقّق
إدخال رمز التحقّق
يقبل اللصق ويوزّعه، ويتنقّل بالحذف، ويعيد الإرسال بمؤقّت
12 تصاميم من هذه العائلة
<div class="sg sgo">
<h5 data-ar="أدخل رمز التحقّق" data-en="Enter the code">أدخل رمز التحقّق</h5>
<p class="sub" data-ar="أُرسل إلى +966 5X XXX 4821" data-en="Sent to +966 5X XXX 4821">أُرسل إلى +966 5X XXX 4821</p>
<div class="boxes" dir="ltr">
<input type="text" inputmode="numeric" maxlength="1" aria-label="الخانة 1">
<input type="text" inputmode="numeric" maxlength="1" aria-label="الخانة 2">
<input type="text" inputmode="numeric" maxlength="1" aria-label="الخانة 3">
<input type="text" inputmode="numeric" maxlength="1" aria-label="الخانة 4">
<input type="text" inputmode="numeric" maxlength="1" aria-label="الخانة 5">
<input type="text" inputmode="numeric" maxlength="1" aria-label="الخانة 6">
</div>
<span class="err"></span>
<div class="foot">
<button class="rs" disabled></button>
<span class="hint" data-ar="الصق الرمز كاملًا ويُوزَّع تلقائيًّا" data-en="Paste the whole code — it distributes itself">الصق الرمز كاملًا ويُوزَّع تلقائيًّا</span>
</div>
</div>
/* pt-scoped */
/* signup-otp — تطبيق مالي */
.sgo{width:100%;height:100%;display:flex;flex-direction:column;
font-size:10px;color:var(--pt-text-secondary);overflow:hidden}
.sgo h5{margin:0;font-size:11px;color:var(--pt-text-primary);font-weight:600}
.sgo .sub{margin:0;font-size:8.5px;color:var(--pt-text-muted)}
.sgo label{display:flex;flex-direction:column;gap:3px}
.sgo label > span{font-size:8.5px;color:var(--pt-text-muted)}
.sgo input, .sgo select{width:100%;font:inherit;font-size:9.5px;
color:var(--pt-text-primary);outline:none}
.sgo input::placeholder{color:var(--pt-text-muted)}
.sgo .err{font-size:8px;color:var(--pt-color-danger-400);min-height:0}
.sgo .ok{color:var(--pt-accent)}
.sgo button{font:inherit;cursor:pointer}
.sgo button:focus-visible, .sgo input:focus-visible{outline:2px solid var(--pt-focus-ring);
outline-offset:1px}
/* شخصية: خانات مربّعة كبيرة، متمركزة، انحناء متوسّط */
.sgo{padding:11px;gap:7px;align-items:center;justify-content:center;text-align:center;
border:1px solid var(--pt-border-subtle);border-radius:var(--pt-radius-lg);
background:var(--pt-bg-inset)}
.sgo .boxes{display:flex;gap:5px}
.sgo .boxes input{width:26px;height:32px;text-align:center;font-size:13px;font-weight:600;
border-radius:var(--pt-radius-md);border:1px solid var(--pt-border-default);
background:var(--pt-surface);font-variant-numeric:tabular-nums;padding:0}
.sgo .boxes input:focus{border-color:var(--pt-accent)}
.sgo .boxes input.full{border-color:var(--pt-accent);color:var(--pt-accent)}
.sgo .foot{display:flex;flex-direction:column;align-items:center;gap:3px}
.sgo .rs{padding:5px 12px;border-radius:var(--pt-radius-full);
border:1px solid var(--pt-border-default);background:transparent;
color:var(--pt-text-secondary);font-size:9px}
.sgo .rs:disabled{opacity:.5;cursor:not-allowed}
.sgo .rs:not(:disabled):hover{border-color:var(--pt-accent);color:var(--pt-accent)}
.sgo .hint{font-size:7.5px;color:var(--pt-text-muted)}
/* يعمل داخل إطار معزول — لا يعتمد على شيء خارجه */
/* pt-remount — يعاد التركيب عند تبديل اللغة */
(function () {
var host = document.querySelector('.sgo');
if (!host) return;
var snapshot = host.innerHTML;
var timers = [];
var ac = null;
/* الجسم كما كتبه المولِّد. يستقبل بدائل مظلَّلة لـ root وdocument
والمؤقّتات، فينظّف نفسه دون أن يعرف أنه قابل لإعادة التركيب. */
function run(root, document, setTimeout, setInterval) {
/* الخطأ يظهر بعد مغادرة الحقل لا مع كل حرف: القراءة أثناء الكتابة
تُشعر المستخدم بالفشل قبل أن ينتهي من الإدخال. */
function bind(input, check, msg) {
var box = input.closest('label') || input.parentElement;
var err = box.querySelector('.err') || box.parentElement.querySelector('.err');
var touched = false;
function paint() {
var good = check(input.value);
input.setAttribute('aria-invalid', String(touched && !good));
if (err) err.textContent = touched && !good ? msg : '';
return good;
}
input.addEventListener('blur', function () { touched = true; paint(); });
input.addEventListener('input', function () { if (touched) paint(); });
return paint;
}
var boxes = [].slice.call(root.querySelectorAll('.boxes input'));
var err = root.querySelector('.err');
var rs = root.querySelector('.rs');
var CODE = '482913';
function digits(v) {
return String(v).replace(/[\u0660-\u0669]/g, function (d) { return d.charCodeAt(0) - 0x0660; })
.replace(/\D/g, '');
}
function value() { return boxes.map(function (b) { return b.value; }).join(''); }
function check() {
var v = value();
boxes.forEach(function (b) { b.classList.toggle('full', !!b.value); });
if (v.length < 6) { err.textContent = ''; return; }
var ok = v === CODE;
err.textContent = ok ? '' : 'الرمز غير صحيح';
err.className = ok ? 'err ok' : 'err';
if (ok) err.textContent = '✓ تمّ التحقّق';
}
boxes.forEach(function (b, i) {
b.addEventListener('input', function () {
b.value = digits(b.value).slice(0, 1);
if (b.value && i < boxes.length - 1) boxes[i + 1].focus();
check();
});
b.addEventListener('keydown', function (e) {
// الحذف من خانة فارغة يرجع للسابقة — وإلّا علق المستخدم
if (e.key === 'Backspace' && !b.value && i > 0) { boxes[i - 1].focus(); }
if (e.key === 'ArrowLeft' && i > 0) boxes[i - 1].focus();
if (e.key === 'ArrowRight' && i < boxes.length - 1) boxes[i + 1].focus();
});
// اللصق: أكثر ما يكسر هذا المكوّن — ستّ خانات تُلصق فتصل واحدة
b.addEventListener('paste', function (e) {
e.preventDefault();
var d = digits((e.clipboardData || window.clipboardData).getData('text')).slice(0, 6);
d.split('').forEach(function (ch, k) { if (boxes[k]) boxes[k].value = ch; });
boxes[Math.min(d.length, boxes.length) - 1].focus();
check();
});
});
var left = 30;
function tick() {
left--;
if (left <= 0) { rs.disabled = false; rs.textContent = 'إعادة الإرسال'; return; }
rs.textContent = 'إعادة الإرسال بعد ' + left + ' ثانية';
setTimeout(tick, 1000);
}
rs.addEventListener('click', function () { left = 30; rs.disabled = true; tick(); });
tick();
}
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(); });
})();
# OTP Code Entry
**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:** OTP Code Entry — Accepts a pasted code, moves back on delete, and re-sends on a timer
**Why this component matters:** Most OTP inputs break on paste — the user copies six digits and only the first lands. Handle the paste event, distribute the digits, and move focus to the last filled box.
**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.