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.
Files changed (3) hide show
  1. package/Modal.svelte +11 -8
  2. package/README.md +28 -0
  3. 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
- console.log("mounting with state:", history.state)
19
- const modal = mount(Modal, {
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() : unmount(modal, { outro: true })
29
+ traverse ? traverseBack() : close()
25
30
  }
26
31
  }
27
32
  })
28
- return function() {
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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inertiax-ui",
3
- "version": "0.0.13",
3
+ "version": "0.0.14",
4
4
  "description": "UI component library for Inertia X",
5
5
  "repository": {
6
6
  "type": "git",