Skip to content

Notify

A notification component used to display notification information at the top of the page.

Component States

Basic Usage

You need to import this component in the page as a mount point.

html
<wd-notify />
ts
import { useNotify } from '@/uni_modules/wot-ui'

const { showNotify, closeNotify } = useNotify()

// Auto-close after 3 seconds
showNotify('Notification content')

// Manually close
closeNotify()

Custom Configuration

Supports customizing colors, popup position, display duration, and whether to show the close button.

ts
// Custom colors
showNotify({
  message: 'Custom colors',
  color: '#ad0000',
  background: '#ffe1e1'
})

// Custom position
showNotify({
  message: 'Custom position',
  position: 'bottom'
})

// Custom duration
showNotify({
  message: 'Custom duration',
  duration: 1000
})

// Show close button
showNotify({
  message: 'Notification content',
  closable: true,
  duration: 0
})

Component Types

Notification Types

Supports four notification types: primary, success, warning, and danger. The default is danger.

ts
// Primary notification
showNotify({ type: 'primary', message: 'Notification content' })

// Success notification
showNotify({ type: 'success', message: 'Notification content' })

// Danger notification
showNotify({ type: 'danger', message: 'Notification content' })

// Warning notification
showNotify({ type: 'warning', message: 'Notification content' })

Component Styles

Floating Notification

Set the variant property to floating to display a floating card-style notification. Floating notifications have independent margins, rounded corners, and shadows, and their prefix icons will automatically adapt to the current type status color.

ts
showNotify({
  type: 'primary',
  message: 'Notification content',
  variant: 'floating',
  closable: true
})

Content Forms

Using Notify Component

If you need to embed components or other custom content within Notify, you can use the Notify component directly and customize it using the default slot.

html
<wd-button type="primary" @click="showNotify">Call using Notify component</wd-button>
<wd-notify type="success" :safe-height="safeHeight" v-model:visible="visible">
  <wd-icon name="check-outline" size="inherit" color="inherit" />
  Success notification
</wd-notify>
ts
import { ref, onMounted } from 'vue'

let timer: ReturnType<typeof setTimeout>
export default {
  setup() {
    const visible = ref(false)
    const safeHeight = ref(0)

    const showNotify = () => {
      visible.value = true
      if (timer) clearTimeout(timer)
      timer = setTimeout(() => {
        visible.value = false
      }, 3000)
    }

    onMounted(() => {
      // #ifdef H5
      safeHeight.value = 44
      // #endif
    })

    return {
      visible,
      showNotify,
      safeHeight
    }
  }
}

Attributes

ParameterDescriptionTypeDefault Value
typeType, optional values are primary success warning dangerNotifyTypedanger
messageDisplay text, supports line breaks via \nstring | number-
durationDisplay duration (ms), when value is 0, notify will not disappearnumber3000
visibleDisplay status (supports v-model)booleanfalse
positionPopup position, optional values are top bottomNotifyPositiontop
colorFont colorstring-
backgroundBackground colorstring-
z-indexSet the component's z-index level to a fixed valuenumber99
safe-heightTop safe heightnumber | string-
selectorSpecify unique identifierstring-
root-portalWhether to detach from the page, used to solve various fixed positioning issuesbooleanfalse
closableWhether to show the close buttonbooleanfalse
variantDisplay form, optional values are filled floatingNotifyVariantfilled
custom-classRoot node style class namestring-
custom-styleRoot node stylestring-

Events

Event NameDescriptionParameters
clickCallback function when clicked(event: MouseEvent) => void
closedCallback function when closed() => void
openedCallback function after displayed() => void

Slots

NameDescription
defaultCustom notification content

Methods

Method NameDescriptionParameters
showNotifyDisplay notificationNotifyOptions / string
closeNotifyClose notification-
setNotifyDefaultOptionsModify default configuration, affecting all showNotify callsNotifyOptions

主题定制

CSS 变量

组件提供了下列 CSS 变量,可用于自定义样式,使用方法请参考 ConfigProvider 全局配置

名称默认值描述
--wot-notify-text-color$text-white通知文字颜色
--wot-notify-padding$padding-tight $padding-loose通知内边距
--wot-notify-font-size$typography-body-size-large通知文字字号
--wot-notify-line-height$typography-body-line--height-size-large通知文字行高
--wot-notify-primary-bg$primary-1主色态背景色
--wot-notify-primary-color$primary-6主色态文字颜色
--wot-notify-success-bg$success-surface成功态背景色
--wot-notify-success-color$success-main成功态文字颜色
--wot-notify-danger-bg$danger-surface危险态背景色
--wot-notify-danger-color$danger-main危险态文字颜色
--wot-notify-warning-bg$warning-surface警告态背景色
--wot-notify-warning-color$warning-main警告态文字颜色
--wot-notify-icon-size$n-18图标尺寸
--wot-notify-icon-spacing$spacing-tight图标间距
--wot-notify-floating-bg$base-whitefloating 变体背景色
--wot-notify-floating-color$text-mainfloating 变体文字颜色
--wot-notify-floating-radius$radius-largefloating 变体圆角
--wot-notify-floating-margin-horizontal$spacing-loosefloating 变体左右间距
--wot-notify-floating-margin-vertical$spacing-loosefloating 变体上下间距
--wot-notify-floating-shadow0 12px 48px 16px rgba(39, 43, 59, 0.03), 0 9px 28px 8px rgba(39, 43, 59, 0.05), 0 5px 12px 4px rgba(39, 43, 59, 0.06)floating 变体阴影

Source Code

Documentation
Component

Released under the MIT License.

Released under the MIT License.