element-plus/packages/tokens/carousel.ts
JeremyWuuuuu 6b74660a20
chore(components): [el-carousel] code style refactor (#6693)
* chore(components): [el-carousel] code style refactor

- Remove duplicated code
- Simplified the code for components

* Wrap resize handle into shallowRef

* Export CourouselItemState type

* Enhance itemInStage method

* Refine code
2022-03-17 22:20:25 +08:00

35 lines
900 B
TypeScript

import type { InjectionKey, Ref } from 'vue'
import type { CarouselItemProps } from '@element-plus/components/carousel'
export type CarouselItemStates = {
hover: boolean
translate: number
scale: number
active: boolean
ready: boolean
inStage: boolean
animating: boolean
}
export type CarouselItemContext = {
props: CarouselItemProps
states: CarouselItemStates
uid: number | undefined
translateItem: (index: number, activeIndex: number, oldIndex?: number) => void
}
export type CarouselContext = {
root: Ref<HTMLElement | undefined>
items: Ref<CarouselItemContext[]>
isCardType: Ref<boolean>
isVertical: Ref<boolean>
loop: boolean
addItem: (item: CarouselItemContext) => void
removeItem: (uid: number | undefined) => void
setActiveItem: (index: number) => void
}
export const carouselContextKey: InjectionKey<CarouselContext> =
Symbol('carouselContextKey')