npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@aircss/svelte-toast

v2.0.2

Published

All the necessary stuff to create toast notifications.

Downloads

6

Readme

svelte-toast

svelte-toast provides all the necessary stuff to create toast notifications.

A toast is a simple feedback message. It only fills the required amount of space and the current activity remains visible and interactive. Toasts automatically disappear after a timeout.

The Toast component

The Toast component is a container holding all the active toasts notifications. It comes with a default styling and a default toast template making it usable out-of-the-box.

<script lang="ts">
	import Toast from '@aircss/svelte-toast';
</script>

<div class="absolute top right w-100 w6-m ma4">
	<Toast />
</div>

Props

  • class: set custom classes for the toast container element (optional, default: "flex column")
  • timeout: default timeout of a toast in ms (optional, default: 5000)

Slot

It is possible to override the default template of a toast by declaring a new template as a child of the Toast element. The values of each toast are exposed through the toast property:

<script lang="ts">
	import Toast from '@aircss/svelte-toast';
</script>

<div class="absolute top right w-100 w6-m ma4">
	<Toast let:toast>
		<div class="w-100 w6-m pa3 bt4 ba bg--white">
			<h1 class="ma0 f-subtitle">{toast.title}</h1>
			<p class="lh-body tj overflow-hidden">
				{toast.message}
			</p>
		</div>
	</Toast>
</div>

The toast API

Creating a new toast only requires to call the send() method of the toast API:

<script lang="ts">
	import { toast } from '@aircss/svelte-toast';
	import Toast from '@aircss/svelte-toast';

	function show() {
		toast.send({
			title: 'Hello world!',
			message: 'This is a simple Svelte X Air CSS toast notification.'
		});
	}
</script>

<div class="absolute top right w-100 w6-m ma4">
	<Toast />
</div>

<button on:click={show}>Show toast</button>

The send() message expect an object as param complying to the Toast interface. The minimal toast bears a little to no data. However, developers should add as much of properties as pleased. Reserved properties are as follow:

  • id: unique identifier of the toast notification (automatically generated)

  • index: rank index of each toast starting with 0 for the least recent one (automatically generated)

  • timestamp: creation time of the toast (automatically generated)

  • dismiss: function to dismiss the toast (automatically generated)

  • timeout: timeout of the toast in ms (optional, default: global timeout)

  • title: title of the toast (optional)

  • message: message of the toast (optional)

  • template: use a Svelte component as a template for the toast (optional)

Svelte components as toast templates

As mentionned in the previous paragraph, the send() method accepts svelte components as templates for toasts. The component only requires a mandatory toast prop compliant with the Toast interface to work:

<script lang="ts">
	export let toast: Toast;
</script>

<div class="w-100 w6-m pa3 bt4 ba bg--white">
	<h1 class="ma0 f-subtitle">{toast.title}</h1>
	<p class="lh-body tj overflow-hidden">
		{toast.message}
	</p>
</div>

The following example shows how to use this component as a toast template:

<script lang="ts">
	import { toast } from '@aircss/svelte-toast';
	import Toast from '@aircss/svelte-toast';

	import MyTemplate from './my-component.svelte';

	function show() {
		toast.send({
			title: 'Hello world!',
			message: 'This is a simple Svelte X Air CSS toast notification.',
			template: MyTemplate
		});
	}
</script>

<div class="absolute top right w-100 w6-m ma4">
	<Toast />
</div>

<button on:click={show}>Show toast</button>