Modal
Recipe
ts
import { defineComponent } from '../packages/varia/src/index.js'
export default defineComponent('modal', {
slots: {
root: 'fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm p-4',
// Choose a modal-size-* class on the root to set the container's max-width.
container:
'relative w-full rounded-lg bg-white shadow-xl ring-1 ring-gray-200 max-h-[90vh] overflow-hidden flex flex-col',
header: 'flex items-start justify-between gap-4 p-4 border-b border-gray-200',
title: 'text-lg font-semibold text-gray-900',
description: 'mt-1 text-sm text-gray-600',
body: 'p-4 overflow-y-auto flex-1',
footer: 'flex items-center justify-end gap-2 p-4 border-t border-gray-200',
close:
'absolute top-3 right-3 inline-flex items-center justify-center rounded-md p-1 text-gray-400 hover:bg-gray-100 hover:text-gray-700 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500',
},
variants: {
size: {
sm: { container: 'max-w-sm' },
md: { container: 'max-w-md' },
lg: { container: 'max-w-lg' },
xl: { container: 'max-w-2xl' },
},
},
})Usage
Confirm deletion
This action can't be undone.
Deleting this project will permanently remove all of its files, history, and shared links. Type the project name to confirm.
html
<div class="modal modal-size-md" role="dialog" aria-modal="true" aria-labelledby="m-title">
<div class="modal__container">
<div class="modal__header">
<div>
<h2 class="modal__title" id="m-title">Confirm deletion</h2>
<p class="modal__description">This action can't be undone.</p>
</div>
<button class="modal__close" type="button" aria-label="Close">×</button>
</div>
<div class="modal__body">
...body content...
</div>
<div class="modal__footer">
<button class="btn btn-c-neutral btn-style-outline btn-s-sm" type="button">Cancel</button>
<button class="btn btn-c-danger btn-style-solid btn-s-sm" type="button">Delete</button>
</div>
</div>
</div>