import * as React from "react"; import * as System from "~/components/system"; import * as Constants from "~/common/constants"; import Group from "~/components/system/Group"; import SystemPage from "~/components/system/SystemPage"; import ViewSourceLink from "~/components/system/ViewSourceLink"; import CodeBlock from "~/components/system/CodeBlock"; export default class SystemPageNotifications extends React.Component { state = { count: 0, }; _handleCreate = (detail) => { System.dispatchCustomEvent({ name: "create-notification", detail: detail }); this.setState({ count: this.state.count + 1 }); }; _handleDelete = () => { System.dispatchCustomEvent({ name: "delete-notification", detail: {} }); }; render() { return ( Notifications

The Notification component is used to alert a user of new information.


Imports

Import React and the Notification Component, as well as the dispatchCustomEvent function.
{`import * as React from "react"; import { GlobalNotification, dispatchCustomEvent } from "slate-react-system";`}


Usage

Declare the component at the root level of your document (e.g. in index.js or App.js) so it is accessible throughout and will not get buried in the DOM tree.
Use style to specify placement of the fixed positioning notification list. Default is bottom right.
{`class App extends React.Component { render() { return ( {this.props.children} ); } }`}


Notification

this._handleCreate({ id: this.state.count, description: "This is a regular notification", }) } > Click for notification
this._handleCreate({ id: this.state.count, description: "This is a dark notification", dark: true, }) } > Click for dark style notification
Click to clear notifications
A notification will only appear once you trigger it by creating a custom event with the title{" "} "create-notification". It can be removed with a custom event entitled{" "} "delete-notification".
Multiple stacked notifications can be created using a single Notification component.{" "} Each co-existing notification must have a unique id.
{`class ExampleOne extends React.Component { state = { count: 0, }; _handleCreate = (detail) => { dispatchCustomEvent({ name: "create-notification", detail: detail }); this.setState({ count: this.state.count + 1 }); }; _handleDelete = () => { dispatchCustomEvent({ name: "delete-notification", detail: {} }); }; render() { return ( this._handleCreate({ id: this.state.count, description: "This is notification number " + this.state.count, }) } > Click for notification
this._handleCreate({ id: this.state.count, description: "This is a dark notification", dark: true, }) } > Click for dark style notification Click to clear notifications
); } }`}



Notification with timeout

this._handleCreate({ id: this.state.count, description: "This disappears after 5 seconds", timeout: 5000, }) } > Click for disappearing notification
Click to clear notifications
You can declare the Notification component with a{" "} timeout (in milliseconds) after which it will automatically disappear.
{`class ExampleTwo extends React.Component { state = { count: 0, }; _handleCreate = (detail) => { dispatchCustomEvent({ name: "create-notification", detail: detail }); this.setState({ count: this.state.count + 1 }); }; render() { return ( this._handleCreate({ id: this.state.count, description: "This disappears after 5 seconds", timeout: 5000, }) } > Click for disappearing notification Click to clear notifications ); } }`}


Notification with status

this._handleCreate({ id: this.state.count, description: "This is an info notification", status: "INFO", }) } > Click for info style notification
this._handleCreate({ id: this.state.count, description: "This is a success notification", status: "SUCCESS", }) } > Click for success style notification
this._handleCreate({ id: this.state.count, description: "This is a warning notification", status: "WARNING", }) } > Click for warning style notification
this._handleCreate({ id: this.state.count, description: "This is an error notification", status: "ERROR", }) } > Click for error style notification
Click to clear notifications

Declare the Notification component with a{" "} status to style it accordingly. This is overridden if dark is set to true.
{`class ExampleThree extends React.Component { state = { count: 0, }; _handleCreate = (detail) => { dispatchCustomEvent({ name: "create-notification", detail: detail }); this.setState({ count: this.state.count + 1 }); }; _handleDelete = () => { dispatchCustomEvent({ name: "delete-notification", detail: {} }); }; render() { return ( this._handleCreate({ id: this.state.count, description: "This is an info notification", status: "INFO", }) } > Click for info style notification this._handleCreate({ id: this.state.count, description: "This is a success notification", status: "SUCCESS", }) } > Click for success style notification this._handleCreate({ id: this.state.count, description: "This is a warning notification", status: "WARNING", }) } > Click for warning style notification this._handleCreate({ id: this.state.count, description: "This is an error notification", status: "ERROR", }) } > Click for error style notification Click to clear notifications ); } }`}

Accepted React Properties




Accepted Create Notification Properties

Note that these properties are passed through a custom event rather than as react properties.
id ), b: ["string", "number"], c: "null", d: "Notification id, must be unique for simultaneously existing notifications", }, { id: 2, a: "status", b: "string", c: "null", d: "Status which determines the styling and color of the notification. Use INFO, SUCCESS, WARNING, or ERROR", }, { id: 3, a: "timeout", b: "int", c: "null", d: "Number of milliseconds before the notification automatically disappears", }, { id: 4, a: "label", b: "string", c: "null", d: "Label text", }, { id: 5, a: "description", b: "string", c: "null", d: "Description text", }, ], }} />
); } }