chore(overlays): generic for present/dismiss options (#26287)

This commit is contained in:
Sean Perkins
2022-11-21 16:57:17 -05:00
committed by GitHub
parent 8aa0aeca6b
commit c943dff5a3
7 changed files with 97 additions and 20 deletions

View File

@ -19,7 +19,7 @@ import { iosEnterAnimation } from './animations/ios.enter';
import { iosLeaveAnimation } from './animations/ios.leave';
import { mdEnterAnimation } from './animations/md.enter';
import { mdLeaveAnimation } from './animations/md.leave';
import type { ToastAttributes } from './toast-interface';
import type { ToastAttributes, ToastPosition } from './toast-interface';
/**
* @virtualProp {"ios" | "md"} mode - The mode determines which platform styles to use.
@ -97,7 +97,7 @@ export class Toast implements ComponentInterface, OverlayInterface {
/**
* The position of the toast on the screen.
*/
@Prop() position: 'top' | 'bottom' | 'middle' = 'bottom';
@Prop() position: ToastPosition = 'bottom';
/**
* An array of buttons for the toast.
@ -156,7 +156,7 @@ export class Toast implements ComponentInterface, OverlayInterface {
*/
@Method()
async present(): Promise<void> {
await present(this, 'toastEnter', iosEnterAnimation, mdEnterAnimation, this.position);
await present<ToastPresentOptions>(this, 'toastEnter', iosEnterAnimation, mdEnterAnimation, this.position);
if (this.duration > 0) {
this.durationTimeout = setTimeout(() => this.dismiss(undefined, 'timeout'), this.duration);
@ -177,7 +177,15 @@ export class Toast implements ComponentInterface, OverlayInterface {
if (this.durationTimeout) {
clearTimeout(this.durationTimeout);
}
return dismiss(this, data, role, 'toastLeave', iosLeaveAnimation, mdLeaveAnimation, this.position);
return dismiss<ToastDismissOptions>(
this,
data,
role,
'toastLeave',
iosLeaveAnimation,
mdLeaveAnimation,
this.position
);
}
/**
@ -344,3 +352,6 @@ const buttonClass = (button: ToastButton): CssClassMap => {
...getClassMap(button.cssClass),
};
};
type ToastPresentOptions = ToastPosition;
type ToastDismissOptions = ToastPosition;