Skip to content

Commit c82fc85

Browse files
authored
feat(transition): expose create transition classes (#21352)
1 parent 21acdff commit c82fc85

File tree

4 files changed

+133
-16
lines changed

4 files changed

+133
-16
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<template>
2+
<v-container>
3+
<v-row justify="center" style="min-height: 160px;">
4+
<v-col class="text-center">
5+
<v-btn
6+
color="primary"
7+
@click="show = !show"
8+
>
9+
Component Transition
10+
</v-btn>
11+
12+
<ComponentTransition>
13+
<v-card
14+
v-show="show"
15+
class="mx-auto mt-5"
16+
color="secondary"
17+
height="100"
18+
width="100"
19+
></v-card>
20+
</ComponentTransition>
21+
</v-col>
22+
</v-row>
23+
</v-container>
24+
</template>
25+
26+
<script setup>
27+
import { ref } from 'vue'
28+
import { createCssTransition } from 'vuetify/components/transitions'
29+
30+
const ComponentTransition = createCssTransition('component-transition')
31+
32+
const show = ref(false)
33+
</script>
34+
35+
<style lang="scss">
36+
.component-transition {
37+
&-enter-active,
38+
&-leave-active {
39+
transition: 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
40+
}
41+
42+
&-enter-from,
43+
&-leave-to {
44+
opacity: 0;
45+
transform: rotate(180deg) scale(0.2) skew(20deg);
46+
filter: hue-rotate(90deg);
47+
}
48+
}
49+
</style>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<template>
2+
<v-container>
3+
<v-row justify="center">
4+
<v-col class="text-center">
5+
<v-menu transition="custom-prop-transition">
6+
<template v-slot:activator="{ props }">
7+
<v-btn
8+
color="primary"
9+
v-bind="props"
10+
>
11+
Prop Transition
12+
</v-btn>
13+
</template>
14+
15+
<v-list>
16+
<v-list-item
17+
v-for="n in 5"
18+
:key="n"
19+
>
20+
<v-list-item-title>
21+
Item {{ n }}
22+
</v-list-item-title>
23+
</v-list-item>
24+
</v-list>
25+
</v-menu>
26+
</v-col>
27+
</v-row>
28+
</v-container>
29+
</template>
30+
31+
<script setup>
32+
import { createCssTransition } from 'vuetify/components/transitions'
33+
34+
createCssTransition('custom-prop-transition')
35+
</script>
36+
37+
<style lang="scss">
38+
.custom-prop-transition {
39+
&-enter-active,
40+
&-leave-active {
41+
transition: 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
42+
transform-origin: top center;
43+
}
44+
45+
&-enter-from,
46+
&-leave-to {
47+
opacity: 0;
48+
transform: scaleY(0) rotateX(-60deg);
49+
transform-origin: top center;
50+
filter: saturate(2) hue-rotate(90deg);
51+
}
52+
}
53+
</style>

packages/docs/src/pages/en/styles/transitions.md

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -108,30 +108,43 @@ Using multiple custom transitions, it is easy to bring a simple todo list to lif
108108

109109
<ExamplesExample file="transitions/misc-todo" />
110110

111-
<!--
112111
## Create your own
113112

114-
You can use Vuetify's transition helper function to easily create your own custom transitions. This function will return an object that you can import into Vue. Using Vue's [functional component](https://vuejs.org/v2/guide/render-function.html#Functional-Components) option will make sure your transition is as efficient as possible. Simply import the function:
113+
You can use Vuetify's transition helper function to easily create your own custom transitions.
115114

116115
```js
117-
import { createSimpleTransition } from 'vuetify/components/transitions/createTransition'
116+
import { createCssTransition } from 'vuetify/components/transitions';
118117

119-
const myTransition = createSimpleTransition('my-transition')
118+
createCssTransition('my-transition')
119+
```
120120

121-
Vue.component('my-transition', myTransition)
121+
The argument passed to the **createCssTransition** function will be the name of the transition that you can hook into your style. This is an example of what `my-transition` looks like:
122+
123+
```scss
124+
.my-transition {
125+
&-enter-active,
126+
&-leave-active {
127+
position: absolute;
128+
transition: 1s;
129+
}
130+
131+
&-enter-from,
132+
&-leave-to {
133+
opacity: 0;
134+
}
135+
}
122136
```
123137

124-
The **createSimpleTransition** function accepts 1 argument, name. This will be the name that you can hook into with your style. This is an example of what `v-fade-transition` looks like:
138+
You can now use this custom transition in a few different ways.
125139

126-
```stylus
127-
.fade-transition
128-
&-leave-active
129-
position: absolute
140+
### As a component
130141

131-
&-enter-active, &-leave, &-leave-to
132-
transition: $primary-transition
142+
The **createCssTransition** function will return a component that you can use in your template.
133143

134-
&-enter, &-leave-to
135-
opacity: 0
136-
```
137-
-->
144+
<ExamplesExample file="transitions/create-css-transition-component" />
145+
146+
### As a prop
147+
148+
Many of Vuetify’s components contain a **transition** prop. You can send the name of your custom transition to the transition prop.
149+
150+
<ExamplesExample file="transitions/create-css-transition-prop" />

packages/vuetify/src/components/transitions/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,5 @@ export type VSlideYTransition = InstanceType<typeof VSlideYTransition>
4343
export type VSlideYReverseTransition = InstanceType<typeof VSlideYReverseTransition>
4444
export type VExpandTransition = InstanceType<typeof VExpandTransition>
4545
export type VExpandXTransition = InstanceType<typeof VExpandXTransition>
46+
47+
export { createCssTransition, createJavascriptTransition }

0 commit comments

Comments
 (0)