المكوّنات · كوبون بثلاثة أنواع خصم
كوبون بثلاثة أنواع خصم
نسبة أو مبلغ ثابت أو شحن مجّاني — ولكلٍّ حسابه وحدّه
12 تصاميم من هذه العائلة
<div class="cm cmn">
<div class="fld"><input class="cp" type="text" placeholder="أدخل كود الخصم" dir="ltr">
<button class="ap" data-ar="طبّق" data-en="Apply">طبّق</button></div>
<p class="msg" role="status"></p>
<ul class="lines"></ul>
<p class="hint" data-ar="جرّب: SALE20 · FLAT50 · FREESHIP" data-en="Try: SALE20 · FLAT50 · FREESHIP">جرّب: SALE20 · FLAT50 · FREESHIP</p>
</div>
/* pt-scoped */
/* commerce-coupon — متجر عطور */
.cmn{width:100%;height:100%;display:flex;flex-direction:column;
font-size:10px;color:var(--pt-text-secondary);overflow:hidden}
.cmn h4{margin:0;font-size:10.5px;color:var(--pt-text-primary);font-weight:600}
.cmn p{margin:0;font-size:8.5px;color:var(--pt-text-muted);line-height:1.75}
.cmn .num{font-variant-numeric:tabular-nums;letter-spacing:-.01em}
.cmn button{font:inherit;cursor:pointer}
.cmn button:disabled{cursor:not-allowed;opacity:.45}
.cmn button:focus-visible, .cmn input:focus-visible, .cmn select:focus-visible{
outline:2px solid var(--pt-focus-ring);outline-offset:1px}
.cmn .bar{height:3px;border-radius:99px;background:var(--pt-border-subtle);overflow:hidden}
.cmn .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){.cmn .bar i{transition:none}
}
@media(pointer:coarse){.cmn button{min-height:44px}
}
/* شخصية: حقل كود بزرّ ملتحم، سطور حساب، انحناء متوسّط */
.cmn{gap:7px;padding:11px 12px;justify-content:center}
.cmn .fld{display:flex;border-radius:var(--pt-radius-md);overflow:hidden;
border:1px solid var(--pt-border-default);background:var(--pt-bg-inset)}
.cmn .fld:focus-within{border-color:var(--pt-accent)}
.cmn input{flex:1;min-width:0;border:0;background:transparent;padding:7px 10px;
font:inherit;font-size:9.5px;color:var(--pt-text-primary);outline:none;
text-transform:uppercase;letter-spacing:.08em}
.cmn .ap{flex:none;border:0;padding:0 14px;background:var(--pt-accent);
color:var(--pt-color-ink-900);font-size:9px;font-weight:700}
.cmn .msg{font-size:8px;min-height:10px}
.cmn .msg.ok{color:var(--pt-accent)}
.cmn .msg.bad{color:var(--pt-color-danger-400)}
.cmn .lines{list-style:none;margin:0;padding:7px 0 0;display:flex;flex-direction:column;gap:3px;
border-top:1px solid var(--pt-border-subtle)}
.cmn .lines li{display:flex;align-items:baseline;justify-content:space-between;gap:8px;
font-size:8.5px}
.cmn .lines li.dis b{color:var(--pt-accent)}
.cmn .lines li.tot{margin-top:3px;padding-top:5px;
border-top:1px solid var(--pt-border-default)}
.cmn .lines li.tot span{color:var(--pt-text-primary);font-weight:600;font-size:9.5px}
.cmn .lines li.tot b{color:var(--pt-accent);font-weight:700;font-size:12px}
.cmn .hint{font-size:7.5px;color:var(--pt-text-muted);font-family:var(--pt-font-mono)}
/* يعمل داخل إطار معزول — لا يعتمد على شيء خارجه */
/* pt-remount — يعاد التركيب عند تبديل اللغة */
(function () {
var host = document.querySelector('.cmn');
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; };
var SUB = 640, SHIP = 35;
/* لكل نوع حدّه: نسبة بلا سقف تحوّل طلبًا كبيرًا إلى خسارة، وحدّ أدنى
للإنفاق يمنع استعمال الكوبون على طلب لا يغطّي تكلفته. */
var CODES = {
SALE20: { type: 'pct', value: 20, cap: 100, min: 300,
ar: 'خصم 20% (بحدّ أقصى ' + money(100, 0) + ')',
en: '20% off (max ' + money(100, 0) + ')' },
FLAT50: { type: 'flat', value: 50, min: 200,
ar: 'خصم ' + money(50, 0), en: money(50, 0) + ' off' },
FREESHIP: { type: 'ship', min: 250,
ar: 'شحن مجّاني', en: 'Free shipping' }
};
var applied = null;
var msg = root.querySelector('.msg'), lines = root.querySelector('.lines');
function discount() {
if (!applied) return { off: 0, ship: SHIP, label: null };
var c = CODES[applied];
if (c.type === 'pct') return { off: Math.min(c.cap, SUB * c.value / 100), ship: SHIP, label: c };
if (c.type === 'flat') return { off: Math.min(SUB, c.value), ship: SHIP, label: c };
return { off: 0, ship: 0, label: c };
}
function draw() {
var d = discount();
var total = SUB - d.off + d.ship;
var rows = [
['<span>' + (ar ? 'المجموع' : 'Subtotal') + '</span><b class="num">' + money(SUB, 0) + '</b>', '']
];
if (d.label) rows.push(['<span>' + (ar ? d.label.ar : d.label.en) + '</span><b class="num">' +
(d.off ? '−' + money(d.off, 0) : (ar ? 'مجّاني' : 'Free')) + '</b>', 'dis']);
rows.push(['<span>' + (ar ? 'الشحن' : 'Shipping') + '</span><b class="num">' +
(d.ship ? money(d.ship, 0) : (ar ? 'مجّاني' : 'Free')) + '</b>', '']);
rows.push(['<span>' + (ar ? 'الإجمالي' : 'Total') + '</span><b class="num">' +
money(total, 0) + '</b>', 'tot']);
lines.innerHTML = rows.map(function (r) {
return '<li class="' + r[1] + '">' + r[0] + '</li>'; }).join('');
}
root.querySelector('.ap').addEventListener('click', function () {
var code = root.querySelector('.cp').value.trim().toUpperCase();
var c = CODES[code];
if (!c) { msg.className = 'msg bad';
msg.textContent = ar ? 'كود غير صالح' : 'Invalid code'; return; }
if (SUB < c.min) { msg.className = 'msg bad';
msg.textContent = ar ? 'يلزم إنفاق ' + money(c.min, 0) + ' على الأقلّ'
: 'Requires a minimum of ' + money(c.min, 0); return; }
applied = code;
msg.className = 'msg ok';
msg.textContent = '✓ ' + (ar ? c.ar : c.en);
draw();
});
root.querySelector('.cp').addEventListener('keydown', function (e) {
if (e.key === 'Enter') root.querySelector('.ap').click();
});
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(); });
})();
# Coupon with Three Discount Types
**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:** Coupon with Three Discount Types — Percentage, fixed amount or free shipping — each with its own cap
**Why this component matters:** Cap percentage discounts and enforce a minimum-spend rule server-side too. A percentage coupon without a ceiling turns one large order into a loss, and client-only checks are trivially bypassed.
**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.