Skip to content
This repository was archived by the owner on Mar 25, 2025. It is now read-only.

Commit 9df16ff

Browse files
lekoafTigge
authored andcommitted
docs: add avanced toasts example
Shows a basic example of how you can create a toaster from scratch.
1 parent 0c99303 commit 9df16ff

File tree

1 file changed

+37
-1
lines changed
  • packages/docs/src/mdx/coreComponents

1 file changed

+37
-1
lines changed

packages/docs/src/mdx/coreComponents/Toast.mdx

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ const MyComponent = () => {
249249
onClose: id => {
250250
console.log('Dismissed toast with ID: %o', id)
251251
},
252-
}
252+
})
253253
}, [])
254254

255255
return (
@@ -262,6 +262,42 @@ const MyComponent = () => {
262262
}
263263
```
264264

265+
## Advanced usage
266+
267+
Not happy with the defaults we've provided? Don't fret. You can create a toast from scratch
268+
as well if you want to.
269+
270+
```typescript
271+
import React, { useCallback } from 'react'
272+
import { useToasts, Button } from 'practical-react-components-core'
273+
274+
const MyComponent = () => {
275+
const { showToast } = useToasts()
276+
277+
const showAdvancedToaster = useCallback(() => {
278+
showToast({
279+
icon: <Icon icon={HomeIcon} />,
280+
label: <Typography>Toast label</Typography>,
281+
message: <Typography>Toast message</Typography>,
282+
// Shows an X the user can click to dismiss the toaster
283+
hasCloseButton: true,
284+
duration: 10000,
285+
onClose: id => {
286+
console.log('Dismissed toast with ID: %o', id)
287+
},
288+
})
289+
}, [])
290+
291+
return (
292+
<Button
293+
label="Custom toaster"
294+
variant="primary"
295+
onClick={showAdvancedToaster}
296+
/>
297+
)
298+
}
299+
```
300+
265301
## Props
266302

267303
useToasts forwards all unknown props to the base native `<div>` component. See

0 commit comments

Comments
 (0)