المكوّنات · سلّة بعتبة شحن مجّاني
سلّة بعتبة شحن مجّاني
المتبقّي للشحن المجّاني محسوب من الفرق لا مكتوبًا
12 تصاميم من هذه العائلة
<div class="cm cmc">
<div class="hd"><h4 data-ar="سلّتك" data-en="Your cart">سلّتك</h4>
<span class="cnt num"></span></div>
<ul class="items"></ul>
<div class="ship">
<div class="bar"><i></i></div>
<p class="msg"></p>
</div>
<div class="tot">
<div class="row"><span data-ar="المجموع" data-en="Subtotal">المجموع</span><b class="sub num"></b></div>
<div class="row"><span data-ar="الشحن" data-en="Shipping">الشحن</span><b class="shp num"></b></div>
<div class="row big"><span data-ar="الإجمالي" data-en="Total">الإجمالي</span><b class="all num"></b></div>
</div>
</div>
/* pt-scoped */
/* commerce-cart — متجر أثاث */
.cmc{width:100%;height:100%;display:flex;flex-direction:column;
font-size:10px;color:var(--pt-text-secondary);overflow:hidden}
.cmc h4{margin:0;font-size:10.5px;color:var(--pt-text-primary);font-weight:600}
.cmc p{margin:0;font-size:8.5px;color:var(--pt-text-muted);line-height:1.75}
.cmc .num{font-variant-numeric:tabular-nums;letter-spacing:-.01em}
.cmc button{font:inherit;cursor:pointer}
.cmc button:disabled{cursor:not-allowed;opacity:.45}
.cmc button:focus-visible, .cmc input:focus-visible, .cmc select:focus-visible{
outline:2px solid var(--pt-focus-ring);outline-offset:1px}
.cmc .bar{height:3px;border-radius:99px;background:var(--pt-border-subtle);overflow:hidden}
.cmc .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){.cmc .bar i{transition:none}
}
@media(pointer:coarse){.cmc button{min-height:44px}
}
/* شخصية: قائمة بأزرار كمّية، شريط تقدّم للشحن، انحناء متوسّط */
.cmc{gap:7px;padding:10px 11px}
.cmc .hd{display:flex;align-items:baseline;justify-content:space-between;gap:8px}
.cmc .cnt{font-size:8px;color:var(--pt-text-muted)}
.cmc .items{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:5px;
flex:1;overflow-y:auto;min-height:0}
.cmc .items li{display:grid;grid-template-columns:30px 1fr auto;gap:7px;align-items:center;
padding-bottom:5px;border-bottom:1px solid var(--pt-border-subtle)}
.cmc .th{width:30px;height:30px;border-radius:var(--pt-radius-sm)}
.cmc .nm{font-size:9px;color:var(--pt-text-primary);line-height:1.4}
.cmc .qt{display:flex;align-items:center;gap:3px;margin-top:2px}
.cmc .qt button{width:16px;height:16px;padding:0;border-radius:var(--pt-radius-xs);
border:1px solid var(--pt-border-default);background:transparent;
color:var(--pt-text-secondary);font-size:9px;line-height:1;min-height:0}
.cmc .qt button:not(:disabled):hover{border-color:var(--pt-accent);color:var(--pt-accent)}
.cmc .qt b{min-width:14px;text-align:center;font-size:9px;color:var(--pt-text-primary)}
.cmc .pr{font-size:9.5px;color:var(--pt-text-primary);font-weight:600;white-space:nowrap}
.cmc .ship{display:flex;flex-direction:column;gap:3px}
.cmc .msg{font-size:8px}
.cmc .msg.ok{color:var(--pt-accent)}
.cmc .tot{display:flex;flex-direction:column;gap:2px;padding-top:6px;
border-top:1px solid var(--pt-border-default)}
.cmc .row{display:flex;align-items:baseline;justify-content:space-between;gap:8px;font-size:8.5px}
.cmc .row b{color:var(--pt-text-secondary)}
.cmc .row.big{margin-top:2px}
.cmc .row.big span{color:var(--pt-text-primary);font-weight:600;font-size:9.5px}
.cmc .row.big b{color:var(--pt-accent);font-weight:700;font-size:12px}
/* يعمل داخل إطار معزول — لا يعتمد على شيء خارجه */
/* pt-remount — يعاد التركيب عند تبديل اللغة */
(function () {
var host = document.querySelector('.cmc');
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 FREE_AT = 1200, FLAT_SHIP = 45; /* بالريال */
var ITEMS = [
{ ar: 'كرسي مكتب مريح', en: 'Ergonomic desk chair', p: 449, q: 1, h: 26 },
{ ar: 'مصباح أرضي', en: 'Floor lamp', p: 189, q: 1, h: 188 },
{ ar: 'رفّ جداري', en: 'Wall shelf', p: 96, q: 2, h: 146 }
];
var list = root.querySelector('.items');
function draw() {
list.innerHTML = ITEMS.map(function (it, i) {
return '<li><span class="th" style="background:hsl(' + it.h + ' 42% 46%)"></span>' +
'<span><span class="nm">' + (ar ? it.ar : it.en) + '</span>' +
'<span class="qt"><button data-d="-1" data-i="' + i + '" aria-label="إنقاص">−</button>' +
'<b class="num">' + it.q + '</b>' +
'<button data-d="1" data-i="' + i + '" aria-label="زيادة">+</button></span></span>' +
'<span class="pr num">' + money(it.p * it.q, 0) + '</span></li>';
}).join('');
calc();
}
function calc() {
var sub = ITEMS.reduce(function (a, it) { return a + it.p * it.q; }, 0);
var qty = ITEMS.reduce(function (a, it) { return a + it.q; }, 0);
/* المتبقّي محسوب من الفرق: رسالة ثابتة «أنفق 200 أخرى» تتقادم مع أوّل
تغيير كمّية — وهي أقوى دفعة في السلّة، فتقادمها يكلّف بيعًا. */
var gap = Math.max(0, FREE_AT - sub);
var free = gap === 0;
var ship = free ? 0 : FLAT_SHIP;
set('.cnt', qty + (ar ? ' قطعة' : ' items'));
set('.sub', money(sub, 0));
set('.shp', free ? (ar ? 'مجّاني' : 'Free') : money(ship, 0));
set('.all', money(sub + ship, 0));
var msg = root.querySelector('.msg');
msg.className = 'msg' + (free ? ' ok' : '');
msg.textContent = free
? (ar ? '✓ حصلت على الشحن المجّاني' : '✓ You got free shipping')
: (ar ? 'أضف ' + money(gap, 0) + ' لتحصل على شحن مجّاني'
: 'Add ' + money(gap, 0) + ' for free shipping');
root.querySelector('.bar i').style.width = Math.min(100, sub / FREE_AT * 100) + '%';
list.querySelectorAll('[data-d="-1"]').forEach(function (b) {
b.disabled = ITEMS[+b.dataset.i].q <= 1;
});
}
list.addEventListener('click', function (e) {
var b = e.target.closest('button');
if (!b) return;
var it = ITEMS[+b.dataset.i];
it.q = Math.max(1, Math.min(9, it.q + (+b.dataset.d)));
draw();
});
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(); });
})();
# Cart with Free-shipping Threshold
**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:** Cart with Free-shipping Threshold — The gap to free shipping is computed, never hand-written
**Why this component matters:** Show the remaining amount to free shipping, computed from the live subtotal. A static “spend 200 more” message goes stale the moment a quantity changes, and it is the single most effective nudge in a cart.
**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.