-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodal_choose.svelte
52 lines (42 loc) · 1.31 KB
/
modal_choose.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
<svelte:options accessors/>
<script>
// Simple modal dialog that presents the user with some options.
//
// Also used for the busy dialog (where the user can't close the dialog until an async operation is done.
// In this scenario, use the UpdateModal(msg) function to give progress updates and call CloseModal when the operation
// is complete.
import Modal from './firesite/modal.svelte';
// text to show the user above the buttons
export let text = 'Proceed with this action?';
// list of buttons and value to send to the callback when clicked
// each must have at least a .label member
export let buttons = [{label:'Ok'}, {label:'Cancel'}];
export let allowCancel = true;
// returned to the caller
export let choice = null;
// used during async operations to give progress updates - called by UpdateModal
export function Update(newMsg)
{
text = newMsg;
}
function Go(value)
{
choice = value;
CloseModal(MODAL_OK);
}
function OnClose(withCode)
{
return allowCancel || withCode == MODAL_OK;
}
</script>
<Modal close={OnClose}>
<h2>Stuff</h2>
<content>
<p>{@html text}</p>
<hbox>
{#each buttons as b, i}
<button class="{b.label == 'Cancel' ? 'red' : 'blue'}" on:click="{() => Go(b)}">{b.label}</button>
{/each}
</hbox>
</content>
</Modal>