inertiax-ui 0.0.15 → 0.0.17
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 +15 -11
- package/README.md +8 -5
- package/package.json +1 -1
package/Modal.svelte
CHANGED
|
@@ -16,27 +16,31 @@
|
|
|
16
16
|
export function createModal(props) {
|
|
17
17
|
const onclose = props.onclose || (() => {})
|
|
18
18
|
let modal = null
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
let traverseBack = null
|
|
20
|
+
function close(traverse = true) {
|
|
21
|
+
if (traverse && traverseBack) {
|
|
22
|
+
traverseBack()
|
|
23
|
+
} else {
|
|
24
|
+
unmount(modal, { outro: true })
|
|
25
|
+
onclose()
|
|
26
|
+
}
|
|
22
27
|
}
|
|
23
|
-
push(function(
|
|
28
|
+
push(function(tb) {
|
|
29
|
+
traverseBack = tb
|
|
24
30
|
modal = mount(Modal, {
|
|
25
31
|
target: document.body,
|
|
26
32
|
props: {
|
|
27
33
|
...props,
|
|
28
|
-
close
|
|
29
|
-
traverse ? traverseBack() : close()
|
|
30
|
-
}
|
|
34
|
+
close
|
|
31
35
|
}
|
|
32
36
|
})
|
|
33
|
-
return close
|
|
37
|
+
return () => close(false)
|
|
34
38
|
})
|
|
35
39
|
return close
|
|
36
40
|
}
|
|
37
41
|
|
|
38
42
|
|
|
39
|
-
|
|
43
|
+
function css(node, { delay = 0 }) {
|
|
40
44
|
// duration on desktop is 300, on mobile 400
|
|
41
45
|
const duration = window.innerWidth > 768 ? 300 : 400;
|
|
42
46
|
return {
|
|
@@ -53,14 +57,14 @@
|
|
|
53
57
|
|
|
54
58
|
<script>
|
|
55
59
|
import { fade } from 'svelte/transition';
|
|
56
|
-
const { src, close } = $props()
|
|
60
|
+
const { src, close, ...rest } = $props()
|
|
57
61
|
</script>
|
|
58
62
|
|
|
59
63
|
<div class="inx-modal_wrapper">
|
|
60
64
|
<!-- svelte-ignore a11y_click_events_have_key_events,a11y_no_static_element_interactions -->
|
|
61
65
|
<div class="inx-modal_bg" onclick={close} transition:fade={{duration: 200}}></div>
|
|
62
66
|
<div class="inx-modal" aria-modal="true" scroll-region role="dialog" transition:css>
|
|
63
|
-
<Frame {src} {close} visitOptions={{ replace: false }} skipHistoryRestore>
|
|
67
|
+
<Frame {...rest} {src} {close} visitOptions={{ replace: false }} skipHistoryRestore>
|
|
64
68
|
<div class="inx-spinner" ></div>
|
|
65
69
|
</Frame>
|
|
66
70
|
<nav>
|
package/README.md
CHANGED
|
@@ -22,13 +22,16 @@ const modal = createModal({
|
|
|
22
22
|
})
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
-
`createModal` returns a `close` function you can call to close the modal programmatically:
|
|
25
|
+
`createModal` returns a `close` function you can call to close the modal programmatically. Call `close()` or `close(true)` to navigate back in history then unmount. Call `close(false)` to unmount without touching history:
|
|
26
26
|
|
|
27
27
|
```js
|
|
28
|
-
const
|
|
28
|
+
const closeModal = createModal({ src: '/profile/edit' })
|
|
29
29
|
|
|
30
|
-
//
|
|
31
|
-
|
|
30
|
+
// Navigate back, then unmount
|
|
31
|
+
closeModal()
|
|
32
|
+
|
|
33
|
+
// Or just unmount, skip history
|
|
34
|
+
closeModal(false)
|
|
32
35
|
```
|
|
33
36
|
|
|
34
37
|
#### `modal` action
|
|
@@ -66,7 +69,7 @@ The Modal component passes a `close` function down to its page component as a pr
|
|
|
66
69
|
<button onclick={close}>Close</button>
|
|
67
70
|
```
|
|
68
71
|
|
|
69
|
-
Note that
|
|
72
|
+
Note that `createModal` also returns a `close` function you can call to close the modal programmatically from the parent.
|
|
70
73
|
|
|
71
74
|
|
|
72
75
|
### `onclose` callback
|