Skip to content

Commit

Permalink
improve emits type
Browse files Browse the repository at this point in the history
  • Loading branch information
makedopamine committed May 13, 2024
1 parent efbb425 commit 31abd48
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 24 deletions.
46 changes: 29 additions & 17 deletions packages/components/select-v2/src/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@ import {
useEmptyValuesProps,
useSizeProp,
} from '@element-plus/hooks'
import {
buildEmits,
buildProps,
definePropType,
iconPropType,
} from '@element-plus/utils'
import { buildProps, definePropType, iconPropType } from '@element-plus/utils'
import { CHANGE_EVENT, UPDATE_MODEL_EVENT } from '@element-plus/constants'
import { useTooltipContentProps } from '@element-plus/components/tooltip'
import { CircleClose } from '@element-plus/icons-vue'
Expand All @@ -20,6 +15,7 @@ import type { Option, OptionType } from './select.types'
import type { Props } from './useProps'
import type { Options, Placement } from '@element-plus/components/popper'
import type { EmitFn } from '@element-plus/utils/vue/typescript'
import type { ExtractPropTypes } from 'vue'

export const SelectProps = buildProps({
/**
Expand Down Expand Up @@ -263,22 +259,38 @@ export const OptionProps = buildProps({
type: definePropType<Option>(Object),
required: true,
},
index: Number,
index: {
type: Number,
required: true,
},
style: Object,
selected: Boolean,
created: Boolean,
} as const)

export const selectEmits = buildEmits([
UPDATE_MODEL_EVENT,
CHANGE_EVENT,
'remove-tag',
'clear',
'visible-change',
'focus',
'blur',
])
export const optionEmits = buildEmits(['select', 'hover'])
export const selectEmits = {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
[UPDATE_MODEL_EVENT]: (val: ISelectV2Props['modelValue']) => true,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
[CHANGE_EVENT]: (val: ISelectV2Props['modelValue']) => true,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
'remove-tag': (val: unknown) => true,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
'visible-change': (visible: boolean) => true,
clear: () => true,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
focus: (event: FocusEvent) => true,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
blur: (event: FocusEvent) => true,
}
export const optionEmits = {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
hover: (index: number) => true,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
select: (val: Option, index: number) => true,
}

export type ISelectV2Props = ExtractPropTypes<typeof SelectProps>
export type IOptionV2Props = ExtractPropTypes<typeof OptionProps>
export type SelectEmitFn = EmitFn<typeof selectEmits>
export type OptionEmitFn = EmitFn<typeof optionEmits>
9 changes: 4 additions & 5 deletions packages/components/select-v2/src/token.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { OptionProps, SelectProps } from './defaults'
import type { ExtractPropTypes, InjectionKey, Ref } from 'vue'
import type { IOptionV2Props, ISelectV2Props } from './defaults'
import type { InjectionKey, Ref } from 'vue'
import type { Option } from './select.types'
import type { TooltipInstance } from '@element-plus/components/tooltip'

export interface SelectV2Context {
props: ExtractPropTypes<typeof SelectProps>
props: ISelectV2Props
expanded: Ref<boolean>
tooltipRef: Ref<TooltipInstance | undefined>
onSelect: (option: Option) => void
Expand All @@ -16,5 +16,4 @@ export interface SelectV2Context {
export const selectV2InjectionKey: InjectionKey<SelectV2Context> = Symbol(
'ElSelectV2Injection'
)
export type IOptionV2Props = ExtractPropTypes<typeof OptionProps>
export type ISelectV2Props = ExtractPropTypes<typeof SelectProps>
export type { ISelectV2Props, IOptionV2Props }
1 change: 0 additions & 1 deletion packages/utils/vue/emits/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/utils/vue/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ export * from './global-node'
export * from './icon'
export * from './install'
export * from './props'
export * from './emits'
export * from './refs'
export * from './size'
export * from './typescript'
Expand Down

0 comments on commit 31abd48

Please sign in to comment.