Skip to content

Commit 2df4558

Browse files
committed
update readme, links
1 parent 2ceb296 commit 2df4558

File tree

2 files changed

+43
-29
lines changed

2 files changed

+43
-29
lines changed

README.md

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,31 @@
22

33
A simple, flexible, zero-dependency modal manager for Svelte.
44

5-
[View documentation](https://svelte-modals.mattjennings.io)
5+
[View documentation](https://svelte-modals.mattjennin.gs)
66

77
## Getting Started
88

9-
```
9+
### Installation
10+
11+
```bash
1012
npm install svelte-modals
1113
```
1214

13-
Add `Modals` somewhere in your app. This is where the modals will render.
15+
### Add \<Modals /> to your app
16+
17+
All opened modals will be rendered inside `<Modals />`. If you're using SvelteKit, `+layout.svelte` would be appropriate
18+
place to put it. Otherwise, wherever you want the modals to be rendered.
1419

1520
```svelte
1621
<script>
17-
import { Modals, closeModal } from 'svelte-modals'
22+
import { Modals } from 'svelte-modals'
1823
</script>
1924
2025
<Modals>
21-
<div slot="backdrop" class="backdrop" on:click={closeModal} />
26+
<!-- shown when any modal is opened -->
27+
{#snippet backdrop({ close })}
28+
<div class="backdrop" onclick={() => close()} />
29+
{/snippet}
2230
</Modals>
2331
2432
<style>
@@ -33,29 +41,33 @@ Add `Modals` somewhere in your app. This is where the modals will render.
3341
</style>
3442
```
3543

36-
Create your Modal component
44+
### Create your Modal component
3745

38-
```html
39-
<script>
40-
import { closeModal } from 'svelte-modals'
41-
42-
// provided by Modals
43-
export let isOpen
46+
Let's create a basic modal component:
4447

45-
export let title
46-
export let message
48+
```svelte
49+
<script>
50+
const {
51+
// provided by <Modals />
52+
isOpen,
53+
close,
54+
55+
// your props
56+
title,
57+
message
58+
} = $props()
4759
</script>
4860
4961
{#if isOpen}
50-
<div role="dialog" class="modal">
51-
<div class="contents">
52-
<h2>{title}</h2>
53-
<p>{message}</p>
54-
<div class="actions">
55-
<button on:click="{closeModal}">OK</button>
62+
<div role="dialog" class="modal">
63+
<div class="contents">
64+
<h2>{title}</h2>
65+
<p>{message}</p>
66+
<div class="actions">
67+
<button onclick={() => close()}>OK</button>
68+
</div>
5669
</div>
5770
</div>
58-
</div>
5971
{/if}
6072
6173
<style>
@@ -75,7 +87,6 @@ Create your Modal component
7587
7688
.contents {
7789
min-width: 240px;
78-
border-radius: 6px;
7990
padding: 16px;
8091
background: white;
8192
display: flex;
@@ -92,6 +103,7 @@ Create your Modal component
92103
p {
93104
text-align: center;
94105
margin-top: 16px;
106+
border-radius: 6px;
95107
}
96108
97109
.actions {
@@ -102,17 +114,19 @@ Create your Modal component
102114
</style>
103115
```
104116

105-
Open it
117+
### Try it out
106118

107-
```html
119+
Import `modals` anywhere in your app to open or close your modals
120+
121+
```svelte
108122
<script>
109-
import { openModal } from 'svelte-modals/legacy'
110-
import Modal from './Modal.svelte'
123+
import { modals } from 'svelte-modals'
124+
import MyModal from '$lib/components/MyModal.svelte'
111125
112126
function handleClick() {
113-
openModal(Modal, { title: 'Alert', message: 'This is an alert' })
127+
modals.open(MyModal, { title: 'Alert', message: 'This is an alert' })
114128
}
115129
</script>
116130
117-
<button on:click="{handleClick}">Open Modal</button>
131+
<button onclick={handleClick}>Open Modal</button>
118132
```

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"stack",
6767
"manager"
6868
],
69-
"homepage": "https://svelte-modals.mattjennings.io",
69+
"homepage": "https://svelte-modals.mattjennin.gs",
7070
"repository": {
7171
"type": "git",
7272
"url": "https://github.com/mattjennings/svelte-modals.git"

0 commit comments

Comments
 (0)