Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(notifications): add notify and NotificationsProvider #645

Merged
merged 1 commit into from
Oct 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .storybook/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const SORT_ORDER = {
"Getting Started",
"Design System",
"Responsive Design",
"Notifications",
"Contributing",
],
Recipes: [],
Expand Down
26 changes: 26 additions & 0 deletions docs/introduction/notifications.stories.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Meta } from "@storybook/addon-docs/blocks";

<Meta title="Introduction/Notifications" />

# Notifications

Notifications are an integral part of any application. Patches uses
[react-toastify](https://github.com/fkhadra/react-toastify) under the hood. We
reexport some parts of react-toastify and apply our own styling.

You need to wrap your application in a PatchesProvider, which you already should
have. Then you can use the `notify` object and dispatch notifications like so:

```
import { notify } from "@openpatch/patches"

notify.info("Info")
notify.warn("Warn")
notify.error("Error")
notify.success("Success")
```

If you want to overwrite the default behaviour of the Notifications, you can
pass an option object to the different functions. Take a look at the
[react-toastify Repository](https://fkhadra.github.io/react-toastify/api/toast)
for more information about that.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
"react-modal": "^3.12.1",
"react-syntax-highlighter": "^15.4.4",
"react-tabs": "^3.2.1",
"react-toastify": "^8.0.3",
"remark-gfm": "^1.0.0",
"styled-system": "^5.1.5"
},
Expand Down
37 changes: 37 additions & 0 deletions src/NotificationsProvider.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Meta } from "@storybook/react/types-6-0";
import { ButtonPrimary } from "./ButtonPrimary";
import { NotificationsProvider, notify } from "./NotificationsProvider";

export default {
title: "Components/NotificationsProvider",
component: NotificationsProvider,
argTypes: {},
} as Meta;

export const Info = () => {
const dispatch = () => {
notify.info("Info");
};
return <ButtonPrimary onClick={dispatch}>Dispatch</ButtonPrimary>;
};

export const Warn = () => {
const dispatch = () => {
notify.warn("Warn");
};
return <ButtonPrimary onClick={dispatch}>Dispatch</ButtonPrimary>;
};

export const Success = () => {
const dispatch = () => {
notify.success("Success");
};
return <ButtonPrimary onClick={dispatch}>Dispatch</ButtonPrimary>;
};

export const Error = () => {
const dispatch = () => {
notify.error("Error");
};
return <ButtonPrimary onClick={dispatch}>Dispatch</ButtonPrimary>;
};
Loading