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

svelte-notifications-stack

v1.1.3

Published

Svelte component for displaying notifications in the application.

Downloads

24

Readme

#svelte-notifications-stack

Svelte component for displaying notifications in the application.

##Usage:

To use notifications-stack, you need to wrap a component that will be used to display notifications. For example, it can be a component that sends data to the server and receives a response, and depending on the response, we can show a notification. Or, you can wrap the entire application and use the notification wherever you need it.

####Default notifications:

Let's say this is your application - App.svelte:

<script>
  import Notifications from 'svelte-notifications-stack';
  import Header from './Header'
  import Pages from './Pages'
  import Footer from './Footer'
</script>
<Notifications maxCount={3}>
  <div>
    <Header />
    <Pages />
    <Footer />
  </div>
</Notifications>

And now we want to use basic notifications in our application in the Pages component - Pages.svelte:

<script>
  import {getContext} from 'svelte';
  import {CONTEXT_NAME} from 'svelte-notifications-stack';


  const {add, types} = getContext(CONTEXT_NAME);
  const handleAddDefaultNotification = (type) => {
    add({message: 'Message', type})
  };
</script>

<div>
  Main page
  <button on:click={()=>handleAddDefaultNotification(types.INFO)}>
    Show info notification
  </button>
</div>

In this example, we take the notification context and use the add method to add the notification:

import {CONTEXT_NAME} from 'svelte-notifications-stack';
const {add, types} = getContext(CONTEXT_NAME);
const handleAddDefaultNotification = (type) => {
  add({message: 'Message', type})
};

Image basic notifications

####Custom notifications:

Let's take the same application code as an example - App.svelte:

<script>
  import Notifications from 'svelte-notifications-stack';
  import Header from './Header'
  import Pages from './Pages'
  import Footer from './Footer'
</script>
<Notifications maxCount={3}>
  <div>
    <Header />
    <Pages />
    <Footer />
  </div>
</Notifications>

And let's create our custom notification:

<script>
  import {getContext} from 'svelte';
  import {CONTEXT_NAME} from 'svelte-notifications-stack';
  import CustomComponent from './CustomComponent';

  const {add} = getContext(CONTEXT_NAME);

  const handleAddCustomNotification = () => {
    add({
      component: CustomComponent, 
      componentProps: ({id})=>({
        id, 
        text: 'Custom text'
      })
    })
  };
</script>
<div>
  Main page
  <button on:click={handleAddCustomNotification}>
    Show custom notification
  </button>
</div>

And in our CustomComponent we receive props witch we passed in componentProps callback:

<script>
  import {getContext} from "svelte";
  import {CONTEXT_NAME} from "svelte-notifications-stack";

  export let id
  export let text
  const {close} = getContext(CONTEXT_NAME);
</script>

<div>
    <div>{text}</div>
    <div on:click={()=>close(id)}>close</div>
</div>

As you can see, we get id, text witch we passed in componentProps callback, and now we can close custom notification with close method from the context on:click={()=>close(id)}

###Notifications.svelte props

| Property | Values | |----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------| | maxCount | default: 5.type: number | | position | default: bottom_right.Place where notifications will be shown: type: top_left, top_right, top_center, bottom_left, bottom_right, bottom_center |

###Context methods and properties

| Property/Method | Arguments/Values | |-----------------|---------------------------------------------------------------------| | add | ({ message, component, componentProps, type, timeout, duration}) | | close | (id) | | updatePosition | (position) | | position | Current position where notifications will be shown | | positions | Object with a list of positions | | types | Object with a list of types |

Method add, takes {message, component, componentProps, type, timeout, duration}

Table explaining properties in add argument:

| Option | Value | |----------------|----------------------------------------------------------------------------------------| | message | string | | component | SvelteComponent | | componentProps | callback with params ({id: number, last: number, timeout: number, duration: number}) | | type | type of notification | | timeout | timeout after which the notification will disappear | | duration | appear transition duration |

Method close takes id for closing custom notification.

Method updatePosition for changing notifications appear position