Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add transition callbacks to Toast #6674

Merged
merged 6 commits into from
Aug 7, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
53 changes: 50 additions & 3 deletions src/Toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import PropTypes from 'prop-types';
import classNames from 'classnames';

import useTimeout from '@restart/hooks/useTimeout';
import { TransitionComponent } from '@restart/ui/types';
import { TransitionCallbacks, TransitionComponent } from '@restart/ui/types';
import ToastFade from './ToastFade';
import ToastHeader from './ToastHeader';
import ToastBody from './ToastBody';
Expand All @@ -14,12 +14,14 @@ import { BsPrefixProps, BsPrefixRefForwardingComponent } from './helpers';
import { Variant } from './types';

export interface ToastProps
extends BsPrefixProps,
extends TransitionCallbacks,
BsPrefixProps,
React.HTMLAttributes<HTMLElement> {
animation?: boolean;
autohide?: boolean;
delay?: number;
onClose?: (e?: React.MouseEvent | React.KeyboardEvent) => void;

show?: boolean;
transition?: TransitionComponent;
bg?: Variant;
Expand Down Expand Up @@ -51,6 +53,36 @@ const propTypes = {
*/
onClose: PropTypes.func,

/**
* Callback fired before the Modal transitions in
*/
onEnter: PropTypes.func,

/**
* Callback fired as the Modal begins to transition in
kyletsang marked this conversation as resolved.
Show resolved Hide resolved
*/
onEntering: PropTypes.func,

/**
* Callback fired after the Modal finishes transitioning in
*/
onEntered: PropTypes.func,

/**
* Transition onExit callback when animation is not `false`
*/
onExit: PropTypes.func,

/**
* Transition onExiting callback when animation is not `false`
*/
onExiting: PropTypes.func,

/**
* Transition onExited callback when animation is not `false`
*/
onExited: PropTypes.func,

/**
* When `true` The modal will show itself.
*/
Expand Down Expand Up @@ -81,6 +113,12 @@ const Toast: BsPrefixRefForwardingComponent<'div', ToastProps> =
delay = 5000,
autohide = false,
onClose,
onEntered,
onExit,
onExiting,
onEnter,
onEntering,
onExited,
bg,
...props
},
Expand Down Expand Up @@ -140,7 +178,16 @@ const Toast: BsPrefixRefForwardingComponent<'div', ToastProps> =
return (
<ToastContext.Provider value={toastContext}>
{hasAnimation && Transition ? (
<Transition in={show} unmountOnExit>
<Transition
in={show}
onEnter={onEnter}
onEntering={onEntering}
onEntered={onEntered}
onExit={onExit}
onExiting={onExiting}
onExited={onExited}
unmountOnExit
>
{toast}
</Transition>
) : (
Expand Down