You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.7 KiB
TypeScript
42 lines
1.7 KiB
TypeScript
// Copyright (C) 2020-2021 Intel Corporation
|
|
//
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
import React, { useState } from 'react';
|
|
import Popover, { PopoverProps } from 'antd/lib/popover';
|
|
|
|
export default function withVisibilityHandling(WrappedComponent: typeof Popover, popoverType: string) {
|
|
return (props: PopoverProps): JSX.Element => {
|
|
const [visible, setVisible] = useState<boolean>(false);
|
|
const { overlayClassName, ...rest } = props;
|
|
const overlayClassNames = typeof overlayClassName === 'string' ? overlayClassName.split(/\s+/) : [];
|
|
const popoverClassName = `cvat-${popoverType}-popover`;
|
|
overlayClassNames.push(popoverClassName);
|
|
|
|
const { overlayStyle } = props;
|
|
return (
|
|
<WrappedComponent
|
|
{...rest}
|
|
overlayStyle={{
|
|
...(typeof overlayStyle === 'object' ? overlayStyle : {}),
|
|
animationDuration: '0s',
|
|
animationDelay: '0s',
|
|
}}
|
|
trigger={visible ? 'click' : 'hover'}
|
|
overlayClassName={overlayClassNames.join(' ').trim()}
|
|
onVisibleChange={(_visible: boolean) => {
|
|
if (_visible) {
|
|
const [element] = window.document.getElementsByClassName(popoverClassName);
|
|
if (element) {
|
|
element.dispatchEvent(new MouseEvent('mousedown', { bubbles: true }));
|
|
(element as HTMLElement).style.pointerEvents = '';
|
|
(element as HTMLElement).style.opacity = '';
|
|
}
|
|
}
|
|
setVisible(_visible);
|
|
}}
|
|
/>
|
|
);
|
|
};
|
|
}
|