-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(notifications): add notify and NotificationsProvider
Notifications can be dispatch by calling notify.info, notify.warn, notify.error or notify.success. The NotificationsProvider is already integrated into the PatchesProvider.
- Loading branch information
1 parent
7d189ac
commit ab0846a
Showing
13 changed files
with
774 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; | ||
}; |
Oops, something went wrong.