This repository has been archived by the owner on Sep 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 83
/
Copy pathExample.svelte
91 lines (83 loc) · 2.18 KB
/
Example.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
<script context="module">
import { theme } from '@/util/stores';
import links from '@/util/links';
import Prism from 'prismjs';
</script>
<script>
import { slide } from 'svelte/transition';
import { Icon, Button } from 'svelte-materialify/src';
export let file = '';
export let style = null;
let component;
let code;
import(
/* webpackChunkName: "examples" */
/* webpackMode: "lazy-once" */
`../../examples/${file}.svelte`
).then(({ default: data }) => {
component = data;
});
import(
/* webpackChunkName: "examples-source" */
/* webpackMode: "lazy-once" */
`!raw-loader!../../examples/${file}.svelte`
).then(({ default: data }) => {
code = Prism.highlight(data, Prism.languages.html, 'html');
});
$: colorInvertable = $theme === 'light';
let codeVisible = false;
let codeThemeDark = false;
</script>
<style>
.example {
margin-bottom: 36px;
border-radius: 4px;
border: thin solid var(--theme-dividers);
}
.example-toolbar {
border-bottom: thin solid var(--theme-dividers);
}
</style>
<svelte:options immutable={true} />
<div class="example">
<div class="example-toolbar text-right pa-1">
{#if colorInvertable}
<Button
fab
icon
size="small"
aria-label="invert color"
on:click={() => (codeThemeDark = !codeThemeDark)}>
<Icon class="mdi mdi-invert-colors" />
</Button>
{/if}
<a
href="{links.docs}/src/examples/{file}.svelte"
aria-label="GitHub"
rel="noopener noreferrer"
target="_blank">
<Button fab icon size="small" aria-label="GitHub" class="text--primary">
<Icon class="mdi mdi-github" />
</Button>
</a>
<Button
fab
icon
size="small"
aria-label="Show Code"
on:click={() => (codeVisible = !codeVisible)}>
<Icon class="mdi mdi-code-tags" />
</Button>
</div>
{#if codeVisible}
<pre transition:slide={{ duration: 250 }} class="language-html ma-0">
<code
class="language-html">
{@html code}
</code>
</pre>
{/if}
<div class="pa-2" class:theme--dark={codeThemeDark} {style}>
<svelte:component this={component} />
</div>
</div>