inertiax-ui 0.0.5 → 0.0.7
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 +28 -6
- package/index.js +1 -1
- package/package.json +1 -1
package/Modal.svelte
CHANGED
|
@@ -9,20 +9,24 @@
|
|
|
9
9
|
node.addEventListener('click', (e) => {
|
|
10
10
|
e.preventDefault()
|
|
11
11
|
const href = node.getAttribute('href')
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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 })
|
|
20
24
|
}
|
|
21
|
-
})
|
|
22
|
-
return function() {
|
|
23
|
-
unmount(modal, { outro: true })
|
|
24
25
|
}
|
|
25
26
|
})
|
|
27
|
+
return function() {
|
|
28
|
+
unmount(modal, { outro: true })
|
|
29
|
+
}
|
|
26
30
|
})
|
|
27
31
|
}
|
|
28
32
|
|
package/README.md
CHANGED
|
@@ -4,12 +4,25 @@ A collection of Svelte components for [Inertia X](https://github.com/buhrmi/iner
|
|
|
4
4
|
|
|
5
5
|
## Modal
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
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. Here you can see the included default style (dark.css), which renders as a bottom sheet on mobile, and centered on the page on desktop.
|
|
9
8
|
|
|
10
9
|

|
|
11
10
|
|
|
12
|
-
###
|
|
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
|
+
Inertia X UI also ships with a `modal` action. This is a small wrapper for `createModal` and passes the `href` attribute as the `src` prop.
|
|
13
26
|
|
|
14
27
|
```svelte
|
|
15
28
|
<script>
|
|
@@ -31,18 +44,27 @@ The Modal component passes a `close` function down to its page component as a pr
|
|
|
31
44
|
<button onclick={close}>Close</button>
|
|
32
45
|
```
|
|
33
46
|
|
|
47
|
+
Note that there is no `close` function on the modal instance itself as components aren't usually able to unmount themselves.
|
|
48
|
+
|
|
34
49
|
## Installation
|
|
35
50
|
|
|
36
|
-
To start using Inertia X UI, install the `inertiax-ui` package and import the CSS style you'd like to use.
|
|
51
|
+
To start using Inertia X UI, install the `inertiax-ui` package and import the CSS style you'd like to use.
|
|
52
|
+
|
|
53
|
+
### Styling
|
|
54
|
+
|
|
55
|
+
Inertia X UI ships with a default [dark.css](./dark.css) style that displays the modal as a bottom sheet.
|
|
37
56
|
|
|
38
57
|
```js
|
|
39
58
|
import 'inertiax-ui/dark.css'
|
|
40
59
|
```
|
|
41
60
|
|
|
42
|
-
For full control, you can of course bring your own CSS
|
|
61
|
+
For full styling control, you can of course bring your own CSS. The key classes to target are:
|
|
43
62
|
|
|
44
63
|
| Class | Element |
|
|
45
64
|
|-------|---------|
|
|
46
65
|
| `.inx-modal_wrapper` | Full-screen overlay container |
|
|
47
66
|
| `.inx-modal_bg` | Clickable backdrop |
|
|
48
|
-
| `.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/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { default as Modal } from './Modal.svelte';
|
|
1
|
+
export { default as Modal, modal, createModal } from './Modal.svelte';
|