Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add slots typing for all components #6603

Open
wants to merge 54 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
16e0e8b
feat(alert): add slots type (#6599)
nailiable Dec 7, 2024
19d637f
feat(auto-complete): add slots type (#6599)
nailiable Dec 7, 2024
f4799d1
fix(auto-complete): slots type (#6599)
nailiable Dec 7, 2024
00c775c
feat(auto-complete): export slots type (#6599)
nailiable Dec 7, 2024
6efc1ff
feat(avatar): add slots type (#6599)
nailiable Dec 7, 2024
f4901d6
feat(avatar-group): add slots type (#6599), may not be particularly p…
nailiable Dec 7, 2024
aa30016
feat(breadcrumb-item): add slots type (#6599)
nailiable Dec 7, 2024
93fd985
feat(breadcrumb-item): export slots type (#6599)
nailiable Dec 7, 2024
1ef779c
feat(button): add slots type (#6599)
nailiable Dec 7, 2024
f1eb605
feat(calendar): add slots type (#6599)
nailiable Dec 7, 2024
afcb2dc
feat(card): add slots type (#6599)
nailiable Dec 7, 2024
14b2a52
feat(carousel): add slots type (#6599)
nailiable Dec 7, 2024
b09b168
feat(cascader): add slots type (#6599)
nailiable Dec 7, 2024
e3ab2bb
feat(collapse): add slots type (#6599)
nailiable Dec 7, 2024
5df707c
feat(color-picker): add slots type (#6599)
nailiable Dec 7, 2024
4cfb159
feat(data-table): add slots type (#6599)
nailiable Dec 7, 2024
bbe901d
feat(date-picker): add slots type (#6599)
nailiable Dec 7, 2024
0139b74
feat(descriptions): add slots type (#6599)
nailiable Dec 7, 2024
26e6ded
feat(dialog): add slots type (#6599)
nailiable Dec 7, 2024
f86adc3
feat(drawer-content): add slots type (#6599)
nailiable Dec 7, 2024
373732c
feat(dynamic-input): add slots type (#6599)
nailiable Dec 7, 2024
e5fab2c
feat(dynamic-tags): add slots type (#6599)
nailiable Dec 7, 2024
fa678e3
feat(ellipsis): add slots type (#6599)
nailiable Dec 7, 2024
acdc030
feat(empty): add slots type (#6599)
nailiable Dec 7, 2024
d12a62f
feat(float-button): add slots type (#6599)
nailiable Dec 7, 2024
c30d73d
feat(image): add slots type (#6599)
nailiable Dec 7, 2024
0c1b522
feat(input): add slots type (#6599)
nailiable Dec 7, 2024
83d9bc5
feat(input-number): add slots type (#6599)
nailiable Dec 7, 2024
8b0c79d
feat(list): add slots type (#6599)
nailiable Dec 7, 2024
bad51fd
feat(mention): add slots type (#6599)
nailiable Dec 7, 2024
3304fee
feat(modal): add slots type (#6599)
nailiable Dec 7, 2024
c4bf7d1
feat(page-header): add slots type (#6599)
nailiable Dec 7, 2024
5657140
feat(pagination): add slots type (#6599)
nailiable Dec 7, 2024
d06255f
feat(popconfirm): add slots type (#6599)
nailiable Dec 7, 2024
0db42a8
feat(popover): add slots type (#6599)
nailiable Dec 7, 2024
a0223dc
feat(popselect): add slots type (#6599)
nailiable Dec 7, 2024
6fd2272
feat(result): add slots type (#6599)
nailiable Dec 7, 2024
1d69061
feat(select): add slots type (#6599)
nailiable Dec 7, 2024
040600b
feat(slider): add slots type (#6599)
nailiable Dec 7, 2024
6e06edf
feat(spin): add slots type (#6599)
nailiable Dec 7, 2024
318ec6f
feat(split): add slots type (#6599)
nailiable Dec 7, 2024
f4220cf
feat(statistic): add slots type (#6599)
nailiable Dec 7, 2024
be2d9d5
feat(step): add slots type (#6599)
nailiable Dec 7, 2024
7dd15f0
feat(switch): add slots type (#6599)
nailiable Dec 7, 2024
a27a085
feat(tabs): add slots type (#6599)
nailiable Dec 7, 2024
968ac46
feat(tag): add slots type (#6599)
nailiable Dec 7, 2024
30ffd0a
feat(thing): add slots type (#6599)
nailiable Dec 7, 2024
63c92b2
feat(time-picker): add slots type (#6599)
nailiable Dec 7, 2024
b18dc5e
feat(time-picker): export slots type (#6599)
nailiable Dec 7, 2024
105c873
feat(timeline): export slots type (#6599)
nailiable Dec 7, 2024
90624f1
feat(tooltip): export slots type (#6599)
nailiable Dec 7, 2024
45366cb
feat(tree): export slots type (#6599)
nailiable Dec 7, 2024
b9f0b9f
feat(tree-select): export slots type (#6599)
nailiable Dec 7, 2024
41ad866
feat(upload-trigger): export slots type (#6599)
nailiable Dec 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/alert/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { alertProps, default as NAlert } from './src/Alert'
export type { AlertProps } from './src/Alert'
export type { AlertProps, AlertSlots } from './src/Alert'
8 changes: 8 additions & 0 deletions src/alert/src/Alert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
mergeProps,
type PropType,
ref,
type SlotsType,
watchEffect
} from 'vue'
import { NBaseClose, NBaseIcon, NFadeInExpandTransition } from '../../_internal'
Expand Down Expand Up @@ -56,10 +57,17 @@ export const alertProps = {

export type AlertProps = ExtractPublicPropTypes<typeof alertProps>

export interface AlertSlots {
default?: any
icon?: any
header?: any
}

export default defineComponent({
name: 'Alert',
inheritAttrs: false,
props: alertProps,
slots: Object as SlotsType<AlertSlots>,
setup(props) {
if (__DEV__) {
watchEffect(() => {
Expand Down
3 changes: 2 additions & 1 deletion src/auto-complete/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export { autoCompleteProps, default as NAutoComplete } from './src/AutoComplete'
export type { AutoCompleteProps } from './src/AutoComplete'
export type { AutoCompleteProps, AutoCompleteSlots } from './src/AutoComplete'
export type {
AutoCompleteDefaultSlotOptions,
AutoCompleteGroupOption,
AutoCompleteInst,
AutoCompleteOption
Expand Down
12 changes: 11 additions & 1 deletion src/auto-complete/src/AutoComplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {
} from '../../select/src/interface'
import type { AutoCompleteTheme } from '../styles'
import type {
AutoCompleteDefaultSlotOptions,
AutoCompleteInst,
AutoCompleteOption,
AutoCompleteOptions,
Expand All @@ -33,6 +34,7 @@ import {
type InputHTMLAttributes,
type PropType,
ref,
type SlotsType,
toRef,
Transition,
watchEffect,
Expand Down Expand Up @@ -114,9 +116,17 @@ export const autoCompleteProps = {

export type AutoCompleteProps = ExtractPublicPropTypes<typeof autoCompleteProps>

export interface AutoCompleteSlots {
default?: (options: AutoCompleteDefaultSlotOptions) => any
empty?: any
prefix?: any
suffix?: any
}

export default defineComponent({
name: 'AutoComplete',
props: autoCompleteProps,
slots: Object as SlotsType<AutoCompleteSlots>,
setup(props) {
if (__DEV__) {
watchEffect(() => {
Expand Down Expand Up @@ -368,7 +378,7 @@ export default defineComponent({
handleFocus: this.handleFocus,
handleBlur: this.handleBlur,
value: this.mergedValue
})
} as AutoCompleteDefaultSlotOptions)
}
const { mergedTheme } = this
return (
Expand Down
8 changes: 8 additions & 0 deletions src/auto-complete/src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,11 @@ export interface AutoCompleteInst {
focus: () => void
blur: () => void
}

export interface AutoCompleteDefaultSlotOptions {
handleInput: (value: string) => void
handleFocus: (e: FocusEvent) => void
handleBlur: (e: FocusEvent) => void
value: string
theme: string | null
}
4 changes: 4 additions & 0 deletions src/avatar-group/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
export { avatarGroupProps, default as NAvatarGroup } from './src/AvatarGroup'
export type { AvatarGroupOption, AvatarGroupProps } from './src/AvatarGroup'
export type {
AvatarGroupAvatarSlotOptions,
AvatarGroupRestSlotOptions
} from './src/interface'
14 changes: 13 additions & 1 deletion src/avatar-group/src/AvatarGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@ import type { ThemeProps } from '../../_mixins'
import type { ExtractPublicPropTypes } from '../../_utils'
import type { Size } from '../../avatar/src/interface'
import type { AvatarGroupTheme } from '../styles'
import type {
AvatarGroupAvatarSlotOptions,
AvatarGroupRestSlotOptions
} from './interface'
import {
computed,
type CSSProperties,
defineComponent,
h,
type PropType,
provide
provide,
type SlotsType
} from 'vue'
import { useConfig, useTheme } from '../../_mixins'
import { useRtl } from '../../_mixins/use-rtl'
Expand Down Expand Up @@ -40,9 +45,16 @@ export const avatarGroupProps = {

export type AvatarGroupProps = ExtractPublicPropTypes<typeof avatarGroupProps>

export interface AvatarGroupSlots {
avatar?: (info: AvatarGroupAvatarSlotOptions) => any
rest?: (info: AvatarGroupRestSlotOptions) => any
default?: any
}

export default defineComponent({
name: 'AvatarGroup',
props: avatarGroupProps,
slots: Object as SlotsType<AvatarGroupSlots>,
setup(props) {
const { mergedClsPrefixRef, mergedRtlRef } = useConfig(props)
const mergedThemeRef = useTheme(
Expand Down
8 changes: 8 additions & 0 deletions src/avatar-group/src/interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export interface AvatarGroupAvatarSlotOptions {
option: Record<string, any>
}

export interface AvatarGroupRestSlotOptions {
options: Array<any>
rest: number
}
2 changes: 1 addition & 1 deletion src/avatar/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { avatarProps, default as NAvatar } from './src/Avatar'
export type { AvatarProps } from './src/Avatar'
export type { AvatarProps, AvatarSlots } from './src/Avatar'
8 changes: 8 additions & 0 deletions src/avatar/src/Avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
onMounted,
type PropType,
ref,
type SlotsType,
type VNodeChild,
watch,
watchEffect
Expand Down Expand Up @@ -65,9 +66,16 @@ export const avatarProps = {

export type AvatarProps = ExtractPublicPropTypes<typeof avatarProps>

export interface AvatarSlots {
default: any
placeholder: any
fallback: any
}

export default defineComponent({
name: 'Avatar',
props: avatarProps,
slots: Object as SlotsType<AvatarSlots>,
setup(props) {
const { mergedClsPrefixRef, inlineThemeDisabled } = useConfig(props)
const hasLoadErrorRef = ref(false)
Expand Down
5 changes: 4 additions & 1 deletion src/breadcrumb/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ export {
breadcrumbItemProps,
default as NBreadcrumbItem
} from './src/BreadcrumbItem'
export type { BreadcrumbItemProps } from './src/BreadcrumbItem'
export type {
BreadcrumbItemProps,
BreadcrumbItemSlots
} from './src/BreadcrumbItem'
9 changes: 8 additions & 1 deletion src/breadcrumb/src/BreadcrumbItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
type ExtractPropTypes,
h,
inject,
type PropType
type PropType,
type SlotsType
} from 'vue'
import { resolveSlot, warn } from '../../_utils'
import { useBrowserLocation } from '../../_utils/composable/use-browser-location'
Expand All @@ -24,9 +25,15 @@ export type BreadcrumbItemProps = Partial<
ExtractPropTypes<typeof breadcrumbItemProps>
>

export interface BreadcrumbItemSlots {
default?: any
separator?: any
}

export default defineComponent({
name: 'BreadcrumbItem',
props: breadcrumbItemProps,
slots: Object as SlotsType<BreadcrumbItemSlots>,
setup(props, { slots }) {
const NBreadcrumb = inject(breadcrumbInjectionKey, null)
if (!NBreadcrumb) {
Expand Down
2 changes: 1 addition & 1 deletion src/button/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ export {
default as NButton,
XButton as NxButton
} from './src/Button'
export type { ButtonProps } from './src/Button'
export type { ButtonProps, ButtonSlots } from './src/Button'
7 changes: 7 additions & 0 deletions src/button/src/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
inject,
type PropType,
ref,
type SlotsType,
type VNodeChild,
watchEffect
} from 'vue'
Expand Down Expand Up @@ -95,9 +96,15 @@ export const buttonProps = {

export type ButtonProps = ExtractPublicPropTypes<typeof buttonProps>

export interface ButtonSlots {
default?: any
icon?: any
}

const Button = defineComponent({
name: 'Button',
props: buttonProps,
slots: Object as SlotsType<ButtonSlots>,
setup(props) {
if (__DEV__) {
watchEffect(() => {
Expand Down
15 changes: 14 additions & 1 deletion src/calendar/src/Calendar.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import type { ThemeProps } from '../../_mixins'
import type { ExtractPublicPropTypes, MaybeArray } from '../../_utils'
import type { CalendarTheme } from '../styles'
import type { DateItem, OnPanelChange, OnUpdateValue } from './interface'
import type {
CalendarDefaultSlotOptions,
CalendarHeaderSlotOptions,
DateItem,
OnPanelChange,
OnUpdateValue
} from './interface'
import {
addMonths,
format,
Expand All @@ -19,6 +25,7 @@ import {
h,
type PropType,
ref,
type SlotsType,
toRef
} from 'vue'
import { NBaseIcon } from '../../_internal'
Expand Down Expand Up @@ -46,9 +53,15 @@ export const calendarProps = {

export type CalendarProps = ExtractPublicPropTypes<typeof calendarProps>

export interface CalendarSlots {
default?: (props: CalendarDefaultSlotOptions) => any
header?: (props: CalendarHeaderSlotOptions) => any
}

export default defineComponent({
name: 'Calendar',
props: calendarProps,
slots: Object as SlotsType<CalendarSlots>,
setup(props) {
const { mergedClsPrefixRef, inlineThemeDisabled } = useConfig(props)
const themeRef = useTheme(
Expand Down
11 changes: 11 additions & 0 deletions src/calendar/src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,14 @@ export interface DateItem {
}

export type OnPanelChange = (info: { year: number, month: number }) => void

export interface CalendarDefaultSlotOptions {
year: number
month: number
date: number
}

export interface CalendarHeaderSlotOptions {
year: number
month: number
}
2 changes: 1 addition & 1 deletion src/card/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { cardProps, default as NCard } from './src/Card'
export type { CardProps, CardSegmented } from './src/Card'
export type { CardProps, CardSegmented, CardSlots } from './src/Card'
11 changes: 11 additions & 0 deletions src/card/src/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
defineComponent,
h,
type PropType,
type SlotsType,
type VNodeChild
} from 'vue'
import { NBaseClose } from '../../_internal'
Expand Down Expand Up @@ -71,9 +72,19 @@ export const cardProps = {

export type CardProps = ExtractPublicPropTypes<typeof cardProps>

export interface CardSlots {
default?: any
cover?: any
header?: any
'header-extra'?: any
footer?: any
action?: any
}

export default defineComponent({
name: 'Card',
props: cardProps,
slots: Object as SlotsType<CardSlots>,
setup(props) {
const handleCloseClick = (): void => {
const { onClose } = props
Expand Down
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
}
Loading