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

@boxfish-studio/svelte-notification-manager

v0.1.0

Published

Notification Manager for Svelte

Downloads

7

Readme

Installation 🧰

$ npm i @boxfish-studio/svelte-notification-manager

or yarn

$ yarn add @boxfish-studio/svelte-notification-manager

How to use 📝

  1. Import the NotificationManager and place it in your layout:
<script lang="ts">
    import { NotificationManager } from '@boxfish-studio/svelte-notification-manager'
</script>

// ...
<NotificationManager />
  1. Import showNotification:
<script lang="ts">
    import { showNotification, type NotificationType } from '@boxfish-studio/svelte-notification-manager'

    function addNotification() {
        showNotification({
            message: "I'm a toast!",
            type: NotificationType.Info,
            duration: 5000,
        })
    }
</script>

<button on:click={addNotification}>Click on me to show a notification!</button>

Customization 🖌️

The NotificationManager component accepts a configuration prop to allow you to customize your notifications. Custom configuration must be of type INotificationConfiguration. All available props are shown below:

interface INotificationConfiguration {
    hasIcon?: boolean
    icons?: {
        [key in NotificationType]?: string
    }
}

enum NotificationType {
    Success = 'success',
    Error = 'error',
    Warning = 'warning',
    Info = 'info',
}

NotificationManager Props

| Name | Description | | ------- | ------------------------------------------------------------------------- | | hasIcon | If the Notification should contain an icon | | icons | An object with the notification type as key, and an image url as a value. |

Example:

<script lang="ts">
    import { NotificationManager, type INotificationConfiguration } from '@boxfish-studio/svelte-notification-manager'

    // Optional configuration
    const configuration: INotificationConfiguration = {
        hasIcon: true,
        icons: {
            warning: '/custom-warning-icon.svg',
        },
    }
</script>

<NotificationManager {configuration} />

Styling

All the elements in the components contain classes that you can point to in your styles to customize the appearance of the notifications, just override the styles in your global css file.

Example:

ul.notification-manager.notification-manager {
    bottom: 2rem;
    left: 2rem;
    /* To remove the default right position */
    right: initial;

    .notification__toast {
        border-radius: 8px;
    }

    .notification--warning {
        background-color: #f58223;
    }

    .notification__message {
        color: black;
        font-size: 18px;
        font-weight: 500;
    }
}

Utility functions

This package exports functions to help with the management of your notifications:

<script lang="ts">
    import { showNotification, removeNotification, updateNotification } from '@boxfish-studio/svelte-notification-manager'
</script>
  1. showNotification: Adds a notification to the store. Receives an object with the notification properties.
<script lang="ts">
    showNotification({
        message: "I'm a toast!",
        type: NotificationType.Info,
        duration: 5000, // Optional
    })
</script>

| Name | type | Description | Required | | -------- | ---------------- | ------------------------------------------------------------------------------------------------------ | -------- | | message | string | The message that will show up in the notification. | true | | type | NotificationType | The type of the notification. This will change then icon and classes in the notification. | true | | duration | number | Duration in milliseconds that will last the toast until the user closes it. Use 0 to make it infinite. | |

  1. removeNotification: Removes a notification from the store. Receives an id of the notification to remove.
<script lang="ts">
    removeNotification(id)
</script>
  1. updateNotification: Updates a notification from the store. Receives an id of the notification to update, and an object with the notification properties to update.
<script lang="ts">
    updateNotification(id, {
        message: 'ERROR!',
        type: NotificationType.Error,
        duration: 0, // Doesn't close automatically.
    })
</script>

Stores

This package also exports a store with an array of the active notifications. This is a writable store of type INotification[]. You can use this array to manage your notifications whenever you want.

<script lang="ts">
    import { notificationStore } from '@boxfish-studio/svelte-notification-manager'

    $: notifications = $notificationStore
</script>
interface INotification {
    id: string
    message: string
    type: NotificationType
    duration?: number
}