feat: use label and legend for boxes

This commit is contained in:
Jet Pham 2025-11-18 00:45:50 -08:00
parent 99ca448d0d
commit 08e0d7e4c3
No known key found for this signature in database

View file

@ -11,57 +11,18 @@ export function BorderedBox({
children,
className = "",
}: BorderedBoxProps) {
// Generate unique ID for this instance to avoid conflicts
const maskId = `borderMask-${Math.random().toString(36).substring(2, 11)}`;
// Calculate SVG mask values - approximate 1ch = 16px for IBM VGA font
const chToPx = 16;
const maskX = 4 + chToPx; // 4px + 1ch
const maskWidth = label ? label.length * chToPx : 0;
return (
<div
className={`relative my-[calc(2ch-2px)] px-[calc(1.5ch-0.5px)] py-[1ch] ${className}`}
<fieldset
className={`my-[calc(2ch-2px)] border-2 border-white px-[calc(1.5ch-0.5px)] pb-[1ch] pt-0 ${className}`}
>
<div
className="absolute inset-0 border-2 border-white"
style={{
maskImage: label ? `url(#${maskId})` : "none",
WebkitMaskImage: label ? `url(#${maskId})` : "none",
}}
/>
{label && (
<svg
className="pointer-events-none absolute inset-0 h-full w-full"
style={{ zIndex: 1 }}
>
<defs>
<mask id={maskId}>
<rect width="100%" height="100%" fill="white" />
<rect
x={maskX}
y="-8"
width={maskWidth}
height="16"
fill="black"
/>
</mask>
</defs>
</svg>
)}
{label && (
<span
className="absolute -top-[1ch] bg-transparent text-white"
style={{ zIndex: 2 }}
>
<legend className="-mx-[0.5ch] px-[0.5ch] text-white">
{label}
</span>
</legend>
)}
<div className="relative z-10">{children}</div>
</div>
{children}
</fieldset>
);
}