{"_id":"@boxfish-studio/svelte-notification-manager","name":"@boxfish-studio/svelte-notification-manager","dist-tags":{"latest":"0.1.0"},"versions":{"0.1.0":{"name":"@boxfish-studio/svelte-notification-manager","version":"0.1.0","type":"module","description":"Notification Manager for Svelte","author":{"name":"Boxfish Studio"},"license":"Apache-2.0","homepage":"https://github.com/boxfish-studio/notification-manager#readme","bugs":{"url":"https://github.com/boxfish-studio/notification-manager/issues"},"scripts":{"dev":"vite","package":"yarn package:copy && yarn package:build && yarn package:clean","package:copy":"mkdir package && cp -r ../shared src/lib/* package/","package:build":"IS_BUILDING_PACKAGE=true svelte-package -i package -o dist","package:clean":"rm -rf package","preview":"vite preview","check":"svelte-check --tsconfig ./tsconfig.json"},"exports":{".":{"types":"./dist/index.d.ts","svelte":"./dist/index.js"}},"types":"./dist/index.d.ts","peerDependencies":{"svelte":"^3.57.0"},"devDependencies":{"@sveltejs/adapter-auto":"^2.1.0","@sveltejs/package":"^2.0.2","@sveltejs/vite-plugin-svelte":"^2.0.3","@tsconfig/svelte":"^4.0.1","@types/node":"^20.2.4","svelte":"^3.57.0","svelte-check":"^2.10.3","svelte-preprocess":"^5.0.4","tslib":"^2.5.3","typescript":"^5.1.3","vite":"^4.3.9","vite-plugin-dts":"^2.3.0"},"gitHead":"2d83ea8e2597eeae902ab050c6d1d1712720fb80","_id":"@boxfish-studio/svelte-notification-manager@0.1.0","_nodeVersion":"16.20.0","_npmVersion":"8.19.4","dist":{"integrity":"sha512-T7UqiamUlu4wr8LdG87LSEndscTxyD0VCUFTp/oBFJcl82mbtj76NkNzNDQ9xWyqN3+u4TdiXKiER+WPwTtDag==","shasum":"83c2208469d1806c5233bcefb93dfa4bceb13f1a","tarball":"https://registry.npmjs.org/@boxfish-studio/svelte-notification-manager/-/svelte-notification-manager-0.1.0.tgz","fileCount":32,"unpackedSize":30528,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDYDMZEqhNlGxnXf9tI9BpEBeuFtUQ+gQe2EiG0rUTwpwIhAOzqBKbU5m9gJ0xpOPMN6AdrYEwVXEMDSW3Svioq55zt"}]},"_npmUser":{"name":"begonaalvarezd","email":"balvarez@boxfish.studio"},"directories":{},"maintainers":[{"name":"begonaalvarezd","email":"balvarez@boxfish.studio"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/svelte-notification-manager_0.1.0_1687948814319_0.6701959085422247"},"_hasShrinkwrap":false}},"time":{"created":"2023-06-28T10:40:14.262Z","0.1.0":"2023-06-28T10:40:14.608Z","modified":"2023-06-28T10:40:14.777Z"},"maintainers":[{"name":"begonaalvarezd","email":"balvarez@boxfish.studio"}],"description":"Notification Manager for Svelte","homepage":"https://github.com/boxfish-studio/notification-manager#readme","author":{"name":"Boxfish Studio"},"bugs":{"url":"https://github.com/boxfish-studio/notification-manager/issues"},"license":"Apache-2.0","readme":"## Installation 🧰\n\n```shell\n$ npm i @boxfish-studio/svelte-notification-manager\n```\n\nor yarn\n\n```shell\n$ yarn add @boxfish-studio/svelte-notification-manager\n```\n\n<br/>\n\n## How to use 📝\n\n1. Import the `NotificationManager` and place it in your layout:\n\n```svelte\n<script lang=\"ts\">\n    import { NotificationManager } from '@boxfish-studio/svelte-notification-manager'\n</script>\n\n// ...\n<NotificationManager />\n```\n\n<br/>\n\n2. Import `showNotification`:\n\n```svelte\n<script lang=\"ts\">\n    import { showNotification, type NotificationType } from '@boxfish-studio/svelte-notification-manager'\n\n    function addNotification() {\n        showNotification({\n            message: \"I'm a toast!\",\n            type: NotificationType.Info,\n            duration: 5000,\n        })\n    }\n</script>\n\n<button on:click={addNotification}>Click on me to show a notification!</button>\n```\n\n<br/>\n\n## Customization 🖌️\n\nThe `NotificationManager` component accepts a `configuration` prop to allow you to customize your notifications.\nCustom configuration must be of type `INotificationConfiguration`. All available props are shown below:\n\n```ts\ninterface INotificationConfiguration {\n    hasIcon?: boolean\n    icons?: {\n        [key in NotificationType]?: string\n    }\n}\n\nenum NotificationType {\n    Success = 'success',\n    Error = 'error',\n    Warning = 'warning',\n    Info = 'info',\n}\n```\n\n### NotificationManager Props\n\n| Name    | Description                                                               |\n| ------- | ------------------------------------------------------------------------- |\n| hasIcon | If the Notification should contain an icon                                |\n| icons   | An object with the notification type as key, and an image url as a value. |\n\nExample:\n\n```svelte\n<script lang=\"ts\">\n    import { NotificationManager, type INotificationConfiguration } from '@boxfish-studio/svelte-notification-manager'\n\n    // Optional configuration\n    const configuration: INotificationConfiguration = {\n        hasIcon: true,\n        icons: {\n            warning: '/custom-warning-icon.svg',\n        },\n    }\n</script>\n\n<NotificationManager {configuration} />\n```\n\n### Styling\n\nAll 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.\n\nExample:\n\n```scss\nul.notification-manager.notification-manager {\n    bottom: 2rem;\n    left: 2rem;\n    /* To remove the default right position */\n    right: initial;\n\n    .notification__toast {\n        border-radius: 8px;\n    }\n\n    .notification--warning {\n        background-color: #f58223;\n    }\n\n    .notification__message {\n        color: black;\n        font-size: 18px;\n        font-weight: 500;\n    }\n}\n```\n\n### Utility functions\n\nThis package exports functions to help with the management of your notifications:\n\n```svelte\n<script lang=\"ts\">\n    import { showNotification, removeNotification, updateNotification } from '@boxfish-studio/svelte-notification-manager'\n</script>\n```\n\n1. **showNotification**: Adds a notification to the store. Receives an object with the notification properties.\n\n```svelte\n<script lang=\"ts\">\n    showNotification({\n        message: \"I'm a toast!\",\n        type: NotificationType.Info,\n        duration: 5000, // Optional\n    })\n</script>\n```\n\n| Name     | type             | Description                                                                                            | Required |\n| -------- | ---------------- | ------------------------------------------------------------------------------------------------------ | -------- |\n| message  | string           | The message that will show up in the notification.                                                     | true     |\n| type     | NotificationType | The type of the notification. This will change then icon and classes in the notification.              | true     |\n| duration | number           | Duration in milliseconds that will last the toast until the user closes it. Use 0 to make it infinite. |          |\n\n2. **removeNotification**: Removes a notification from the store. Receives an id of the notification to remove.\n\n```svelte\n<script lang=\"ts\">\n    removeNotification(id)\n</script>\n```\n\n3. **updateNotification**: Updates a notification from the store. Receives an id of the notification to update, and an object with the notification properties to update.\n\n```svelte\n<script lang=\"ts\">\n    updateNotification(id, {\n        message: 'ERROR!',\n        type: NotificationType.Error,\n        duration: 0, // Doesn't close automatically.\n    })\n</script>\n```\n\n### Stores\n\nThis package also exports a store with an array of the active notifications. This is a writable store of type `INotification[]`.\nYou can use this array to manage your notifications whenever you want.\n\n```svelte\n<script lang=\"ts\">\n    import { notificationStore } from '@boxfish-studio/svelte-notification-manager'\n\n    $: notifications = $notificationStore\n</script>\n```\n\n```ts\ninterface INotification {\n    id: string\n    message: string\n    type: NotificationType\n    duration?: number\n}\n```\n\n<hr/>\n\n<div align=\"center\">\n\tMade with :heart: by [Boxfish Studio](https://boxfish.studio/). </br></br>\n\t<img src=\"https://avatars.githubusercontent.com/u/36508409?s=200&v=4\" alt=\"Boxfish Logo\" width=\"50\" height=\"50\"/>\n</div>\n","readmeFilename":"README.md"}