@empathyco/x-components
Version:
Empathy X Components
82 lines (59 loc) • 2.21 kB
Markdown
---
title: Fade
---
# Fade
Renders a transition wrapping the element passed in the default slot. The animation just fades
in/out the element by changing its opacity.
## Props
| Name | Description | Type | Default |
| ------------------- | ------------------------------------------------------------------------------ | -------------------- | ----------------- |
| <code>appear</code> | Indicates if the transition must be applied on the initial render of the node. | <code>boolean</code> | <code>true</code> |
## Slots
| Name | Description | Bindings<br />(name - type - description) |
| -------------------- | ------------------------------------------- | ----------------------------------------- |
| <code>default</code> | (Required) to add content to the transition | None |
## Examples
The `Fade` component is intended to be used as animation to wrap an element with `v-if` or `v-show` and animate it. The animation just fades in/out the element by changing its opacity.
### Basic usage with `v-if`
```vue live
<template>
<Fade>
<ComponentOrElement v-if="open" />
</Fade>
</template>
<script setup>
import { ref } from "vue";
import Fade from "@empathyco/x-components/js/components/animations/fade.vue";
const open = ref(false);
</script>
```
### Usage with `v-show`
```vue live
<template>
<Fade>
<ComponentOrElement v-show="open" />
</Fade>
</template>
<script setup>
import { ref } from "vue";
import Fade from "@empathyco/x-components/js/components/animations/fade.vue";
const open = ref(true);
</script>
```
### Example with dynamic content
```vue live
<template>
<div>
<button @click="open = !open">Toggle</button>
<Fade>
<div v-if="open" style="background: #eee;">Expanded content</div>
<div v-else style="background: #ccc;">Collapsed content</div>
</Fade>
</div>
</template>
<script setup>
import { ref } from "vue";
import Fade from "@empathyco/x-components/js/components/animations/fade.vue";
const open = ref(false);
</script>
```