المكوّنات · عرض مكمّل بتوفير محسوب
عرض مكمّل بتوفير محسوب
التوفير محسوب من فرق السعرين، ويتغيّر مع كل اختيار
12 تصاميم من هذه العائلة
<div class="cm cmu">
<div class="hd"><h4 data-ar="أضفها معًا ووفّر" data-en="Buy together and save">أضفها معًا ووفّر</h4>
<span class="save num"></span></div>
<ul class="bundle"></ul>
<div class="foot">
<div class="pr"><b class="now num"></b><s class="was num"></s></div>
<button class="add" data-ar="أضف المحدَّد" data-en="Add selected">أضف المحدَّد</button>
</div>
</div>
/* pt-scoped */
/* commerce-upsell — متجر رياضة */
.cmu{width:100%;height:100%;display:flex;flex-direction:column;
font-size:10px;color:var(--pt-text-secondary);overflow:hidden}
.cmu h4{margin:0;font-size:10.5px;color:var(--pt-text-primary);font-weight:600}
.cmu p{margin:0;font-size:8.5px;color:var(--pt-text-muted);line-height:1.75}
.cmu .num{font-variant-numeric:tabular-nums;letter-spacing:-.01em}
.cmu button{font:inherit;cursor:pointer}
.cmu button:disabled{cursor:not-allowed;opacity:.45}
.cmu button:focus-visible, .cmu input:focus-visible, .cmu select:focus-visible{
outline:2px solid var(--pt-focus-ring);outline-offset:1px}
.cmu .bar{height:3px;border-radius:99px;background:var(--pt-border-subtle);overflow:hidden}
.cmu .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){.cmu .bar i{transition:none}
}
@media(pointer:coarse){.cmu button{min-height:44px}
}
/* شخصية: بطاقات أفقية بمربّعات اختيار، انحناء متوسّط */
.cmu{gap:7px;padding:10px 11px;justify-content:center}
.cmu .hd{display:flex;align-items:baseline;justify-content:space-between;gap:8px}
.cmu .save{font-size:8.5px;color:var(--pt-accent);font-weight:700}
.cmu .bundle{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:4px}
.cmu .bundle li{display:flex;align-items:center;gap:7px;padding:5px 7px;
border-radius:var(--pt-radius-md);border:1px solid var(--pt-border-subtle);
background:var(--pt-bg-inset)}
.cmu .bundle li.on{border-color:var(--pt-accent)}
.cmu .bundle input{width:12px;height:12px;flex:none;accent-color:var(--pt-accent);cursor:pointer}
.cmu .th{width:22px;height:22px;flex:none;border-radius:var(--pt-radius-xs)}
.cmu .l{flex:1;font-size:8.5px;color:var(--pt-text-secondary);cursor:pointer;
white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.cmu .p{font-size:8.5px;color:var(--pt-text-primary);font-variant-numeric:tabular-nums}
.cmu .foot{display:flex;align-items:center;justify-content:space-between;gap:8px;
padding-top:6px;border-top:1px solid var(--pt-border-subtle)}
.cmu .pr{display:flex;align-items:baseline;gap:5px}
.cmu .now{font-size:13px;color:var(--pt-accent);font-weight:700}
.cmu .was{font-size:8.5px;color:var(--pt-text-muted)}
.cmu .add{padding:6px 13px;border-radius:var(--pt-radius-md);border:0;
background:var(--pt-accent);color:var(--pt-color-ink-900);font-size:9px;font-weight:700}
/* يعمل داخل إطار معزول — لا يعتمد على شيء خارجه */
/* pt-remount — يعاد التركيب عند تبديل اللغة */
(function () {
var host = document.querySelector('.cmu');
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 }); };
/* العملة: $ ($) — سوق عالمي.
الأرقام مخزَّنة بـالريال وتُحوَّل، فتبقى
المبالغ معقولة في كل سوق. والتحويل لا التبديل: «18,500» راتبًا بالريال
معقول، وبالدينار الأردني ثروة.
وخانتان عشريتان — الوحدة تُقسَّم إلى مئة. */
var money = (function () {
var RATE = 1, DEC = 2;
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 : '$' + s;
};
})();
var set = function (sel, t) { var e = root.querySelector(sel); if (e) e.textContent = t; return e; };
/* الخصم يزيد بعدد القطع — والتوفير يُعاد حسابه مع كل اختيار.
شارة «وفّر 15%» ثابتة بجانب اختيار متغيّر تُفقد ثقة العميل بحسابك. */
var TIERS = { 1: 0, 2: 0.08, 3: 0.15 };
var ITEMS = [
{ ar: 'حذاء جري', en: 'Running shoes', p: 429, h: 208, on: true },
{ ar: 'جوارب ضغط', en: 'Compression socks', p: 79, h: 146, on: true },
{ ar: 'زجاجة ماء رياضية', en: 'Sports bottle', p: 55, h: 32, on: false }
];
var list = root.querySelector('.bundle');
function draw() {
list.innerHTML = ITEMS.map(function (it, i) {
return '<li class="' + (it.on ? 'on' : '') + '">' +
'<input type="checkbox" id="ub' + i + '"' + (it.on ? ' checked' : '') + '>' +
'<span class="th" style="background:hsl(' + it.h + ' 45% 50%)"></span>' +
'<label class="l" for="ub' + i + '">' + (ar ? it.ar : it.en) + '</label>' +
'<span class="p">' + money(it.p, 0) + '</span></li>';
}).join('');
var on = ITEMS.filter(function (it) { return it.on; });
var full = on.reduce(function (a, it) { return a + it.p; }, 0);
var pct = TIERS[on.length] || 0;
var now = full * (1 - pct);
set('.now', money(now, 0));
var was = root.querySelector('.was');
was.textContent = pct ? money(full, 0) : '';
set('.save', pct ? (ar ? 'وفّر ' + money(full - now, 0) + ' (' + Math.round(pct * 100) + '%)'
: 'Save ' + money(full - now, 0)) : '');
root.querySelector('.add').disabled = on.length === 0;
}
list.addEventListener('change', function (e) {
ITEMS[+e.target.id.replace('ub', '')].on = e.target.checked; 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(); });
})();
# Bundle Upsell with Computed Saving
**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:** Bundle Upsell with Computed Saving — The saving is computed from the price difference and updates with each pick
**Why this component matters:** Recompute the bundle saving from the selected items every time. A static “save 15%” badge beside a dynamic selection is the fastest way to lose a customer’s trust in your arithmetic.
**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.