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

feat(Popup): add transition callbacks #1388

Merged
merged 4 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 46 additions & 2 deletions src/components/Popup/Popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,62 @@ import './Popup.scss';
export type PopupPlacement = PopperPlacement;
export type PopupAnchorRef = PopperAnchorRef;

type VoidFunction = () => void;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is already VoidFunction type provided by TypeScript

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


export interface PopupProps extends DOMProps, LayerExtendableProps, PopperProps, QAProps {
open?: boolean;
children?: React.ReactNode;
/** Manages `Popup` visibility */
open?: boolean;
/** `Popup` will not be removed from the DOM upon hiding */
keepMounted?: boolean;
/** Render an arrow pointing to the anchor */
hasArrow?: boolean;
/** Do not use `LayerManager` on stacking popups */
disableLayer?: boolean;
/** @deprecated Add onClick handler to children */
onClick?: React.MouseEventHandler<HTMLDivElement>;
/** `mouseenter` event handler */
onMouseEnter?: React.MouseEventHandler<HTMLDivElement>;
/** `mouseleave` event handler */
onMouseLeave?: React.MouseEventHandler<HTMLDivElement>;
/** `focus` event handler */
onFocus?: React.FocusEventHandler<HTMLDivElement>;
/** `blur` event handler */
onBlur?: React.FocusEventHandler<HTMLDivElement>;
/** On start open popup animation void callback */
onTransitionEnter?: VoidFunction;
/** On finish open popup animation void callback */
onTransitionEntered?: VoidFunction;
/** On start close popup animation void callback */
onTransitionExit?: VoidFunction;
/** On finish close popup animation void callback */
onTransitionExited?: VoidFunction;
/** Do not use `Portal` for children */
disablePortal?: boolean;
/** DOM element children to be mounted to */
container?: HTMLElement;
/** HTML `class` attribute for content node */
contentClassName?: string;
/** If true, the focus will return to the anchor element */
restoreFocus?: boolean;
/** Element the focus will be restored to, depends on `restoreFocus` */
restoreFocusRef?: React.RefObject<HTMLElement>;
/** `aria-label` attribute, use this attribute only if you didn't have visible caption */
'aria-label'?: React.AriaAttributes['aria-label'];
/** `aria-labelledby` attribute, prefer this attribute if you have visible caption */
'aria-labelledby'?: React.AriaAttributes['aria-labelledby'];
/** `aria-role` attribute */
role?: React.AriaRole;
/** HTML `id` attribute */
id?: string;
/** Enable focus trapping behavior */
focusTrap?: boolean;
/** While open, the focus will be set to the first interactive element in the content */
autoFocus?: boolean;
}

const b = block('popup');
const ARROW_SIZE = 8;

export function Popup({
keepMounted = false,
hasArrow = false,
Expand All @@ -71,6 +99,10 @@ export function Popup({
onMouseLeave,
onFocus,
onBlur,
onTransitionEnter,
onTransitionEntered,
onTransitionExit,
onTransitionExited,
disablePortal,
container,
strategy,
Expand Down Expand Up @@ -132,6 +164,18 @@ export function Popup({
mountOnEnter={!keepMounted}
unmountOnExit={!keepMounted}
appear={true}
onEnter={() => {
onTransitionEnter?.();
}}
onEntered={() => {
onTransitionEntered?.();
}}
onExit={() => {
onTransitionExit?.();
}}
onExited={() => {
onTransitionExited?.();
}}
>
<div
ref={handleRef}
Expand Down
4 changes: 4 additions & 0 deletions src/components/Popup/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ LANDING_BLOCK-->
| onMouseEnter | `mouseenter` event handler | `Function` | |
| onMouseLeave | `mouseleave` event handler | `Function` | |
| onOutsideClick | Outside click event handler | `Function` | |
| onTransitionEnter | On start open popup animation | `Function` | |
| onTransitionEntered | On finish open popup animation | `Function` | |
| onTransitionExit | On start close popup animation | `Function` | |
| onTransitionExited | On finish close popup animation | `Function` | |
| open | Manages `Popup` visibility | `boolean` | `false` |
| placement | `Popper.js` placement | `PopupPlacement` `Array<PopupPlacement>` | |
| qa | Test attribute (`data-qa`) | `string` | |
Expand Down
Loading