المكوّنات · خيارات شحن بتاريخ محسوب
خيارات شحن بتاريخ محسوب
الوصول محسوب بأيّام العمل، يتخطّى الجمعة والسبت
12 تصاميم من هذه العائلة
<div class="cm cms">
<h4 data-ar="اختر طريقة الشحن" data-en="Choose shipping">اختر طريقة الشحن</h4>
<ul class="opts" role="radiogroup" aria-label="طريقة الشحن"></ul>
<div class="note"><span class="pick"></span></div>
</div>
/* pt-scoped */
/* commerce-shipping — متجر كتب */
.cms{width:100%;height:100%;display:flex;flex-direction:column;
font-size:10px;color:var(--pt-text-secondary);overflow:hidden}
.cms h4{margin:0;font-size:10.5px;color:var(--pt-text-primary);font-weight:600}
.cms p{margin:0;font-size:8.5px;color:var(--pt-text-muted);line-height:1.75}
.cms .num{font-variant-numeric:tabular-nums;letter-spacing:-.01em}
.cms button{font:inherit;cursor:pointer}
.cms button:disabled{cursor:not-allowed;opacity:.45}
.cms button:focus-visible, .cms input:focus-visible, .cms select:focus-visible{
outline:2px solid var(--pt-focus-ring);outline-offset:1px}
.cms .bar{height:3px;border-radius:99px;background:var(--pt-border-subtle);overflow:hidden}
.cms .bar i{display:block;height:100%;background:var(--pt-accent);border-radius:inherit;
transition:width var(--pt-motion-duration-normal) var(--pt-motion-easing-standard)}
@media(prefers-reduced-motion:reduce){.cms .bar i{transition:none}
}
@media(pointer:coarse){.cms button{min-height:44px}
}
/* شخصية: خيارات كبطاقات مختارة، انحناء كبير */
.cms{gap:7px;padding:10px 11px;justify-content:center}
.cms .opts{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:5px}
.cms .opts li{display:flex;align-items:center;gap:8px;padding:8px 10px;
border-radius:var(--pt-radius-lg);border:1px solid var(--pt-border-default);
background:var(--pt-bg-inset);cursor:pointer;
transition:border-color var(--pt-motion-duration-fast) var(--pt-motion-easing-standard)}
.cms .opts li:hover{border-color:var(--pt-accent)}
.cms .opts li[aria-checked=true]{border-color:var(--pt-accent);background:var(--pt-accent-muted)}
.cms .dot{width:12px;height:12px;flex:none;border-radius:50%;
border:1.5px solid var(--pt-border-strong);display:grid;place-items:center}
.cms li[aria-checked=true] .dot{border-color:var(--pt-accent)}
.cms li[aria-checked=true] .dot::after{content:'';width:6px;height:6px;border-radius:50%;
background:var(--pt-accent)}
.cms .txt{flex:1;display:flex;flex-direction:column;gap:1px;min-width:0}
.cms .t{font-size:9.5px;color:var(--pt-text-primary);font-weight:600}
.cms .d{font-size:8px;color:var(--pt-text-muted)}
.cms .p{font-size:9.5px;font-weight:700;color:var(--pt-accent);white-space:nowrap}
.cms .note{font-size:8px;color:var(--pt-text-muted);min-height:11px}
@media(prefers-reduced-motion:reduce){.cms .opts li{transition:none}
}
/* يعمل داخل إطار معزول — لا يعتمد على شيء خارجه */
/* pt-remount — يعاد التركيب عند تبديل اللغة */
(function () {
var host = document.querySelector('.cms');
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, d) { return Number(v).toLocaleString('en-US', {
minimumFractionDigits: d === undefined ? 2 : d,
maximumFractionDigits: d === undefined ? 2 : d }); };
/* العملة: د.أ (JOD) — سوق الأردن.
الأرقام مخزَّنة بـالريال وتُحوَّل، فتبقى
المبالغ معقولة في كل سوق. والتحويل لا التبديل: «18,500» راتبًا بالريال
معقول، وبالدينار الأردني ثروة.
وثلاث خانات عشرية — الدينار يُقسَّم إلى ألف فلس. */
var money = (function () {
var RATE = 0.709, DEC = 3;
return function (v, d) {
var out = (Number(v) / 3.75) * RATE;
var places = d === undefined ? DEC : d;
var s = out.toLocaleString('en-US', {
minimumFractionDigits: places, maximumFractionDigits: places });
return ar ? s + ' د.أ' : 'JOD ' + s;
};
})();
var set = function (sel, t) { var e = root.querySelector(sel); if (e) e.textContent = t; return e; };
var OPTS = [
{ ar: 'عادي', en: 'Standard', days: 5, price: 25 },
{ ar: 'سريع', en: 'Express', days: 2, price: 60 },
{ ar: 'اليوم التالي', en: 'Next day', days: 1, price: 120 }
];
/* أيّام العمل لا أيّام التقويم، وعطلة الخليج الجمعة والسبت.
افتراض السبت والأحد يَعِد بتاريخ خاطئ في كل أسبوع. */
var WEEKEND = [5, 6]; /* 5=الجمعة 6=السبت */
function addBusiness(days) {
var d = new Date(); d.setHours(0, 0, 0, 0);
var left = days;
while (left > 0) {
d.setDate(d.getDate() + 1);
if (WEEKEND.indexOf(d.getDay()) === -1) left--;
}
return d;
}
function fmt(d) {
return d.toLocaleDateString(ar ? 'ar-SA-u-nu-latn' : 'en-GB',
{ weekday: 'long', day: 'numeric', month: 'short' });
}
var list = root.querySelector('.opts');
var pick = 0;
function draw() {
list.innerHTML = OPTS.map(function (o, i) {
var when = addBusiness(o.days);
return '<li role="radio" tabindex="0" aria-checked="' + (i === pick) + '">' +
'<span class="dot" aria-hidden="true"></span>' +
'<span class="txt"><span class="t">' + (ar ? o.ar : o.en) + '</span>' +
'<span class="d num">' + (ar ? 'يصل ' : 'Arrives ') + fmt(when) + '</span></span>' +
'<span class="p num">' + money(o.price, 0) + '</span></li>';
}).join('');
var o = OPTS[pick], w = addBusiness(o.days);
set('.pick', ar
? 'اخترت ' + o.ar + ' — ' + o.days + ' أيّام عمل، ويصل ' + fmt(w)
: o.en + ' selected — ' + o.days + ' business days, arriving ' + fmt(w));
}
list.addEventListener('click', function (e) {
var li = e.target.closest('li');
if (li) { pick = [].indexOf.call(list.children, li); draw(); }
});
list.addEventListener('keydown', function (e) {
if (e.key !== 'Enter' && e.key !== ' ') return;
var li = e.target.closest('li');
if (li) { e.preventDefault(); pick = [].indexOf.call(list.children, li); draw();
list.children[pick].focus(); }
});
draw();
}
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(); });
})();
# Shipping with Computed Dates
**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:** Shipping with Computed Dates — Arrival computed in business days, skipping Friday and Saturday
**Why this component matters:** Compute the arrival date by adding business days, not calendar days — and use the local weekend. In the Gulf that is Friday and Saturday, so a Western Sat/Sun assumption ships the wrong promise.
**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.