generated from eea/volto-addon-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #183 from eea/develop
fix: customize SidebarPopup volto component
- Loading branch information
Showing
5 changed files
with
125 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
## SidebarPopup | ||
|
||
- https://github.com/plone/volto/pull/5520/files | ||
- refs #257682 | ||
|
||
## ObjectBrowserNav | ||
|
||
- Allow previewing images when selecting them with the file picker | ||
- refs #152099 |
82 changes: 82 additions & 0 deletions
82
src/customizations/volto/components/manage/Sidebar/SidebarPopup.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Check this https://github.com/plone/volto/pull/5520 | ||
import React from 'react'; | ||
import { Portal } from 'react-portal'; | ||
import { CSSTransition } from 'react-transition-group'; | ||
import PropTypes from 'prop-types'; | ||
import { doesNodeContainClick } from 'semantic-ui-react/dist/commonjs/lib'; | ||
|
||
const DEFAULT_TIMEOUT = 500; | ||
|
||
const SidebarPopup = (props) => { | ||
const { children, open, onClose, overlay } = props; | ||
|
||
const asideElement = React.useRef(); | ||
|
||
const handleClickOutside = (e) => { | ||
if (asideElement && doesNodeContainClick(asideElement.current, e)) return; | ||
onClose(); | ||
}; | ||
|
||
React.useEffect(() => { | ||
document.addEventListener('mousedown', handleClickOutside, false); | ||
return () => { | ||
document.removeEventListener('mousedown', handleClickOutside, false); | ||
}; | ||
}); | ||
|
||
return ( | ||
<> | ||
{overlay && ( | ||
<CSSTransition | ||
in={open} | ||
timeout={DEFAULT_TIMEOUT} | ||
classNames="overlay-container" | ||
unmountOnExit | ||
> | ||
<Portal node={document?.body}> | ||
<div className="overlay-container"></div> | ||
</Portal> | ||
</CSSTransition> | ||
)} | ||
<CSSTransition | ||
in={open} | ||
timeout={DEFAULT_TIMEOUT} | ||
classNames="sidebar-container" | ||
unmountOnExit | ||
> | ||
<Portal> | ||
<aside | ||
id="test" | ||
role="presentation" | ||
onClick={(e) => { | ||
e.stopPropagation(); | ||
}} | ||
onKeyDown={(e) => { | ||
e.stopPropagation(); | ||
}} | ||
ref={asideElement} | ||
key="sidebarpopup" | ||
className="sidebar-container" | ||
style={{ overflowY: 'auto' }} | ||
> | ||
{children} | ||
</aside> | ||
</Portal> | ||
</CSSTransition> | ||
</> | ||
); | ||
}; | ||
|
||
SidebarPopup.propTypes = { | ||
open: PropTypes.bool, | ||
onClose: PropTypes.func, | ||
overlay: PropTypes.bool, | ||
}; | ||
|
||
SidebarPopup.defaultProps = { | ||
open: false, | ||
onClose: () => {}, | ||
overlay: false, | ||
}; | ||
|
||
export default SidebarPopup; |