element-plus/packages/hooks/use-transition/index.ts
三咲智子 55348b30b6
style: use prettier (#3228)
* style: use prettier

* style: just prettier format, no code changes

* style: eslint fix
object-shorthand, prefer-const

* style: fix no-void

* style: no-console
2021-09-04 19:29:28 +08:00

34 lines
793 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`
),
}
}