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)
用户参与
星数317
关注者数3
派生数25
提交数85
已启用问题?
问题数22
打开的问题数12
拉请求数14
打开的拉请求数10
关闭的拉请求数4
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?