inertiax-ui 0.0.15 → 0.0.16

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 CHANGED
@@ -16,27 +16,31 @@
16
16
  export function createModal(props) {
17
17
  const onclose = props.onclose || (() => {})
18
18
  let modal = null
19
- function close() {
20
- unmount(modal, { outro: true })
21
- onclose()
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(traverseBack) {
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: function(traverse = true) {
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
- function css(node, { delay = 0 }) {
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 {
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 modal = createModal({ src: '/profile/edit' })
28
+ const closeModal = createModal({ src: '/profile/edit' })
29
29
 
30
- // Later, close the modal
31
- modal()
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 there is no `close` function on the modal instance itself as components aren't usually able to unmount themselves.
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inertiax-ui",
3
- "version": "0.0.15",
3
+ "version": "0.0.16",
4
4
  "description": "UI component library for Inertia X",
5
5
  "repository": {
6
6
  "type": "git",