المكوّنات · بطاقة منتج
بطاقة منتج
الخصم محسوب من السعرين لا مكتوبًا يدويًّا
12 تصاميم من هذه العائلة
<div class="cd cdp"><article class="card">
<div class="img"><span class="badge num"></span></div>
<div class="body">
<h5 data-ar="سمّاعة لاسلكية بعزل الضجيج" data-en="Wireless noise-cancelling headphones">سمّاعة لاسلكية بعزل الضجيج</h5>
<div class="rate"><span class="stars" aria-hidden="true"></span>
<span class="rn num"></span><span class="cnt num"></span></div>
<div class="prices"><b class="now num"></b><s class="was num"></s></div>
<button class="add" data-ar="أضف للسلّة" data-en="Add to cart">أضف للسلّة</button>
</div>
</article></div>
/* pt-scoped */
/* card-product — متجر إلكتروني */
.cdp{width:100%;height:100%;display:flex;align-items:center;justify-content:center;
padding:8px;font-size:10px;color:var(--pt-text-secondary);overflow:hidden}
.cdp .card{display:flex;overflow:hidden;background:var(--pt-surface);
border:1px solid var(--pt-border-subtle)}
.cdp h5{margin:0;font-size:11px;color:var(--pt-text-primary);font-weight:600;line-height:1.4}
.cdp p{margin:0;font-size:8.5px;color:var(--pt-text-muted);line-height:1.7}
.cdp .num{font-variant-numeric:tabular-nums;letter-spacing:-.01em}
.cdp .img{flex:none;position:relative;overflow:hidden}
.cdp button{font:inherit;cursor:pointer}
.cdp button:focus-visible{outline:2px solid var(--pt-focus-ring);outline-offset:1px}
.cdp .bar{height:3px;border-radius:99px;background:var(--pt-border-subtle);overflow:hidden}
.cdp .bar i{display:block;height:100%;background:var(--pt-accent);border-radius:inherit;
transition:width var(--pt-motion-duration-slow) var(--pt-motion-easing-standard)}
@media(prefers-reduced-motion:reduce){.cdp .bar i{transition:none}
}
/* شكل: عمودية بغطاء علوي، انحناء متوسّط */
.cdp .card{flex-direction:column;width:186px;border-radius:var(--pt-radius-lg)}
.cdp .img{height:78px;background:linear-gradient(135deg,#3a3f6b,#6f5aa8 55%,#b98fc4)}
.cdp .badge{position:absolute;inset-block-start:6px;inset-inline-start:6px;
padding:2px 6px;border-radius:var(--pt-radius-full);background:var(--pt-color-danger-500);
color:#fff;font-size:8px;font-weight:700}
.cdp .body{display:flex;flex-direction:column;gap:5px;padding:9px}
.cdp .rate{display:flex;align-items:center;gap:4px;font-size:8px}
.cdp .stars{color:var(--pt-accent);letter-spacing:1px;font-size:8.5px}
.cdp .rn{color:var(--pt-text-secondary);font-weight:600}
.cdp .cnt{color:var(--pt-text-muted)}
.cdp .prices{display:flex;align-items:baseline;gap:6px}
.cdp .now{font-size:13px;color:var(--pt-text-primary);font-weight:700}
.cdp .was{font-size:9px;color:var(--pt-text-muted)}
.cdp .add{padding:6px;border-radius:var(--pt-radius-md);border:0;background:var(--pt-accent);
color:var(--pt-color-ink-900);font-size:9px;font-weight:600}
.cdp .add.done{background:var(--pt-accent-muted);color:var(--pt-accent)}
/* يعمل داخل إطار معزول — لا يعتمد على شيء خارجه */
/* pt-remount — يعاد التركيب عند تبديل اللغة */
(function () {
var host = document.querySelector('.cdp');
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 PEG = 3.75; /* الريال مربوط بالدولار */
var n = function (v, d) { return Number(v).toLocaleString('en-US', {
minimumFractionDigits: d || 0, maximumFractionDigits: d || 0 }); };
/* العملة: ر.س بعد الرقم عربيًّا، $ قبله إنجليزيًّا */
var money = function (usd, d) {
return ar ? n(usd * PEG, d) + ' ر.س' : '$' + n(usd, d);
};
var set = function (sel, txt) {
var el = root.querySelector(sel); if (el) el.textContent = txt; return el;
};
var LIST = 129, SALE = 89, RATING = 4.4, REVIEWS = 312;
// الشارة مشتقّة من السعرين — فلا يمكن أن تناقضهما
var off = Math.round((1 - SALE / LIST) * 100);
set('.badge', '−' + off + '%');
set('.now', money(SALE));
set('.was', money(LIST));
set('.rn', RATING.toFixed(1));
set('.cnt', '(' + n(REVIEWS) + ')');
// النجوم من التقييم نفسه: ممتلئة ثم نصف إن تجاوز الكسر الربع
var full = Math.floor(RATING), half = RATING - full >= 0.25;
set('.stars', '★'.repeat(full) + (half ? '⯪' : '') + '☆'.repeat(5 - full - (half ? 1 : 0)));
var add = root.querySelector('.add');
add.addEventListener('click', function () {
add.classList.add('done');
add.textContent = ar ? '✓ في السلّة' : '✓ In cart';
setTimeout(function () {
add.classList.remove('done');
add.textContent = ar ? 'أضف للسلّة' : 'Add to cart';
}, 1400);
});
}
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(); });
})();
# Product Card
**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:** Product Card — The discount is computed from both prices, never hand-written
**Why this component matters:** Hard-coding “-30%” next to two prices guarantees they will disagree after the first price edit. Derive the badge from list and sale price so it can never be wrong.
**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.