-
Notifications
You must be signed in to change notification settings - Fork 8
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
fix(pie-docs): DSW-2222 add toast provider docs #2104
Open
raoufswe
wants to merge
2
commits into
main
Choose a base branch
from
dsw-2222-toast-provider-docs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
139 changes: 139 additions & 0 deletions
139
apps/pie-docs/src/components/toast/toast-provider/code.md
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,139 @@ | ||||||
--- | ||||||
eleventyNavigation: | ||||||
key: Toast Provider | ||||||
parent: Toast | ||||||
order: 4 | ||||||
shouldShowContents: true | ||||||
eleventyComputed: | ||||||
props: "{% include './props.json' %}" | ||||||
events: "{% include './events.json' %}" | ||||||
--- | ||||||
|
||||||
## Overview | ||||||
|
||||||
<p> | ||||||
<a href="https://www.npmjs.com/@justeattakeaway/pie-toast-provider" style="text-decoration: none"> | ||||||
<img alt="GitHub Workflow Status" src="https://img.shields.io/npm/v/@justeattakeaway/pie-toast.svg?label=pie-toast-provider"> | ||||||
</a> | ||||||
|
||||||
<a href="https://www.npmjs.com/package/@justeattakeaway/pie-webc"> | ||||||
<img alt="GitHub Workflow Status" src="https://img.shields.io/npm/v/@justeattakeaway/pie-webc.svg?label=pie-webc"> | ||||||
</a> | ||||||
</p> | ||||||
|
||||||
`pie-toast-provider` is a Web Component built using [Lit](https://lit.dev/). It offers a simple and accessible toast provider component for web applications. | ||||||
|
||||||
This component can be easily integrated into various frontend frameworks and customised through a set of properties. | ||||||
|
||||||
The `pie-toast-provider` component provides centralized management for toast notifications in an application. It ensures that toasts are displayed in [priority order](/components/toast/#priority-queue) based on their variant and actionable state, using a queueing system. The component handles the lifecycle of each toast, including dismissing the current toast and showing the next one. | ||||||
|
||||||
{% notification { | ||||||
type: "information", | ||||||
iconName: "engineers", | ||||||
message: "You can try out this component on our [Storybook](https://webc.pie.design/?path=/docs/toast-provider) instance!" | ||||||
} %} | ||||||
|
||||||
## Installation | ||||||
|
||||||
To install `pie-toast-provider` in your application, run the following on your command line: | ||||||
|
||||||
```shell | ||||||
npm i @justeattakeaway/pie-webc | ||||||
``` | ||||||
|
||||||
```shell | ||||||
yarn add @justeattakeaway/pie-webc | ||||||
``` | ||||||
|
||||||
{% notification { | ||||||
type: "neutral", | ||||||
iconName: "link", | ||||||
message: "For more information on using PIE components as part of an application, check out the [Getting Started Guide](https://github.com/justeattakeaway/pie/wiki/Getting-started-with-PIE-Web-Components)." | ||||||
} %} | ||||||
|
||||||
## Props | ||||||
|
||||||
{% componentDetailsTable { | ||||||
tableData: props | ||||||
} %} | ||||||
|
||||||
## Events | ||||||
|
||||||
{% componentDetailsTable { | ||||||
tableData: events | ||||||
} %} | ||||||
|
||||||
## Examples | ||||||
|
||||||
The usage guideline is: | ||||||
|
||||||
- Place `pie-toast-provider` at the root level of your application or page. | ||||||
- Use the `toaster` utility from any where in your app to dynamically create toasts. | ||||||
|
||||||
### Importing the component | ||||||
|
||||||
For HTML: | ||||||
|
||||||
```js | ||||||
// import as module into a js file e.g. main.js | ||||||
import '@justeattakeaway/pie-webc/components/toast-provider.js' | ||||||
``` | ||||||
|
||||||
```html | ||||||
<!-- pass js file into <script> tag --> | ||||||
<pie-toast-provider></pie-toast-provider> | ||||||
<script type="module" src="/main.js"></script> | ||||||
``` | ||||||
|
||||||
For Native JS Applications, Vue, Angular, Svelte etc.: | ||||||
|
||||||
```js | ||||||
// Vue templates (using Nuxt 3) | ||||||
import '@justeattakeaway/pie-webc/components/toast-provider.js'; | ||||||
|
||||||
<pie-toast-provider></pie-toast-provider> | ||||||
``` | ||||||
|
||||||
For React Applications: | ||||||
|
||||||
```jsx | ||||||
import { PieToastProvider } from '@justeattakeaway/pie-webc/react/toast-provider.js'; | ||||||
|
||||||
<PieToastProvider></PieToastProvider> | ||||||
``` | ||||||
|
||||||
### Creating Toasts with `toaster` | ||||||
|
||||||
The `toaster` utility dynamically creates toasts. It can be imported and called from any file or component in your application. | ||||||
|
||||||
```js | ||||||
import { toaster } from '@justeattakeaway/pie-webc/components/toast-provider.js'; | ||||||
|
||||||
toaster.createToast({ | ||||||
message: 'This is a success toast!', | ||||||
variant: 'success', | ||||||
isDismissible: true, | ||||||
}); | ||||||
|
||||||
``` | ||||||
|
||||||
To clear all active and queued toasts: | ||||||
|
||||||
```js | ||||||
toaster.clearToasts(); | ||||||
|
||||||
``` | ||||||
|
||||||
{% notification { | ||||||
type: "neutral", | ||||||
iconName: "link", | ||||||
message: "For more examples, see [here](https://github.com/justeattakeaway/pie-aperture/tree/main)." | ||||||
} %} | ||||||
|
||||||
## Changelog | ||||||
|
||||||
{% notification { | ||||||
type: "neutral", | ||||||
iconName: "link", | ||||||
message: "See [here](https://github.com/justeattakeaway/pie/blob/main/packages/components/pie-toast/CHANGELOG.md)." | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Note this this URL doesn't currently exist as the component hasn't been published to npm yet, but the changelog.md will get generated in this location once that's been done 👍🏼 |
||||||
} %} |
15 changes: 15 additions & 0 deletions
15
apps/pie-docs/src/components/toast/toast-provider/events.json
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,15 @@ | ||
{ | ||
"headings": [ | ||
"Event", | ||
"Type", | ||
"Description" | ||
], | ||
"rows": [ | ||
[ | ||
"`pie-toast-provider-queue-update`", | ||
"`CustomEvent`", | ||
"Triggered when a toast is added or removed from the queue." | ||
] | ||
] | ||
} | ||
|
19 changes: 19 additions & 0 deletions
19
apps/pie-docs/src/components/toast/toast-provider/props.json
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,19 @@ | ||
{ | ||
"headings": ["Prop", "Options", "Description", "Default"], | ||
"rows": [ | ||
[ | ||
"options", | ||
{ | ||
"type": "code", | ||
"item": [["{}"]] | ||
}, | ||
"Default options for all toasts; accepts all toast props.", | ||
{ | ||
"type": "code", | ||
"item": [["{}"]] | ||
} | ||
] | ||
] | ||
} | ||
|
||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just my POV, but I think this reads a bit nicer 👍🏼