toasterTypes: change toaster to ref

Instead of rendering the toaster separate from the main index, add it
there so we can inherit all of the context providers. This requires
passing the ref object instead of the toaster instance itself, so
sagas have to be updated.
This commit is contained in:
David Lechner
2022-10-19 18:26:37 -05:00
committed by David Lechner
parent be9272ca9c
commit fa27649fe3
27 changed files with 121 additions and 141 deletions
+30
View File
@@ -0,0 +1,30 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2021-2022 The Pybricks Authors
import type { ToastProps, ToasterInstance } from '@blueprintjs/core';
/**
* Template type alert callbacks.
*
* This is called when an alert is dismissed.
*
* @param action: The action that the user selected. This is usually 'dismiss'.
*/
export type ToastActionHandler<A extends string> = (action: A) => void;
/**
* Template type for all toast creation functions for alert components.
*
* @param onAction A callback that is called when the toast is dismissed.
* @param props Additional properties required by this toast, if any (usually
* replacements for translations).
*/
export type CreateToast<
P extends Record<string, unknown> = never,
A extends string = 'dismiss',
> = (onAction: ToastActionHandler<A>, props: P) => ToastProps;
/**
* Type compatible with React.RefObject<ToasterInstance>.
*/
export type ToasterRef = { current: ToasterInstance | null };