المكوّنات · زرّ عائم يتحوّل إلى لوحة
زرّ عائم يتحوّل إلى لوحة
يتمدّد من دائرة إلى نموذج، ويعود عند الإغلاق
7 تصاميم من هذه العائلة
<div class="ap apfm"><div class="ph">
<div class="sb"><span class="tm num"></span>
<span class="r" aria-hidden="true"><span>▲</span><span>◗</span><span class="bt num"></span></span></div>
<div class="scr"><div class="body">
<h6 data-ar="مصروفات اليوم" data-en="Today's spending">مصروفات اليوم</h6>
<b class="tot num"></b>
<ul class="ex"></ul>
</div></div>
<div class="morph">
<button class="trig tap" aria-expanded="false" aria-controls="mpanel" aria-label="أضف مصروفًا">+</button>
<div id="mpanel" class="panel" hidden>
<div class="ph-hd"><b data-ar="مصروف جديد" data-en="New expense">مصروف جديد</b>
<button class="cl tap" aria-label="إغلاق">✕</button></div>
<input class="am" type="text" inputmode="decimal" placeholder="0.00" dir="ltr"
aria-label="المبلغ">
<div class="cats"></div>
<button class="sv" disabled data-ar="حفظ" data-en="Save">حفظ</button>
</div>
</div>
<div class="safe"></div>
</div></div>
/* pt-scoped */
/* appfab-morph — تطبيق مالي */
.apfm{width:100%;height:100%;display:flex;align-items:center;
justify-content:center;padding:6px;font-size:10px;color:var(--pt-text-secondary);
overflow:hidden}
.apfm .ph{position:relative;width:198px;height:100%;max-height:224px;display:flex;
flex-direction:column;overflow:hidden;background:var(--pt-bg-base);
border:1px solid var(--pt-border-default);border-radius:20px;
box-shadow:var(--pt-shadow-3)}
/* شريط الحالة — ليس تزيينًا: يثبت أعلى الشاشة فلا يبدأ المحتوى عند الحافّة */
.apfm .sb{flex:none;display:flex;align-items:center;justify-content:space-between;
padding:5px 12px 2px;font-size:7px;color:var(--pt-text-muted);
font-variant-numeric:tabular-nums}
.apfm .sb .r{display:flex;gap:3px}
.apfm .scr{flex:1;min-height:0;display:flex;flex-direction:column;overflow:hidden}
.apfm .body{flex:1;min-height:0;overflow-y:auto;overflow-x:hidden;
-webkit-overflow-scrolling:touch}
.apfm .body::-webkit-scrollbar{width:0}
/* المنطقة الآمنة السفلية — شريط الإيماءات يأكل ما تحته */
.apfm .safe{flex:none;height:9px;display:grid;place-items:center}
.apfm .safe::after{content:'';width:52px;height:3px;border-radius:99px;
background:var(--pt-border-strong)}
.apfm h6{margin:0;font-size:10px;color:var(--pt-text-primary);font-weight:600;line-height:1.4}
.apfm p{margin:0;font-size:8px;color:var(--pt-text-muted);line-height:1.65}
.apfm .num{font-variant-numeric:tabular-nums}
.apfm button{font:inherit;cursor:pointer;
transition:background 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)}
.apfm button:focus-visible, .apfm a:focus-visible, .apfm input:focus-visible{
outline:2px solid var(--pt-focus-ring);outline-offset:-1px}
/* هدف اللمس: 44 بكسلًا على الشاشات اللمسية، ومساحة نقر ممتدّة على غيرها */
@media(pointer:coarse){.apfm .tap{min-width:44px;min-height:44px}
}
.apfm .tap{position:relative}
.apfm .tap::before{content:'';position:absolute;inset:-6px}
@media(prefers-reduced-motion:reduce){.apfm *{transition:none!important;animation:none!important}
}
.apfm .ph{position:relative}
.apfm .body{padding:9px 13px 48px}
.apfm .tot{display:block;font-size:20px;color:var(--pt-accent);font-weight:700;margin:2px 0 8px}
.apfm .ex{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:5px}
.apfm .ex li{display:flex;align-items:center;justify-content:space-between;gap:8px;
font-size:8.5px;padding-bottom:5px;border-bottom:1px solid var(--pt-border-subtle)}
.apfm .ex .c{color:var(--pt-text-muted);font-size:7.5px}
.apfm .ex .v{color:var(--pt-text-primary);font-weight:700;font-variant-numeric:tabular-nums}
.apfm .morph{position:absolute;inset-block-end:14px;inset-inline-end:12px;z-index:5}
.apfm .trig{width:42px;height:42px;border-radius:50%;border:0;background:var(--pt-accent);
color:var(--pt-color-ink-900);font-size:19px;display:grid;place-items:center;
box-shadow:var(--pt-shadow-4)}
.apfm .trig[aria-expanded=true]{display:none}
.apfm .panel{position:absolute;inset-block-end:0;inset-inline-end:0;width:168px;
display:flex;flex-direction:column;gap:7px;padding:10px;border-radius:var(--pt-radius-lg);
background:var(--pt-bg-overlay);border:1px solid var(--pt-border-default);
box-shadow:var(--pt-shadow-5);
animation:apfmIn var(--pt-motion-duration-normal) var(--pt-motion-easing-emphasized)}
@keyframes apfmIn{from{opacity:0;transform:scale(.72);transform-origin:100% 100%}
to{opacity:1;transform:none}}
.apfm .ph-hd{display:flex;align-items:center;justify-content:space-between;gap:8px;
font-size:9px;color:var(--pt-text-primary)}
.apfm .cl{width:20px;height:20px;border:0;border-radius:50%;background:var(--pt-bg-inset);
color:var(--pt-text-muted);font-size:8px;display:grid;place-items:center}
.apfm .am{padding:7px 9px;border-radius:var(--pt-radius-md);
border:1px solid var(--pt-border-default);background:var(--pt-bg-inset);font:inherit;
font-size:13px;font-weight:700;color:var(--pt-text-primary);text-align:center;
font-variant-numeric:tabular-nums;outline:none}
.apfm .cats{display:flex;flex-wrap:wrap;gap:4px}
.apfm .cats button{padding:3px 8px;border-radius:99px;border:1px solid var(--pt-border-default);
background:transparent;color:var(--pt-text-muted);font-size:7.5px}
.apfm .cats button[aria-pressed=true]{background:var(--pt-accent-muted);
border-color:var(--pt-accent);color:var(--pt-accent)}
.apfm .sv{padding:7px;border-radius:var(--pt-radius-md);border:0;background:var(--pt-accent);
color:var(--pt-color-ink-900);font-size:9px;font-weight:700}
.apfm .sv:disabled{opacity:.4;cursor:not-allowed}
/* يعمل داخل إطار معزول — لا يعتمد على شيء خارجه */
/* pt-remount — يعاد التركيب عند تبديل اللغة */
(function () {
var host = document.querySelector('.apfm');
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, d) { return Number(v).toLocaleString('en-US', {
minimumFractionDigits: d || 0, maximumFractionDigits: d || 0 }); };
var money = function (usd, d) {
return ar ? n(usd * 3.75, d) + ' ر.س' : '$' + n(usd, d);
};
var set = function (sel, txt) {
var el = root.querySelector(sel); if (el) el.textContent = txt; return el;
};
/* الساعة بأرقام لاتينية دائمًا — قرار موحّد في المشروع كلّه */
(function clock() {
var t = root.querySelector('.tm');
if (!t) return;
function tick() {
var d = new Date();
t.textContent = String(d.getHours()).padStart(2, '0') + ':' +
String(d.getMinutes()).padStart(2, '0');
setTimeout(tick, 20000);
}
tick();
})();
var bt = root.querySelector('.bt');
if (bt) bt.textContent = '84%';
/* اهتزاز خفيف حيث يوجد — تأكيد لمسيّ لا يعتمد عليه شيء */
var buzz = function (ms) { try { if (navigator.vibrate) navigator.vibrate(ms || 8); } catch (e) {} };
var CATS = ['طعام', 'مواصلات', 'تسوّق', 'فواتير'];
var EX = [
{ t: 'قهوة الصباح', c: 'طعام', v: 4.5 },
{ t: 'بنزين', c: 'مواصلات', v: 22 },
{ t: 'اشتراك إنترنت', c: 'فواتير', v: 78 }
];
var ul = root.querySelector('.ex'), tot = root.querySelector('.tot');
function draw() {
ul.innerHTML = EX.map(function (x) {
return '<li><span>' + x.t + '<br><span class="c">' + x.c + '</span></span>' +
'<span class="v">' + money(x.v, 2) + '</span></li>';
}).join('');
tot.textContent = money(EX.reduce(function (a, x) { return a + x.v; }, 0), 2);
}
var trig = root.querySelector('.trig'), panel = root.querySelector('.panel');
var cl = root.querySelector('.cl'), am = root.querySelector('.am');
var cats = root.querySelector('.cats'), sv = root.querySelector('.sv');
cats.innerHTML = CATS.map(function (c, i) {
return '<button type="button" aria-pressed="' + (i === 0) + '">' + c + '</button>';
}).join('');
/* استمرارية التركيز: يدخل اللوحة عند الفتح ويعود للمُطلِق عند الإغلاق،
وإلّا ضاع موضع مستخدم لوحة المفاتيح تمامًا. */
function set(v) {
panel.hidden = !v;
trig.setAttribute('aria-expanded', String(v));
if (v) am.focus(); else trig.focus();
}
trig.addEventListener('click', function () { buzz(); set(true); });
cl.addEventListener('click', function () { set(false); });
document.addEventListener('keydown', function (e) {
if (e.key === 'Escape' && !panel.hidden) set(false);
});
cats.addEventListener('click', function (e) {
var b = e.target.closest('button'); if (!b) return;
cats.querySelectorAll('button').forEach(function (x) {
x.setAttribute('aria-pressed', String(x === b));
});
});
am.addEventListener('input', function () {
am.value = am.value.replace(/[^\d.]/g, '').replace(/(\..*)\./g, '$1');
sv.disabled = !(parseFloat(am.value) > 0);
});
sv.addEventListener('click', function () {
var c = cats.querySelector('[aria-pressed=true]').textContent;
EX.unshift({ t: 'مصروف ' + c, c: c, v: parseFloat(am.value) });
am.value = ''; sv.disabled = true;
draw(); set(false); buzz(14);
});
draw();
}
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(); });
})();
# FAB that Morphs into a Panel
**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:** FAB that Morphs into a Panel — Expands from a circle into a form and returns on close
**Why this component matters:** The morph must keep focus continuity: move focus into the panel when it opens and back to the trigger when it closes, or keyboard users lose their place entirely.
**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.