المكوّنات · عدّاد كمّية
عدّاد كمّية
يحترم المخزون والحدّ الأدنى، ويحسب الإجمالي فورًا
12 تصاميم من هذه العائلة
<div class="bt btq">
<div class="stp">
<button class="mn" aria-label="إنقاص">−</button>
<input class="qt" type="text" inputmode="numeric" aria-label="الكمّية" value="1">
<button class="pl" aria-label="زيادة">+</button>
</div>
<div class="info"><span class="stk num"></span><b class="tot num"></b></div>
<p class="lbl" data-ar="جرّب كتابة 999 — يُقصّ إلى المتاح" data-en="Try typing 999 — it clamps to stock">جرّب كتابة 999 — يُقصّ إلى المتاح</p>
</div>
/* pt-scoped */
/* button-stepper — سلّة متجر */
.btq{width:100%;height:100%;display:flex;flex-direction:column;
align-items:center;justify-content:center;gap:9px;padding:10px;
font-size:10px;color:var(--pt-text-secondary);overflow:hidden}
.btq .lbl{font-size:8px;color:var(--pt-text-muted);text-align:center}
.btq button{font:inherit;cursor:pointer;display:inline-flex;align-items:center;
justify-content:center;gap:5px;white-space:nowrap;
transition:background var(--pt-motion-duration-fast) var(--pt-motion-easing-standard),
border-color var(--pt-motion-duration-fast) var(--pt-motion-easing-standard),
color var(--pt-motion-duration-fast) var(--pt-motion-easing-standard),
transform var(--pt-motion-duration-fast) var(--pt-motion-easing-standard),
box-shadow var(--pt-motion-duration-fast) var(--pt-motion-easing-standard)}
.btq button:disabled{cursor:not-allowed}
.btq button:focus-visible{outline:2px solid var(--pt-focus-ring);outline-offset:2px}
/* أي زرّ ينزل بمقدار بكسل عند الضغط — تأكيد لمسيّ قبل وصول الردّ */
.btq button:not(:disabled):active{transform:translateY(1px)}
@media(prefers-reduced-motion:reduce){.btq button{transition:none}
.btq button:not(:disabled):active{transform:none}
}
/* هدف اللمس 44 بكسلًا على الشاشات اللمسية دون تضخيم سطح المكتب */
@media(pointer:coarse){.btq button{min-height:44px;min-width:44px}
}
/* شكل: ثلاثة أجزاء ملتحمة، انحناء كامل، حقل بلا حدود */
.btq .stp{display:flex;align-items:center;border-radius:var(--pt-radius-full);
border:1px solid var(--pt-border-default);background:var(--pt-bg-inset);overflow:hidden}
.btq .stp button{width:30px;height:30px;padding:0;border:0;background:transparent;
color:var(--pt-text-secondary);font-size:14px;line-height:1}
.btq .stp button:not(:disabled):hover{background:var(--pt-surface-hover);color:var(--pt-accent)}
.btq .stp button:disabled{opacity:.32}
.btq .qt{width:38px;height:30px;border:0;background:transparent;text-align:center;
font:inherit;font-size:11px;font-weight:700;color:var(--pt-text-primary);
font-variant-numeric:tabular-nums;outline:none}
.btq .qt:focus-visible{outline:2px solid var(--pt-focus-ring);outline-offset:-2px;
border-radius:var(--pt-radius-sm)}
.btq .info{display:flex;flex-direction:column;align-items:center;gap:2px}
.btq .stk{font-size:8px;color:var(--pt-text-muted)}
.btq .stk.low{color:var(--pt-color-warn-400)}
.btq .tot{font-size:13px;color:var(--pt-accent);font-weight:700}
/* يعمل داخل إطار معزول — لا يعتمد على شيء خارجه */
/* pt-remount — يعاد التركيب عند تبديل اللغة */
(function () {
var host = document.querySelector('.btq');
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) { return Number(v).toLocaleString('en-US'); };
var MIN = 1, STOCK = 8, UNIT = 145; /* بالريال */
var qt = root.querySelector('.qt'), mn = root.querySelector('.mn'), pl = root.querySelector('.pl');
var stk = root.querySelector('.stk'), tot = root.querySelector('.tot');
function digits(v) {
return String(v).replace(/[\u0660-\u0669]/g, function (d) { return d.charCodeAt(0) - 0x0660; })
.replace(/\D/g, '');
}
/* القصّ على كل مسار — الأزرار والكتابة واللصق. حراسة الأزرار وحدها
تمرّر 999 مكتوبة، فيفشل الطلب عند الدفع بدل أن يُمنع هنا. */
function clamp(v) { return Math.max(MIN, Math.min(STOCK, v || MIN)); }
function refresh(raw) {
var q = clamp(parseInt(digits(raw === undefined ? qt.value : raw), 10));
qt.value = q;
mn.disabled = q <= MIN;
pl.disabled = q >= STOCK;
stk.className = 'stk' + (STOCK - q <= 2 ? ' low' : '');
stk.textContent = ar ? 'المتاح ' + STOCK + ' قطع' : STOCK + ' in stock';
tot.textContent = ar ? n(q * UNIT) + ' ر.س' : '$' + n(Math.round(q * UNIT / 3.75));
}
mn.addEventListener('click', function () { refresh(+qt.value - 1); });
pl.addEventListener('click', function () { refresh(+qt.value + 1); });
qt.addEventListener('input', function () { qt.value = digits(qt.value).slice(0, 3); });
qt.addEventListener('blur', function () { refresh(); });
qt.addEventListener('keydown', function (e) {
if (e.key === 'ArrowUp') { e.preventDefault(); refresh(+qt.value + 1); }
if (e.key === 'ArrowDown') { e.preventDefault(); refresh(+qt.value - 1); }
if (e.key === 'Enter') refresh();
});
refresh(1);
}
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(); });
})();
# Quantity Stepper
**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:** Quantity Stepper — Respects stock and minimum, recomputing the line total instantly
**Why this component matters:** Clamp on every path — buttons, typing, and paste. A stepper that guards only its buttons lets a typed 999 through and the order fails at checkout instead of here.
**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.