/
modal-action.svelte
114 lines (112 loc) · 2.64 KB
/
modal-action.svelte
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
<script>/** Transitions */
import { slide } from 'svelte/transition';
/** Icons */
import { mdiClose } from "@mdi/js";
/** Properties */
export let title = "";
let isShowing = false;
export const sheet = {
show() {
isShowing = true;
},
showWithData(data) {
isShowing = true;
},
hide() {
isShowing = false;
},
onKeyEvent(e) {
if (e.key === 'Escape') {
e.preventDefault();
sheet.hide();
}
}
};
</script>
<svelte:window on:keydown={sheet.onKeyEvent} />
{#if isShowing}
<div aria-modal="true" role="dialog"
class="option-sheet-backdrop"
on:click|self={sheet.hide}
on:keyup>
<div class="option-sheet centered-page small container dark" transition:slide>
<header class="option-sheet-header">
<h1>{title}</h1>
<button class="flat-button option-sheet-cancel" on:click={sheet.hide}>
<svg viewBox="0 0 24 24">
<path d="{mdiClose}" />
</svg>
</button>
</header>
<div class="option-sheet-content">
<slot></slot>
</div>
</div>
</div>
{/if}
<style>.option-sheet-backdrop {
position: absolute;
width: 100vw;
height: 100vh;
top: 0;
left: 0;
z-index: 100001;
display: flex;
flex-direction: column-reverse;
justify-content: flex-start;
}
.option-sheet-backdrop .option-sheet {
border-radius: 8px;
box-sizing: border-box;
max-height: calc(100vh - 64px);
max-width: calc(100vw - 32px);
width: max-content;
margin: 32px auto;
height: min-content;
padding: 8px;
box-shadow: 0 0 16px -8px black;
overflow: hidden;
}
.option-sheet-backdrop .option-sheet .option-sheet-header {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 8px;
/** font */
font-size: 16px;
font-weight: bold;
text-align: center;
line-height: 24px;
color: var(--pt-text);
}
.option-sheet-backdrop .option-sheet .option-sheet-header h1 {
flex-grow: 1;
margin-left: 40px;
}
.option-sheet-backdrop .option-sheet .option-sheet-header * {
color: inherit;
}
.option-sheet-backdrop .option-sheet .option-sheet-header .option-sheet-cancel {
width: 32px;
height: 32px;
padding: 4px;
border-radius: 50%;
border: none;
}
.option-sheet-backdrop .option-sheet .option-sheet-header .option-sheet-cancel:hover {
cursor: pointer;
}
.option-sheet-backdrop .option-sheet .option-sheet-header .option-sheet-cancel svg {
width: 24px;
height: 24px;
fill: var(--pt-text);
}
.option-sheet-backdrop .option-sheet .option-sheet-content {
max-height: calc(100vh - 48px - 56px);
box-sizing: border-box;
overflow-y: scroll;
display: flex;
justify-content: center;
gap: 8px;
flex-wrap: wrap;
}</style>