@payfit/unity-components
Version:
45 lines (44 loc) • 1.63 kB
TypeScript
import { ReactNode } from 'react';
import { ToastActionProps } from './parts/ToastAction.js';
import { UnityToastProps } from './UnityToast.js';
interface Base {
title: ReactNode;
content?: ReactNode;
datadogPrivacy?: 'allow' | 'mask' | 'hidden';
}
interface WithAction {
action: ReactNode;
actionOnPress: ToastActionProps['onPress'];
}
interface SuccessParams extends Base {
variant: Extract<UnityToastProps['variant'], 'success'>;
duration?: number;
action?: never;
actionOnPress?: never;
}
interface ErrorParams extends Base {
variant: Extract<UnityToastProps['variant'], 'error'>;
duration?: never;
action?: never;
actionOnPress?: never;
}
interface SuccessParamsWithAction extends Base, WithAction {
variant: Extract<UnityToastProps['variant'], 'success'>;
duration?: number;
}
interface ErrorParamsWithAction extends Base, WithAction {
variant: Extract<UnityToastProps['variant'], 'error'>;
duration?: never;
}
/**
* creates a toast
* @param prop the object which contains all the properties
* @param prop.title the toast title
* @param prop.content (optional) the content of the toast
* @param prop.variant the toast type
* @param prop.action (optional) the label of the action
* @param prop.actionOnPress (optional) the function to trigger when click on the action
* @param prop.duration (optional) to override the toast duration
*/
declare function toast({ title, content, variant, action, actionOnPress, duration, datadogPrivacy, }: SuccessParams | ErrorParams | SuccessParamsWithAction | ErrorParamsWithAction): string;
export { toast };