Store Modal Shell
Accessible dialog shell for store modals and drawers: scrim, focus trap, Escape, scroll lock and focus restore. Centre, drawer and top variants.
npx shadcn@latest add https://ui.develop-better-solutions.com/r/store-modal-shell.jsonUses:store-theme
Usage
store-modal-shell-example.tsx
"use client";
import { useState } from "react";
import { CloseButton, ModalShell, type ModalVariant } from "@dbs/ui";
import { StoreScope, triggerClass } from "./_store";
export default function StoreModalShellExample() {
const [open, setOpen] = useState<ModalVariant | null>(null);
const close = () => setOpen(null);
return (
<StoreScope minHeight={420}>
<div className="flex flex-wrap gap-3">
{(["center", "drawer", "top"] as const).map((v) => (
<button key={v} type="button" className={triggerClass} onClick={() => setOpen(v)}>
Open {v}
</button>
))}
</div>
<ModalShell open={open !== null} onClose={close} labelId="shell-title" variant={open ?? "center"} className="max-w-md">
<div className="flex items-start justify-between p-6">
<div>
<h2 id="shell-title" className="text-xl font-bold tracking-[-0.02em]">
Dialog title
</h2>
<p className="mt-2 text-sm text-[var(--store-soft)]">
Focus is trapped here. Press Escape or click the scrim to close.
</p>
</div>
<CloseButton onClick={close} label="Close dialog" />
</div>
</ModalShell>
</StoreScope>
);
}