Here is how to.
npm i -D yas-modal
tailwind.config.cjs
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')
]
...
};
ModalTarget
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