| 1 | /** |
| 2 | * <v-after/> click animations component |
| 3 | * |
| 4 | * Learn more: https://sli.dev/guide/animations.html#click-animation |
| 5 | */ |
| 6 | |
| 7 | import type { Directive, VNode } from 'vue' |
| 8 | import { toArray } from '@antfu/utils' |
| 9 | import { defineComponent, h, resolveDirective, withDirectives } from 'vue' |
| 10 | import { VClickMount } from '../modules/v-click-mount' |
| 11 | |
| 12 | export default defineComponent({ |
| 13 | props: { |
| 14 | hide: { |
| 15 | type: Boolean, |
| 16 | default: false, |
| 17 | }, |
| 18 | /** |
| 19 | * Mount the content when the previous click is reached and unmount it when it's hidden, |
| 20 | * instead of only toggling its visibility. |
| 21 | */ |
| 22 | mount: { |
| 23 | type: Boolean, |
| 24 | default: false, |
| 25 | }, |
| 26 | }, |
| 27 | render() { |
| 28 | if (this.mount) { |
| 29 | return h( |
| 30 | VClickMount, |
| 31 | { |
| 32 | at: '+0', |
| 33 | hide: this.hide, |
| 34 | }, |
| 35 | { |
| 36 | default: () => this.$slots.default?.(), |
| 37 | }, |
| 38 | ) |
| 39 | } |
| 40 | |
| 41 | const after = resolveDirective('after')! |
| 42 | const modifiers = { hide: this.hide } |
| 43 | |
| 44 | function applyDirective(node: VNode, directive: Directive) { |
| 45 | return withDirectives(node, [ |
| 46 | [directive, undefined, '', modifiers], |
| 47 | ]) |
| 48 | } |
| 49 | |
| 50 | let defaults = this.$slots.default?.() |
| 51 | |
| 52 | if (!defaults) |
| 53 | return |
| 54 | |
| 55 | defaults = toArray(defaults) |
| 56 | |
| 57 | return defaults.map(i => applyDirective(h(i), after)) |
| 58 | }, |
| 59 | }) |
| 60 |