المكوّنات · تسجيل بتحقّق عمري
تسجيل بتحقّق عمري
العمر محسوب بفرق التواريخ لا بطرح السنوات
12 تصاميم من هذه العائلة
<div class="sg sgg">
<h5 data-ar="تسجيل عضوية" data-en="Membership sign-up">تسجيل عضوية</h5>
<label><span data-ar="تاريخ الميلاد" data-en="Date of birth">تاريخ الميلاد</span>
<div class="dob">
<select class="dd" aria-label="اليوم"></select>
<select class="mm" aria-label="الشهر"></select>
<select class="yy" aria-label="السنة"></select>
</div>
<span class="err"></span></label>
<div class="out"><span class="age num"></span><span class="cat"></span></div>
<button class="go" disabled data-ar="تسجيل" data-en="Register">تسجيل</button>
</div>
/* pt-scoped */
/* signup-age — نادٍ رياضي */
.sgg{width:100%;height:100%;display:flex;flex-direction:column;
font-size:10px;color:var(--pt-text-secondary);overflow:hidden}
.sgg h5{margin:0;font-size:11px;color:var(--pt-text-primary);font-weight:600}
.sgg .sub{margin:0;font-size:8.5px;color:var(--pt-text-muted)}
.sgg label{display:flex;flex-direction:column;gap:3px}
.sgg label > span{font-size:8.5px;color:var(--pt-text-muted)}
.sgg input, .sgg select{width:100%;font:inherit;font-size:9.5px;
color:var(--pt-text-primary);outline:none}
.sgg input::placeholder{color:var(--pt-text-muted)}
.sgg .err{font-size:8px;color:var(--pt-color-danger-400);min-height:0}
.sgg .ok{color:var(--pt-accent)}
.sgg button{font:inherit;cursor:pointer}
.sgg button:focus-visible, .sgg input:focus-visible{outline:2px solid var(--pt-focus-ring);
outline-offset:1px}
/* شخصية: ثلاثة منتقيات متساوية، نتيجة بارزة، انحناء كبير */
.sgg{padding:11px;gap:7px;justify-content:center;
border:1px solid var(--pt-border-subtle);border-radius:var(--pt-radius-xl);
background:var(--pt-bg-inset)}
.sgg .dob{display:grid;grid-template-columns:1fr 1.4fr 1fr;gap:5px}
.sgg select{padding:6px 6px;border-radius:var(--pt-radius-lg);
border:1px solid var(--pt-border-default);background:var(--pt-surface);
font-variant-numeric:tabular-nums}
.sgg .out{display:flex;align-items:baseline;gap:7px;min-height:16px}
.sgg .age{font-size:14px;font-weight:700;color:var(--pt-text-primary)}
.sgg .cat{font-size:8px;padding:2px 8px;border-radius:var(--pt-radius-full);
background:var(--pt-accent-muted);color:var(--pt-accent);font-weight:600}
.sgg .cat.no{background:color-mix(in srgb,var(--pt-color-danger-400) 18%,transparent);
color:var(--pt-color-danger-400)}
.sgg .go{padding:7px;border-radius:var(--pt-radius-full);border:0;background:var(--pt-accent);
color:var(--pt-color-ink-900);font-size:9.5px;font-weight:600}
.sgg .go:disabled{opacity:.45;cursor:not-allowed}
/* يعمل داخل إطار معزول — لا يعتمد على شيء خارجه */
/* pt-remount — يعاد التركيب عند تبديل اللغة */
(function () {
var host = document.querySelector('.sgg');
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 MONTHS = ['يناير', 'فبراير', 'مارس', 'أبريل', 'مايو', 'يونيو',
'يوليو', 'أغسطس', 'سبتمبر', 'أكتوبر', 'نوفمبر', 'ديسمبر'];
var dd = root.querySelector('.dd'), mm = root.querySelector('.mm'), yy = root.querySelector('.yy');
var age = root.querySelector('.age'), cat = root.querySelector('.cat');
var go = root.querySelector('.go'), err = root.querySelector('.err');
var now = new Date(), thisYear = now.getFullYear();
function fill(sel, from, to, label) {
var out = '<option value="">' + label + '</option>';
for (var i = from; i <= to; i++)
out += '<option value="' + i + '">' + (sel === mm ? MONTHS[i - 1] : i) + '</option>';
sel.innerHTML = out;
}
fill(dd, 1, 31, 'يوم'); fill(mm, 1, 12, 'شهر'); fill(yy, thisYear - 90, thisYear - 4, 'سنة');
/* أيّام الشهر تتغيّر — وفبراير في السنة الكبيسة 29 لا 28 */
function daysIn(m, y) { return new Date(y, m, 0).getDate(); }
function syncDays() {
if (!mm.value || !yy.value) return;
var max = daysIn(+mm.value, +yy.value), keep = dd.value;
fill(dd, 1, max, 'يوم');
dd.value = keep && +keep <= max ? keep : '';
}
/* العمر بفرق التواريخ: طرح السنتين خطأ لمن لم يحلّ ميلاده بعد هذا العام */
function exactAge() {
if (!dd.value || !mm.value || !yy.value) return null;
var b = new Date(+yy.value, +mm.value - 1, +dd.value);
var a = now.getFullYear() - b.getFullYear();
var m = now.getMonth() - b.getMonth();
if (m < 0 || (m === 0 && now.getDate() < b.getDate())) a--;
return a;
}
function refresh() {
var a = exactAge();
if (a === null) { age.textContent = ''; cat.textContent = ''; cat.className = 'cat';
go.disabled = true; err.textContent = ''; return; }
age.textContent = a + ' سنة';
var ok = a >= 16;
cat.className = 'cat ' + (ok ? '' : 'no');
cat.textContent = a >= 60 ? 'فئة كبار السنّ' : a >= 18 ? 'عضوية كاملة'
: a >= 16 ? 'عضوية بموافقة وليّ الأمر' : 'دون السنّ المسموح';
err.textContent = ok ? '' : 'الحدّ الأدنى للعضوية 16 سنة';
go.disabled = !ok;
}
[mm, yy].forEach(function (s) {
s.addEventListener('change', function () { syncDays(); refresh(); });
});
dd.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(); });
})();
# Sign-up with Age Check
**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:** Sign-up with Age Check — Age computed from the full date difference, not by subtracting years
**Why this component matters:** Subtracting birth year from current year is wrong for anyone whose birthday has not passed yet this year — and that is roughly half your users on any given day.
**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.