Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add basic transition #964

Draft
wants to merge 2 commits into
base: d20
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
156 changes: 156 additions & 0 deletions packages/veui-theme-dls/components/transition.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
@import "../lib.less";

.@{veui-prefix}-transition {
// 渐现 fade-in
&-fade-in-enter-active {
transition-duration: 200ms;
transition-property: opacity;
transition-timing-function: linear;
}

&-fade-in-enter {
opacity: 0;
}

// 放大渐现 scale-fade-in
&-scale-fade-in-enter-active {
transition-duration: 200ms;
transition-property: opacity, transform;
transition-timing-function: linear;
}

&-scale-fade-in-enter {
opacity: 0;
transform: scale3d(0, 0, 1);
}

// 移入 slide-in
&-slide-in-enter-active {
transition-property: transform;
transition-duration: 200ms;
transition-timing-function: ease-out;
}

&-slide-in-enter {
transform: translate3d(
var(--dls-transition-translate-from-x, 0),
var(--dls-transition-translate-from-y, 0),
0
);
}

// 渐现移入 slide-fade-in
&-slide-fade-in-enter-active {
transition-property: opacity, transform;
transition-duration: 200ms;
transition-timing-function: linear;
}

&-slide-fade-in-enter {
opacity: 0;
transform: translate3d(
var(--dls-transition-translate-from-x, 0),
var(--dls-transition-translate-from-y, 0),
0
);
}

// 渐变移入 slide-scale-fade-in
&-slide-scale-fade-in-enter-active {
transition-property: opacity, transform;
transition-duration: 200ms;
transition-timing-function: linear;
}

&-slide-scale-fade-in-enter {
opacity: 0;
transform: translate3d(
var(--dls-transition-translate-from-x, 0),
var(--dls-transition-translate-from-y, 0),
0
)
scale3d(0, 0, 1);
}

// 移动 move
&-move {
transition-property: transform;
transition-duration: 200ms;
transform: translate3d(
var(--dls-transition-translate-x, 0),
var(--dls-transition-translate-y, 0),
0
);
}

// 渐隐 fade-out
&-fade-out-leave-active {
transition-duration: 100ms;
transition-property: opacity;
transition-timing-function: linear;
}

&-fade-out-leave-to {
opacity: 0;
}

// 缩小渐隐 scale-fade-out
&-scale-fade-out-leave-active {
transition-duration: 100ms;
transition-property: opacity, transform;
transition-timing-function: linear;
}

&-scale-fade-out-leave-to {
opacity: 0;
transform: scale3d(0, 0, 1);
}

// 移出 slide-out
&-slide-out-leave-active {
transition-duration: 100ms;
transition-property: transform;
transition-timing-function: ease-in;
}

&-slide-out-leave-to {
transform: translate3d(
var(--dls-transition-translate-to-x, 0),
var(--dls-transition-translate-to-y, 0),
0
);
}

// 渐隐移出 slide-fade-out
&-slide-fade-out-leave-active {
transition-duration: 100ms;
transition-property: opacity, transform;
transition-timing-function: ease-in;
}

&-slide-fade-out-leave-to {
opacity: 0;
transform: translate3d(
var(--dls-transition-translate-to-x, 0),
var(--dls-transition-translate-to-y, 0),
0
);
}

// 渐变移出 slide-scale-fade-out
&-slide-scale-fade-out-leave-active {
transition-duration: 100ms;
transition-property: opacity, transform;
transition-timing-function: ease-in;
}

&-slide-scale-fade-out-leave-to {
opacity: 0;
transform: translate3d(
var(--dls-transition-translate-to-x, 0),
var(--dls-transition-translate-to-y, 0),
0
)
scale3d(0, 0, 1);
}
}
1 change: 1 addition & 0 deletions packages/veui-theme-dls/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,5 @@ import './components/time-picker.less'
import './components/toast.less'
import './components/toast-list.less'
import './components/transfer.less'
import './components/transition.less'
import './components/uploader.less'
10 changes: 7 additions & 3 deletions packages/veui/components.json
Original file line number Diff line number Diff line change
Expand Up @@ -249,15 +249,15 @@
},
{
"name": "Form",
"path": "Form/Form.vue"
"path": "Form"
},
{
"name": "Form",
"path": "Form"
"path": "Form/index.js"
},
{
"name": "Form",
"path": "Form/index.js"
"path": "Form/Form.vue"
},
{
"name": "GridColumn",
Expand Down Expand Up @@ -455,6 +455,10 @@
"name": "Transfer",
"path": "Transfer/index.js"
},
{
"name": "Transition",
"path": "Transition.vue"
},
{
"name": "Uploader",
"path": "Uploader/Uploader.vue"
Expand Down
164 changes: 164 additions & 0 deletions packages/veui/demo/cases/Transition.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
<template>
<article class="veui-transition-demo">
<h1><code>&lt;veui-transition&gt;</code></h1>
<section
v-for="({ name, effect, style }, idx) in transitions"
:key="idx"
>
<veui-button @click="handleClick(effect)">{{ name }}</veui-button>
<veui-transition
:name="effect"
appear
:style="
effect !== 'move'
? style
: {
'--dls-transition-translate-x': `${50 * count}px`,
'--dls-transition-translate-y': '0px'
}
"
@after-leave="afterOut(effect)"
>
<div
v-if="trigger[effect]"
class="content"
/>
</veui-transition>
</section>
</article>
</template>

<script>
import { Transition, Button } from 'veui'

const transitions = [
{
name: '渐现',
effect: 'fade-in'
},
{
name: '放大渐现',
effect: 'scale-fade-in'
},
{
name: '移入',
effect: 'slide-in',
style: {
'--dls-transition-translate-from-x': '250px', // ?
'--dls-transition-translate-from-y': '0px'
}
},
{
name: '渐现移入',
effect: 'slide-fade-in',
style: {
'--dls-transition-translate-from-x': '250px',
'--dls-transition-translate-from-y': '0px'
}
},
{
name: '渐变移入',
effect: 'slide-scale-fade-in',
style: {
'--dls-transition-translate-from-x': '250px',
'--dls-transition-translate-from-y': '-250px'
}
},
{
name: '移动',
effect: 'move'
},
{
name: '渐隐',
effect: 'fade-out'
},
{
name: '缩小渐隐',
effect: 'scale-fade-out'
},
{
name: '移出',
effect: 'slide-out',
style: {
'--dls-transition-translate-to-x': '250px',
'--dls-transition-translate-to-y': '0px'
}
},
{
name: '渐隐移出',
effect: 'slide-fade-out',
style: {
'--dls-transition-translate-to-x': '250px',
'--dls-transition-translate-to-y': '0px'
}
},
{
name: '渐变移出',
effect: 'slide-scale-fade-out',
style: {
'--dls-transition-translate-to-x': '250px',
'--dls-transition-translate-to-y': '-250px'
}
}
]

export default {
name: 'demo-transition',
components: {
'veui-transition': Transition,
'veui-button': Button
},
data () {
return {
transitions,
count: 0,
trigger: transitions.reduce((acc, { effect }) => {
acc[effect] = true
return acc
}, {})
}
},
methods: {
afterOut (effect) {
if (effect.includes('out')) {
setTimeout(() => {
this.trigger[effect] = true
}, 600)
}
},
handleClick (effect) {
if (effect === 'move') {
this.count++
this.count %= 4
return
}

if (effect.includes('in')) {
this.trigger[effect] = false
this.$nextTick(() => {
this.trigger[effect] = true
})
} else if (effect.includes('out')) {
this.trigger[effect] = false
}
}
}
}
</script>

<style lang="less" scoped>
section {
height: 150px;
display: flex;
align-items: center;
}

.content {
background-color: royalblue;
border-radius: 5%;
width: 60px;
height: 60px;
margin-right: 600px;
margin-left: auto;
}
</style>
6 changes: 6 additions & 0 deletions packages/veui/demo/cases/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import Plugins from './Plugins'
import Cascader from './Cascader'
import ConfigProvider from './ConfigProvider'
import Layout from './Layout'
import Transition from './Transition'

export default [
{
Expand All @@ -75,6 +76,11 @@ export default [
name: 'Alert',
component: Alert
},
{
path: '/transition',
name: 'Transition',
component: Transition
},
{
path: '/alert-box',
name: 'AlertBox',
Expand Down
Loading