useToast / 通知

显示重要的全局通知信息。

基础的

基础示例。

多行

显示多行或过长的文本。

动作

在通知中附加一个按钮。

取消

使用 passive (消极地) 改变按钮的状态与样式。

自定义模板

ReactNode 代替字符串展示更丰富的信息。

类型

APIs / 接口文档

useToasts

const {
  // 当前 DOM 中所有可用实例
  toasts: Array<Toast>

  // 创建一个立即显示的通知
  setToast: (toast: ToastInput) => void

  // 立刻隐藏所有的通知
  removeAll: () => void

  // 按 ID 查询指定的实例
  findToastOneByID: (ident: string) => Toast | undefined

  // 按 ID 移除一个指定通知
  removeToastOneByID: (ident: string) => void
} = useToasts(layout: ToastLayout)

ToastLayout

参数描述类型默认值
padding通用 CSS 属性string-
margin通用 CSS 属性string-
width通用 CSS 属性string-
maxWidth通用 CSS 属性string90vw
maxHeight通用 CSS 属性string75px
placement组件弹出的位置ToastPlacementbottomRight

ToastInput

参数描述类型默认值
id唯一识别 ID,可自动生成string-
text组件内显示的信息string, ReactNode-
type组件的样式类型ToastTypesdefault
delay自动关闭前等待的时间number2000
actions指定一个默认的动作ToastAction-

ToastPlacement

type ToastPlacement = 'topLeft' | 'topRight' | 'bottomLeft' | 'bottomRight'

ToastAction

interface ToastAction {
  name: string
  handler: (event: React.MouseEventHandler<HTMLButtonElement>, cancel: Function) => void
  passive?: boolean
}

ToastTypes

type ToastTypes = 'default' \| 'secondary' | 'success' | 'warning' | 'error'