Svelte Notifications

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

Github stars Tracking Chart

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.

Main metrics

Overview
Name With Ownerbeyonk-group/svelte-notifications
Primary LanguageSvelte
Program languageJavaScript (Language Count: 3)
Platform
License:
所有者活动
Created At2018-11-23 01:01:14
Pushed At2025-02-26 10:39:34
Last Commit At2025-02-26 10:39:24
Release Count26
Last Release Namev4.3.0 (Posted on 2025-02-26 10:39:24)
First Release Namev0.1.0 (Posted on 2018-11-23 10:43:48)
用户参与
Stargazers Count317
Watchers Count3
Fork Count25
Commits Count85
Has Issues Enabled
Issues Count22
Issue Open Count12
Pull Requests Count14
Pull Requests Open Count10
Pull Requests Close Count4
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private