|
| 1 | +# API |
| 2 | + |
| 3 | +<style> |
| 4 | +h2 { |
| 5 | + @apply border-b-2 pb-2 border-gray-200; |
| 6 | +} |
| 7 | +</style> |
| 8 | + |
| 9 | +## ModalStack |
| 10 | + |
| 11 | +Handles the rendering of your modals in the stack |
| 12 | + |
| 13 | +### Slots |
| 14 | + |
| 15 | +#### `backdrop` |
| 16 | + |
| 17 | +Renders when any modals are open. The slot is empty by default. |
| 18 | + |
| 19 | +```svelte |
| 20 | +<script> |
| 21 | + import { ModalStack, closeModal } from 'svelte-modal-stack' |
| 22 | +</script> |
| 23 | +
|
| 24 | +<ModalStack> |
| 25 | + <div |
| 26 | + slot="backdrop" |
| 27 | + class="backdrop" |
| 28 | + on:click={closeModal} |
| 29 | + /> |
| 30 | +</ModalStack> |
| 31 | +
|
| 32 | +<style> |
| 33 | + .backdrop { |
| 34 | + position: fixed; |
| 35 | + top: 0; |
| 36 | + bottom: 0; |
| 37 | + right: 0; |
| 38 | + left: 0; |
| 39 | + background: rgba(0, 0, 0, 0.5); |
| 40 | +} |
| 41 | +</style> |
| 42 | +``` |
| 43 | + |
| 44 | +<br /> |
| 45 | + |
| 46 | +#### `modals` |
| 47 | + |
| 48 | +Renders all modals in the stack. If you want to take over how they're rendered yourself, you can |
| 49 | +do so here. |
| 50 | + |
| 51 | +```svelte |
| 52 | +<script> |
| 53 | + import { ModalStack, stack } from 'svelte-modal-stack' |
| 54 | +</script> |
| 55 | +
|
| 56 | +<ModalStack> |
| 57 | + <slot name="modals"> |
| 58 | + {#each $stack as modal, i (i)} |
| 59 | + <svelte:component |
| 60 | + this={modal.component} |
| 61 | + isOpen={i === $stack.length - 1} |
| 62 | + {...modal.props || {}} |
| 63 | + /> |
| 64 | + {/each} |
| 65 | + </slot> |
| 66 | +</ModalStack> |
| 67 | +``` |
| 68 | + |
| 69 | +## openModal |
| 70 | + |
| 71 | +Opens a new modal |
| 72 | + |
| 73 | +```js |
| 74 | +import { openModal } from 'svelte-modal-stack' |
| 75 | + |
| 76 | +openModal(component, props, options) |
| 77 | +``` |
| 78 | + |
| 79 | +| Param | Type | Required | Description | |
| 80 | +| --------------- | ---------------------------- | -------- | --------------------------------------------------- | |
| 81 | +| component | <code>SvelteComponent</code> | Yes | Your Svelte modal component | |
| 82 | +| props | <code>any</code> | No | Props for the modal | |
| 83 | +| options | <code>object</code> | No | | |
| 84 | +| options.replace | <code>boolean</code> | No | This modal will replace the last modal in the stack | |
| 85 | + |
| 86 | +## closeModal |
| 87 | + |
| 88 | +Closes the last modal in the stack |
| 89 | + |
| 90 | +```js |
| 91 | +import { closeModal } from 'svelte-modal-stack' |
| 92 | + |
| 93 | +closeModal() |
| 94 | +``` |
| 95 | + |
| 96 | +## closeModals |
| 97 | + |
| 98 | +Closes the provided amount of modals |
| 99 | + |
| 100 | +```js |
| 101 | +import { closeModals } from 'svelte-modal-stack' |
| 102 | + |
| 103 | +closeModals(2) |
| 104 | +``` |
| 105 | + |
| 106 | +| Param | Type | Required | Description | |
| 107 | +| ------ | ------------------- | -------- | ----------------------------- | |
| 108 | +| amount | <code>number</code> | Yes | The number of modals to close | |
| 109 | + |
| 110 | +## closeAllModals |
| 111 | + |
| 112 | +Closes all modals in the stack |
| 113 | + |
| 114 | +```js |
| 115 | +import { closeAllModals } from 'svelte-modal-stack' |
| 116 | + |
| 117 | +closeAllModals() |
| 118 | +``` |
| 119 | + |
| 120 | +## stack |
| 121 | + |
| 122 | +A Svelte store containing the modal components and their props |
| 123 | + |
| 124 | +## action |
| 125 | + |
| 126 | +A Svelte store describing how the current modal came to be active ("push" or "pop"). This can be useful for transitions if they should animate differently based on the action. |
0 commit comments