-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(Toast): explain how a toast can be shown (#528)
* docs(Toast): explain how a toast can be shown Closes #519 * Update packages/main/src/webComponents/Toast/Toast.mdx Co-authored-by: Lukas Harbarth <lukas742@gmx.net> Co-authored-by: Lukas Harbarth <lukas742@gmx.net>
- Loading branch information
1 parent
80b6240
commit 1154b35
Showing
2 changed files
with
59 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Story, Props, Title, Subtitle, Description, Primary, Stories } from '@storybook/addon-docs/blocks'; | ||
|
||
<Title /> | ||
<Subtitle /> | ||
<Description /> | ||
<br /> | ||
|
||
## Show a toast | ||
The `Toast` component has an imperative API for getting displayed. It will not be displayed just because it is part of the DOM. | ||
In order to show the Toast, you have to get a reference to the `Toast` DOM element and call the `show`-method. | ||
You can either access the DOM element by using a React `ref` or work with IDs. | ||
|
||
**Example** | ||
```jsx | ||
export const MyComponentWithAToast() { | ||
const toast = useRef(); | ||
|
||
const showToast = () => { | ||
toast.current.show(); | ||
}; | ||
return ( | ||
<ThemeProvider> | ||
<Button onClick={showToast}>Show Toast</Button> | ||
<Toast ref={toast}>This is my Toast!</Toast> | ||
</ThemeProvider> | ||
); | ||
} | ||
``` | ||
<Story id="ui5-web-components-toast--generated-default-story"/> | ||
|
||
<Props /> |
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