-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathPageControl.svelte
80 lines (70 loc) · 2.14 KB
/
PageControl.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
<script lang="ts" context="module">
import type { FastboardApp } from "@netless/fastboard-core";
import type { GenericIcon, I18nData, IconType, Language, Theme } from "../../typings";
const i18n: I18nData<"prev" | "next" | "add"> = {
en: {
prev: "Prev Page",
next: "Next Page",
add: "Add Page",
},
"zh-CN": {
prev: "上一页",
next: "下一页",
add: "添加页面",
},
};
</script>
<script lang="ts">
import Icon from "../Icon";
import Icons from "../Icons";
import Button from "../Button";
export let app: FastboardApp | null | undefined = null;
export let theme: Theme = "light";
export let language: Language = "en";
export let icons: GenericIcon<"prev" | "next" | "add"> | undefined = undefined;
const name = "fastboard-page-control";
$: writable = app?.writable;
$: phase = app?.phase;
$: disabled = !($writable && $phase === "connected");
$: t = i18n[language];
let type: IconType;
$: type = disabled ? "disable" : "normal";
$: index = app?.sceneIndex;
$: length = app?.sceneLength;
$: prev_disabled = disabled || !$index;
$: next_disabled = disabled || $length == null || $index === $length - 1;
function prevPage() {
app?.prevPage();
}
function nextPage() {
app?.nextPage();
}
function addPage() {
app?.addPage({ after: true });
app?.nextPage();
}
</script>
<div class="{name} {theme}">
<Button class="prev" {name} {theme} disabled={prev_disabled} on:click={prevPage} content={t.prev}>
<Icon src={icons?.prev[type]} alt="[prev]">
<Icons.Left {theme} />
</Icon>
</Button>
<span class="{name}-text {theme}">
{#if $index == null || $length == null}
…
{:else}
{$index + 1}/{$length}
{/if}
</span>
<Button class="next" {name} {theme} disabled={next_disabled} on:click={nextPage} content={t.next}>
<Icon src={icons?.next[type]} alt="[next]">
<Icons.Right {theme} />
</Icon>
</Button>
<Button class="add" {name} {theme} {disabled} on:click={addPage} content={t.add}>
<Icon src={icons?.add[type]} alt="[add]">
<Icons.WhiteboardAdd {theme} />
</Icon>
</Button>
</div>