Components
Dialog (Modal)
A modal dialog with focus trapping, scroll locking and an accessible title.
Installation
Install @vinui/react from GitHub with pnpm, then import its stylesheet once, in your root layout or entry file:
pnpm add github:vindotski/vinui#path:packages/react
import '@vinui/react/styles.css';
Usage
A modal dialog built on Headless UI's Dialog. Focus is trapped inside while open, page scrolling is locked, and Escape or a click outside closes it:
import { Button, Dialog, DialogActions, DialogDescription, DialogTitle } from '@vinui/react';
<Dialog open={open} onClose={() => setOpen(false)} role="alertdialog" size="sm">
<DialogTitle>Delete project?</DialogTitle>
<DialogDescription>This can’t be undone.</DialogDescription>
<DialogActions>
<Button variant="secondary" onClick={() => setOpen(false)} autoFocus>
Cancel
</Button>
<Button onClick={deleteProject}>Delete</Button>
</DialogActions>
</Dialog>;
- Sizes are
sm,md(default) andlg; dialogs are full-width on small screens. DialogTitleandDialogDescriptionlabel the dialog for screen readers. Put other content inDialogBody.DialogActionsright-aligns buttons, stacking them on small screens with the last (primary) on top.- Put
autoFocuson the element to focus first; userole="alertdialog"for confirmations.
More to come
Detailed examples, keyboard interaction and the full component API are on their way.