inertiax-ui 0.0.4 → 0.0.6

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
@@ -9,18 +9,24 @@
9
9
  node.addEventListener('click', (e) => {
10
10
  e.preventDefault()
11
11
  const href = node.getAttribute('href')
12
- push(function(traverseBack) {
13
- const modal = mount(Modal, {
14
- target: document.body,
15
- props: {
16
- src: href,
17
- close: traverseBack
12
+ createModal({ src: href })
13
+ })
14
+ }
15
+
16
+ export function createModal(props) {
17
+ push(function(traverseBack) {
18
+ const modal = mount(Modal, {
19
+ target: document.body,
20
+ props: {
21
+ ...props,
22
+ close: function(traverse = true) {
23
+ traverse ? traverseBack() : unmount(modal, { outro: true })
18
24
  }
19
- })
20
- return function () {
21
- unmount(modal, { outro: true })
22
25
  }
23
26
  })
27
+ return function() {
28
+ unmount(modal, { outro: true })
29
+ }
24
30
  })
25
31
  }
26
32
 
@@ -32,10 +38,10 @@
32
38
  delay,
33
39
  duration,
34
40
  easing: cubicOut,
35
- // tick: (t) => {
36
- // node.style.setProperty("--progress", t);
37
- // },
38
- css: (t) => `--progress: ${t}`
41
+ tick: (t) => {
42
+ node.style.setProperty("--progress", t);
43
+ },
44
+ // css: (t) => `--progress: ${t}`
39
45
  };
40
46
  }
41
47
  </script>
@@ -49,7 +55,9 @@
49
55
  <!-- svelte-ignore a11y_click_events_have_key_events,a11y_no_static_element_interactions -->
50
56
  <div class="inx-modal_bg" onclick={close} transition:fade={{duration: 200}}></div>
51
57
  <div class="inx-modal" aria-modal="true" role="dialog" transition:css>
52
- <Frame {src} {close} />
58
+ <Frame {src} {close}>
59
+ <div class="inx-spinner" ></div>
60
+ </Frame>
53
61
  <nav>
54
62
  <button onclick={close} aria-label="Close modal">
55
63
  <div class="i-material-symbols-light:close-rounded">Close</div>
@@ -57,4 +65,3 @@
57
65
  </nav>
58
66
  </div>
59
67
  </div>
60
-
package/README.md CHANGED
@@ -4,9 +4,25 @@ A collection of Svelte components for [Inertia X](https://github.com/buhrmi/iner
4
4
 
5
5
  ## Modal
6
6
 
7
- The Modal component displays an [Inertia X Frame](https://github.com/buhrmi/inertiax#frame-component) within a modal. It can be created via the `modal` action:
7
+ The Modal component displays an [Inertia X Frame](https://github.com/buhrmi/inertiax#frame-component) within a modal.
8
8
 
9
- ### Opening a modal
9
+ ![dark.css demo](./dark.css.webp)
10
+
11
+ ### Creating a modal
12
+
13
+ You can programmatically create a Modal using the `createModal(props)` function. All passed props are handed down to the Frame component, in addition to a `close` function (see below).
14
+
15
+ ```js
16
+ import { createModal } from 'inertiax-ui'
17
+
18
+ const modal = createModal({
19
+ src: '/profile/edit'
20
+ })
21
+ ```
22
+
23
+ #### `modal` action
24
+
25
+ The easiest way to create a modal is to use the `modal` action. This will automatically mount a Modal component in the document root.
10
26
 
11
27
  ```svelte
12
28
  <script>
@@ -18,7 +34,7 @@ The Modal component displays an [Inertia X Frame](https://github.com/buhrmi/iner
18
34
 
19
35
  ### Closing a modal
20
36
 
21
- 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.
37
+ 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.
22
38
 
23
39
  ```svelte
24
40
  <script>
@@ -28,18 +44,27 @@ The Modal component passes a `close` function down to its page component as a pr
28
44
  <button onclick={close}>Close</button>
29
45
  ```
30
46
 
47
+ Note that there is no `close` function on the modal instance itself as components aren't usually able to unmount themselves.
48
+
49
+ ## Installation
50
+
51
+ To start using Inertia X UI, install the `inertiax-ui` package and import the CSS style you'd like to use.
52
+
31
53
  ### Styling
32
54
 
33
- Inertia X UI ships with a default dark style that displays the modal as a bottom sheet.
55
+ Inertia X UI ships with a default [dark.css](./dark.css) style that displays the modal as a bottom sheet.
34
56
 
35
57
  ```js
36
58
  import 'inertiax-ui/dark.css'
37
59
  ```
38
60
 
39
- For full control, you can of course bring your own CSS styling. The key classes to target are:
61
+ For full styling control, you can of course bring your own CSS. The key classes to target are:
40
62
 
41
63
  | Class | Element |
42
64
  |-------|---------|
43
65
  | `.inx-modal_wrapper` | Full-screen overlay container |
44
66
  | `.inx-modal_bg` | Clickable backdrop |
45
- | `.inx-modal` | The modal panel itself |
67
+ | `.inx-modal` | The modal panel itself |
68
+ | `.inx-spinner` | The loading animation spinner |
69
+
70
+ Additionally, Svelte injects a `--progress` variable with the current progress of the modal in- and out-transition (0 to 1). You can use it to create your own in- and out-transitions.
package/dark.css CHANGED
@@ -52,3 +52,21 @@
52
52
  border-radius: var(--inx-modal-radius, 2rem);
53
53
  }
54
54
  }
55
+
56
+ .inx-spinner {
57
+ width: 32px;
58
+ height: 32px;
59
+ border: 2px solid #fff;
60
+ border-top-color: transparent;
61
+ border-radius: 50%;
62
+ animation: spin 1s linear infinite;
63
+ margin: auto;
64
+ position: absolute;
65
+ top: 50%;
66
+ left: 50%;
67
+ transform: translate(-50%, -50%);
68
+ }
69
+
70
+ @keyframes spin {
71
+ to { transform:translate(-50%, -50%) rotate(360deg); }
72
+ }
package/index.js CHANGED
@@ -1 +1 @@
1
- export { default as Modal } from './Modal.svelte';
1
+ export { default as Modal, modal, createModal } from './Modal.svelte';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inertiax-ui",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "UI component library for Inertia X",
5
5
  "repository": {
6
6
  "type": "git",