@sveltia/ui 0.2.0 → 0.2.2
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/package/components/composite/calendar.svelte +239 -0
- package/package/components/composite/calendar.svelte.d.ts +27 -0
- package/package/components/composite/checkbox-group.svelte +43 -0
- package/package/components/composite/checkbox-group.svelte.d.ts +34 -0
- package/package/components/composite/combobox.svelte +208 -0
- package/package/components/composite/combobox.svelte.d.ts +47 -0
- package/package/components/composite/disclosure.svelte +60 -0
- package/package/components/composite/disclosure.svelte.d.ts +35 -0
- package/package/components/composite/grid.svelte +24 -0
- package/package/components/composite/grid.svelte.d.ts +31 -0
- package/package/components/composite/listbox.svelte +63 -0
- package/package/components/composite/listbox.svelte.d.ts +52 -0
- package/package/components/composite/menu-item-group.svelte +31 -0
- package/package/components/composite/menu-item-group.svelte.d.ts +33 -0
- package/package/components/composite/menu.svelte +44 -0
- package/package/components/composite/menu.svelte.d.ts +41 -0
- package/package/components/composite/radio-button-group.svelte +45 -0
- package/package/components/composite/radio-button-group.svelte.d.ts +36 -0
- package/package/components/composite/select-button-group.svelte +71 -0
- package/package/components/composite/select-button-group.svelte.d.ts +44 -0
- package/package/components/composite/select.svelte +34 -0
- package/package/components/composite/select.svelte.d.ts +38 -0
- package/package/components/composite/tab-list.svelte +76 -0
- package/package/components/composite/tab-list.svelte.d.ts +55 -0
- package/package/components/core/button.svelte +222 -0
- package/package/components/core/button.svelte.d.ts +109 -0
- package/package/components/core/checkbox.svelte +114 -0
- package/package/components/core/checkbox.svelte.d.ts +45 -0
- package/package/components/core/dialog.svelte +288 -0
- package/package/components/core/dialog.svelte.d.ts +73 -0
- package/package/components/core/drawer.svelte +338 -0
- package/package/components/core/drawer.svelte.d.ts +59 -0
- package/package/components/core/grid-cell.svelte +14 -0
- package/package/components/core/grid-cell.svelte.d.ts +29 -0
- package/package/components/core/group.svelte +31 -0
- package/package/components/core/group.svelte.d.ts +33 -0
- package/package/components/core/icon.svelte +21 -0
- package/package/components/core/icon.svelte.d.ts +27 -0
- package/package/components/core/menu-button.svelte +57 -0
- package/package/components/core/menu-button.svelte.d.ts +46 -0
- package/package/components/core/menu-item-checkbox.svelte +24 -0
- package/package/components/core/menu-item-checkbox.svelte.d.ts +34 -0
- package/package/components/core/menu-item-radio.svelte +19 -0
- package/package/components/core/menu-item-radio.svelte.d.ts +34 -0
- package/package/components/core/menu-item.svelte +113 -0
- package/package/components/core/menu-item.svelte.d.ts +44 -0
- package/package/components/core/number-input.svelte +112 -0
- package/package/components/core/number-input.svelte.d.ts +42 -0
- package/package/components/core/option.svelte +65 -0
- package/package/components/core/option.svelte.d.ts +60 -0
- package/package/components/core/password-input.svelte +81 -0
- package/package/components/core/password-input.svelte.d.ts +36 -0
- package/package/components/core/radio-button.svelte +93 -0
- package/package/components/core/radio-button.svelte.d.ts +37 -0
- package/package/components/core/row-group.svelte +14 -0
- package/package/components/core/row-group.svelte.d.ts +29 -0
- package/package/components/core/row.svelte +14 -0
- package/package/components/core/row.svelte.d.ts +33 -0
- package/package/components/core/search-bar.svelte +91 -0
- package/package/components/core/search-bar.svelte.d.ts +49 -0
- package/package/components/core/select-button.svelte +31 -0
- package/package/components/core/select-button.svelte.d.ts +52 -0
- package/package/components/core/separator.svelte +28 -0
- package/package/components/core/separator.svelte.d.ts +26 -0
- package/package/components/core/slider.svelte +271 -0
- package/package/components/core/slider.svelte.d.ts +51 -0
- package/package/components/core/spacer.svelte +22 -0
- package/package/components/core/spacer.svelte.d.ts +25 -0
- package/package/components/core/switch.svelte +86 -0
- package/package/components/core/switch.svelte.d.ts +37 -0
- package/package/components/core/tab-panel.svelte +23 -0
- package/package/components/core/tab-panel.svelte.d.ts +33 -0
- package/package/components/core/tab.svelte +22 -0
- package/package/components/core/tab.svelte.d.ts +45 -0
- package/package/components/core/text-area.svelte +90 -0
- package/package/components/core/text-area.svelte.d.ts +57 -0
- package/package/components/core/text-input.svelte +146 -0
- package/package/components/core/text-input.svelte.d.ts +71 -0
- package/package/components/core/toolbar.svelte +74 -0
- package/package/components/core/toolbar.svelte.d.ts +35 -0
- package/package/components/editor/markdown.svelte +78 -0
- package/package/components/editor/markdown.svelte.d.ts +25 -0
- package/package/components/helpers/group.d.ts +37 -0
- package/package/components/helpers/group.js +246 -0
- package/package/components/helpers/popup.d.ts +31 -0
- package/package/components/helpers/popup.js +165 -0
- package/package/components/helpers/util.d.ts +1 -0
- package/package/components/helpers/util.js +8 -0
- package/package/components/util/app-shell.svelte +354 -0
- package/package/components/util/app-shell.svelte.d.ts +38 -0
- package/package/components/util/misc.d.ts +2 -0
- package/package/components/util/misc.js +22 -0
- package/package/components/util/popup.svelte +155 -0
- package/package/components/util/popup.svelte.d.ts +53 -0
- package/package/components/util/portal.svelte +34 -0
- package/package/components/util/portal.svelte.d.ts +28 -0
- package/package/index.d.ts +43 -0
- package/package/index.js +68 -0
- package/package/locales/en.d.ts +42 -0
- package/package/locales/en.js +41 -0
- package/package/locales/ja.d.ts +42 -0
- package/package/locales/ja.js +41 -0
- package/package/styles/core.scss +134 -0
- package/package/styles/variables.scss +184 -0
- package/package/typedef.d.ts +0 -0
- package/package/typedef.js +0 -0
- package/package.json +2 -3
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
@see https://w3c.github.io/aria/#dialog
|
|
4
|
+
@see https://w3c.github.io/aria-practices/#dialog_modal
|
|
5
|
+
-->
|
|
6
|
+
<script>
|
|
7
|
+
import { createEventDispatcher, onMount } from 'svelte';
|
|
8
|
+
import { _ } from 'svelte-i18n';
|
|
9
|
+
import Button from './button.svelte';
|
|
10
|
+
import Icon from './icon.svelte';
|
|
11
|
+
import Spacer from './spacer.svelte';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* CSS class name on the button.
|
|
15
|
+
* @type {String}
|
|
16
|
+
*/
|
|
17
|
+
let className = '';
|
|
18
|
+
|
|
19
|
+
export { className as class };
|
|
20
|
+
|
|
21
|
+
export let open = false;
|
|
22
|
+
|
|
23
|
+
export let title = '';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Width of the dialog.
|
|
27
|
+
* @type {('small'|'medium'|'large')}
|
|
28
|
+
*/
|
|
29
|
+
export let size = 'medium';
|
|
30
|
+
|
|
31
|
+
export let modal = true;
|
|
32
|
+
|
|
33
|
+
export let showCancel = true;
|
|
34
|
+
|
|
35
|
+
export let showOk = true;
|
|
36
|
+
|
|
37
|
+
export let showClose = false;
|
|
38
|
+
|
|
39
|
+
export let okLabel = '';
|
|
40
|
+
|
|
41
|
+
export let okDisabled = false;
|
|
42
|
+
|
|
43
|
+
export let cancelLabel = '';
|
|
44
|
+
|
|
45
|
+
export let cancelDisabled = false;
|
|
46
|
+
|
|
47
|
+
export let closeOnBackdropClick = false;
|
|
48
|
+
|
|
49
|
+
const dispatch = createEventDispatcher();
|
|
50
|
+
/** @type {?HTMLDialogElement} */
|
|
51
|
+
let dialog;
|
|
52
|
+
/** @type {?HTMLFormElement} */
|
|
53
|
+
let form;
|
|
54
|
+
let showDialog = false;
|
|
55
|
+
let showContent = false;
|
|
56
|
+
|
|
57
|
+
const openDialog = async () => {
|
|
58
|
+
(document.querySelector('.sui.app-shell') || document.body).appendChild(dialog);
|
|
59
|
+
showContent = true;
|
|
60
|
+
|
|
61
|
+
if (modal) {
|
|
62
|
+
dialog.showModal();
|
|
63
|
+
} else {
|
|
64
|
+
dialog.show();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
window.requestAnimationFrame(() => {
|
|
68
|
+
showDialog = true;
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const closeDialog = async () => {
|
|
73
|
+
showDialog = false;
|
|
74
|
+
|
|
75
|
+
if (dialog.returnValue === 'ok') {
|
|
76
|
+
dispatch('ok');
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (dialog.returnValue === 'cancel') {
|
|
80
|
+
dispatch('cancel');
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
dispatch('close', dialog.returnValue);
|
|
84
|
+
|
|
85
|
+
await new Promise((resolve) => {
|
|
86
|
+
form.addEventListener('transitionend', () => resolve(), { once: true });
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
showContent = false;
|
|
90
|
+
dialog?.close();
|
|
91
|
+
dialog?.remove();
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const toggleDialog = () => {
|
|
95
|
+
if (dialog) {
|
|
96
|
+
if (open) {
|
|
97
|
+
openDialog();
|
|
98
|
+
} else {
|
|
99
|
+
closeDialog();
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
// Call the function only when the `open` prop is changed
|
|
105
|
+
$: toggleDialog(open);
|
|
106
|
+
|
|
107
|
+
onMount(() => {
|
|
108
|
+
dialog.remove();
|
|
109
|
+
|
|
110
|
+
// onUnmount
|
|
111
|
+
return () => {
|
|
112
|
+
dialog?.close();
|
|
113
|
+
dialog?.remove();
|
|
114
|
+
};
|
|
115
|
+
});
|
|
116
|
+
</script>
|
|
117
|
+
|
|
118
|
+
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
|
119
|
+
<dialog
|
|
120
|
+
bind:this={dialog}
|
|
121
|
+
class="sui dialog {className} {size}"
|
|
122
|
+
class:open={showDialog}
|
|
123
|
+
on:click={({ target }) => {
|
|
124
|
+
if (closeOnBackdropClick && target?.matches('dialog')) {
|
|
125
|
+
dialog.returnValue = 'cancel';
|
|
126
|
+
open = false;
|
|
127
|
+
}
|
|
128
|
+
}}
|
|
129
|
+
on:cancel|preventDefault={() => {
|
|
130
|
+
// Cancelled with the Escape key
|
|
131
|
+
open = false;
|
|
132
|
+
}}
|
|
133
|
+
>
|
|
134
|
+
<form method="dialog" bind:this={form} on:submit|preventDefault>
|
|
135
|
+
{#if showContent}
|
|
136
|
+
{#if title || showClose || $$slots.header || $$slots['header-extra']}
|
|
137
|
+
<div class="header">
|
|
138
|
+
{#if $$slots.header}
|
|
139
|
+
<slot name="header" />
|
|
140
|
+
{:else}
|
|
141
|
+
<div class="title">
|
|
142
|
+
{title}
|
|
143
|
+
</div>
|
|
144
|
+
<Spacer flex={true} />
|
|
145
|
+
{#if $$slots['header-extra']}
|
|
146
|
+
<slot name="header-extra" />
|
|
147
|
+
{/if}
|
|
148
|
+
{#if showClose}
|
|
149
|
+
<Button
|
|
150
|
+
class="ghost iconic"
|
|
151
|
+
on:click={() => {
|
|
152
|
+
dialog.returnValue = 'close';
|
|
153
|
+
open = false;
|
|
154
|
+
}}
|
|
155
|
+
>
|
|
156
|
+
<Icon slot="start-icon" name="close" label={$_('_sui._.close')} />
|
|
157
|
+
</Button>
|
|
158
|
+
{/if}
|
|
159
|
+
{/if}
|
|
160
|
+
</div>
|
|
161
|
+
{/if}
|
|
162
|
+
<div class="main">
|
|
163
|
+
<slot />
|
|
164
|
+
</div>
|
|
165
|
+
{#if showOk || showCancel || $$slots.footer || $$slots['footer-extra']}
|
|
166
|
+
<div class="footer">
|
|
167
|
+
{#if $$slots.footer}
|
|
168
|
+
<slot name="footer" />
|
|
169
|
+
{:else}
|
|
170
|
+
{#if $$slots['footer-extra']}
|
|
171
|
+
<slot name="footer-extra" />
|
|
172
|
+
{/if}
|
|
173
|
+
<Spacer flex={true} />
|
|
174
|
+
{#if showOk}
|
|
175
|
+
<Button
|
|
176
|
+
class="primary"
|
|
177
|
+
label={okLabel || $_('_sui._.ok')}
|
|
178
|
+
disabled={okDisabled}
|
|
179
|
+
on:click={() => {
|
|
180
|
+
dialog.returnValue = 'ok';
|
|
181
|
+
open = false;
|
|
182
|
+
}}
|
|
183
|
+
/>
|
|
184
|
+
{/if}
|
|
185
|
+
{#if showCancel}
|
|
186
|
+
<Button
|
|
187
|
+
class="secondary"
|
|
188
|
+
label={cancelLabel || $_('_sui._.cancel')}
|
|
189
|
+
disabled={cancelDisabled}
|
|
190
|
+
on:click={() => {
|
|
191
|
+
dialog.returnValue = 'cancel';
|
|
192
|
+
open = false;
|
|
193
|
+
}}
|
|
194
|
+
/>
|
|
195
|
+
{/if}
|
|
196
|
+
{/if}
|
|
197
|
+
</div>
|
|
198
|
+
{/if}
|
|
199
|
+
{/if}
|
|
200
|
+
</form>
|
|
201
|
+
</dialog>
|
|
202
|
+
|
|
203
|
+
<style>dialog {
|
|
204
|
+
display: flex;
|
|
205
|
+
justify-content: center;
|
|
206
|
+
align-items: center;
|
|
207
|
+
outline: 0;
|
|
208
|
+
background-color: var(--popup-backdrop-color);
|
|
209
|
+
}
|
|
210
|
+
dialog.open form {
|
|
211
|
+
opacity: 1;
|
|
212
|
+
transform: scale(100%);
|
|
213
|
+
transition-duration: 100ms;
|
|
214
|
+
}
|
|
215
|
+
dialog:not(.open) {
|
|
216
|
+
pointer-events: none !important;
|
|
217
|
+
}
|
|
218
|
+
dialog:not(.open) form {
|
|
219
|
+
opacity: 0;
|
|
220
|
+
transform: scale(90%);
|
|
221
|
+
pointer-events: none;
|
|
222
|
+
transition-duration: 200ms;
|
|
223
|
+
}
|
|
224
|
+
dialog:not(.open) :global(*) {
|
|
225
|
+
pointer-events: none !important;
|
|
226
|
+
}
|
|
227
|
+
dialog :global(a),
|
|
228
|
+
dialog :global(input),
|
|
229
|
+
dialog :global(textarea),
|
|
230
|
+
dialog :global(button),
|
|
231
|
+
dialog :global([tabindex="0"]) {
|
|
232
|
+
pointer-events: all;
|
|
233
|
+
}
|
|
234
|
+
dialog form {
|
|
235
|
+
display: flex;
|
|
236
|
+
flex-direction: column;
|
|
237
|
+
border-radius: 4px;
|
|
238
|
+
background-color: var(--secondary-background-color-translucent);
|
|
239
|
+
backdrop-filter: blur(16px);
|
|
240
|
+
box-shadow: 0 8px 16px var(--popup-shadow-color);
|
|
241
|
+
will-change: opacity, transform;
|
|
242
|
+
transition-property: opacity, transform;
|
|
243
|
+
}
|
|
244
|
+
dialog.small form {
|
|
245
|
+
width: 400px;
|
|
246
|
+
max-height: 400px;
|
|
247
|
+
}
|
|
248
|
+
dialog.medium form {
|
|
249
|
+
width: 600px;
|
|
250
|
+
max-height: 600px;
|
|
251
|
+
}
|
|
252
|
+
dialog.large form {
|
|
253
|
+
width: 800px;
|
|
254
|
+
max-height: 800px;
|
|
255
|
+
}
|
|
256
|
+
dialog.x-large form {
|
|
257
|
+
width: 1000px;
|
|
258
|
+
max-height: 1000px;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
.header,
|
|
262
|
+
.footer {
|
|
263
|
+
display: flex;
|
|
264
|
+
align-items: center;
|
|
265
|
+
gap: 8px;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
.header {
|
|
269
|
+
box-sizing: content-box;
|
|
270
|
+
margin: 0 16px;
|
|
271
|
+
border-width: 0 0 1px;
|
|
272
|
+
border-color: var(--secondary-border-color);
|
|
273
|
+
padding: 16px 8px;
|
|
274
|
+
height: 32px;
|
|
275
|
+
}
|
|
276
|
+
.header .title {
|
|
277
|
+
font-size: var(--font-size--large);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
.footer {
|
|
281
|
+
margin: 0 24px 24px;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
.main {
|
|
285
|
+
overflow: auto;
|
|
286
|
+
margin: 24px 24px;
|
|
287
|
+
white-space: normal;
|
|
288
|
+
}</style>
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/** @typedef {typeof __propDef.props} DialogProps */
|
|
2
|
+
/** @typedef {typeof __propDef.events} DialogEvents */
|
|
3
|
+
/** @typedef {typeof __propDef.slots} DialogSlots */
|
|
4
|
+
/**
|
|
5
|
+
* @see https://w3c.github.io/aria/#dialog
|
|
6
|
+
* @see https://w3c.github.io/aria-practices/#dialog_modal
|
|
7
|
+
*/
|
|
8
|
+
export default class Dialog extends SvelteComponentTyped<{
|
|
9
|
+
title?: string;
|
|
10
|
+
open?: boolean;
|
|
11
|
+
class?: string;
|
|
12
|
+
size?: "small" | "medium" | "large";
|
|
13
|
+
modal?: boolean;
|
|
14
|
+
showCancel?: boolean;
|
|
15
|
+
showOk?: boolean;
|
|
16
|
+
showClose?: boolean;
|
|
17
|
+
okLabel?: string;
|
|
18
|
+
okDisabled?: boolean;
|
|
19
|
+
cancelLabel?: string;
|
|
20
|
+
cancelDisabled?: boolean;
|
|
21
|
+
closeOnBackdropClick?: boolean;
|
|
22
|
+
}, {
|
|
23
|
+
submit: SubmitEvent;
|
|
24
|
+
ok: CustomEvent<any>;
|
|
25
|
+
cancel: CustomEvent<any>;
|
|
26
|
+
close: CustomEvent<any>;
|
|
27
|
+
} & {
|
|
28
|
+
[evt: string]: CustomEvent<any>;
|
|
29
|
+
}, {
|
|
30
|
+
header: {};
|
|
31
|
+
'header-extra': {};
|
|
32
|
+
default: {};
|
|
33
|
+
footer: {};
|
|
34
|
+
'footer-extra': {};
|
|
35
|
+
}> {
|
|
36
|
+
}
|
|
37
|
+
export type DialogProps = typeof __propDef.props;
|
|
38
|
+
export type DialogEvents = typeof __propDef.events;
|
|
39
|
+
export type DialogSlots = typeof __propDef.slots;
|
|
40
|
+
import { SvelteComponentTyped } from "svelte";
|
|
41
|
+
declare const __propDef: {
|
|
42
|
+
props: {
|
|
43
|
+
title?: string;
|
|
44
|
+
open?: boolean;
|
|
45
|
+
class?: string;
|
|
46
|
+
size?: ('small' | 'medium' | 'large');
|
|
47
|
+
modal?: boolean;
|
|
48
|
+
showCancel?: boolean;
|
|
49
|
+
showOk?: boolean;
|
|
50
|
+
showClose?: boolean;
|
|
51
|
+
okLabel?: string;
|
|
52
|
+
okDisabled?: boolean;
|
|
53
|
+
cancelLabel?: string;
|
|
54
|
+
cancelDisabled?: boolean;
|
|
55
|
+
closeOnBackdropClick?: boolean;
|
|
56
|
+
};
|
|
57
|
+
events: {
|
|
58
|
+
submit: SubmitEvent;
|
|
59
|
+
ok: CustomEvent<any>;
|
|
60
|
+
cancel: CustomEvent<any>;
|
|
61
|
+
close: CustomEvent<any>;
|
|
62
|
+
} & {
|
|
63
|
+
[evt: string]: CustomEvent<any>;
|
|
64
|
+
};
|
|
65
|
+
slots: {
|
|
66
|
+
header: {};
|
|
67
|
+
'header-extra': {};
|
|
68
|
+
default: {};
|
|
69
|
+
footer: {};
|
|
70
|
+
'footer-extra': {};
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
export {};
|
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
@see https://w3c.github.io/aria/#dialog
|
|
4
|
+
@see https://w3c.github.io/aria-practices/#dialog_modal
|
|
5
|
+
-->
|
|
6
|
+
<script>
|
|
7
|
+
import { createEventDispatcher, onMount } from 'svelte';
|
|
8
|
+
import { _ } from 'svelte-i18n';
|
|
9
|
+
import Button from './button.svelte';
|
|
10
|
+
import Icon from './icon.svelte';
|
|
11
|
+
import Spacer from './spacer.svelte';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* CSS class name on the button.
|
|
15
|
+
* @type {String}
|
|
16
|
+
*/
|
|
17
|
+
let className = '';
|
|
18
|
+
|
|
19
|
+
export { className as class };
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Whether to open the drawer.
|
|
23
|
+
*/
|
|
24
|
+
export let open = false;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Title text displayed on the header.
|
|
28
|
+
*/
|
|
29
|
+
export let title = '';
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Position of the drawer.
|
|
33
|
+
* @type {('top'|'right'|'bottom'|'left')}
|
|
34
|
+
*/
|
|
35
|
+
export let position = 'right';
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Width or height of the drawer.
|
|
39
|
+
* @type {('small'|'medium'|'large'|'x-large')}
|
|
40
|
+
*/
|
|
41
|
+
export let size = 'small';
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Whether to show the Close button.
|
|
45
|
+
* @type {('inside'|'outside'|false)}
|
|
46
|
+
*/
|
|
47
|
+
export let showClose = 'outside';
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Whether to close the drawer when the backdrop (outside of the drawer) is clicked.
|
|
51
|
+
*/
|
|
52
|
+
export let closeOnBackdropClick = false;
|
|
53
|
+
|
|
54
|
+
const dispatch = createEventDispatcher();
|
|
55
|
+
/** @type {?HTMLDialogElement} */
|
|
56
|
+
let dialog;
|
|
57
|
+
/** @type {?HTMLFormElement} */
|
|
58
|
+
let form;
|
|
59
|
+
let showDialog = false;
|
|
60
|
+
let showContent = false;
|
|
61
|
+
|
|
62
|
+
$: orientation = position === 'right' || position === 'left' ? 'vertical' : 'horizontal';
|
|
63
|
+
|
|
64
|
+
const openDialog = async () => {
|
|
65
|
+
(document.querySelector('.sui.app-shell') || document.body).appendChild(dialog);
|
|
66
|
+
showContent = true;
|
|
67
|
+
dialog.showModal();
|
|
68
|
+
|
|
69
|
+
window.requestAnimationFrame(() => {
|
|
70
|
+
showDialog = true;
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const closeDialog = async () => {
|
|
75
|
+
showDialog = false;
|
|
76
|
+
|
|
77
|
+
if (dialog.returnValue === 'ok') {
|
|
78
|
+
dispatch('ok');
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (dialog.returnValue === 'cancel') {
|
|
82
|
+
dispatch('cancel');
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
dispatch('close', dialog.returnValue);
|
|
86
|
+
|
|
87
|
+
await new Promise((resolve) => {
|
|
88
|
+
form.addEventListener('transitionend', () => resolve(), { once: true });
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
showContent = false;
|
|
92
|
+
dialog?.close();
|
|
93
|
+
dialog?.remove();
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const toggleDialog = () => {
|
|
97
|
+
if (dialog) {
|
|
98
|
+
if (open) {
|
|
99
|
+
openDialog();
|
|
100
|
+
} else {
|
|
101
|
+
closeDialog();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
// Call the function only when the `open` prop is changed
|
|
107
|
+
$: toggleDialog(open);
|
|
108
|
+
|
|
109
|
+
onMount(() => {
|
|
110
|
+
dialog.remove();
|
|
111
|
+
|
|
112
|
+
// onUnmount
|
|
113
|
+
return () => {
|
|
114
|
+
dialog?.close();
|
|
115
|
+
dialog?.remove();
|
|
116
|
+
};
|
|
117
|
+
});
|
|
118
|
+
</script>
|
|
119
|
+
|
|
120
|
+
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
|
121
|
+
<dialog
|
|
122
|
+
bind:this={dialog}
|
|
123
|
+
class="sui dialog {className} {size} {position} {orientation}"
|
|
124
|
+
class:open={showDialog}
|
|
125
|
+
on:click={({ target }) => {
|
|
126
|
+
if (closeOnBackdropClick && target?.matches('dialog')) {
|
|
127
|
+
dialog.returnValue = 'cancel';
|
|
128
|
+
open = false;
|
|
129
|
+
}
|
|
130
|
+
}}
|
|
131
|
+
on:cancel|preventDefault={() => {
|
|
132
|
+
// Cancelled with the Escape key
|
|
133
|
+
open = false;
|
|
134
|
+
}}
|
|
135
|
+
>
|
|
136
|
+
<form method="dialog" bind:this={form} on:submit|preventDefault>
|
|
137
|
+
<div class="extra-control">
|
|
138
|
+
{#if showClose === 'outside'}
|
|
139
|
+
<Button
|
|
140
|
+
class="ghost iconic close"
|
|
141
|
+
on:click={() => {
|
|
142
|
+
dialog.returnValue = 'close';
|
|
143
|
+
open = false;
|
|
144
|
+
}}
|
|
145
|
+
>
|
|
146
|
+
<Icon slot="start-icon" name="close" label={$_('_sui._.close')} />
|
|
147
|
+
</Button>
|
|
148
|
+
{/if}
|
|
149
|
+
</div>
|
|
150
|
+
{#if showContent}
|
|
151
|
+
{#if title || showClose === 'inside' || $$slots.header || $$slots['header-extra']}
|
|
152
|
+
<div class="header">
|
|
153
|
+
{#if $$slots.header}
|
|
154
|
+
<slot name="header" />
|
|
155
|
+
{:else}
|
|
156
|
+
<div class="title">
|
|
157
|
+
{title}
|
|
158
|
+
</div>
|
|
159
|
+
<Spacer flex={true} />
|
|
160
|
+
{#if $$slots['header-extra']}
|
|
161
|
+
<slot name="header-extra" />
|
|
162
|
+
{/if}
|
|
163
|
+
{#if showClose === 'inside'}
|
|
164
|
+
<Button
|
|
165
|
+
class="ghost iconic close"
|
|
166
|
+
on:click={() => {
|
|
167
|
+
dialog.returnValue = 'close';
|
|
168
|
+
open = false;
|
|
169
|
+
}}
|
|
170
|
+
>
|
|
171
|
+
<Icon slot="start-icon" name="close" label={$_('_sui._.close')} />
|
|
172
|
+
</Button>
|
|
173
|
+
{/if}
|
|
174
|
+
{/if}
|
|
175
|
+
</div>
|
|
176
|
+
{/if}
|
|
177
|
+
<div class="main">
|
|
178
|
+
<slot />
|
|
179
|
+
</div>
|
|
180
|
+
{#if $$slots.footer}
|
|
181
|
+
<div class="footer">
|
|
182
|
+
<slot name="footer" />
|
|
183
|
+
</div>
|
|
184
|
+
{/if}
|
|
185
|
+
{/if}
|
|
186
|
+
</form>
|
|
187
|
+
</dialog>
|
|
188
|
+
|
|
189
|
+
<style>dialog {
|
|
190
|
+
overflow: hidden;
|
|
191
|
+
outline: 0;
|
|
192
|
+
background-color: var(--popup-backdrop-color);
|
|
193
|
+
}
|
|
194
|
+
dialog.open form {
|
|
195
|
+
opacity: 1;
|
|
196
|
+
transform: translateX(0%);
|
|
197
|
+
transition-duration: 100ms;
|
|
198
|
+
}
|
|
199
|
+
dialog:not(.open) {
|
|
200
|
+
pointer-events: none !important;
|
|
201
|
+
}
|
|
202
|
+
dialog:not(.open) form {
|
|
203
|
+
opacity: 0;
|
|
204
|
+
transform: translateX(105%);
|
|
205
|
+
pointer-events: none;
|
|
206
|
+
transition-duration: 200ms;
|
|
207
|
+
}
|
|
208
|
+
dialog:not(.open) :global(*) {
|
|
209
|
+
pointer-events: none !important;
|
|
210
|
+
}
|
|
211
|
+
dialog :global(a),
|
|
212
|
+
dialog :global(input),
|
|
213
|
+
dialog :global(textarea),
|
|
214
|
+
dialog :global(button),
|
|
215
|
+
dialog :global([tabindex="0"]) {
|
|
216
|
+
pointer-events: all;
|
|
217
|
+
}
|
|
218
|
+
dialog form {
|
|
219
|
+
position: absolute;
|
|
220
|
+
display: flex;
|
|
221
|
+
flex-direction: column;
|
|
222
|
+
border-radius: 4px;
|
|
223
|
+
background-color: var(--secondary-background-color-translucent);
|
|
224
|
+
backdrop-filter: blur(16px);
|
|
225
|
+
box-shadow: 0 8px 16px var(--popup-shadow-color);
|
|
226
|
+
will-change: opacity, transform;
|
|
227
|
+
transition-property: opacity, transform;
|
|
228
|
+
}
|
|
229
|
+
dialog form .extra-control {
|
|
230
|
+
position: absolute;
|
|
231
|
+
}
|
|
232
|
+
dialog form .extra-control :global(button.close) {
|
|
233
|
+
margin: 8px;
|
|
234
|
+
}
|
|
235
|
+
dialog.right form {
|
|
236
|
+
inset: 0 0 0 auto;
|
|
237
|
+
}
|
|
238
|
+
dialog.right form .extra-control {
|
|
239
|
+
inset: 0 100% auto auto;
|
|
240
|
+
}
|
|
241
|
+
dialog.right:not(.open) form {
|
|
242
|
+
transform: translateX(105%);
|
|
243
|
+
}
|
|
244
|
+
dialog.left form {
|
|
245
|
+
inset: 0 auto 0 0;
|
|
246
|
+
}
|
|
247
|
+
dialog.left form .extra-control {
|
|
248
|
+
inset: 0 auto auto 100%;
|
|
249
|
+
}
|
|
250
|
+
dialog.left:not(.open) form {
|
|
251
|
+
transform: translateX(-105%);
|
|
252
|
+
}
|
|
253
|
+
dialog.vertical {
|
|
254
|
+
height: 100%;
|
|
255
|
+
max-width: 100vw;
|
|
256
|
+
}
|
|
257
|
+
dialog.vertical.open form {
|
|
258
|
+
transform: translateX(0%);
|
|
259
|
+
}
|
|
260
|
+
dialog.vertical.small form {
|
|
261
|
+
width: 400px;
|
|
262
|
+
}
|
|
263
|
+
dialog.vertical.medium form {
|
|
264
|
+
width: 600px;
|
|
265
|
+
}
|
|
266
|
+
dialog.vertical.large form {
|
|
267
|
+
width: 800px;
|
|
268
|
+
}
|
|
269
|
+
dialog.vertical.x-large form {
|
|
270
|
+
width: 1000px;
|
|
271
|
+
}
|
|
272
|
+
dialog.top form {
|
|
273
|
+
inset: 0 0 auto 0;
|
|
274
|
+
}
|
|
275
|
+
dialog.top form .extra-control {
|
|
276
|
+
inset: 100% 0 auto auto;
|
|
277
|
+
}
|
|
278
|
+
dialog.top:not(.open) form {
|
|
279
|
+
transform: translateY(-105%);
|
|
280
|
+
}
|
|
281
|
+
dialog.bottom form {
|
|
282
|
+
inset: auto 0 0 0;
|
|
283
|
+
}
|
|
284
|
+
dialog.bottom form .extra-control {
|
|
285
|
+
inset: auto 0 100% auto;
|
|
286
|
+
}
|
|
287
|
+
dialog.bottom:not(.open) form {
|
|
288
|
+
transform: translateY(105%);
|
|
289
|
+
}
|
|
290
|
+
dialog.horizontal {
|
|
291
|
+
width: 100%;
|
|
292
|
+
max-height: 100vh;
|
|
293
|
+
}
|
|
294
|
+
dialog.horizontal.open form {
|
|
295
|
+
transform: translateY(0%);
|
|
296
|
+
}
|
|
297
|
+
dialog.horizontal.small form {
|
|
298
|
+
height: 400px;
|
|
299
|
+
}
|
|
300
|
+
dialog.horizontal.medium form {
|
|
301
|
+
height: 600px;
|
|
302
|
+
}
|
|
303
|
+
dialog.horizontal.large form {
|
|
304
|
+
height: 800px;
|
|
305
|
+
}
|
|
306
|
+
dialog.horizontal.x-large form {
|
|
307
|
+
height: 1000px;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
.header,
|
|
311
|
+
.footer {
|
|
312
|
+
display: flex;
|
|
313
|
+
align-items: center;
|
|
314
|
+
gap: 8px;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
.header {
|
|
318
|
+
box-sizing: content-box;
|
|
319
|
+
margin: 0 16px;
|
|
320
|
+
border-width: 0 0 1px;
|
|
321
|
+
border-color: var(--secondary-border-color);
|
|
322
|
+
padding: 16px 8px;
|
|
323
|
+
height: 32px;
|
|
324
|
+
}
|
|
325
|
+
.header .title {
|
|
326
|
+
font-size: var(--font-size--large);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
.footer {
|
|
330
|
+
margin: 0 24px 24px;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
.main {
|
|
334
|
+
flex: auto;
|
|
335
|
+
overflow: auto;
|
|
336
|
+
margin: 24px 24px;
|
|
337
|
+
white-space: normal;
|
|
338
|
+
}</style>
|