🚧 improve useAsModal rendering
This commit is contained in:
parent
1680c0cd52
commit
6d121491aa
4 changed files with 16 additions and 12 deletions
|
@ -23,7 +23,7 @@ const SidebarWrapper = styled.div`
|
||||||
const Sidebar = ({ title, onPressClose }) => (
|
const Sidebar = ({ title, onPressClose }) => (
|
||||||
<SidebarWrapper>
|
<SidebarWrapper>
|
||||||
{title &&
|
{title &&
|
||||||
<Header slim title={title}>
|
<Header slim title={title} fixed={false}>
|
||||||
<IconButton onPress={onPressClose} icon={ExitIcon} aria-label="Return to ide view" />
|
<IconButton onPress={onPressClose} icon={ExitIcon} aria-label="Return to ide view" />
|
||||||
</Header>}
|
</Header>}
|
||||||
</SidebarWrapper>
|
</SidebarWrapper>
|
||||||
|
|
|
@ -14,7 +14,7 @@ const textColor = ({ transparent, inverted }) => prop((transparent === false &&
|
||||||
|
|
||||||
|
|
||||||
const HeaderDiv = styled.div`
|
const HeaderDiv = styled.div`
|
||||||
position: fixed;
|
${props => props.fixed && 'position: fixed;'}
|
||||||
width: 100%;
|
width: 100%;
|
||||||
background: ${props => background(props)};
|
background: ${props => background(props)};
|
||||||
color: ${textColor};
|
color: ${textColor};
|
||||||
|
@ -57,9 +57,9 @@ const TitleContainer = styled.div`
|
||||||
|
|
||||||
const Header = ({
|
const Header = ({
|
||||||
title, subtitle, leftButton, children,
|
title, subtitle, leftButton, children,
|
||||||
transparent, inverted, slim
|
transparent, inverted, slim, fixed
|
||||||
}) => (
|
}) => (
|
||||||
<HeaderDiv transparent={transparent} slim={slim} inverted={inverted}>
|
<HeaderDiv transparent={transparent} slim={slim} inverted={inverted} fixed={fixed}>
|
||||||
{leftButton}
|
{leftButton}
|
||||||
<TitleContainer padded={subtitle === null}>
|
<TitleContainer padded={subtitle === null}>
|
||||||
{title && <h2>{title}</h2>}
|
{title && <h2>{title}</h2>}
|
||||||
|
@ -79,6 +79,7 @@ Header.propTypes = {
|
||||||
transparent: PropTypes.bool,
|
transparent: PropTypes.bool,
|
||||||
inverted: PropTypes.bool,
|
inverted: PropTypes.bool,
|
||||||
slim: PropTypes.bool,
|
slim: PropTypes.bool,
|
||||||
|
fixed: PropTypes.bool,
|
||||||
};
|
};
|
||||||
|
|
||||||
Header.defaultProps = {
|
Header.defaultProps = {
|
||||||
|
@ -88,7 +89,8 @@ Header.defaultProps = {
|
||||||
children: [],
|
children: [],
|
||||||
transparent: false,
|
transparent: false,
|
||||||
inverted: false,
|
inverted: false,
|
||||||
slim: false
|
slim: false,
|
||||||
|
fixed: true
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Header;
|
export default Header;
|
||||||
|
|
|
@ -12,13 +12,16 @@ const BackgroundOverlay = styled.div`
|
||||||
opacity: 0.3;
|
opacity: 0.3;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export default (component, hasOverlay = false) => {
|
export default (Element, hasOverlay = false) => {
|
||||||
const [visible, toggle, setRef] = useModalBehavior();
|
const [visible, toggle, setRef] = useModalBehavior();
|
||||||
|
|
||||||
const wrapper = () => (<div>
|
// const Comp = styled(() => Element).attrs({ onPressClose: toggle });
|
||||||
{hasOverlay && visible && <BackgroundOverlay />}
|
|
||||||
<div ref={setRef}> {visible && component} </div>
|
const wrapper = () => (visible &&
|
||||||
</div>); // eslint-disable-line
|
<div>
|
||||||
|
{hasOverlay && <BackgroundOverlay />}
|
||||||
|
<div ref={setRef}> {Element} </div>
|
||||||
|
</div>); // eslint-disable-line}
|
||||||
|
|
||||||
return [toggle, wrapper];
|
return [toggle, wrapper];
|
||||||
};
|
};
|
||||||
|
|
|
@ -97,8 +97,7 @@ const MobileIDEView = (props) => {
|
||||||
/>);
|
/>);
|
||||||
|
|
||||||
const [toggleExplorer, Explorer] = useAsModal(<Sidebar
|
const [toggleExplorer, Explorer] = useAsModal(<Sidebar
|
||||||
title="hahaha"
|
title="Files"
|
||||||
onPressClose={() => {}}
|
|
||||||
/>, true);
|
/>, true);
|
||||||
|
|
||||||
// toggle sidebar starting opened
|
// toggle sidebar starting opened
|
||||||
|
|
Loading…
Reference in a new issue