|
| 1 | +<h1 align="center">react-notifications</h1> |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | +<p align="center">:atom: react notifications made easy.</p> |
| 6 | + |
| 7 | +### Why ⁉️ |
| 8 | + |
| 9 | +Why another react notification system ? Why not, this project appears from the need to have an easy and very customizable react library, and more important, to be a project who everyone can contribute to improve it. |
| 10 | + |
| 11 | +Make your pull request with your ideas. 🧙♂️ |
| 12 | + |
| 13 | +### Features 😎 |
| 14 | + |
| 15 | +- Fast and simple to use. |
| 16 | +- Custom Notification component. |
| 17 | +- Easy customization. |
| 18 | +- Multiple notifications type. |
| 19 | +- Multiple animations. (**WIP**) |
| 20 | + |
| 21 | +## Documentation 🔗 |
| 22 | + |
| 23 | +Go to [Documentation](https://react-easy-notifications.vercel.app/) to look more features and functionalities. |
| 24 | + |
| 25 | +visit the npm package [npm package](https://www.npmjs.com/package/doom-react-notifications) |
| 26 | + |
| 27 | +### Installation 🐚 |
| 28 | + |
| 29 | +First install the library you can use the package manager what you like. |
| 30 | + |
| 31 | +```bash |
| 32 | +$ npm i doom-react-notifications |
| 33 | +$ pnpm i doom-react-notifications |
| 34 | +$ yarn add doom-react-notifications |
| 35 | +``` |
| 36 | + |
| 37 | +### Usage 📖 |
| 38 | + |
| 39 | +First you need to know the notification object, have basic properties to manage the notification. |
| 40 | + |
| 41 | +```jsx |
| 42 | +const notification = { |
| 43 | + type: "success", // type of the notification (success, danger, error, info...) |
| 44 | + title: "Title of the notification", |
| 45 | + message: "body message of the notification", |
| 46 | +}; |
| 47 | +``` |
| 48 | + |
| 49 | +To start using the library you only need to envolve your notification space in the component `<NotificationProvier />`, then you can use the hook `useNotification`, the example below show you a simple case of use. |
| 50 | + |
| 51 | +```jsx |
| 52 | +import { |
| 53 | + NotificationProvider, |
| 54 | + NotificationConsumer, |
| 55 | +} from "doom-react-notifications"; |
| 56 | +import { Button } from "./components/Button"; |
| 57 | +import "doom-react-notifications/dist/style.css"; // you can change the styles. |
| 58 | + |
| 59 | +export default function App() { |
| 60 | + return ( |
| 61 | + <NotificationProvider> |
| 62 | + <Button /> |
| 63 | + <NotificationConsumer /> |
| 64 | + </NotificationProvider> |
| 65 | + ); |
| 66 | +} |
| 67 | +``` |
| 68 | + |
| 69 | +And then trigger the notification with the hook provided for the library. |
| 70 | + |
| 71 | +```jsx |
| 72 | +import {useNotification} from "doom-react-notifications"; |
| 73 | + |
| 74 | +export function Button () { |
| 75 | + const { showNotification } = useNotification(); |
| 76 | + |
| 77 | + const handleClick = () => { |
| 78 | + showNotification({ |
| 79 | + ... |
| 80 | + }); |
| 81 | + } |
| 82 | + |
| 83 | + return ( |
| 84 | + <button onClick={handleClick}> |
| 85 | + Show Notification |
| 86 | + </button> |
| 87 | + ) |
| 88 | +} |
| 89 | +``` |
| 90 | + |
| 91 | +#### Custom Notification Component 💅 |
| 92 | + |
| 93 | +You can create your own notification component with your custom structure and styles, to use it pass the custom component as Custom prop to `<NotificationProvider />`, as show below. |
| 94 | + |
| 95 | +```jsx |
| 96 | +// Create a component that is given all the necessary properties for the notification as a props. |
| 97 | +const CustomNotification = ({ type, message, onClick }) => { |
| 98 | + return ( |
| 99 | + <div onClick={onClick} style={{ borderStyle: "dashed" }}> |
| 100 | + <p className="notification-title">{title}</p> |
| 101 | + <p className="notification-message">{message} with custom skeleton</p> |
| 102 | + </div> |
| 103 | + ); |
| 104 | +}; |
| 105 | + |
| 106 | +// Then pass the component as Custom prop. |
| 107 | +export default function App() { |
| 108 | + return ( |
| 109 | + <NotificationProvider> |
| 110 | + <Button /> |
| 111 | + <NotificationConsumer Custom={CustomNotification} /> |
| 112 | + </NotificationProvider> |
| 113 | + ); |
| 114 | +} |
| 115 | +``` |
| 116 | + |
| 117 | +### Contributing ❤️ |
| 118 | + |
| 119 | +To make a contribution, open a pull request, i be glad to read and share ideas of how improve this project. |
0 commit comments