Skip to content

Commit b75c7d7

Browse files
committed
api page
1 parent 2de1862 commit b75c7d7

File tree

5 files changed

+144
-11
lines changed

5 files changed

+144
-11
lines changed

src/lib/store.d.ts

+9-6
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@ import { SvelteComponentDev } from 'svelte/internal'
33
import { Writable } from 'svelte/store'
44

55
/**
6-
* Adds a Modal component to the stack
6+
* Opens a new modal
77
*/
88
export const openModal: <T>(
99
component: SvelteComponent | SvelteComponentTyped<T> | SvelteComponentDev,
1010
props?: T,
11-
options?: { replace?: boolean }
11+
options?: {
12+
/**
13+
* This modal will replace the last modal in the stack
14+
*/
15+
replace?: boolean
16+
}
1217
) => void
1318

1419
/**
@@ -37,9 +42,7 @@ export const stack: Writable<Array<{ component: SvelteComponent; props?: unknown
3742
export const transitioning: Writable<null | 'in' | 'out'>
3843

3944
/**
40-
* A store describing how the current modal came to be active. "push" means it was
41-
* newly added (from openModal), "pop" means the modal ahead of it was closed (closeModal).
42-
*
43-
* This can be useful for animations
45+
* A Svelte store describing how the current modal came to be active ("push" or "pop").
46+
* This can be useful for transitions if they should animate differently based on the action.
4447
*/
4548
export const action: Writable<null | 'push' | 'pop'>

src/routes/_components/Sidebar.svelte

+4-2
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@
3232

3333
<div class="mt-5 flex-1 h-0 overflow-y-auto">
3434
<nav class="px-2 space-y-1">
35-
<a href="/" class:active={$page.path === '/'}>Getting Started</a>
35+
<a href="/" class:active={$page.path === '/'}>Intro</a>
3636
<a href="/stacking-modals" class:active={$page.path === '/stacking-modals'}
3737
>Stacking Modals</a
3838
>
3939
<a href="/animation" class:active={$page.path === '/animation'}>Animation</a>
40+
<a href="/api" class:active={$page.path === '/api'}>API</a>
4041
</nav>
4142
</div>
4243
</div>
@@ -54,11 +55,12 @@
5455
<div class="border-r border-gray-200 pb-4 flex flex-col flex-grow overflow-y-auto">
5556
<div class="flex-grow mt-5 flex flex-col">
5657
<nav class="flex-1 bg-white px-2 space-y-1">
57-
<a href="/" class:active={$page.path === '/'}>Getting Started</a>
58+
<a href="/" class:active={$page.path === '/'}>Intro</a>
5859
<a href="/stacking-modals" class:active={$page.path === '/stacking-modals'}
5960
>Stacking Modals</a
6061
>
6162
<a href="/animation" class:active={$page.path === '/animation'}>Animation</a>
63+
<a href="/api" class:active={$page.path === '/api'}>API</a>
6264
</nav>
6365
</div>
6466
</div>

src/routes/animation/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
}
1313
</script>
1414

15-
## Animations
15+
# Animations
1616

1717
You can use Svelte transitions just like you would any other component.
1818

src/routes/api.md

+126
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
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.

src/routes/index.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66

77
# svelte-modal-stack
88

9+
A simple, flexible, zero-dependency modal stack manager for Svelte.
10+
11+
## Getting Started
12+
913
```
1014
npm install svelte-modal-stack
1115
```
1216

13-
## Basic Usage
14-
1517
Add `ModalStack` at the root of your app (or in your \_\_layout if using SvelteKit)
1618

1719
```svelte

0 commit comments

Comments
 (0)