- Modals are always rendered in the div near the root of your app. This allows you not to think if some of the parents of your component have a relativish position.
- Modals can show modals, can show modals.
- Works just fine on mobile in fullscreen mode
Here is how to.
npm i -D yas-modal
Adds tailwind classes from the modal into your app's CSS.
/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
'./src/**/*.{html,js,svelte,ts}',
require('path').join(require.resolve('yas-modal'), '../**/*.svelte')
]
...
};
Wrap the slot in your root +layout.svelte
into the ModalTarget component. This will create a div in the root of your app and set it as a context for all child components as modal-target
<script>
import { ModalTarget } from 'yas-modal'
</script>
<ModalTarget><slot/></ModalTarget>
<script>
import { Modal } from 'yas-modal'
let show_modal = false;
</script>
<button on:click={()=> show_modal = true}>Click me</button>
{#if show_modal}
<Modal on:close={() => show_modal = false}>
<h1 slot="header">Title</h1>
Modal Content
<div slot="footer">Footer</div>
</Modal>
{/if}
MIT