Skip to content

Toast Service

const toastService = new ToastService()

Guidelines

Only render one variant of toast at a time. Never combine toast-message and workflow-toast.

Limit the max amount of toasts visible to not overflow other action items.

tpg-workflow-toast should be mounted inside the content of tpg-workflow-panel.

Properties

maxVisible

maxVisible is defined on instantiation of ToastService. It controls how mnay toasts can be visible before the toasts start to queue up and wait for their turn.

mount

mountis defined on instantiation of ToastService. Only set this if you want to render the toasts within an element. mount defines where to place the toast stack. Default is document.body.

Note - When setting mount, the toast stack will change from posiiton: fixed to position: absolute and you need to set the mounted object to have position: relative.

placement

Where to place the toast.

Toast Variants

We have two different variants of toasts, take a look at the props and how to style them on their own page.

Toast Message

Workflow Toast

Examples

Triggering the toast

Use this to showcase the toast in the entire view.

Triggering the toast within a specific container

Passing down custom framework components

ToastService can also handle custom framework components as long as they have the same interface as one of the toast variants. This can be useful if you want to create wrapper components around the toast variants to add additional functionality or styling.

function App() {
const toastServiceRef = useRef<ToastService | undefined>(undefined);
useEffect(() => {
toastServiceRef.current = new ToastService({});
}, []);
const showToast = (component: React.ReactElement) => {
let root: Root;
toastServiceRef.current?.addCustomComponent({
cleanup: () => {
root.unmount();
},
render: (container) => {
root = createRoot(container);
root.render(component);
},
});
};
return (
<button
onClick={() =>
showToast(<TpgToastMessage message="This is a toast message!" />)
}
>
Show Toast
</button>
);
}