المكوّنات · كثافة وأعمدة قابلة للإخفاء
كثافة وأعمدة قابلة للإخفاء
ثلاث كثافات، وأعمدة تُخفى وتعود، والحالة تُحفظ
12 تصاميم من هذه العائلة
<div class="tb tbn">
<div class="head">
<div class="seg" role="radiogroup" aria-label="الكثافة">
<button role="radio" data-d="cozy" aria-checked="false" data-ar="مريح" data-en="Cozy">مريح</button>
<button role="radio" data-d="norm" aria-checked="true" data-ar="عادي" data-en="Normal">عادي</button>
<button role="radio" data-d="tight" aria-checked="false" data-ar="مضغوط" data-en="Tight">مضغوط</button>
</div>
<div class="cols"></div>
<span class="cnt"></span>
</div>
<div class="wrap"><table><thead><tr></tr></thead><tbody></tbody></table></div>
</div>
/* pt-scoped */
/* table-density — لوحة تحليلات */
.tbn{width:100%;height:100%;display:flex;flex-direction:column;gap:6px;
font-size:10px;color:var(--pt-text-secondary);overflow:hidden;padding:9px 10px}
.tbn .wrap{flex:1;min-height:0;overflow:auto;border-radius:var(--pt-radius-sm);
border:1px solid var(--pt-border-subtle)}
.tbn table{width:100%;border-collapse:collapse;font-size:8.5px}
.tbn th, .tbn td{padding:5px 7px;text-align:start;white-space:nowrap}
.tbn thead th{position:sticky;inset-block-start:0;z-index:2;background:var(--pt-bg-inset);
color:var(--pt-text-muted);font-weight:500;font-size:8px;
border-bottom:1px solid var(--pt-border-default)}
.tbn tbody tr{border-bottom:1px solid var(--pt-border-subtle)}
.tbn tbody tr:last-child{border-bottom:0}
.tbn tbody tr:hover{background:var(--pt-surface-hover)}
.tbn tbody td{color:var(--pt-text-secondary)}
.tbn .e{text-align:end;font-variant-numeric:tabular-nums}
.tbn .head{display:flex;align-items:center;gap:7px;flex-wrap:wrap}
.tbn .head h4{margin:0;font-size:10px;color:var(--pt-text-primary);font-weight:600}
.tbn .cnt{font-size:8px;color:var(--pt-text-muted);font-variant-numeric:tabular-nums;
margin-inline-start:auto}
.tbn button{font:inherit;cursor:pointer}
.tbn button:focus-visible, .tbn input:focus-visible, .tbn select:focus-visible, .tbn th:focus-visible{outline:2px solid var(--pt-focus-ring);outline-offset:-2px}
.tbn .empty{padding:12px;text-align:center;font-size:9px;color:var(--pt-text-muted)}
/* شخصية: شريط تحكّم مضغوط، كثافات ثلاث، انحناء صغير */
.tbn .seg{display:flex;gap:1px;padding:2px;border-radius:var(--pt-radius-xs);
background:var(--pt-bg-inset);border:1px solid var(--pt-border-subtle)}
.tbn .seg button{padding:2px 8px;border:0;border-radius:var(--pt-radius-xs);
background:transparent;color:var(--pt-text-muted);font-size:7.5px}
.tbn .seg button[aria-checked=true]{background:var(--pt-accent);color:var(--pt-color-ink-900);
font-weight:600}
.tbn .cols{display:flex;gap:3px}
.tbn .cols button{padding:2px 7px;border-radius:var(--pt-radius-full);
border:1px solid var(--pt-border-default);background:transparent;
color:var(--pt-text-muted);font-size:7.5px}
.tbn .cols button[aria-pressed=true]{border-color:var(--pt-accent);color:var(--pt-accent);
background:var(--pt-accent-muted)}
.tbn.cozy th, .tbn.cozy td{padding:8px 9px}
.tbn.norm th, .tbn.norm td{padding:5px 7px}
.tbn.tight th, .tbn.tight td{padding:2px 6px;font-size:8px}
/* يعمل داخل إطار معزول — لا يعتمد على شيء خارجه */
/* pt-remount — يعاد التركيب عند تبديل اللغة */
(function () {
var host = document.querySelector('.tbn');
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 }); };
/* التطبيع العربي: «الموظفين» و«موظفين» و«مُوَظَّفين» كلمة واحدة */
function norm(s) {
return String(s).replace(/[\u064B-\u0652\u0670\u0640]/g, '')
.replace(/[\u0622\u0623\u0625\u0671]/g, '\u0627')
.replace(/\u0629/g, '\u0647').replace(/\u0649/g, '\u064A')
.replace(/[\u0660-\u0669]/g, function (d) { return d.charCodeAt(0) - 0x0660; })
.toLowerCase().replace(/\s+/g, ' ').trim();
}
var COLS = [
{ k: 'pg', ar: 'الصفحة', en: 'Page', e: false, on: true },
{ k: 'vw', ar: 'الزيارات', en: 'Views', e: true, on: true },
{ k: 'us', ar: 'الزوّار', en: 'Visitors', e: true, on: true },
{ k: 'br', ar: 'الارتداد', en: 'Bounce', e: true, on: true },
{ k: 'tm', ar: 'المدّة', en: 'Avg time', e: true, on: false }
];
var ROWS = [
{ pg: '/components/', vw: 18420, us: 9840, br: 0.32, tm: 214 },
{ pg: '/prompts/', vw: 12310, us: 7120, br: 0.28, tm: 186 },
{ pg: '/', vw: 24800, us: 15300, br: 0.51, tm: 92 },
{ pg: '/request/', vw: 3140, us: 2410, br: 0.19, tm: 340 },
{ pg: '/components/table-sort/', vw: 1820, us: 1290, br: 0.24, tm: 268 }
];
var KEY = 'tb-density', CKEY = 'tb-cols';
var dens = 'norm';
try {
dens = localStorage.getItem(KEY) || 'norm';
var saved = JSON.parse(localStorage.getItem(CKEY) || 'null');
if (saved) COLS.forEach(function (c) { if (c.k in saved) c.on = saved[c.k]; });
} catch (e) {}
function save() {
try {
localStorage.setItem(KEY, dens);
var m = {}; COLS.forEach(function (c) { m[c.k] = c.on; });
localStorage.setItem(CKEY, JSON.stringify(m));
} catch (e) {}
}
function fmt(r, c) {
if (c.k === 'br') return Math.round(r.br * 100) + '%';
if (c.k === 'tm') return Math.floor(r.tm / 60) + ':' + String(r.tm % 60).padStart(2, '0');
if (c.k === 'pg') return r.pg;
return n(r[c.k]);
}
function draw() {
root.className = 'tb tbn ' + dens;
var on = COLS.filter(function (c) { return c.on; });
root.querySelector('thead tr').innerHTML = on.map(function (c) {
return '<th scope="col"' + (c.e ? ' class="e"' : '') + '>' + (ar ? c.ar : c.en) + '</th>';
}).join('');
root.querySelector('tbody').innerHTML = ROWS.map(function (r) {
return '<tr>' + on.map(function (c) {
return '<td' + (c.e ? ' class="e"' : '') + (c.k === 'pg' ? ' dir="ltr"' : '') + '>' +
fmt(r, c) + '</td>';
}).join('') + '</tr>';
}).join('');
root.querySelector('.cols').innerHTML = COLS.slice(1).map(function (c) {
return '<button type="button" data-k="' + c.k + '" aria-pressed="' + c.on + '">' +
(ar ? c.ar : c.en) + '</button>';
}).join('');
root.querySelectorAll('.seg button').forEach(function (b) {
b.setAttribute('aria-checked', String(b.dataset.d === dens));
});
root.querySelector('.cnt').textContent = on.length + ' / ' + COLS.length +
(ar ? ' أعمدة' : ' cols');
}
root.querySelector('.seg').addEventListener('click', function (e) {
var b = e.target.closest('button'); if (!b) return;
dens = b.dataset.d; save(); draw();
});
root.addEventListener('click', function (e) {
var b = e.target.closest('.cols button'); if (!b) return;
var c = COLS.find(function (x) { return x.k === b.dataset.k; });
/* عمود واحد على الأقلّ يبقى — جدول بلا أعمدة ليس حالةً مفيدة */
if (c.on && COLS.filter(function (x) { return x.on; }).length <= 1) return;
c.on = !c.on; save(); draw();
});
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(); });
})();
# Density and Column Toggles
**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:** Density and Column Toggles — Three densities and hideable columns, with the choice remembered
**Why this component matters:** Persist the density and column choices: a table someone tuned to their screen should stay that way on the next visit, or they retune it every session and stop bothering.
**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.