File tree 4 files changed +73
-0
lines changed
4 files changed +73
-0
lines changed Original file line number Diff line number Diff line change
1
+ .body {
2
+ position : absolute ;
3
+
4
+ bottom : 20% ;
5
+ left : 50% ;
6
+
7
+ background-color : rgba (0 , 0 , 0 , 0.8 );
8
+ color : #fff ;
9
+
10
+ font-size : 15px ;
11
+ padding : 8px 12px ;
12
+ border-radius : 4px ;
13
+
14
+ max-width : 50% ;
15
+ white-space : pre-line ;
16
+ }
Original file line number Diff line number Diff line change
1
+ import { defineComponent } from 'vue'
2
+ import { Popup } from '@0x30/vue-navigation-layout'
3
+ import styles from './index.module.scss'
4
+ import anime from 'animejs'
5
+
6
+ const Toast = defineComponent ( {
7
+ name : 'Toast' ,
8
+ props : {
9
+ title : String ,
10
+ className : String ,
11
+ } ,
12
+ setup : ( props ) => {
13
+ return ( ) => < div class = { props . className ?? styles . body } > { props . title } </ div >
14
+ } ,
15
+ } )
16
+
17
+ type ToastOptoions = {
18
+ duration ?: number
19
+ className ?: string
20
+ }
21
+
22
+ export const useToast = ( title : string , options ?: ToastOptoions ) => {
23
+ const [ show , close ] = Popup ( {
24
+ onEnter ( el , done ) {
25
+ anime . set ( el , { translateX : '-50%' } )
26
+ anime ( {
27
+ targets : el ,
28
+ opacity : [ 0 , 1 ] ,
29
+ scale : [ 0.8 , 1 ] ,
30
+ translateX : '-50%' ,
31
+ duration : 300 ,
32
+ easing : 'easeOutExpo' ,
33
+ complete : done ,
34
+ } )
35
+ } ,
36
+ onLeave ( el , done ) {
37
+ anime ( {
38
+ targets : el ,
39
+ opacity : [ 1 , 0 ] ,
40
+ duration : 300 ,
41
+ easing : 'easeInQuad' ,
42
+ complete : done ,
43
+ } )
44
+ } ,
45
+ } )
46
+ show ( < Toast title = { title } className = { options ?. className } /> )
47
+ window . setTimeout ( close , options ?. duration ?? 2000 )
48
+ }
Original file line number Diff line number Diff line change @@ -4,3 +4,4 @@ export * from './components/Safearea'
4
4
export { default as SidePage } from './components/SidePage'
5
5
export * from './components/Loading'
6
6
export * from './util/Popup'
7
+ export * from './components/Toast'
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import DetailPage from '../detail'
11
11
12
12
import styles from './index.module.scss'
13
13
import { useHooks , wait } from '../../util'
14
+ import { useToast } from '@0x30/vue-navigation-layout'
14
15
15
16
const Component = defineComponent ( {
16
17
name : 'HomePage' ,
@@ -68,6 +69,13 @@ const Component = defineComponent({
68
69
>
69
70
popup
70
71
</ button >
72
+ < button
73
+ onClick = { async ( ) => {
74
+ useToast ( `Hello world.` )
75
+ } }
76
+ >
77
+ toast
78
+ </ button >
71
79
</ div >
72
80
< br />
73
81
< span > SidePage</ span >
You can’t perform that action at this time.
0 commit comments