-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat: Implement toast dismiss #27810
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
Merged
ling1726
merged 18 commits into
microsoft:master
from
ling1726:react-toast/feat/dismiss-toast
May 10, 2023
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
9e65c44
feat: Implement state management for toasts
ling1726 09e42f9
remove redundant import
ling1726 7e15b98
remove props
ling1726 0c9f61c
useToastFactory
ling1726 72d5cf1
review feedback
ling1726 aa53249
rename toast controls
ling1726 43664a5
don't create duplicate toasts
ling1726 56f4c84
make position styles vanilla
ling1726 686cac1
refactor Timer
ling1726 9c3566c
fix cruft
ling1726 815c30c
remove unnecessary callbacks
ling1726 d77f18c
stop leaking react
ling1726 ce1387c
update toaster
ling1726 8eed249
update useToaster
ling1726 6305979
update timer usage
ling1726 4a35e67
update timer usage
ling1726 9519939
Merge remote-tracking branch 'origin/master' into react-toast/feat/di…
ling1726 b8173d5
feat: Implement toast dismiss
ling1726 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| export { Toaster } from './components/Toaster'; | ||
|
|
||
| export { useToastController } from './state'; | ||
| export type { ToastPosition } from './state'; | ||
| export type { ToastPosition, ToastId } from './state'; |
This file contains hidden or 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 |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| export const EVENTS = { | ||
| show: 'fui-toast-show', | ||
| dismiss: 'fui-toast-dismiss', | ||
| } as const; |
This file contains hidden or 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 hidden or 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
11 changes: 11 additions & 0 deletions
11
packages/react-components/react-toast/src/state/vanilla/dismissToast.ts
This file contains hidden or 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,11 @@ | ||
| import { EVENTS } from '../constants'; | ||
| import { DismissToastEventDetail, ToastId } from '../types'; | ||
|
|
||
| export function dismissToast(toastId: ToastId | undefined = undefined, targetDocument: Document) { | ||
| const event = new CustomEvent<DismissToastEventDetail>(EVENTS.dismiss, { | ||
| bubbles: false, | ||
| cancelable: false, | ||
| detail: { toastId }, | ||
| }); | ||
| targetDocument.dispatchEvent(event); | ||
| } |
This file contains hidden or 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
1 change: 1 addition & 0 deletions
1
packages/react-components/react-toast/src/state/vanilla/index.ts
This file contains hidden or 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 |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| export * from './dispatchToast'; | ||
| export * from './dismissToast'; | ||
| export * from './toast'; | ||
| export * from './toaster'; | ||
| export * from './getPositionStyles'; |
This file contains hidden or 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
15 changes: 15 additions & 0 deletions
15
packages/react-components/react-toast/stories/Toast/DismissAll.stories.tsx
This file contains hidden or 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 @@ | ||
| import * as React from 'react'; | ||
| import { Toaster, useToastController } from '@fluentui/react-toast'; | ||
|
|
||
| export const DismissAll = () => { | ||
| const { dispatchToast, dismissToast } = useToastController(); | ||
| const notify = () => dispatchToast('This is a toast'); | ||
|
|
||
| return ( | ||
| <> | ||
| <Toaster /> | ||
| <button onClick={() => notify()}>Make toast</button> | ||
| <button onClick={() => dismissToast()}>Dismiss all</button> | ||
| </> | ||
| ); | ||
| }; |
15 changes: 15 additions & 0 deletions
15
packages/react-components/react-toast/stories/Toast/DismissToast.stories.tsx
This file contains hidden or 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 @@ | ||
| import * as React from 'react'; | ||
| import { Toaster, useToastController, ToastId } from '@fluentui/react-toast'; | ||
|
|
||
| export const DismissToast = () => { | ||
| const { dispatchToast, dismissToast } = useToastController(); | ||
| const notify = (id: ToastId) => dispatchToast('This is a toast', { toastId: id }); | ||
|
|
||
| return ( | ||
| <> | ||
| <Toaster /> | ||
| <button onClick={() => notify('example')}>Make toast</button> | ||
| <button onClick={() => dismissToast('example')}>Dismiss all</button> | ||
| </> | ||
| ); | ||
| }; |
2 changes: 2 additions & 0 deletions
2
packages/react-components/react-toast/stories/Toast/index.stories.tsx
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.