# toasted-notes

> Flexible, easy to implement toast notifications for react

Latest version **3.2.0** (published 2019-12-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install toasted-notes
pnpm add toasted-notes
yarn add toasted-notes
bun add toasted-notes
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.2.0 |
| Published | 2019-12-24 |
| First published | 2018-06-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 71.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Ben McMahen |
| Maintainers | bmcmahen |
| Keywords | react-component, toast, notifications |

## Links

- npm: https://www.npmjs.com/package/toasted-notes
- Homepage: https://github.com/bmcmahen/toasted-notes
- npm.io page: https://npm.io/package/toasted-notes

## Dependencies (3)

- [@reach/alert](https://npm.io/package/@reach/alert.md) ^0.1.2
- [@types/react](https://npm.io/package/@types/react.md) ^16.8.10
- [@types/react-dom](https://npm.io/package/@types/react-dom.md) ^16.8.3

## Alternatives

- [update-check](https://npm.io/package/update-check.md) — 4.0M weekly downloads
- [react-native-onesignal](https://npm.io/package/react-native-onesignal.md) — 134.5K weekly downloads
- [react-redux-toastr](https://npm.io/package/react-redux-toastr.md) — 33.7K weekly downloads
- [@nocobase/plugin-notification-manager](https://npm.io/package/@nocobase/plugin-notification-manager.md) — 2.0K weekly downloads
- [react-simple-toasts](https://npm.io/package/react-simple-toasts.md) — 1.9K weekly downloads

## Recent versions

- 3.2.0 (latest) — 2019-12-24
- 3.0.0 — 2019-08-30
- 2.1.6 — 2019-06-14
- 2.1.5 — 2019-04-02
- 2.1.4 — 2019-03-30
- 2.1.3 — 2019-03-29
- 2.1.2 — 2019-03-29
- 2.1.1 — 2019-03-29
- 2.0.3 — 2019-02-21
- 2.0.2 — 2019-02-20
- 2.0.1 — 2019-02-20
- 2.0.0 — 2019-02-20
- 1.1.0 — 2018-08-17
- 1.0.1 — 2018-07-24
- 1.0.0 — 2018-06-13

## README

<div align="center">
    
# Toasted-notes
  
[![npm package](https://img.shields.io/npm/v/toasted-notes/latest.svg)](https://www.npmjs.com/package/toasted-notes)
[![Tweet](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](https://twitter.com/intent/tweet?text=toasted%20notes%20is%20a%20react%20library%20for%20creating%20simple%2C%20flexible%20toast%20notifications.&url=https://github.com/bmcmahen/toasted-notes&hashtags=react,javascript)
[![Follow on Twitter](https://img.shields.io/twitter/follow/benmcmahen.svg?style=social&logo=twitter)](
https://twitter.com/intent/follow?screen_name=benmcmahen
)

</div>

A simple but flexible implementation of toast style notifications for React extracted from [Sancho UI](https://github.com/bmcmahen/sancho).

[View the demo and documentation](https://toasted-notes.netlify.com/).

## Features

- **An imperative API.** This means that you don't need to set component state or render elements to trigger notifications. Instead, just call a function.
- **Render whatever you want.** Utilize the render callback to create entirely custom notifications.
- **Functional default styles.** Import the provided css for some nice styling defaults or write your own styles.

## Install

Install `toasted-notes` and its peer dependency, `react-spring`, using yarn or npm.

```
yarn add toasted-notes react-spring
```

## Example

```jsx
import toaster from "toasted-notes";
import "toasted-notes/src/styles.css"; // optional styles

const HelloWorld = () => (
  <button
    onClick={() => {
      toaster.notify("Hello world", {
        duration: 2000
      });
    }}
  >
    Say hello
  </button>
);
```

## API

The notify function accepts either a string, a react node, or a render callback.

```jsx
// using a string
toaster.notify("With a simple string");

// using jsx
toaster.notify(<div>Hi there</div>);

// using a render callback
toaster.notify(({ onClose }) => (
  <div>
    <span>My custom toaster</span>
    <button onClick={onClose}>Close me please</button>
  </div>
));
```

It also accepts options.

```javascript
toaster.notify("Hello world", {
  position: "bottom-left", // top-left, top, top-right, bottom-left, bottom, bottom-right
  duration: null // This notification will not automatically close
});
```

## Using Context

One downside to the current API is that render callbacks and custom nodes won't get access to any application context, such as theming variables provided by styled-components. To ensure that render callbacks have access to the necessary context, you'll need to supply that context to the callback.

```jsx
const CustomNotification = ({ title }) => {
  const theme = useTheme();
  return <div style={{ color: theme.primary }}>{title}</div>;
};

const CustomNotificationWithTheme = withTheme(CustomNotification);

toaster.notify(() => <CustomNotificationWithTheme title="I am pretty" />);
```

## Contributors

- [Einar Löve](https://github.com/einarlove)

## License

MIT

## Prior art

Way back, this was originally based on the wonderful implementation of notifications in [evergreen](https://evergreen.segment.com).

---
_Source: https://npm.io/package/toasted-notes · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
