feat(admin): per-row badge preview with unconfigured tooltip, Excel-style column filters and search in Contacts/Registrations
- New shared BadgeRender module (resolveText/resolveQr/BadgeElementBody/BadgePagePreview/fitScale) reused by the badge editor and the new read-only preview modal - Registrations: Badge button on every row opens a live preview of that attendee's badge; grayed out with a Uiverse-style APPE-red tooltip when the event has no badge configured - Contacts + Registrations: per-column multi-select filters (LinkedIn/Visibility/Admin; Type/Ticket/Checked in) with Excel-style live counts, plus general search (contacts: first/last/email; registrations: +type) - New Tooltip and ColumnFilter primitives in ui.tsx (portal-based, escape/outside-click close) - e2e: registration-badge-preview.spec.ts (13) + table-filters.spec.ts (13), all green; docs synced
This commit is contained in:
1 parent
6b277a2a67
commit
3d4dc207ff
10 files changed
+988
-121
No files matched your search
@@ -1,4 +1,6 @@
|
||||
import { type ReactNode } from 'react';
|
||||
import { cloneElement, isValidElement, useEffect, useRef, useState, useId, type ReactElement, type ReactNode } from 'react';
|
||||
import { createPortal } from 'react-dom';
|
||||
import { Filter } from 'lucide-react';
|
||||
import { QRCodeSVG } from 'qrcode.react';
|
||||
|
||||
const AV_COLORS = ['#d50000', '#20b2aa', '#e11d48', '#0d9488', '#f59e0b', '#0ea5e9', '#dc2626', '#7c3aed', '#16a34a', '#ea580c', '#0891b2', '#db2777'];
|
||||
@@ -108,3 +110,139 @@ export function Toggle({
|
||||
</label>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hover/focus tooltip rendered through a portal, so it is never clipped by
|
||||
* scrollable or `overflow: hidden` ancestors (e.g. data tables). The card
|
||||
* visual follows the Uiverse dark-glass tooltip already used in Interfaces,
|
||||
* re-themed to the APPE red accent. Wrap any element — including a disabled
|
||||
* button, whose own mouse events browsers suppress.
|
||||
*/
|
||||
export function Tooltip({ content, title, children }: {
|
||||
content: ReactNode;
|
||||
title?: string;
|
||||
children: ReactNode;
|
||||
}) {
|
||||
const anchor = useRef<HTMLSpanElement>(null);
|
||||
const id = useId();
|
||||
const [pos, setPos] = useState<{ x: number; y: number } | null>(null);
|
||||
const show = () => {
|
||||
const r = anchor.current?.getBoundingClientRect();
|
||||
if (r) setPos({ x: r.left + r.width / 2, y: r.top });
|
||||
};
|
||||
const hide = () => setPos(null);
|
||||
// Point the control at the card so screen readers announce the explanation
|
||||
// when it is focused (focus also reveals it visually).
|
||||
const child = isValidElement(children)
|
||||
? cloneElement(children as ReactElement<{ 'aria-describedby'?: string }>, { 'aria-describedby': id })
|
||||
: children;
|
||||
return (
|
||||
<span className="tip-anchor" ref={anchor} onMouseEnter={show} onMouseLeave={hide} onFocus={show} onBlur={hide}>
|
||||
{child}
|
||||
{pos && createPortal(
|
||||
<div className="tip-card" role="tooltip" id={id} style={{ left: pos.x, top: pos.y - 10 }}>
|
||||
{title && (
|
||||
<div className="tip-head">
|
||||
<span className="tip-ico" aria-hidden="true">
|
||||
<svg viewBox="0 0 20 20" fill="currentColor" width="15" height="15">
|
||||
<path clipRule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z" fillRule="evenodd" />
|
||||
</svg>
|
||||
</span>
|
||||
<strong>{title}</strong>
|
||||
</div>
|
||||
)}
|
||||
<p>{content}</p>
|
||||
<span className="tip-arrow" aria-hidden="true" />
|
||||
</div>,
|
||||
document.body,
|
||||
)}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
/** One selectable value inside a `ColumnFilter`, with a live result count. */
|
||||
export interface ColumnFilterOption {
|
||||
value: string;
|
||||
label: string;
|
||||
count: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Excel-style multi-select filter for a table column. Rendered through a portal
|
||||
* so the dropdown is never clipped by the table's `overflow: hidden`. An empty
|
||||
* selection means "no filter" (everything matches).
|
||||
*/
|
||||
export function ColumnFilter({ label, options, selected, onChange }: {
|
||||
label: string;
|
||||
options: ColumnFilterOption[];
|
||||
selected: string[];
|
||||
onChange: (next: string[]) => void;
|
||||
}) {
|
||||
const btnRef = useRef<HTMLButtonElement>(null);
|
||||
const popRef = useRef<HTMLDivElement>(null);
|
||||
const [open, setOpen] = useState(false);
|
||||
const [pos, setPos] = useState<{ left: number; top: number } | null>(null);
|
||||
const active = selected.length > 0;
|
||||
|
||||
const toggleOpen = () => {
|
||||
if (!open) {
|
||||
const r = btnRef.current?.getBoundingClientRect();
|
||||
if (r) setPos({ left: Math.min(Math.max(8, r.left), window.innerWidth - 240), top: r.bottom + 6 });
|
||||
}
|
||||
setOpen((o) => !o);
|
||||
};
|
||||
const toggleValue = (value: string) =>
|
||||
onChange(selected.includes(value) ? selected.filter((v) => v !== value) : [...selected, value]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!open) return;
|
||||
const onDown = (e: MouseEvent) => {
|
||||
const t = e.target as Node;
|
||||
if (popRef.current?.contains(t) || btnRef.current?.contains(t)) return;
|
||||
setOpen(false);
|
||||
};
|
||||
const onKey = (e: KeyboardEvent) => { if (e.key === 'Escape') setOpen(false); };
|
||||
const onScroll = () => setOpen(false);
|
||||
window.addEventListener('mousedown', onDown);
|
||||
window.addEventListener('keydown', onKey);
|
||||
window.addEventListener('scroll', onScroll, true);
|
||||
return () => {
|
||||
window.removeEventListener('mousedown', onDown);
|
||||
window.removeEventListener('keydown', onKey);
|
||||
window.removeEventListener('scroll', onScroll, true);
|
||||
};
|
||||
}, [open]);
|
||||
|
||||
return (
|
||||
<span className="colfilter">
|
||||
<button
|
||||
ref={btnRef}
|
||||
type="button"
|
||||
className={`colfilter-btn ${active ? 'on' : ''}`}
|
||||
onClick={toggleOpen}
|
||||
aria-label={`Filter ${label}`}
|
||||
aria-expanded={open}
|
||||
title={`Filter ${label}`}
|
||||
>
|
||||
<Filter size={13} aria-hidden="true" />
|
||||
{active && <span className="colfilter-count">{selected.length}</span>}
|
||||
</button>
|
||||
{open && pos && createPortal(
|
||||
<div className="colfilter-pop" ref={popRef} role="group" aria-label={`Filter ${label}`} style={{ left: pos.left, top: pos.top }}>
|
||||
<div className="colfilter-head">
|
||||
<strong>{label}</strong>
|
||||
{active && <button type="button" className="colfilter-clear" onClick={() => onChange([])}>Clear</button>}
|
||||
</div>
|
||||
{options.map((o) => (
|
||||
<label key={o.value} className="colfilter-opt">
|
||||
<input type="checkbox" checked={selected.includes(o.value)} onChange={() => toggleValue(o.value)} />
|
||||
<span className="lbl">{o.label}</span>
|
||||
<span className="cnt">{o.count}</span>
|
||||
</label>
|
||||
))}
|
||||
</div>,
|
||||
document.body,
|
||||
)}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user