Skip to content

Commit

Permalink
feat(carousel): add slots type (tusen-ai#6599)
Browse files Browse the repository at this point in the history
  • Loading branch information
nailiable committed Dec 7, 2024
1 parent afcb2dc commit 14b2a52
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/carousel/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
export { carouselProps, default as NCarousel } from './src/Carousel'
export type { CarouselProps } from './src/Carousel'
export type { CarouselProps, CarouselSlots } from './src/Carousel'
export { default as NCarouselItem } from './src/CarouselItem'
export type { CarouselInst } from './src/interface'
export type {
CarouselArrowSlotOptions,
CarouselDotSlotOptions,
CarouselInst
} from './src/interface'
18 changes: 17 additions & 1 deletion src/carousel/src/Carousel.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
import type { CSSProperties, PropType, Ref, TransitionProps, VNode } from 'vue'
import type {
CSSProperties,
PropType,
Ref,
SlotsType,
TransitionProps,
VNode
} from 'vue'
import type { ThemeProps } from '../../_mixins'
import type { ExtractPublicPropTypes } from '../../_utils'
import type { CarouselTheme } from '../styles'
import type {
ArrowScopedSlotProps,
CarouselArrowSlotOptions,
CarouselDotSlotOptions,
CarouselInst,
DotScopedSlotProps,
Size
Expand Down Expand Up @@ -139,12 +148,19 @@ export const carouselProps = {

export type CarouselProps = ExtractPublicPropTypes<typeof carouselProps>

export interface CarouselSlots {
default?: () => any
arrow?: (info: CarouselArrowSlotOptions) => any
dots?: (info: CarouselDotSlotOptions) => any
}

// only one carousel is allowed to trigger touch globally
let globalDragging = false

export default defineComponent({
name: 'Carousel',
props: carouselProps,
slots: Object as SlotsType<CarouselSlots>,
setup(props) {
const { mergedClsPrefixRef, inlineThemeDisabled } = useConfig(props)
// Dom
Expand Down
14 changes: 14 additions & 0 deletions src/carousel/src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,17 @@ export interface Size {
width: number
height: number
}

export interface CarouselArrowSlotOptions {
total: number
currentIndex: number
to: (index: number) => void
prev: () => void
next: () => void
}

export interface CarouselDotSlotOptions {
total: number
currentIndex: number
to: (index: number) => void
}

0 comments on commit 14b2a52

Please sign in to comment.