返回 slidev
VClick.ts
根目录 / packages / client / builtin / VClick.ts
1 /**
2 * <v-click/> click animations component
3 *
4 * Learn more: https://sli.dev/guide/animations.html#click-animation
5 */
6
7 import type { RawAtValue } from '@slidev/types'
8 import type { PropType, VNode } from 'vue'
9 import { defineComponent, h, Text } from 'vue'
10 import { CLICKS_MAX } from '../constants'
11 import { VClickMount } from '../modules/v-click-mount'
12 import VClicks from './VClicks'
13
14 export default defineComponent({
15 props: {
16 at: {
17 type: [Number, String, Array, Boolean] as PropType<RawAtValue>,
18 default: '+1',
19 },
20 hide: {
21 type: Boolean,
22 default: false,
23 },
24 /**
25 * Mount the content when its click is reached and unmount it when it's hidden,
26 * instead of only toggling its visibility.
27 */
28 mount: {
29 type: Boolean,
30 default: false,
31 },
32 /**
33 * @deprecated use `animation` instead
34 */
35 fade: {
36 type: Boolean,
37 default: false,
38 },
39 animation: {
40 type: String,
41 default: undefined,
42 },
43 wrapText: {
44 type: Function as PropType<(text: VNode) => VNode>,
45 default: (text: VNode) => h('span', text),
46 },
47 },
48 render() {
49 if (this.mount) {
50 return h(
51 VClickMount,
52 {
53 at: this.at,
54 hide: this.hide,
55 animation: this.fade
56 ? `${this.animation ?? ''} fade`
57 : this.animation,
58 wrapText: this.wrapText,
59 },
60 {
61 default: () => this.$slots.default?.(),
62 },
63 )
64 }
65
66 return h(
67 VClicks,
68 {
69 every: CLICKS_MAX,
70 at: this.at as string | number,
71 hide: this.hide,
72 fade: this.fade,
73 animation: this.animation,
74 handleSpecialElements: false,
75 },
76 {
77 default: () =>
78 this.$slots.default?.().map(v =>
79 v.type === Text
80 ? this.wrapText(v)
81 : v,
82 ),
83 },
84 )
85 },
86 })
87
87 lines TYPESCRIPT