make sidebar close via hook toggle

This commit is contained in:
ghalestrilo 2020-08-07 18:32:50 -03:00
parent 6fa1b23613
commit faaa6d2edb
4 changed files with 20 additions and 8 deletions

View file

@ -5,18 +5,20 @@ import Sidebar from './Sidebar';
import ConnectedFileNode from '../../modules/IDE/components/FileNode';
const Explorer = ({ id, canEdit }) => (
<Sidebar title="Files">
<ConnectedFileNode id={id} canEdit={canEdit} />
const Explorer = ({ id, canEdit, onPressClose }) => (
<Sidebar title="Files" onPressClose={onPressClose}>
<ConnectedFileNode id={id} canEdit={canEdit} onClickFile={onPressClose} />
</Sidebar>
);
Explorer.propTypes = {
id: PropTypes.number.isRequired,
onPressClose: PropTypes.func,
canEdit: PropTypes.bool
};
Explorer.defaultProps = {
canEdit: false
canEdit: false,
onPressClose: () => {}
};
export default Explorer;

View file

@ -20,11 +20,13 @@ const SidebarWrapper = styled.div`
box-shadow: 0 6px 6px 0 rgba(0,0,0,0.10);
`;
// onClick={() => alert('haha')}
const Sidebar = ({ title, onPressClose, children }) => (
<SidebarWrapper>
{title &&
<Header slim title={title} fixed={false}>
<IconButton onPress={onPressClose} icon={ExitIcon} aria-label="Return to ide view" />
<IconButton onClick={onPressClose} icon={ExitIcon} aria-label="Return to ide view" />
</Header>}
{children}
</SidebarWrapper>

View file

@ -20,7 +20,11 @@ export default (Element, hasOverlay = false) => {
const wrapper = () => (visible &&
<div>
{hasOverlay && <BackgroundOverlay />}
<div ref={setRef}> {Element} </div>
<div ref={setRef}>
{ (typeof (Element) === 'function')
? Element(toggle)
: Element}
</div>
</div>);
return [toggle, wrapper];

View file

@ -116,8 +116,12 @@ const MobileIDEView = (props) => {
align="right"
/>);
const [toggleExplorer, Explorer] = useAsModal(<MobileExplorer id={getRootFileID(files)} canEdit={false} />, true);
const [toggleExplorer, Explorer] = useAsModal(toggle =>
(<MobileExplorer
id={getRootFileID(files)}
canEdit={false}
onPressClose={toggle}
/>), true);
// toggle sidebar starting opened
// useEffect(toggleExplorer, []);