Files
pybricks-code/src/toasterTypes.tsx
T
David Lechner fa27649fe3 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.
2022-10-19 18:26:37 -05:00

31 lines
967 B
TypeScript

// 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 };