import { ToastPosition } from "react-hot-toast"; import { Action, RequiredToasterProps } from "../../types"; import { BoxProps } from "../Box"; import { IconType } from "../Icon"; /** * Redefines RequiredToasterProps for Snackbar’s instance */ export type SnackbarToasterProps = RequiredToasterProps; /** * The positioning options are a subset that are supported by Toaster; addtional * options may be added as needed */ type SnackbarPosition = Extract; /** * Props that are shared between all implementations of the Snackbar */ type SnackbarSharedProps = { /** * Position of the snackbar in relation to the browser window */ position?: SnackbarPosition; /** * The amount of time (in milliseconds) the snackbar appears on-screen. If * undefined, then the Snackbar will stay on-screen indefinitely. An undefined * duration would be used in cases when the Snackbar is used as a loading * message (e.g., an in progress API call). */ duration?: number; }; /** * Defines the type for a custom Snackbar component */ type SnackbarWithComponentProps = { /** * Component to render as the Snackbar */ component: React.ReactNode; message?: never; }; /** * Defines the type for the default Snackbar which requires a message string */ type SnackbarWithMessageProps = { /** * The message shown in the Snackbar; ideally short and succinct */ message: React.ReactNode; component?: never; }; /** * Defines the type which determines if a Snackbar is visible */ type SnackbarIsVisibleProp = { isVisible: boolean; }; /** * Additional props for the Snackbar component */ type SnackbarOtherProps = { /** * Adds an action next to the message */ action?: Action; /** * When a loading icon is detected, it will automatically spin. * * Sizing is handled automatically, too. */ icon?: IconType; /** * Prevent the close button from rendering. Useful in cases when the Snackbar * is used as a loading message (e.g., an in progress API call). */ disableClose?: boolean; }; /** * Snackbar component props */ export type SnackbarProps = Omit & SnackbarOtherProps & SnackbarSharedProps & BoxProps; /** * Snackbar.Root component props */ export type SnackbarRootProps = BoxProps; /** * Snackbar.Icon component props */ export type SnackbarIconProps = Pick; /** * Snackbar.Text component props */ export type SnackbarTextProps = { children: React.ReactNode }; /** * Snackbar context props */ export type SnackbarContextProps = SnackbarToasterProps & SnackbarSharedProps; /** * Snackbar provider props */ export type SnackbarProviderProps = SnackbarToasterProps & SnackbarSharedProps & Omit; /** * Defines the type for showing a Snackbar using the default component, which * requires a message and includes optional other props */ type ShowSnackbarWithMessageProps = SnackbarWithMessageProps & SnackbarOtherProps & SnackbarSharedProps & BoxProps; /** * Defines the type for showing a Snackbar with a custom component */ type ShowSnackbarWithComponentProps = SnackbarWithComponentProps & SnackbarSharedProps; /** * Defines the type for the showSnackbar helper */ export type ShowSnackbarProps = | ShowSnackbarWithMessageProps | ShowSnackbarWithComponentProps; /** * Defines the type for the hook to show a Snackbar using the default component, * which requires a message and includes optional other props */ type SnackbarWithMessageHookProps = SnackbarWithMessageProps & SnackbarOtherProps & SnackbarSharedProps & SnackbarIsVisibleProp & BoxProps; /** * Defines the type for the hook to showi a Snackbar with a custom component */ type SnackbarWithComponentHookProps = SnackbarWithComponentProps & SnackbarSharedProps & SnackbarIsVisibleProp; /** * Defines the type for the useSnackbar hook */ export type SnackbarHookProps = | SnackbarWithMessageHookProps | SnackbarWithComponentHookProps;