Modals are opened using a “last in first out” stack. Each time a modal is opened
it gets added to the top of the stack. When closed it unmounts and is removed,
revealing the next modal in the stack (if there is one).
Each modal component receives an isActive prop to determine if it is the currently shown modal.
This should be used by your modal component to conditionally render or display itself.
Opening Modals
To open a modal, import modals and call modals.open(YourModalComponent, props).
Stacking Modals
You can call modals.open any time to open a new modal. This will add the new modal to the top of the stack,
keeping the previous modals mounted but updating their isActive prop to false.
Closing Modals
From anywhere in your app you can call modals.close() to close the top modal, modals.close(amount) to
close the last given number of modals, or modals.closeAll() to close all modals.
The close() Prop
Modals receive a close prop which will close the modal and resolve
their corresponding modals.open with the given value.
If you are using Typescript, you can define the type of the value by using the ModalProps interface.
Transitions
Transitions can be added to your modal components just like any other Svelte component. However they
must be global transitions because they are mounted and unmounted by the ModalStack component.
Transitions between Modals
By default, when opening one modal after another the transitions for both will play at the same time.
Depending on your animation this might be ok, but often it’s cleaner to transition one at a time.
To control this behaviour, you can forward on the onintrostart and onoutroend props to your modal.
This tells ModalStack to wait for the transition to finish before opening the next modal.
Lazy Loading
Modal components can be lazy loaded with dynamic imports
While the component is being imported, the <ModalStack /> component will render backdrop and loading snippets.
Snippets
Snippets can be passed in as props the same way you would with a regular Svelte 5 component.
Props
Modal components receive the following props:
If you’re using Typescript, you should use this interface to define the props of your modal components.