• Stars
    star
    309
  • Rank 135,306 (Top 3 %)
  • Language Svelte
  • Created about 6 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Svelte toast notifications component that can be used in any JS application

Beyonk

Svelte Notifications

js-standard-style Svelte v3

Svelte Notifications component

  • Uses SvelteKit 🎉
  • v3 compatible
  • Uses stores for completely hassle free operation
  • Can persist across full page reloads!

Demo

A Demo of this component is available.

Alternatively, check the project out from github and npm run dev.

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:

const options = {
  timeout: 3000, // milliseconds
  persist: false, // automatic timeout (ignores above)
  showProgess: true, // Show (or Hide) the progress bar
  icon: null // Add svelte component to render an icon
}

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

Persisting across apps

Your notifications can persist across multiple apps / page reloads, as long as they use this library. This is useful for a scenario where you show a notification and then redirect the browser to a different application, or trigger a full reload of the page.

This is completely automatic and uses session storage.

To ensure that notifications don't persist across apps where they should not, set the sessionKey attribute to something unique to each app.

<NotificationDisplay sessionKey="foo" />

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!', { timeout: 5000 }) // built in theme
  notifier.send('custom-theme', 'Notifications work!', { timeout: 5000 }) // custom theme
}
</script>
Show Progress:

You can show or hide the progress bar per message

<NotificationDisplay />

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

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

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

You can make a message persist and never timeout, having a close button that the user can click to remove it.

<NotificationDisplay />

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

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

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

You can include custom svelte components to render icons (or anything).

<NotificationDisplay />

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

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

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

// Icon.svelte

<svg width="1em" height="1em" viewBox="0 0 36 36">
  <path
    fill="currentColor"
    d="M18 34a16 16 0 1 1 16-16a16 16 0 0 1-16 16Zm0-30a14 14 0 1 0 14 14A14 14 0 0 0 18 4Z"
  </path>
</svg>

Credits

More Repositories

1

svelte-mapbox

MapBox Map and Autocomplete components for Svelte (or Vanilla JS)
Svelte
342
star
2

gdpr-cookie-consent-banner

A GDPR compliant cookie consent banner implementation
Svelte
250
star
3

svelte-carousel

A super lightweight, super simple Carousel for Svelte 3
Svelte
213
star
4

svelte-social-auth

Social Auth for Svelte v3
Svelte
169
star
5

svelte-datepicker

A lightweight datepicker written in Svelte
Svelte
141
star
6

sapper-rbac

RBAC for Sapper
JavaScript
81
star
7

svelte-googlemaps

Svelte Google Maps Components
Svelte
79
star
8

svelte-google-analytics

Google Analytics component for Svelte
JavaScript
77
star
9

http

An isomorphic http client for Svelte applications
JavaScript
45
star
10

svelte-scrollspy

Scroll Spy component for Svelte
JavaScript
38
star
11

now-sapper-demo

Now v2 (Serverless) Sapper Application
JavaScript
23
star
12

svelte-facebook-pixel

A facebook pixel module for Svelte / SvelteKit
Svelte
22
star
13

svelte-toggle

Toggle component for Svelte
Svelte
22
star
14

async-script-loader

Asynchronous script loading for SPAs
JavaScript
17
star
15

svelte-steps

Progress Steps component for Svelte
Svelte
17
star
16

svelte-component-livereload-template

Svelte component template with LiveReload and Jest unit testing
JavaScript
14
star
17

svelte-simple-icons

Simple Brand Icons for Svelte
JavaScript
13
star
18

svelte-tag-input

A super simple, extremely lightweight tag input for Svelte and Vanilla JS
CSS
8
star
19

reorient

Transforms json from one format into another
JavaScript
7
star
20

now-v2-ghost

Experiment trying to get ghost to run on now's v2 platform
CSS
7
star
21

svelte-facebook-customer-chat

Facebook Messaging Platform - Customer Chat Integration
HTML
6
star
22

svelte-scheduler

Scheduling and Calendaring component for Svelte
JavaScript
5
star
23

svelte-trustpilot

Svelte / Vanilla JS Trustpilot Widget with proper SPA support
Svelte
4
star
24

pino-logtail

Pino Logtail log transport
JavaScript
3
star
25

svelte-slim-select

A thin svelte wrapper around slim-select
HTML
3
star
26

svelte-favicons

A favicons generator for your web application.
HTML
3
star
27

initials-avatar

Create avatars from user initials in pure javascript
JavaScript
3
star
28

marker-clusterer-ssr

An SSR compatible implementation of Google Maps MarkerClusterer
JavaScript
2
star
29

svelte-intercom

Intercom for Svelte or Vanilla JS Apps
JavaScript
2
star
30

hapi-view-models

View model support for hapi
JavaScript
2
star
31

blemish

Super simplistic markdown parser
JavaScript
2
star
32

promise-retry

Retryable promises for node and the browser
JavaScript
1
star
33

sanity-template-sveltekit-basic

Empty Sanity SvelteKit Template
JavaScript
1
star
34

svelte-usetiful

Single tag Usetiful integration for Svelte
Svelte
1
star