Skip to content

Message ​

Introduction ​

The message component is used to display operation feedback information to users.
You can display message prompts through functional calls like MYMessage().

Basic Usage ​

Use function calls to display different types of message prompts.

Code Demo
展开代码

Show Close Button ​

Use the showClose prop to display a close button.

Code Demo
展开代码

Custom Duration ​

Use the duration prop to customize how long the message is displayed.

Code Demo
展开代码

Custom Position ​

Use the position prop to set the display position of the message.

Code Demo
展开代码

HTML Content Support ​

Use the dangerouslyUseHTMLString prop to support HTML content (be aware of XSS risks).

Code Demo
展开代码

Manual Close Control ​

You can manually control the closing of a message via the return value.

Code Demo
展开代码

Close Callback ​

Use the onClose prop to execute a callback function when the message is closed.

Code Demo
展开代码

Offset Setting ​

Use the offset prop to set the offset of the message container.

Code Demo
展开代码

Combined Usage ​

Finally, here's an example combining multiple APIs for a complete message prompt:

Code Demo
展开代码

API Reference ​

Function Calls ​

typescript
// Basic usage
MYMessage(options: MessageOption): MessageHandle
MYMessage(content: string): MessageHandle

// Shortcut methods
MYMessage.success(content: string, options?: MessageOption): MessageHandle
MYMessage.info(content: string, options?: MessageOption): MessageHandle
MYMessage.warning(content: string, options?: MessageOption): MessageHandle
MYMessage.error(content: string, options?: MessageOption): MessageHandle
MYMessage.default(content: string, options?: MessageOption): MessageHandle

MessageOption Parameters ​

ParameterDescriptionTypeOptionsDefault
contentMessage contentstring | VNode——
typeMessage typestringinfo/success/warning/error/default'info'
durationDisplay duration (ms)number—3000
showCloseShow close buttonboolean—false
dangerouslyUseHTMLStringUse HTML contentboolean—false
positionMessage positionstringtop-right/top-left/bottom-right/bottom-left/top-center/bottom-center'top-right'
offsetOffset valuenumber—20
zIndexz-index valuenumber—9999
onCloseClose callbackfunction——

MessageHandle Return Value ​

PropertyDescriptionType
idMessage IDstring
closeClose message methodfunction

Global Configuration ​

typescript
MYMessage.config({
  duration: 5000,
  position: 'top-center',
  max: 5,
  offset: 30,
  zIndex: 10000
})

Type Definitions ​

typescript
type MessageType = 'info' | 'success' | 'warning' | 'error' | 'default'

type Position = 
  | 'top-right'
  | 'top-left'
  | 'bottom-right'
  | 'bottom-left'
  | 'top-center'
  | 'bottom-center'

interface MessageOption {
  id?: string
  content?: string | VNode
  type?: MessageType
  duration?: number
  showClose?: boolean
  dangerouslyUseHTMLString?: boolean
  position?: Position
  offset?: number
  zIndex?: number
  onClose?: () => void
}

interface MessageHandle {
  id: string
  close: () => void
}

interface MessageGlobalConfig {
  duration?: number
  position?: Position
  max?: number
  offset?: number
  zIndex?: number
}

Released under the MIT License.