Skip to content

Commit

Permalink
feat(collapse): 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 b09b168 commit e3ab2bb
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/collapse/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
export { collapseProps, default as NCollapse } from './src/Collapse'
export type { CollapseProps } from './src/Collapse'
export type { CollapseProps, CollapseSlots } from './src/Collapse'
export { collapseItemProps, default as NCollapseItem } from './src/CollapseItem'
export type { CollapseItemProps } from './src/CollapseItem'
export type { CollapseItemProps, CollapseItemSlots } from './src/CollapseItem'
export type {
CollapseArrowSlotOptions,
CollapseItemArrowSlotOptions,
CollapseItemHeaderExtraSlotOptions,
CollapseItemHeaderSlotOptions
} from './src/interface'
10 changes: 9 additions & 1 deletion src/collapse/src/Collapse.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { ThemeProps } from '../../_mixins'
import type { ExtractPublicPropTypes, MaybeArray } from '../../_utils'
import type {
CollapseArrowSlotOptions,
HeaderClickInfo,
OnItemHeaderClick,
OnItemHeaderClickImpl,
Expand All @@ -18,7 +19,8 @@ import {
provide,
type Ref,
ref,
type Slots
type Slots,
type SlotsType
} from 'vue'
import { useConfig, useTheme, useThemeClass } from '../../_mixins'
import { useRtl } from '../../_mixins/use-rtl'
Expand Down Expand Up @@ -82,6 +84,11 @@ export const collapseProps = {

export type CollapseProps = ExtractPublicPropTypes<typeof collapseProps>

export interface CollapseSlots {
default?: any
arrow?: (props: CollapseArrowSlotOptions) => any
}

export interface NCollapseInjection {
props: ExtractPropTypes<typeof collapseProps>
expandedNamesRef: Ref<string | number | Array<string | number> | null>
Expand All @@ -100,6 +107,7 @@ export const collapseInjectionKey
export default defineComponent({
name: 'Collapse',
props: collapseProps,
slots: Object as SlotsType<CollapseSlots>,
setup(props, { slots }) {
const { mergedClsPrefixRef, inlineThemeDisabled, mergedRtlRef }
= useConfig(props)
Expand Down
12 changes: 12 additions & 0 deletions src/collapse/src/CollapseItem.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import type { ExtractPublicPropTypes } from '../../_utils'
import type {
CollapseItemArrowSlotOptions,
CollapseItemHeaderExtraSlotOptions,
CollapseItemHeaderSlotOptions
} from './interface'
import { createId, happensIn } from 'seemly'
import { useMemo } from 'vooks'
import { computed, defineComponent, h, inject, type PropType, toRef } from 'vue'
Expand Down Expand Up @@ -26,6 +31,13 @@ export const collapseItemProps = {

export type CollapseItemProps = ExtractPublicPropTypes<typeof collapseItemProps>

export interface CollapseItemSlots {
default?: any
header?: (props: CollapseItemHeaderSlotOptions) => any
'header-extra'?: (props: CollapseItemHeaderExtraSlotOptions) => any
arrow?: (props: CollapseItemArrowSlotOptions) => any
}

export default defineComponent({
name: 'CollapseItem',
props: collapseItemProps,
Expand Down
16 changes: 16 additions & 0 deletions src/collapse/src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,19 @@ export interface HeaderClickInfo<T> {
expanded: boolean
event: MouseEvent
}

export interface CollapseArrowSlotOptions {
collapsed: boolean
}

export interface CollapseItemHeaderSlotOptions {
collapsed: boolean
}

export interface CollapseItemHeaderExtraSlotOptions {
collapsed: boolean
}

export interface CollapseItemArrowSlotOptions {
collapsed: boolean
}

0 comments on commit e3ab2bb

Please sign in to comment.