mirror of
https://github.com/element-plus/element-plus.git
synced 2026-03-13 07:51:17 +08:00
* chore: upgrade deps * chore: replace __ExtractPublicPropTypes with ExtractPublicPropTypes * fix: get rid of type errors * fix: resolve test errors with @vue/test-utils v2.4.6 * fix: resolve test errors with Vue 3.5.22 * ci: set pnpm flag * chore: update the Vue peer dependency version * Apply suggestion from @tolking Co-authored-by: qiang <qw13131wang@gmail.com> * docs: update example code Co-authored-by: warmthsea <2586244885@qq.com> * chore: remove csstype (#22487) * chore: fix merge code type error * chore: fix test:ssr error - Cannot read properties of undefined (reading 'getSSRProps') * chore: fix typecheck:vitest error * chore: update pnpm yaml file * test: fix collapse accordion error * chore: update deps * chore: fix type error * chore: lock file * chore: sync change sync with the remove of vue macro * refactor: use computed instead of eagerComputed * fix: timeline.test.tsx typecheck * chore: clean lock file try dont throw CodeFactor issues in ci did: - rm pnpm-lock.yaml - rm -rf ./**/node_modules - pnpm store prune - pnpm cache delete - pnpm install Also stay in 3.1.0 for vue-tsc in order to avoid the warnings of template refs, see https://github.com/vuejs/language-tools/issues/5815 * chore: format code --------- Co-authored-by: Dsaquel <291874700n@gmail.com> Co-authored-by: qiang <qw13131wang@gmail.com> Co-authored-by: warmthsea <2586244885@qq.com> Co-authored-by: Noblet Ouways <91417411+Dsaquel@users.noreply.github.com> Co-authored-by: sea <45450994+warmthsea@users.noreply.github.com> Co-authored-by: btea <2356281422@qq.com>
237 lines
5.2 KiB
TypeScript
237 lines
5.2 KiB
TypeScript
import {
|
|
buildProps,
|
|
definePropType,
|
|
iconPropType,
|
|
isClient,
|
|
mutable,
|
|
} from '@element-plus/utils'
|
|
|
|
import type {
|
|
AppContext,
|
|
ExtractPropTypes,
|
|
ExtractPublicPropTypes,
|
|
VNode,
|
|
} from 'vue'
|
|
import type { Mutable } from '@element-plus/utils'
|
|
import type MessageConstructor from './message.vue'
|
|
|
|
export const messageTypes = [
|
|
'primary',
|
|
'success',
|
|
'info',
|
|
'warning',
|
|
'error',
|
|
] as const
|
|
|
|
export const messagePlacement = [
|
|
'top',
|
|
'top-left',
|
|
'top-right',
|
|
'bottom',
|
|
'bottom-left',
|
|
'bottom-right',
|
|
] as const
|
|
|
|
export const MESSAGE_DEFAULT_PLACEMENT = 'top'
|
|
|
|
export type MessageType = (typeof messageTypes)[number]
|
|
export type MessagePlacement = (typeof messagePlacement)[number]
|
|
/** @deprecated please use `MessageType` instead */
|
|
export type messageType = MessageType // will be removed in 3.0.0.
|
|
|
|
export interface MessageConfigContext {
|
|
max?: number
|
|
grouping?: boolean
|
|
duration?: number
|
|
offset?: number
|
|
showClose?: boolean
|
|
plain?: boolean
|
|
placement?: string
|
|
}
|
|
|
|
export const messageDefaults = mutable({
|
|
customClass: '',
|
|
dangerouslyUseHTMLString: false,
|
|
duration: 3000,
|
|
icon: undefined,
|
|
id: '',
|
|
message: '',
|
|
onClose: undefined,
|
|
showClose: false,
|
|
type: 'info',
|
|
plain: false,
|
|
offset: 16,
|
|
placement: undefined,
|
|
zIndex: 0,
|
|
grouping: false,
|
|
repeatNum: 1,
|
|
appendTo: isClient ? document.body : (undefined as never),
|
|
} as const)
|
|
|
|
export const messageProps = buildProps({
|
|
/**
|
|
* @description custom class name for Message
|
|
*/
|
|
customClass: {
|
|
type: String,
|
|
default: messageDefaults.customClass,
|
|
},
|
|
/**
|
|
* @description whether `message` is treated as HTML string
|
|
*/
|
|
dangerouslyUseHTMLString: {
|
|
type: Boolean,
|
|
default: messageDefaults.dangerouslyUseHTMLString,
|
|
},
|
|
/**
|
|
* @description display duration, millisecond. If set to 0, it will not turn off automatically
|
|
*/
|
|
duration: {
|
|
type: Number,
|
|
default: messageDefaults.duration,
|
|
},
|
|
/**
|
|
* @description custom icon component, overrides `type`
|
|
*/
|
|
icon: {
|
|
type: iconPropType,
|
|
default: messageDefaults.icon,
|
|
},
|
|
/**
|
|
* @description message dom id
|
|
*/
|
|
id: {
|
|
type: String,
|
|
default: messageDefaults.id,
|
|
},
|
|
/**
|
|
* @description message text
|
|
*/
|
|
message: {
|
|
type: definePropType<string | VNode | (() => VNode)>([
|
|
String,
|
|
Object,
|
|
Function,
|
|
]),
|
|
default: messageDefaults.message,
|
|
},
|
|
/**
|
|
* @description callback function when closed with the message instance as the parameter
|
|
*/
|
|
onClose: {
|
|
type: definePropType<() => void>(Function),
|
|
default: messageDefaults.onClose,
|
|
},
|
|
/**
|
|
* @description whether to show a close button
|
|
*/
|
|
showClose: {
|
|
type: Boolean,
|
|
default: messageDefaults.showClose,
|
|
},
|
|
/**
|
|
* @description message type
|
|
*/
|
|
type: {
|
|
type: String,
|
|
values: messageTypes,
|
|
default: messageDefaults.type,
|
|
},
|
|
/**
|
|
* @description whether message is plain
|
|
*/
|
|
plain: {
|
|
type: Boolean,
|
|
default: messageDefaults.plain,
|
|
},
|
|
/**
|
|
* @description set the distance to the top of viewport
|
|
*/
|
|
offset: {
|
|
type: Number,
|
|
default: messageDefaults.offset,
|
|
},
|
|
/**
|
|
* @description message placement position
|
|
*/
|
|
placement: {
|
|
type: String,
|
|
values: messagePlacement,
|
|
default: messageDefaults.placement,
|
|
},
|
|
/**
|
|
* @description input box size
|
|
*/
|
|
zIndex: {
|
|
type: Number,
|
|
default: messageDefaults.zIndex,
|
|
},
|
|
/**
|
|
* @description merge messages with the same content, type of VNode message is not supported
|
|
*/
|
|
grouping: {
|
|
type: Boolean,
|
|
default: messageDefaults.grouping,
|
|
},
|
|
/**
|
|
* @description The number of repetitions, similar to badge, is used as the initial number when used with `grouping`
|
|
*/
|
|
repeatNum: {
|
|
type: Number,
|
|
default: messageDefaults.repeatNum,
|
|
},
|
|
} as const)
|
|
export type MessageProps = ExtractPropTypes<typeof messageProps>
|
|
export type MessagePropsPublic = ExtractPublicPropTypes<typeof messageProps>
|
|
|
|
export const messageEmits = {
|
|
destroy: () => true,
|
|
}
|
|
export type MessageEmits = typeof messageEmits
|
|
|
|
export type MessageInstance = InstanceType<typeof MessageConstructor> & unknown
|
|
|
|
export type MessageOptions = Partial<
|
|
Mutable<
|
|
Omit<MessageProps, 'id'> & {
|
|
appendTo?: HTMLElement | string
|
|
}
|
|
>
|
|
>
|
|
export type MessageParams = MessageOptions | MessageOptions['message']
|
|
export type MessageParamsNormalized = Omit<MessageProps, 'id'> & {
|
|
/**
|
|
* @description set the root element for the message, default to `document.body`
|
|
*/
|
|
appendTo: HTMLElement
|
|
}
|
|
export type MessageOptionsWithType = Omit<MessageOptions, 'type'>
|
|
export type MessageParamsWithType =
|
|
| MessageOptionsWithType
|
|
| MessageOptions['message']
|
|
|
|
export interface MessageHandler {
|
|
/**
|
|
* @description close the Message
|
|
*/
|
|
close: () => void
|
|
}
|
|
|
|
export type MessageFn = {
|
|
(options?: MessageParams, appContext?: null | AppContext): MessageHandler
|
|
closeAll(type?: MessageType): void
|
|
closeAllByPlacement(position: MessagePlacement): void
|
|
}
|
|
export type MessageTypedFn = (
|
|
options?: MessageParamsWithType,
|
|
appContext?: null | AppContext
|
|
) => MessageHandler
|
|
|
|
export type Message = MessageFn & {
|
|
primary: MessageTypedFn
|
|
success: MessageTypedFn
|
|
warning: MessageTypedFn
|
|
info: MessageTypedFn
|
|
error: MessageTypedFn
|
|
}
|