File tree Expand file tree Collapse file tree 3 files changed +65
-3
lines changed Expand file tree Collapse file tree 3 files changed +65
-3
lines changed Original file line number Diff line number Diff line change 1
1
<template >
2
- <div class =' min-w-screen min-h-screen flex flex-col p-5' >
2
+ <div class =" min-w-screen min-h-screen flex flex-col p-5" >
3
3
<slot />
4
4
</div >
5
5
</template >
Original file line number Diff line number Diff line change
1
+ <template >
2
+ <div
3
+ v-if =" state.show"
4
+ v-bind:class =" {
5
+ 'bg-black text-white': !state.error && !state.success,
6
+ 'bg-green-500 text-white': state.success,
7
+ 'bg-red-500 text-white': state.error,
8
+ }"
9
+ class =" fixed top-2 right-2 shadow-xl border w-60 px-5 py-4 rounded-md z-20"
10
+ >
11
+ {{ state.message }}
12
+ </div >
13
+ </template >
14
+
15
+ <script setup>
16
+ import { reactive } from " vue" ;
17
+
18
+ const state = reactive ({
19
+ message: " " ,
20
+ show: false ,
21
+ success: false ,
22
+ error: false ,
23
+ });
24
+
25
+ function createToast (message , options = { delay: 2500 }) {
26
+ state .message = message;
27
+ state .show = true ;
28
+ setTimeout (() => {
29
+ state .show = false ;
30
+ }, options .delay );
31
+ }
32
+
33
+ function createSuccessToast (message , options ) {
34
+ state .success = true ;
35
+ state .error = false ;
36
+ createToast (message, options);
37
+ }
38
+
39
+ function createErrorToast (message , options ) {
40
+ state .success = false ;
41
+ state .error = true ;
42
+ createToast (message, options);
43
+ }
44
+
45
+ defineExpose ({
46
+ createToast,
47
+ createSuccessToast,
48
+ createErrorToast,
49
+ });
50
+ </script >
51
+
52
+
53
+ <style scoped>
54
+ @tailwind base;
55
+ @tailwind components;
56
+ @tailwind utilities;
57
+ </style >
Original file line number Diff line number Diff line change 1
1
<template >
2
2
<BaseLayout >
3
+ <Toast ref =" toastRef" />
3
4
<h1
4
5
class ="
5
6
mb-12
@@ -60,11 +61,14 @@ import MenuItem from "../components/menu-item.vue";
60
61
import Editor from " ../components/editor.vue" ;
61
62
import Button from " ../components/button.vue" ;
62
63
import Preview from " ../components/preview.vue" ;
64
+ import Toast from " ../components/toast.vue" ;
63
65
import { copy } from " ../lib/copy" ;
64
66
import { defaultMarkdownText } from " ../resources/default-md" ;
65
- import { reactive , onMounted , onUnmounted } from " vue" ;
67
+ import { reactive , onMounted , ref , onUnmounted } from " vue" ;
66
68
import marked from " marked" ;
67
69
70
+ const toastRef = ref (null );
71
+
68
72
const state = reactive ({ code: defaultMarkdownText, showPreview: false });
69
73
70
74
onMounted (() => {
@@ -97,11 +101,12 @@ function handleChange(code) {
97
101
}
98
102
99
103
async function handleCopyAsHTML () {
100
- if (! value ) {
104
+ if (! state . code ) {
101
105
return ;
102
106
}
103
107
const htmlValue = marked (state .code );
104
108
await copy (htmlValue);
109
+ toastRef .value .createSuccessToast (" Copied!" );
105
110
}
106
111
107
112
function handlePreviewToggle () {
You can’t perform that action at this time.
0 commit comments