toasted-notes

WebJar for toasted-notes

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

toasted-notes
Last Version

Last Version

3.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

toasted-notes
WebJar for toasted-notes
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/bmcmahen/toasted-notes

Download toasted-notes

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/toasted-notes/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>toasted-notes</artifactId>
    <version>3.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/toasted-notes/
implementation 'org.webjars.npm:toasted-notes:3.0.0'
// https://jarcasting.com/artifacts/org.webjars.npm/toasted-notes/
implementation ("org.webjars.npm:toasted-notes:3.0.0")
'org.webjars.npm:toasted-notes:jar:3.0.0'
<dependency org="org.webjars.npm" name="toasted-notes" rev="3.0.0">
  <artifact name="toasted-notes" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='toasted-notes', version='3.0.0')
)
libraryDependencies += "org.webjars.npm" % "toasted-notes" % "3.0.0"
[org.webjars.npm/toasted-notes "3.0.0"]

Dependencies

compile (3)

Group / Artifact Type Version
org.webjars.npm » reach__alert jar [0.1.2,0.2)
org.webjars.npm : types__react jar [16.8.10,17)
org.webjars.npm : types__react-dom jar [16.8.3,17)

Project Modules

There are no modules declared in this project.

Toasted-notes

npm package Tweet Follow on Twitter

A simple but flexible implementation of toast style notifications for React extracted from Sancho UI.

View the demo and documentation.

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

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.

// 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.

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.

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

License

MIT

Prior art

Way back, this was originally based on the wonderful implementation of notifications in evergreen.

Versions

Version
3.0.0