mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-10 03:11:07 +00:00
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
This commit is contained in:
43
frontend/src/components/click-outside.js
Normal file
43
frontend/src/components/click-outside.js
Normal file
@@ -0,0 +1,43 @@
|
||||
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;
|
Reference in New Issue
Block a user