✨ make sidebar close via hook toggle
This commit is contained in:
parent
6fa1b23613
commit
faaa6d2edb
4 changed files with 20 additions and 8 deletions
|
@ -5,18 +5,20 @@ import Sidebar from './Sidebar';
|
||||||
import ConnectedFileNode from '../../modules/IDE/components/FileNode';
|
import ConnectedFileNode from '../../modules/IDE/components/FileNode';
|
||||||
|
|
||||||
|
|
||||||
const Explorer = ({ id, canEdit }) => (
|
const Explorer = ({ id, canEdit, onPressClose }) => (
|
||||||
<Sidebar title="Files">
|
<Sidebar title="Files" onPressClose={onPressClose}>
|
||||||
<ConnectedFileNode id={id} canEdit={canEdit} />
|
<ConnectedFileNode id={id} canEdit={canEdit} onClickFile={onPressClose} />
|
||||||
</Sidebar>
|
</Sidebar>
|
||||||
);
|
);
|
||||||
|
|
||||||
Explorer.propTypes = {
|
Explorer.propTypes = {
|
||||||
id: PropTypes.number.isRequired,
|
id: PropTypes.number.isRequired,
|
||||||
|
onPressClose: PropTypes.func,
|
||||||
canEdit: PropTypes.bool
|
canEdit: PropTypes.bool
|
||||||
};
|
};
|
||||||
Explorer.defaultProps = {
|
Explorer.defaultProps = {
|
||||||
canEdit: false
|
canEdit: false,
|
||||||
|
onPressClose: () => {}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Explorer;
|
export default Explorer;
|
||||||
|
|
|
@ -20,11 +20,13 @@ const SidebarWrapper = styled.div`
|
||||||
box-shadow: 0 6px 6px 0 rgba(0,0,0,0.10);
|
box-shadow: 0 6px 6px 0 rgba(0,0,0,0.10);
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
// onClick={() => alert('haha')}
|
||||||
|
|
||||||
const Sidebar = ({ title, onPressClose, children }) => (
|
const Sidebar = ({ title, onPressClose, children }) => (
|
||||||
<SidebarWrapper>
|
<SidebarWrapper>
|
||||||
{title &&
|
{title &&
|
||||||
<Header slim title={title} fixed={false}>
|
<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>}
|
</Header>}
|
||||||
{children}
|
{children}
|
||||||
</SidebarWrapper>
|
</SidebarWrapper>
|
||||||
|
|
|
@ -20,7 +20,11 @@ export default (Element, hasOverlay = false) => {
|
||||||
const wrapper = () => (visible &&
|
const wrapper = () => (visible &&
|
||||||
<div>
|
<div>
|
||||||
{hasOverlay && <BackgroundOverlay />}
|
{hasOverlay && <BackgroundOverlay />}
|
||||||
<div ref={setRef}> {Element} </div>
|
<div ref={setRef}>
|
||||||
|
{ (typeof (Element) === 'function')
|
||||||
|
? Element(toggle)
|
||||||
|
: Element}
|
||||||
|
</div>
|
||||||
</div>);
|
</div>);
|
||||||
|
|
||||||
return [toggle, wrapper];
|
return [toggle, wrapper];
|
||||||
|
|
|
@ -116,8 +116,12 @@ const MobileIDEView = (props) => {
|
||||||
align="right"
|
align="right"
|
||||||
/>);
|
/>);
|
||||||
|
|
||||||
|
const [toggleExplorer, Explorer] = useAsModal(toggle =>
|
||||||
const [toggleExplorer, Explorer] = useAsModal(<MobileExplorer id={getRootFileID(files)} canEdit={false} />, true);
|
(<MobileExplorer
|
||||||
|
id={getRootFileID(files)}
|
||||||
|
canEdit={false}
|
||||||
|
onPressClose={toggle}
|
||||||
|
/>), true);
|
||||||
|
|
||||||
// toggle sidebar starting opened
|
// toggle sidebar starting opened
|
||||||
// useEffect(toggleExplorer, []);
|
// useEffect(toggleExplorer, []);
|
||||||
|
|
Loading…
Reference in a new issue