Skip to content

Commit 5bf584d

Browse files
feat: add slots typing for all components (#6603)
* feat(alert): add slots type (#6599) * feat(auto-complete): add slots type (#6599) * fix(auto-complete): slots type (#6599) * feat(auto-complete): export slots type (#6599) * feat(avatar): add slots type (#6599) * feat(avatar-group): add slots type (#6599), may not be particularly precise * feat(breadcrumb-item): add slots type (#6599) * feat(breadcrumb-item): export slots type (#6599) * feat(button): add slots type (#6599) * feat(calendar): add slots type (#6599) * feat(card): add slots type (#6599) * feat(carousel): add slots type (#6599) * feat(cascader): add slots type (#6599) * feat(collapse): add slots type (#6599) * feat(color-picker): add slots type (#6599) * feat(data-table): add slots type (#6599) * feat(date-picker): add slots type (#6599) * feat(descriptions): add slots type (#6599) * feat(dialog): add slots type (#6599) * feat(drawer-content): add slots type (#6599) * feat(dynamic-input): add slots type (#6599) * feat(dynamic-tags): add slots type (#6599) * feat(ellipsis): add slots type (#6599) * feat(empty): add slots type (#6599) * feat(float-button): add slots type (#6599) * feat(image): add slots type (#6599) * feat(input): add slots type (#6599) * feat(input-number): add slots type (#6599) * feat(list): add slots type (#6599) * feat(mention): add slots type (#6599) * feat(modal): add slots type (#6599) * feat(page-header): add slots type (#6599) * feat(pagination): add slots type (#6599) * feat(popconfirm): add slots type (#6599) * feat(popover): add slots type (#6599) * feat(popselect): add slots type (#6599) * feat(result): add slots type (#6599) * feat(select): add slots type (#6599) * feat(slider): add slots type (#6599) * feat(spin): add slots type (#6599) * feat(split): add slots type (#6599) * feat(statistic): add slots type (#6599) * feat(step): add slots type (#6599) * feat(switch): add slots type (#6599) * feat(tabs): add slots type (#6599) * feat(tag): add slots type (#6599) * feat(thing): add slots type (#6599) * feat(time-picker): add slots type (#6599) * feat(time-picker): export slots type (#6599) * feat(timeline): export slots type (#6599) * feat(tooltip): export slots type (#6599) * feat(tree): export slots type (#6599) * feat(tree-select): export slots type (#6599) * feat(upload-trigger): export slots type (#6599) --------- Co-authored-by: Naily <[email protected]>
1 parent 8bd232c commit 5bf584d

File tree

113 files changed

+705
-72
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+705
-72
lines changed

src/alert/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
export { alertProps, default as NAlert } from './src/Alert'
2-
export type { AlertProps } from './src/Alert'
2+
export type { AlertProps, AlertSlots } from './src/Alert'

src/alert/src/Alert.tsx

+8
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
mergeProps,
1111
type PropType,
1212
ref,
13+
type SlotsType,
1314
watchEffect
1415
} from 'vue'
1516
import { NBaseClose, NBaseIcon, NFadeInExpandTransition } from '../../_internal'
@@ -56,10 +57,17 @@ export const alertProps = {
5657

5758
export type AlertProps = ExtractPublicPropTypes<typeof alertProps>
5859

60+
export interface AlertSlots {
61+
default?: any
62+
icon?: any
63+
header?: any
64+
}
65+
5966
export default defineComponent({
6067
name: 'Alert',
6168
inheritAttrs: false,
6269
props: alertProps,
70+
slots: Object as SlotsType<AlertSlots>,
6371
setup(props) {
6472
if (__DEV__) {
6573
watchEffect(() => {

src/auto-complete/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export { autoCompleteProps, default as NAutoComplete } from './src/AutoComplete'
2-
export type { AutoCompleteProps } from './src/AutoComplete'
2+
export type { AutoCompleteProps, AutoCompleteSlots } from './src/AutoComplete'
33
export type {
4+
AutoCompleteDefaultSlotOptions,
45
AutoCompleteGroupOption,
56
AutoCompleteInst,
67
AutoCompleteOption

src/auto-complete/src/AutoComplete.tsx

+11-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type {
1212
} from '../../select/src/interface'
1313
import type { AutoCompleteTheme } from '../styles'
1414
import type {
15+
AutoCompleteDefaultSlotOptions,
1516
AutoCompleteInst,
1617
AutoCompleteOption,
1718
AutoCompleteOptions,
@@ -33,6 +34,7 @@ import {
3334
type InputHTMLAttributes,
3435
type PropType,
3536
ref,
37+
type SlotsType,
3638
toRef,
3739
Transition,
3840
watchEffect,
@@ -114,9 +116,17 @@ export const autoCompleteProps = {
114116

115117
export type AutoCompleteProps = ExtractPublicPropTypes<typeof autoCompleteProps>
116118

119+
export interface AutoCompleteSlots {
120+
default?: (options: AutoCompleteDefaultSlotOptions) => any
121+
empty?: any
122+
prefix?: any
123+
suffix?: any
124+
}
125+
117126
export default defineComponent({
118127
name: 'AutoComplete',
119128
props: autoCompleteProps,
129+
slots: Object as SlotsType<AutoCompleteSlots>,
120130
setup(props) {
121131
if (__DEV__) {
122132
watchEffect(() => {
@@ -368,7 +378,7 @@ export default defineComponent({
368378
handleFocus: this.handleFocus,
369379
handleBlur: this.handleBlur,
370380
value: this.mergedValue
371-
})
381+
} as AutoCompleteDefaultSlotOptions)
372382
}
373383
const { mergedTheme } = this
374384
return (

src/auto-complete/src/interface.ts

+8
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,11 @@ export interface AutoCompleteInst {
2222
focus: () => void
2323
blur: () => void
2424
}
25+
26+
export interface AutoCompleteDefaultSlotOptions {
27+
handleInput: (value: string) => void
28+
handleFocus: (e: FocusEvent) => void
29+
handleBlur: (e: FocusEvent) => void
30+
value: string
31+
theme: string | null
32+
}

src/avatar-group/index.ts

+4
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
export { avatarGroupProps, default as NAvatarGroup } from './src/AvatarGroup'
22
export type { AvatarGroupOption, AvatarGroupProps } from './src/AvatarGroup'
3+
export type {
4+
AvatarGroupAvatarSlotOptions,
5+
AvatarGroupRestSlotOptions
6+
} from './src/interface'

src/avatar-group/src/AvatarGroup.tsx

+13-1
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@ import type { ThemeProps } from '../../_mixins'
22
import type { ExtractPublicPropTypes } from '../../_utils'
33
import type { Size } from '../../avatar/src/interface'
44
import type { AvatarGroupTheme } from '../styles'
5+
import type {
6+
AvatarGroupAvatarSlotOptions,
7+
AvatarGroupRestSlotOptions
8+
} from './interface'
59
import {
610
computed,
711
type CSSProperties,
812
defineComponent,
913
h,
1014
type PropType,
11-
provide
15+
provide,
16+
type SlotsType
1217
} from 'vue'
1318
import { useConfig, useTheme } from '../../_mixins'
1419
import { useRtl } from '../../_mixins/use-rtl'
@@ -40,9 +45,16 @@ export const avatarGroupProps = {
4045

4146
export type AvatarGroupProps = ExtractPublicPropTypes<typeof avatarGroupProps>
4247

48+
export interface AvatarGroupSlots {
49+
avatar?: (info: AvatarGroupAvatarSlotOptions) => any
50+
rest?: (info: AvatarGroupRestSlotOptions) => any
51+
default?: any
52+
}
53+
4354
export default defineComponent({
4455
name: 'AvatarGroup',
4556
props: avatarGroupProps,
57+
slots: Object as SlotsType<AvatarGroupSlots>,
4658
setup(props) {
4759
const { mergedClsPrefixRef, mergedRtlRef } = useConfig(props)
4860
const mergedThemeRef = useTheme(

src/avatar-group/src/interface.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export interface AvatarGroupAvatarSlotOptions {
2+
option: Record<string, any>
3+
}
4+
5+
export interface AvatarGroupRestSlotOptions {
6+
options: Array<any>
7+
rest: number
8+
}

src/avatar/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
export { avatarProps, default as NAvatar } from './src/Avatar'
2-
export type { AvatarProps } from './src/Avatar'
2+
export type { AvatarProps, AvatarSlots } from './src/Avatar'

src/avatar/src/Avatar.tsx

+8
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
onMounted,
1313
type PropType,
1414
ref,
15+
type SlotsType,
1516
type VNodeChild,
1617
watch,
1718
watchEffect
@@ -65,9 +66,16 @@ export const avatarProps = {
6566

6667
export type AvatarProps = ExtractPublicPropTypes<typeof avatarProps>
6768

69+
export interface AvatarSlots {
70+
default: any
71+
placeholder: any
72+
fallback: any
73+
}
74+
6875
export default defineComponent({
6976
name: 'Avatar',
7077
props: avatarProps,
78+
slots: Object as SlotsType<AvatarSlots>,
7179
setup(props) {
7280
const { mergedClsPrefixRef, inlineThemeDisabled } = useConfig(props)
7381
const hasLoadErrorRef = ref(false)

src/breadcrumb/index.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@ export {
44
breadcrumbItemProps,
55
default as NBreadcrumbItem
66
} from './src/BreadcrumbItem'
7-
export type { BreadcrumbItemProps } from './src/BreadcrumbItem'
7+
export type {
8+
BreadcrumbItemProps,
9+
BreadcrumbItemSlots
10+
} from './src/BreadcrumbItem'

src/breadcrumb/src/BreadcrumbItem.tsx

+8-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import {
44
type ExtractPropTypes,
55
h,
66
inject,
7-
type PropType
7+
type PropType,
8+
type SlotsType
89
} from 'vue'
910
import { resolveSlot, warn } from '../../_utils'
1011
import { useBrowserLocation } from '../../_utils/composable/use-browser-location'
@@ -24,9 +25,15 @@ export type BreadcrumbItemProps = Partial<
2425
ExtractPropTypes<typeof breadcrumbItemProps>
2526
>
2627

28+
export interface BreadcrumbItemSlots {
29+
default?: any
30+
separator?: any
31+
}
32+
2733
export default defineComponent({
2834
name: 'BreadcrumbItem',
2935
props: breadcrumbItemProps,
36+
slots: Object as SlotsType<BreadcrumbItemSlots>,
3037
setup(props, { slots }) {
3138
const NBreadcrumb = inject(breadcrumbInjectionKey, null)
3239
if (!NBreadcrumb) {

src/button/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ export {
33
default as NButton,
44
XButton as NxButton
55
} from './src/Button'
6-
export type { ButtonProps } from './src/Button'
6+
export type { ButtonProps, ButtonSlots } from './src/Button'

src/button/src/Button.tsx

+7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
inject,
1616
type PropType,
1717
ref,
18+
type SlotsType,
1819
type VNodeChild,
1920
watchEffect
2021
} from 'vue'
@@ -95,9 +96,15 @@ export const buttonProps = {
9596

9697
export type ButtonProps = ExtractPublicPropTypes<typeof buttonProps>
9798

99+
export interface ButtonSlots {
100+
default?: any
101+
icon?: any
102+
}
103+
98104
const Button = defineComponent({
99105
name: 'Button',
100106
props: buttonProps,
107+
slots: Object as SlotsType<ButtonSlots>,
101108
setup(props) {
102109
if (__DEV__) {
103110
watchEffect(() => {

src/calendar/src/Calendar.tsx

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import type { ThemeProps } from '../../_mixins'
22
import type { ExtractPublicPropTypes, MaybeArray } from '../../_utils'
33
import type { CalendarTheme } from '../styles'
4-
import type { DateItem, OnPanelChange, OnUpdateValue } from './interface'
4+
import type {
5+
CalendarDefaultSlotOptions,
6+
CalendarHeaderSlotOptions,
7+
DateItem,
8+
OnPanelChange,
9+
OnUpdateValue
10+
} from './interface'
511
import {
612
addMonths,
713
format,
@@ -19,6 +25,7 @@ import {
1925
h,
2026
type PropType,
2127
ref,
28+
type SlotsType,
2229
toRef
2330
} from 'vue'
2431
import { NBaseIcon } from '../../_internal'
@@ -46,9 +53,15 @@ export const calendarProps = {
4653

4754
export type CalendarProps = ExtractPublicPropTypes<typeof calendarProps>
4855

56+
export interface CalendarSlots {
57+
default?: (props: CalendarDefaultSlotOptions) => any
58+
header?: (props: CalendarHeaderSlotOptions) => any
59+
}
60+
4961
export default defineComponent({
5062
name: 'Calendar',
5163
props: calendarProps,
64+
slots: Object as SlotsType<CalendarSlots>,
5265
setup(props) {
5366
const { mergedClsPrefixRef, inlineThemeDisabled } = useConfig(props)
5467
const themeRef = useTheme(

src/calendar/src/interface.ts

+11
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,14 @@ export interface DateItem {
77
}
88

99
export type OnPanelChange = (info: { year: number, month: number }) => void
10+
11+
export interface CalendarDefaultSlotOptions {
12+
year: number
13+
month: number
14+
date: number
15+
}
16+
17+
export interface CalendarHeaderSlotOptions {
18+
year: number
19+
month: number
20+
}

src/card/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
export { cardProps, default as NCard } from './src/Card'
2-
export type { CardProps, CardSegmented } from './src/Card'
2+
export type { CardProps, CardSegmented, CardSlots } from './src/Card'

src/card/src/Card.tsx

+11
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
defineComponent,
99
h,
1010
type PropType,
11+
type SlotsType,
1112
type VNodeChild
1213
} from 'vue'
1314
import { NBaseClose } from '../../_internal'
@@ -71,9 +72,19 @@ export const cardProps = {
7172

7273
export type CardProps = ExtractPublicPropTypes<typeof cardProps>
7374

75+
export interface CardSlots {
76+
default?: any
77+
cover?: any
78+
header?: any
79+
'header-extra'?: any
80+
footer?: any
81+
action?: any
82+
}
83+
7484
export default defineComponent({
7585
name: 'Card',
7686
props: cardProps,
87+
slots: Object as SlotsType<CardSlots>,
7788
setup(props) {
7889
const handleCloseClick = (): void => {
7990
const { onClose } = props

src/carousel/index.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
export { carouselProps, default as NCarousel } from './src/Carousel'
2-
export type { CarouselProps } from './src/Carousel'
2+
export type { CarouselProps, CarouselSlots } from './src/Carousel'
33
export { default as NCarouselItem } from './src/CarouselItem'
4-
export type { CarouselInst } from './src/interface'
4+
export type {
5+
CarouselArrowSlotOptions,
6+
CarouselDotSlotOptions,
7+
CarouselInst
8+
} from './src/interface'

src/carousel/src/Carousel.tsx

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1-
import type { CSSProperties, PropType, Ref, TransitionProps, VNode } from 'vue'
1+
import type {
2+
CSSProperties,
3+
PropType,
4+
Ref,
5+
SlotsType,
6+
TransitionProps,
7+
VNode
8+
} from 'vue'
29
import type { ThemeProps } from '../../_mixins'
310
import type { ExtractPublicPropTypes } from '../../_utils'
411
import type { CarouselTheme } from '../styles'
512
import type {
613
ArrowScopedSlotProps,
14+
CarouselArrowSlotOptions,
15+
CarouselDotSlotOptions,
716
CarouselInst,
817
DotScopedSlotProps,
918
Size
@@ -139,12 +148,19 @@ export const carouselProps = {
139148

140149
export type CarouselProps = ExtractPublicPropTypes<typeof carouselProps>
141150

151+
export interface CarouselSlots {
152+
default?: () => any
153+
arrow?: (info: CarouselArrowSlotOptions) => any
154+
dots?: (info: CarouselDotSlotOptions) => any
155+
}
156+
142157
// only one carousel is allowed to trigger touch globally
143158
let globalDragging = false
144159

145160
export default defineComponent({
146161
name: 'Carousel',
147162
props: carouselProps,
163+
slots: Object as SlotsType<CarouselSlots>,
148164
setup(props) {
149165
const { mergedClsPrefixRef, inlineThemeDisabled } = useConfig(props)
150166
// Dom

src/carousel/src/interface.ts

+14
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,17 @@ export interface Size {
2525
width: number
2626
height: number
2727
}
28+
29+
export interface CarouselArrowSlotOptions {
30+
total: number
31+
currentIndex: number
32+
to: (index: number) => void
33+
prev: () => void
34+
next: () => void
35+
}
36+
37+
export interface CarouselDotSlotOptions {
38+
total: number
39+
currentIndex: number
40+
to: (index: number) => void
41+
}

0 commit comments

Comments
 (0)