Svelte Notifications

可在任何 JS 应用程序中使用的 Svelte Toast(吐司提示)通知组件。「Svelte toast notifications component that can be used in any JS application」

Github星跟蹤圖

Svelte Notifications

js-standard-style CircleCI Svelte v2 Svelte v3

Svelte Notifications component

  • v3 compatible
  • uses stores for completely hassle free operation

Demo

A Demo of this component is available.

Usage

npm i -D @beyonk/svelte-notifications
<NotificationDisplay />

<button on:click={someFunction}>Show message</button>

<script>
import { NotificationDisplay, notifier } from '@beyonk/svelte-notifications'

function someFunction () {
  notifier.success('Notifications work!')
}
</script>

Notification types

You can call multiple types of notification:

notifier.show('danger', message, displayTimeMs)
notifier.danger(message, displayTimeMs),
notifier.warning(message, displayTimeMs),
notifier.info(message, displayTimeMs),
notifier.success(message, displayTimeMs)

Notification themes

You can customise the themes:

<NotificationDisplay {themes} />

<button on:click={someFunction}>Show message</button>

<script>
import { NotificationDisplay, notifier } from '@beyonk/svelte-notifications'

let themes = { // These are the defaults
  danger: '#bb2124',
  success: '#22bb33',
  warning: '#f0ad4e',
  info: '#5bc0de',
  default: '#aaaaaa' // relates to simply '.show()'
}

function someFunction () {
  notifier.success('Notifications work!')
}
</script>
Custom types
<NotificationDisplay {themes} />

<button on:click={someFunction}>Show message</button>

<script>
import { NotificationDisplay, notifier } from '@beyonk/svelte-notifications'

let themes = {
  myColour: '#ff00bb'
}

function someFunction () {
  notifier.send('myColour', 'Notifications work!')
}
</script>

Timeouts

You can set a default timeout:

<NotificationDisplay {timeout} />

<button on:click={someFunction}>Show message</button>

<script>
import { NotificationDisplay, notifier } from '@beyonk/svelte-notifications'

let timeout = 3000 // The default

function someFunction () {
  notifier.success('Notifications work!')
}
</script>
Custom timeout:

You can set a timeout per message

<NotificationDisplay />

<button on:click={someFunction}>Show message</button>

<script>
import { NotificationDisplay, notifier } from '@beyonk/svelte-notifications'

function someFunction () {
  notifier.success('Notifications work!', 5000) // built in theme
  notifier.send('custom-theme', 'Notifications work!', 5000) // custom theme
}
</script>

Credits

  • Original code by Antony Jones
  • Animation and performance improvements by jg.

主要指標

概覽
名稱與所有者beyonk-group/svelte-notifications
主編程語言Svelte
編程語言JavaScript (語言數: 3)
平台
許可證
所有者活动
創建於2018-11-23 01:01:14
推送於2025-02-26 10:39:34
最后一次提交2025-02-26 10:39:24
發布數26
最新版本名稱v4.3.0 (發布於 2025-02-26 10:39:24)
第一版名稱v0.1.0 (發布於 2018-11-23 10:43:48)
用户参与
星數319
關注者數3
派生數25
提交數85
已啟用問題?
問題數22
打開的問題數12
拉請求數14
打開的拉請求數10
關閉的拉請求數4
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?