المكوّنات · أزرار مشاركة متوسّعة
أزرار مشاركة متوسّعة
زرّ واحد ينفتح إلى خيارات، مع عدّاد يزيد فعلًا
12 تصاميم من هذه العائلة
<div class="bt btsh">
<div class="shell">
<button class="tg" aria-expanded="false" aria-controls="shl">
<span aria-hidden="true">↗</span>
<span data-ar="مشاركة" data-en="Share">مشاركة</span>
<b class="ct num"></b></button>
<div id="shl" class="opts" hidden>
<button data-k="نسخ الرابط" data-ar="نسخ الرابط" data-en="Copy link">🔗</button>
<button data-k="واتساب" data-ar="واتساب" data-en="WhatsApp">💬</button>
<button data-k="بريد" data-ar="بريد" data-en="Email">✉</button>
<button data-k="طباعة" data-ar="طباعة" data-en="Print">🖨</button>
</div>
</div>
<div class="log" role="status" aria-live="polite"></div>
</div>
/* pt-scoped */
/* button-share — منصّة محتوى */
.btsh{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}
.btsh .lbl{font-size:8px;color:var(--pt-text-muted);text-align:center}
.btsh 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)}
.btsh button:disabled{cursor:not-allowed}
.btsh button:focus-visible{outline:2px solid var(--pt-focus-ring);outline-offset:2px}
/* أي زرّ ينزل بمقدار بكسل عند الضغط — تأكيد لمسيّ قبل وصول الردّ */
.btsh button:not(:disabled):active{transform:translateY(1px)}
@media(prefers-reduced-motion:reduce){.btsh button{transition:none}
.btsh button:not(:disabled):active{transform:none}
}
/* هدف اللمس 44 بكسلًا على الشاشات اللمسية دون تضخيم سطح المكتب */
@media(pointer:coarse){.btsh button{min-height:44px;min-width:44px}
}
/* شكل: شبحيّ محدَّد، خيارات تنبثق أفقيًّا، انحناء كامل */
.btsh .shell{display:flex;align-items:center;gap:5px}
.btsh .tg{padding:7px 14px;border-radius:var(--pt-radius-full);
border:1px solid var(--pt-border-default);background:transparent;
color:var(--pt-text-secondary);font-size:9.5px;font-weight:600}
.btsh .tg:hover, .btsh .tg[aria-expanded=true]{border-color:var(--pt-accent);color:var(--pt-accent)}
.btsh .ct{font-size:8px;padding:1px 6px;border-radius:var(--pt-radius-full);
background:var(--pt-bg-inset);color:var(--pt-text-muted);font-variant-numeric:tabular-nums}
.btsh .opts{display:flex;gap:4px}
.btsh .opts button{width:28px;height:28px;padding:0;border-radius:50%;
border:1px solid var(--pt-border-subtle);background:var(--pt-bg-inset);
color:var(--pt-text-secondary);font-size:11px;
animation:btpop var(--pt-motion-duration-normal) var(--pt-motion-easing-emphasized) backwards}
.btsh .opts button:nth-child(1){animation-delay:0ms}
.btsh .opts button:nth-child(2){animation-delay:40ms}
.btsh .opts button:nth-child(3){animation-delay:80ms}
.btsh .opts button:nth-child(4){animation-delay:120ms}
.btsh .opts button:hover{border-color:var(--pt-accent);color:var(--pt-accent)}
@keyframes btpop{from{opacity:0;transform:scale(.6)}to{opacity:1;transform:scale(1)}}
@media(prefers-reduced-motion:reduce){.btsh .opts button{animation:none}
}
.btsh .log{min-height:14px;font-size:8px;color:var(--pt-text-muted)}
/* يعمل داخل إطار معزول — لا يعتمد على شيء خارجه */
/* pt-remount — يعاد التركيب عند تبديل اللغة */
(function () {
var host = document.querySelector('.btsh');
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 tg = root.querySelector('.tg'), opts = root.querySelector('.opts');
var ct = root.querySelector('.ct'), log = root.querySelector('.log');
var count = 128;
ct.textContent = n(count);
tg.addEventListener('click', function () {
/* لوحة المشاركة الأصلية أفضل حيث توجد — لمسة واحدة على الجوّال.
والقائمة الخاصّة بديل لا نسخة موازية تُشحن معها دائمًا. */
if (navigator.share) {
navigator.share({ title: document.title, url: location.href })
.then(function () { bump('لوحة النظام'); })
.catch(function () {});
return;
}
var open = opts.hidden;
opts.hidden = !open;
tg.setAttribute('aria-expanded', String(open));
if (open) log.textContent = ar ? 'لوحة النظام غير متاحة — هذه البدائل'
: 'Native sheet unavailable — fallback options';
});
function bump(k) {
ct.textContent = n(++count);
log.textContent = (ar ? 'شُوركت عبر ' : 'Shared via ') + k;
setTimeout(function () { log.textContent = ''; }, 1500);
}
opts.addEventListener('click', function (e) {
var b = e.target.closest('button');
if (!b) return;
bump(b.dataset.k);
opts.hidden = true;
tg.setAttribute('aria-expanded', 'false');
});
}
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(); });
})();
# Expanding Share Buttons
**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:** Expanding Share Buttons — One button expands into options, with a counter that actually increments
**Why this component matters:** Prefer the native share sheet when navigator.share exists — it is one tap on mobile — and fall back to your own list everywhere else instead of shipping both blindly.
**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.