@atlaskit/profilecard
Version:
A React component to display a card with user information.
39 lines • 1.21 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
import React, { useCallback, useMemo } from 'react';
const PopupTriggerInner = ({
children,
trigger,
showProfilecard,
hideProfilecard,
ariaLabelledBy,
...props
}, ref) => {
const onMouseEnter = useCallback(() => {
showProfilecard();
}, [showProfilecard]);
const onKeyPress = useCallback(event => {
if (event.key === 'Enter' || event.key === ' ') {
event.preventDefault();
showProfilecard();
}
}, [showProfilecard]);
const onClick = useCallback(event => {
// Prevent the click event from propagating to parent containers.
event.stopPropagation();
showProfilecard();
}, [showProfilecard]);
const containerListeners = useMemo(() => trigger === 'hover' ? {
onMouseEnter,
onMouseLeave: hideProfilecard,
onBlur: hideProfilecard,
onKeyPress
} : {
onClick,
onKeyPress
}, [hideProfilecard, onClick, onKeyPress, onMouseEnter, trigger]);
return /*#__PURE__*/React.createElement("span", _extends({}, props, containerListeners, {
ref: ref,
"aria-labelledby": ariaLabelledBy
}), children);
};
export const PopupTrigger = /*#__PURE__*/React.forwardRef(PopupTriggerInner);