From e3ab2bba8dc2a1fdc420666c72bc308ea4f4f678 Mon Sep 17 00:00:00 2001 From: Naily Date: Sat, 7 Dec 2024 22:22:14 +0800 Subject: [PATCH] feat(collapse): add slots type (#6599) --- src/collapse/index.ts | 10 ++++++++-- src/collapse/src/Collapse.tsx | 10 +++++++++- src/collapse/src/CollapseItem.tsx | 12 ++++++++++++ src/collapse/src/interface.ts | 16 ++++++++++++++++ 4 files changed, 45 insertions(+), 3 deletions(-) diff --git a/src/collapse/index.ts b/src/collapse/index.ts index 5897ca13679..97afb1d046d 100644 --- a/src/collapse/index.ts +++ b/src/collapse/index.ts @@ -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' diff --git a/src/collapse/src/Collapse.tsx b/src/collapse/src/Collapse.tsx index 56b4fa5a3df..951fd26f48e 100644 --- a/src/collapse/src/Collapse.tsx +++ b/src/collapse/src/Collapse.tsx @@ -1,6 +1,7 @@ import type { ThemeProps } from '../../_mixins' import type { ExtractPublicPropTypes, MaybeArray } from '../../_utils' import type { + CollapseArrowSlotOptions, HeaderClickInfo, OnItemHeaderClick, OnItemHeaderClickImpl, @@ -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' @@ -82,6 +84,11 @@ export const collapseProps = { export type CollapseProps = ExtractPublicPropTypes +export interface CollapseSlots { + default?: any + arrow?: (props: CollapseArrowSlotOptions) => any +} + export interface NCollapseInjection { props: ExtractPropTypes expandedNamesRef: Ref | null> @@ -100,6 +107,7 @@ export const collapseInjectionKey export default defineComponent({ name: 'Collapse', props: collapseProps, + slots: Object as SlotsType, setup(props, { slots }) { const { mergedClsPrefixRef, inlineThemeDisabled, mergedRtlRef } = useConfig(props) diff --git a/src/collapse/src/CollapseItem.tsx b/src/collapse/src/CollapseItem.tsx index 2b9e51f9221..5d629e5d81a 100644 --- a/src/collapse/src/CollapseItem.tsx +++ b/src/collapse/src/CollapseItem.tsx @@ -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' @@ -26,6 +31,13 @@ export const collapseItemProps = { export type CollapseItemProps = ExtractPublicPropTypes +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, diff --git a/src/collapse/src/interface.ts b/src/collapse/src/interface.ts index 7fe3765d773..87cb6c1d5db 100644 --- a/src/collapse/src/interface.ts +++ b/src/collapse/src/interface.ts @@ -36,3 +36,19 @@ export interface HeaderClickInfo { expanded: boolean event: MouseEvent } + +export interface CollapseArrowSlotOptions { + collapsed: boolean +} + +export interface CollapseItemHeaderSlotOptions { + collapsed: boolean +} + +export interface CollapseItemHeaderExtraSlotOptions { + collapsed: boolean +} + +export interface CollapseItemArrowSlotOptions { + collapsed: boolean +}