inertiax-ui 0.0.13 → 0.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Modal.svelte +11 -8
- package/README.md +28 -0
- package/package.json +1 -1
package/Modal.svelte
CHANGED
|
@@ -5,29 +5,32 @@
|
|
|
5
5
|
import { cubicOut } from 'svelte/easing';
|
|
6
6
|
import { push } from './history'
|
|
7
7
|
|
|
8
|
-
export function modal(node) {
|
|
8
|
+
export function modal(node, props) {
|
|
9
9
|
node.addEventListener('click', (e) => {
|
|
10
10
|
e.preventDefault()
|
|
11
11
|
const href = node.getAttribute('href')
|
|
12
|
-
createModal({ src: href })
|
|
12
|
+
createModal({ src: href, ...props })
|
|
13
13
|
})
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export function createModal(props) {
|
|
17
|
+
const onclose = props.onclose || (() => {})
|
|
17
18
|
push(function(traverseBack) {
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
let modal = null
|
|
20
|
+
function close() {
|
|
21
|
+
unmount(modal, { outro: true })
|
|
22
|
+
onclose()
|
|
23
|
+
}
|
|
24
|
+
modal = mount(Modal, {
|
|
20
25
|
target: document.body,
|
|
21
26
|
props: {
|
|
22
27
|
...props,
|
|
23
28
|
close: function(traverse = true) {
|
|
24
|
-
traverse ? traverseBack() :
|
|
29
|
+
traverse ? traverseBack() : close()
|
|
25
30
|
}
|
|
26
31
|
}
|
|
27
32
|
})
|
|
28
|
-
return
|
|
29
|
-
unmount(modal, { outro: true })
|
|
30
|
-
}
|
|
33
|
+
return close
|
|
31
34
|
})
|
|
32
35
|
}
|
|
33
36
|
|
package/README.md
CHANGED
|
@@ -34,6 +34,17 @@ Inertia X UI also ships with a `modal` action. This is a small wrapper for `crea
|
|
|
34
34
|
<a href="/profile/edit" use:modal>Edit profile</a>
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
+
You can also pass options like `onclose`:
|
|
38
|
+
|
|
39
|
+
```svelte
|
|
40
|
+
<script>
|
|
41
|
+
import { modal } from 'inertiax-ui'
|
|
42
|
+
import { router } from 'inertiax-svelte'
|
|
43
|
+
</script>
|
|
44
|
+
|
|
45
|
+
<a href="/profile/edit" use:modal={{ onclose: () => router.reload() }}>Edit profile</a>
|
|
46
|
+
```
|
|
47
|
+
|
|
37
48
|
### Closing a modal
|
|
38
49
|
|
|
39
50
|
The Modal component passes a `close` function down to its page component as a prop. You can call this function to close it. Behind the scenes, calling `close` will use the browsers Navigation API to traverse the history back to before the modal was opened, which in turn triggers callbacks that unmount the modal. Alternatively, you can call `close(false)` to close the modal without going back in history. This will prevent forward-navigation from re-opening the modal.
|
|
@@ -48,6 +59,23 @@ The Modal component passes a `close` function down to its page component as a pr
|
|
|
48
59
|
|
|
49
60
|
Note that there is no `close` function on the modal instance itself as components aren't usually able to unmount themselves.
|
|
50
61
|
|
|
62
|
+
|
|
63
|
+
### `onclose` callback
|
|
64
|
+
|
|
65
|
+
Pass an `onclose` callback to run custom logic when the modal closes. This fires regardless of how the modal was closed — via the close button, backdrop click, or browser back button.
|
|
66
|
+
|
|
67
|
+
```js
|
|
68
|
+
import { createModal } from 'inertiax-ui'
|
|
69
|
+
import { router } from 'inertiax-svelte'
|
|
70
|
+
|
|
71
|
+
createModal({
|
|
72
|
+
src: '/profile/edit',
|
|
73
|
+
onclose: () => router.reload()
|
|
74
|
+
})
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Common use cases: reloading the parent page after an edit, resetting form state, or cleaning up side effects.
|
|
78
|
+
|
|
51
79
|
## Installation
|
|
52
80
|
|
|
53
81
|
To start using Inertia X UI, install the `inertiax-ui` package and import the CSS style you'd like to use.
|