1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-04 08:28:11 +00:00
Files
seahub/frontend/src/components/click-outside.js
Jerry Ren 890880a5c8 refactor(metadata): remove ui-component (#7492)
1. ModalPortal
2. Icon
3. IconBtn
4. Loading
5. CenteredLoading
6. ClickOutside
7. SearchInput
8. Switch
9. CustomizeAddTool
10. SfCalendar
11. SfFilterCalendar
12. CustomizeSelect
13. CustomizePopover
14. FieldDisplaySettings
15. Formatters
16. remove duplicate codes
2025-03-01 10:12:48 +08:00

44 lines
883 B
JavaScript

import React from 'react';
import PropTypes from 'prop-types';
class ClickOutside extends React.Component {
isClickedInside = false;
componentDidMount() {
document.addEventListener('mousedown', this.handleDocumentClick);
}
componentWillUnmount() {
document.removeEventListener('mousedown', this.handleDocumentClick);
}
handleDocumentClick = (e) => {
if (this.isClickedInside) {
this.isClickedInside = false;
return;
}
this.props.onClickOutside(e);
};
handleMouseDown = () => {
this.isClickedInside = true;
};
render() {
return React.cloneElement(
React.Children.only(this.props.children), {
onMouseDownCapture: this.handleMouseDown
}
);
}
}
ClickOutside.propTypes = {
children: PropTypes.element.isRequired,
onClickOutside: PropTypes.func.isRequired,
};
export default ClickOutside;