-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Expand file tree
/
Copy pathpopup.svelte
More file actions
141 lines (127 loc) · 3.69 KB
/
popup.svelte
File metadata and controls
141 lines (127 loc) · 3.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<script>
import { createEventDispatcher, onMount, onDestroy } from 'svelte';
import { colorClasses } from '../shared/mixins.js';
import { classNames, createEmitter } from '../shared/utils.js';
import { restProps } from '../shared/rest-props.js';
import { app, f7ready } from '../shared/f7.js';
import { modalStateClasses } from '../shared/modal-state-classes.js';
const emit = createEmitter(createEventDispatcher, $$props);
let className = undefined;
export { className as class };
export let style = '';
export let tabletFullscreen = undefined;
export let opened = undefined;
export let animate = undefined;
export let backdrop = undefined;
export let backdropEl = undefined;
export let closeByBackdropClick = undefined;
export let closeOnEscape = undefined;
export let swipeToClose = undefined;
export let swipeHandler = undefined;
export let push = undefined;
export let containerEl = undefined;
let el;
let f7Popup;
const state = {
isOpened: opened,
isClosing: false,
};
export function instance() {
return f7Popup;
}
$: classes = classNames(
className,
'popup',
{
'popup-tablet-fullscreen': tabletFullscreen,
'popup-push': push,
},
modalStateClasses(state),
colorClasses($$props),
);
function onSwipeStart(instance) {
emit('popupSwipeStart', [instance]);
}
function onSwipeMove(instance) {
emit('popupSwipeMove', [instance]);
}
function onSwipeEnd(instance) {
emit('popupSwipeEnd', [instance]);
}
function onSwipeClose(instance) {
emit('popupSwipeClose', [instance]);
}
function onOpen(instance) {
Object.assign(state, {
isOpened: true,
isClosing: false,
});
emit('popupOpen', [instance]);
opened = true;
}
function onOpened(instance) {
emit('popupOpened', [instance]);
}
function onClose(instance) {
Object.assign(state, {
isOpened: false,
isClosing: true,
});
emit('popupClose', [instance]);
}
function onClosed(instance) {
Object.assign(state, {
isClosing: false,
});
emit('popupClosed', [instance]);
opened = false;
}
let initialWatched = false;
function watchOpened(openedPassed) {
if (!initialWatched) {
initialWatched = true;
return;
}
if (!f7Popup) return;
if (openedPassed) f7Popup.open();
else f7Popup.close();
}
$: watchOpened(opened);
onMount(() => {
const popupParams = {
el,
on: {
swipeStart: onSwipeStart,
swipeMove: onSwipeMove,
swipeEnd: onSwipeEnd,
swipeClose: onSwipeClose,
open: onOpen,
opened: onOpened,
close: onClose,
closed: onClosed,
},
};
if (typeof closeByBackdropClick !== 'undefined')
popupParams.closeByBackdropClick = closeByBackdropClick;
if (typeof closeOnEscape !== 'undefined') popupParams.closeOnEscape = closeOnEscape;
if (typeof animate !== 'undefined') popupParams.animate = animate;
if (typeof backdrop !== 'undefined') popupParams.backdrop = backdrop;
if (typeof backdropEl !== 'undefined') popupParams.backdropEl = backdropEl;
if (typeof swipeToClose !== 'undefined') popupParams.swipeToClose = swipeToClose;
if (typeof swipeHandler !== 'undefined') popupParams.swipeHandler = swipeHandler;
if (typeof containerEl !== 'undefined') popupParams.containerEl = containerEl;
f7ready(() => {
f7Popup = app.f7.popup.create(popupParams);
if (opened) {
f7Popup.open(false, true);
}
});
});
onDestroy(() => {
if (f7Popup) f7Popup.destroy();
f7Popup = null;
});
</script>
<div class={classes} bind:this={el} {style} {...restProps($$restProps)}>
<slot popup={f7Popup} />
</div>