المكوّنات · زرّ منقسم بقائمة
زرّ منقسم بقائمة
إجراء افتراضي مباشر، وبدائله خلف سهم
12 تصاميم من هذه العائلة
<div class="bt btp">
<div class="split">
<button class="main" data-ar="تصدير PDF" data-en="Export PDF">تصدير PDF</button>
<button class="arw" aria-expanded="false" aria-controls="spm" aria-haspopup="menu"
aria-label="خيارات تصدير أخرى">⌄</button>
</div>
<ul id="spm" role="menu" hidden>
<li role="none"><button role="menuitem" data-f="XLSX" data-ar="تصدير Excel" data-en="Export Excel">تصدير Excel</button></li>
<li role="none"><button role="menuitem" data-f="CSV" data-ar="تصدير CSV" data-en="Export CSV">تصدير CSV</button></li>
<li role="none"><button role="menuitem" data-f="ZATCA" data-ar="ملفّ فوترة إلكترونية" data-en="E-invoicing file">ملفّ فوترة إلكترونية</button></li>
</ul>
<div class="log" role="status" aria-live="polite"></div>
</div>
/* pt-scoped */
/* button-split — نظام محاسبة */
.btp{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}
.btp .lbl{font-size:8px;color:var(--pt-text-muted);text-align:center}
.btp 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)}
.btp button:disabled{cursor:not-allowed}
.btp button:focus-visible{outline:2px solid var(--pt-focus-ring);outline-offset:2px}
/* أي زرّ ينزل بمقدار بكسل عند الضغط — تأكيد لمسيّ قبل وصول الردّ */
.btp button:not(:disabled):active{transform:translateY(1px)}
@media(prefers-reduced-motion:reduce){.btp button{transition:none}
.btp button:not(:disabled):active{transform:none}
}
/* هدف اللمس 44 بكسلًا على الشاشات اللمسية دون تضخيم سطح المكتب */
@media(pointer:coarse){.btp button{min-height:44px;min-width:44px}
}
/* شكل: نصفان ملتحمان، انحناء متوسّط، فاصل رفيع بينهما */
.btp{position:relative}
.btp .split{display:flex}
.btp .split button{border:0;background:var(--pt-accent);color:var(--pt-color-ink-900);
font-size:9.5px;font-weight:600;padding:8px 14px}
.btp .main{border-start-start-radius:var(--pt-radius-md);
border-end-start-radius:var(--pt-radius-md)}
.btp .arw{padding:8px 10px;border-start-end-radius:var(--pt-radius-md);
border-end-end-radius:var(--pt-radius-md);
box-shadow:inset 1px 0 0 color-mix(in srgb,var(--pt-color-ink-900) 22%,transparent)}
[dir=ltr] .btp .arw{box-shadow:inset -1px 0 0 color-mix(in srgb,var(--pt-color-ink-900) 22%,transparent)}
.btp .split button:hover{background:color-mix(in srgb,var(--pt-accent) 84%,#fff)}
.btp .arw[aria-expanded=true]{background:color-mix(in srgb,var(--pt-accent) 70%,#000)}
.btp ul{position:absolute;inset-block-start:calc(50% + 20px);z-index:6;margin:0;padding:4px;
list-style:none;display:flex;flex-direction:column;gap:1px;min-width:150px;
border-radius:var(--pt-radius-md);background:var(--pt-bg-overlay);
border:1px solid var(--pt-border-default);box-shadow:var(--pt-shadow-4)}
.btp ul button{width:100%;padding:6px 9px;border:0;border-radius:var(--pt-radius-sm);
background:transparent;color:var(--pt-text-secondary);font-size:9px;justify-content:flex-start}
.btp ul button:hover{background:var(--pt-surface-hover);color:var(--pt-text-primary)}
.btp .log{min-height:14px;font-size:8px;color:var(--pt-accent)}
/* يعمل داخل إطار معزول — لا يعتمد على شيء خارجه */
/* pt-remount — يعاد التركيب عند تبديل اللغة */
(function () {
var host = document.querySelector('.btp');
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 main = root.querySelector('.main'), arw = root.querySelector('.arw');
var menu = root.querySelector('#spm'), log = root.querySelector('.log');
var items = [].slice.call(menu.querySelectorAll('button'));
function set(v) {
menu.hidden = !v;
arw.setAttribute('aria-expanded', String(v));
if (v) items[0].focus();
}
arw.addEventListener('click', function (e) { e.stopPropagation(); set(menu.hidden); });
menu.addEventListener('click', function (e) {
var b = e.target.closest('button');
if (!b) return;
// الاختيار يصير الافتراضي — المرّة القادمة نقرة واحدة لا نقرتان
main.textContent = b.textContent;
log.textContent = (ar ? 'صُدّر ملفّ ' : 'Exported ') + b.dataset.f;
set(false); main.focus();
});
main.addEventListener('click', function () {
log.textContent = (ar ? 'جارٍ التصدير: ' : 'Exporting: ') + main.textContent;
});
document.addEventListener('click', function () { if (!menu.hidden) set(false); });
document.addEventListener('keydown', function (e) {
if (menu.hidden) return;
if (e.key === 'Escape') { set(false); arw.focus(); return; }
var i = items.indexOf(document.activeElement);
if (e.key === 'ArrowDown') { e.preventDefault(); items[(i + 1) % items.length].focus(); }
if (e.key === 'ArrowUp') { e.preventDefault(); items[(i - 1 + items.length) % items.length].focus(); }
});
}
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(); });
})();
# Split Button
**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:** Split Button — The default action is one click; its alternatives sit behind an arrow
**Why this component matters:** The split button is two controls in one shell: give each its own accessible name, or a screen reader announces the same label twice with no way to tell them apart.
**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.