المكوّنات · تسجيل بالعنوان الوطني
تسجيل بالعنوان الوطني
رمز بريدي ورقم مبنى ورقم إضافي، كلٌّ بطوله الصحيح
12 تصاميم من هذه العائلة
<div class="sg sga">
<h5 data-ar="عنوان الاستلام" data-en="Pickup address">عنوان الاستلام</h5>
<div class="grid">
<label><span data-ar="رقم المبنى" data-en="Building">رقم المبنى</span>
<input class="bn" inputmode="numeric" maxlength="4" placeholder="1234" dir="ltr"></label>
<label><span data-ar="الرمز البريدي" data-en="Postal">الرمز البريدي</span>
<input class="pc" inputmode="numeric" maxlength="5" placeholder="12345" dir="ltr"></label>
<label><span data-ar="الرقم الإضافي" data-en="Additional">الرقم الإضافي</span>
<input class="an" inputmode="numeric" maxlength="4" placeholder="6789" dir="ltr"></label>
<label><span data-ar="المدينة" data-en="City">المدينة</span>
<select class="ct"><option>الرياض</option><option>جدّة</option>
<option>الدمّام</option><option>أبها</option></select></label>
</div>
<span class="err"></span>
<div class="full" dir="ltr"></div>
<button class="go" disabled data-ar="حفظ العنوان" data-en="Save address">حفظ العنوان</button>
</div>
/* pt-scoped */
/* signup-address — شركة شحن */
.sga{width:100%;height:100%;display:flex;flex-direction:column;
font-size:10px;color:var(--pt-text-secondary);overflow:hidden}
.sga h5{margin:0;font-size:11px;color:var(--pt-text-primary);font-weight:600}
.sga .sub{margin:0;font-size:8.5px;color:var(--pt-text-muted)}
.sga label{display:flex;flex-direction:column;gap:3px}
.sga label > span{font-size:8.5px;color:var(--pt-text-muted)}
.sga input, .sga select{width:100%;font:inherit;font-size:9.5px;
color:var(--pt-text-primary);outline:none}
.sga input::placeholder{color:var(--pt-text-muted)}
.sga .err{font-size:8px;color:var(--pt-color-danger-400);min-height:0}
.sga .ok{color:var(--pt-accent)}
.sga button{font:inherit;cursor:pointer}
.sga button:focus-visible, .sga input:focus-visible{outline:2px solid var(--pt-focus-ring);
outline-offset:1px}
/* شخصية: شبكة رباعية، حقول قصيرة متساوية، انحناء متوسّط */
.sga{padding:10px;gap:6px;justify-content:center;
border:1px solid var(--pt-border-subtle);border-radius:var(--pt-radius-md);
background:var(--pt-bg-inset)}
.sga .grid{display:grid;grid-template-columns:1fr 1fr;gap:5px 7px}
.sga input, .sga select{padding:6px 8px;border-radius:var(--pt-radius-sm);
border:1px solid var(--pt-border-default);background:var(--pt-surface);
font-variant-numeric:tabular-nums;letter-spacing:.06em}
.sga input[aria-invalid=true]{border-color:var(--pt-color-danger-400)}
.sga input[aria-invalid=false]{border-color:color-mix(in srgb,var(--pt-accent) 50%,transparent)}
.sga .full{min-height:13px;padding:4px 7px;border-radius:var(--pt-radius-sm);
background:var(--pt-surface);font-family:var(--pt-font-mono);font-size:8px;
color:var(--pt-accent);text-align:start}
.sga .go{padding:7px;border-radius:var(--pt-radius-sm);border:0;background:var(--pt-accent);
color:var(--pt-color-ink-900);font-size:9.5px;font-weight:600}
.sga .go:disabled{opacity:.45;cursor:not-allowed}
/* يعمل داخل إطار معزول — لا يعتمد على شيء خارجه */
/* pt-remount — يعاد التركيب عند تبديل اللغة */
(function () {
var host = document.querySelector('.sga');
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 bn = root.querySelector('.bn'), pc = root.querySelector('.pc');
var an = root.querySelector('.an'), ct = root.querySelector('.ct');
var full = root.querySelector('.full'), go = root.querySelector('.go');
var err = root.querySelector('.err');
function digits(v) {
return String(v).replace(/[\u0660-\u0669]/g, function (d) { return d.charCodeAt(0) - 0x0660; })
.replace(/\D/g, '');
}
/* لكل جزء طوله الثابت — والتحقّق على الطول لا على وجود قيمة */
var PARTS = [{ el: bn, len: 4 }, { el: pc, len: 5 }, { el: an, len: 4 }];
function ok(p) { return digits(p.el.value).length === p.len; }
function refresh() {
var all = PARTS.every(ok);
PARTS.forEach(function (p) {
p.el.setAttribute('aria-invalid', String(p.el.value.length > 0 && !ok(p)));
});
err.textContent = PARTS.some(function (p) { return p.el.value && !ok(p); })
? 'أكمل الخانات — المبنى 4 والبريدي 5 والإضافي 4' : '';
full.textContent = all
? digits(bn.value) + ', ' + ct.value + ' ' + digits(pc.value) + '-' + digits(an.value)
: '';
go.disabled = !all;
}
PARTS.forEach(function (p, i) {
p.el.addEventListener('input', function () {
p.el.value = digits(p.el.value).slice(0, p.len);
// الانتقال التلقائي عند اكتمال الطول — فلا يعدّ المستخدم الخانات
if (p.el.value.length === p.len && PARTS[i + 1]) PARTS[i + 1].el.focus();
refresh();
});
});
ct.addEventListener('change', refresh);
refresh();
}
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(); });
})();
# National Address Sign-up
**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:** National Address Sign-up — Postal code, building number and additional number — each with its correct length
**Why this component matters:** The Saudi national address has four fixed-width parts. Validate each on its own length and auto-advance focus, so the user never has to count digits.
**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.