|
| 1 | +# jupyterlab_toastify |
| 2 | + |
| 3 | +[](https://mybinder.org/v2/gh/fcollonval/jupyterlab_toastify/master?urlpath=lab) |
| 4 | +[](https://github.com/fcollonval/jupyterlab_toastify/actions?query=workflow%3ACI) |
| 5 | +[](https://www.npmjs.com/package/jupyterlab_toastify) |
| 6 | + |
| 7 | +Integrate [`react-toastify`](https://github.com/fkhadra/react-toastify) nicely in JupyterLab. |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | +## Usage |
| 12 | + |
| 13 | +```javascript |
| 14 | +import { INotification } from "jupyterlab_toastify"; |
| 15 | + |
| 16 | +// Error message notification - do not close automatically |
| 17 | +INotification.error("Error"); |
| 18 | +// Warning message notification - do not close automatically |
| 19 | +INotification.warning("Warning"); |
| 20 | +// Info message notification |
| 21 | +INotification.info("Info"); |
| 22 | +// Success message notification |
| 23 | +INotification.success("Success"); |
| 24 | + |
| 25 | +// Background task with progression animation |
| 26 | +let id = await INotification.inProgress("Task in progress!"); |
| 27 | +// -> Update text |
| 28 | +INotification.update({ |
| 29 | + toastId: id, |
| 30 | + message: "Updating task..." |
| 31 | +}); |
| 32 | +// -> Update text, status and set closing delay (in ms) |
| 33 | +INotification.update({ |
| 34 | + toastId: id, |
| 35 | + message: "Task succeed", |
| 36 | + type: "success", |
| 37 | + autoClose: 3000 |
| 38 | +}); |
| 39 | + |
| 40 | +// Notification with two buttons |
| 41 | +INotification.error("Error with button", { |
| 42 | + buttons: [ |
| 43 | + { |
| 44 | + label: "Action1", |
| 45 | + callback: () => alert("Action1 was clicked") |
| 46 | + }, |
| 47 | + { |
| 48 | + label: "Action2", |
| 49 | + callback: () => alert("Action2 was clicked") |
| 50 | + } |
| 51 | + ] |
| 52 | +}); |
| 53 | + |
| 54 | +// Close a toast specified by its id |
| 55 | +INotification.dismiss(id); |
| 56 | + |
| 57 | +// Close all toasts |
| 58 | +INotification.dismiss(); |
| 59 | + |
| 60 | +// Default call using `toast` function |
| 61 | +// See https://github.com/fkhadra/react-toastify |
| 62 | +INotification.notify("Default"); |
| 63 | +``` |
| 64 | + |
| 65 | +To close a notification, click on the close button. |
| 66 | + |
| 67 | +## Prerequisites |
| 68 | + |
| 69 | +- [react](https://reactjs.org/) ^16.0 || ^17.0 |
| 70 | +- [react-toastify](https://github.com/fkhadra/react-toastify) ^6.0 |
| 71 | + |
| 72 | +## Installation |
| 73 | + |
| 74 | +This is a pure NPM package since v4. You don't need to install a JupyterLab extension. |
| 75 | + |
| 76 | +The toast container will be added to the DOM automatically by `react-toastify`. |
| 77 | + |
| 78 | +> All functions are asynchronous as `react-toastify` is lazy loaded if required. |
| 79 | +
|
| 80 | +## Changelog |
| 81 | + |
| 82 | +### v4.1.1 |
| 83 | + |
| 84 | +- Bug fixes: |
| 85 | + - Remove dependency on `@jupyterlab/ui-components` |
| 86 | + |
| 87 | +### v4.1.0 |
| 88 | + |
| 89 | +- Features |
| 90 | + - Use SVG icons |
| 91 | + |
| 92 | +### v4.0.0 |
| 93 | + |
| 94 | +- Features |
| 95 | + - `react-toastify` v5 introduces the ability to add the toast container automatically. |
| 96 | + This extension uses that ability to remove the need of having a dedicated JupyterLab extension |
| 97 | + to be installed by users. |
| 98 | + - Lazy load `react-toastify` => all functions are asynchronous |
| 99 | + - Bump to `react-toastify` v6 |
| 100 | + |
| 101 | +### v3.0.0 |
| 102 | + |
| 103 | +Port to JupyterLab v2 |
| 104 | + |
| 105 | +### v2.3.1 |
| 106 | + |
| 107 | +- BUG `INotification.warning` does not accept options. |
| 108 | +- Respect latest extension cookiecutter parameters |
| 109 | + |
| 110 | +### v2.3.0 |
| 111 | + |
| 112 | +- Port to JupyterLab v1 |
| 113 | + |
| 114 | +### v2.2.0 |
| 115 | + |
| 116 | +- Different corrections |
| 117 | +- `buttons` optional in `update` |
| 118 | +- `dismiss` is visible through the `INotification` proxy |
| 119 | + |
| 120 | +### v2.1.0 |
| 121 | + |
| 122 | +- Update to JupyterLab 0.35 |
| 123 | +- Update to react-toastify 4.4 => change enum for notifications type to `react-toastify\TypeOptions` |
| 124 | + |
| 125 | +### v2.0.0 |
| 126 | + |
| 127 | +- API change: helper functions accept options in addition to the message |
| 128 | +- API change: `update` requires object as input and not a lot of arguments |
| 129 | +- New option `buttons` to add buttons with custom callback to the notification |
| 130 | + |
| 131 | +### v1.x |
| 132 | + |
| 133 | +- First version using `react-toastify` |
| 134 | +- Five scenarii: |
| 135 | + - Error |
| 136 | + - Warning |
| 137 | + - Info |
| 138 | + - Success |
| 139 | + - InProgress |
| 140 | + |
| 141 | +## Development |
| 142 | + |
| 143 | +For a development install (requires npm version 4 or later), do the following in the repository directory: |
| 144 | + |
| 145 | +```bash |
| 146 | +npm install |
| 147 | +npm run build |
| 148 | +jupyter labextension install . |
| 149 | +``` |
| 150 | + |
| 151 | +To rebuild the package and the JupyterLab app: |
| 152 | + |
| 153 | +```bash |
| 154 | +npm run build |
| 155 | +jupyter lab build |
| 156 | +``` |
0 commit comments