Getting started
bash
npm install @risklight/modalRequirements:
- Node and module format. Node 22.12+, ESM.
require()also works on Node 22.12+. - Peer dependencies.
vue3.3+,vue-router4 or 5, andreact18 or 19 are optional. Install only what you use.
Pick an adapter
| You use | Import from | Entry point |
|---|---|---|
| Vue 3 or Nuxt | @risklight/modal/vue | createVueModal() + <ModalContainer> |
| React 18/19 | @risklight/modal/react | createReactModal() + <ModalProvider> + <ModalContainer> |
| Plain JS | @risklight/modal/vanilla | createVanillaModal() |
| Another framework (Svelte, Solid…) | see Custom integrations | createModal() |
Vue in 30 seconds
ts
import { createApp } from 'vue'
import { createVueModal } from '@risklight/modal/vue'
createApp(App).use(createVueModal()).mount('#app')vue
<template>
<RouterView />
<ModalContainer />
</template>
<script setup lang="ts">
import { ModalContainer } from '@risklight/modal/vue'
</script>ts
const modal = useModal()
const ok = await modal.prompt<boolean>(ConfirmDelete, { title: 'Delete the report?' })The Vue, React and plain JS pages show the full setup for each adapter.
Core ideas
- Manager.
createVueModal(),createReactModal()andcreateVanillaModal()each create a manager. A manager holds stacks of modals, and you can create as many managers as you need (one per app, one per SSR request). - Namespace. A manager holds one stack per namespace, and
defaultis used unless you passnamespace. A container renders one namespace. - Handle.
open,pushandpromptcreate a handle. Use it to close the modal, add guards, listen to events or await the result. - Container. The container renders a namespace's stack and handles Escape, the backdrop, focus,
inertand scroll lock.