element-plus/packages/hooks/use-transition/index.ts
jeremywu 425567ec3b
refactor(hooks): refactor transition (#2556)
* refactor(hooks): refactor transition

- Introduce new hook named useTransition
- Update transition.scss with css vars

* - Align variable name.

* - Update transitions to cssvars

* - Address PR comments
2021-07-18 20:08:58 +08:00

36 lines
810 B
TypeScript

import { computed, ref, watch, nextTick } from 'vue'
import type { ExtractPropTypes, Ref } from 'vue'
export const useTransitionProps = {
transitionDuration: {
type: Number,
default: 0.3,
},
transitionShow: String,
transitionHide: String,
}
export const useTransition = (
props: ExtractPropTypes<typeof useTransitionProps>,
indicator: Ref<boolean>,
) => {
const transitionState = ref(indicator.value)
watch(indicator, val => {
nextTick(() => transitionState.value = val)
})
return {
transition: computed(() => {
return `el-transition--${
transitionState.value
? props.transitionShow
: props.transitionHide
}`
}),
transitionStyle: computed(() =>
`--el-transition-duration: ${props.transitionDuration}s`,
),
}
}