المكوّنات · زرّ نسخ بتأكيد
زرّ نسخ بتأكيد
ينسخ فعلًا، وله بديل يعمل بلا صلاحيات الحافظة
12 تصاميم من هذه العائلة
<div class="bt btc">
<div class="row">
<code class="key">pk_live_4KdM82nQx7Ta</code>
<button class="cp" aria-label="نسخ المفتاح"><span class="ic">⧉</span>
<span class="tx" data-ar="نسخ" data-en="Copy">نسخ</span></button>
</div>
<div class="log" role="status" aria-live="polite"></div>
</div>
/* pt-scoped */
/* button-copy — لوحة مطوّر */
.btc{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}
.btc .lbl{font-size:8px;color:var(--pt-text-muted);text-align:center}
.btc 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)}
.btc button:disabled{cursor:not-allowed}
.btc button:focus-visible{outline:2px solid var(--pt-focus-ring);outline-offset:2px}
/* أي زرّ ينزل بمقدار بكسل عند الضغط — تأكيد لمسيّ قبل وصول الردّ */
.btc button:not(:disabled):active{transform:translateY(1px)}
@media(prefers-reduced-motion:reduce){.btc button{transition:none}
.btc button:not(:disabled):active{transform:none}
}
/* هدف اللمس 44 بكسلًا على الشاشات اللمسية دون تضخيم سطح المكتب */
@media(pointer:coarse){.btc button{min-height:44px;min-width:44px}
}
/* شكل: حقل شفرة بزرّ ملتحم، انحناء صغير، خطّ أحادي */
.btc .row{display:flex;align-items:stretch;border-radius:var(--pt-radius-sm);overflow:hidden;
border:1px solid var(--pt-border-default);background:var(--pt-bg-inset)}
.btc .key{flex:1;padding:8px 10px;font-family:var(--pt-font-mono);font-size:9px;
color:var(--pt-text-secondary);direction:ltr;text-align:start;
display:flex;align-items:center;user-select:all}
.btc .cp{padding:0 12px;border:0;border-inline-start:1px solid var(--pt-border-default);
background:var(--pt-surface);color:var(--pt-text-secondary);font-size:9px;font-weight:600}
.btc .cp:hover{background:var(--pt-surface-hover);color:var(--pt-accent)}
.btc .cp.done{background:var(--pt-accent-muted);color:var(--pt-accent)}
.btc .cp.fail{background:color-mix(in srgb,var(--pt-color-danger-400) 16%,transparent);
color:var(--pt-color-danger-400)}
.btc .log{min-height:14px;font-size:8px;color:var(--pt-text-muted)}
/* يعمل داخل إطار معزول — لا يعتمد على شيء خارجه */
/* pt-remount — يعاد التركيب عند تبديل اللغة */
(function () {
var host = document.querySelector('.btc');
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 cp = root.querySelector('.cp'), key = root.querySelector('.key');
var ic = root.querySelector('.ic'), tx = root.querySelector('.tx'), log = root.querySelector('.log');
function flash(ok, msg) {
cp.classList.add(ok ? 'done' : 'fail');
ic.textContent = ok ? '✓' : '✕';
tx.textContent = ok ? (ar ? 'نُسخ' : 'Copied') : (ar ? 'تعذّر' : 'Failed');
log.textContent = msg;
setTimeout(function () {
cp.classList.remove('done', 'fail');
ic.textContent = '⧉';
tx.textContent = ar ? 'نسخ' : 'Copy';
log.textContent = '';
}, 1600);
}
/* البديل ليس ترفًا: واجهة الحافظة تُرفض خارج السياق الآمن أو بلا إذن،
وإظهار «نُسخ» حينها كذب على المستخدم. */
function fallback(text) {
var ta = document.createElement('textarea');
ta.value = text;
ta.setAttribute('readonly', '');
ta.style.cssText = 'position:fixed;inset-block-start:-100px;opacity:0';
document.body.appendChild(ta);
ta.select();
var ok = false;
try { ok = document.execCommand('copy'); } catch (e) { ok = false; }
document.body.removeChild(ta);
return ok;
}
cp.addEventListener('click', function () {
var text = key.textContent.trim();
if (navigator.clipboard && navigator.clipboard.writeText) {
navigator.clipboard.writeText(text).then(
function () { flash(true, ar ? 'عبر واجهة الحافظة' : 'via Clipboard API'); },
function () {
var ok = fallback(text);
flash(ok, ok ? (ar ? 'عبر الطريقة البديلة' : 'via fallback')
: (ar ? 'الحافظة محجوبة — حدّد النصّ وانسخه' : 'Clipboard blocked — select manually'));
}
);
} else {
var ok = fallback(text);
flash(ok, ok ? (ar ? 'عبر الطريقة البديلة' : 'via fallback')
: (ar ? 'الحافظة غير متاحة' : 'Clipboard unavailable'));
}
});
}
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(); });
})();
# Copy Button with Confirmation
**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:** Copy Button with Confirmation — Actually copies, with a fallback when clipboard permission is unavailable
**Why this component matters:** The Clipboard API rejects outside a secure context or without permission. Always keep a selection-based fallback and report failure honestly instead of showing a false “Copied”.
**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.