♻️ make dropdown left/rightable
This commit is contained in:
parent
8da6497457
commit
e430652483
5 changed files with 27 additions and 47 deletions
|
@ -13,8 +13,9 @@ const DropdownWrapper = styled.ul`
|
||||||
color: ${prop('primaryTextColor')};
|
color: ${prop('primaryTextColor')};
|
||||||
|
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: ${remSize(64)};
|
right: ${props => (props.right ? 0 : 'initial')};
|
||||||
right: ${remSize(16)};
|
left: ${props => (props.left ? 0 : 'initial')};
|
||||||
|
|
||||||
|
|
||||||
text-align: left;
|
text-align: left;
|
||||||
width: ${remSize(180)};
|
width: ${remSize(180)};
|
||||||
|
@ -56,8 +57,8 @@ const DropdownWrapper = styled.ul`
|
||||||
// TODO: Add Icon to the left of the items in the menu
|
// TODO: Add Icon to the left of the items in the menu
|
||||||
// const MaybeIcon = (Element, label) => Element && <Element aria-label={label} />;
|
// const MaybeIcon = (Element, label) => Element && <Element aria-label={label} />;
|
||||||
|
|
||||||
const Dropdown = ({ items }) => (
|
const Dropdown = ({ items, right, left }) => (
|
||||||
<DropdownWrapper>
|
<DropdownWrapper right={right} left={left}>
|
||||||
{/* className="nav__items-left" */}
|
{/* className="nav__items-left" */}
|
||||||
{items && items.map(({ title, icon, href }) => (
|
{items && items.map(({ title, icon, href }) => (
|
||||||
<li key={`nav-${title && title.toLowerCase()}`}>
|
<li key={`nav-${title && title.toLowerCase()}`}>
|
||||||
|
@ -72,6 +73,8 @@ const Dropdown = ({ items }) => (
|
||||||
);
|
);
|
||||||
|
|
||||||
Dropdown.propTypes = {
|
Dropdown.propTypes = {
|
||||||
|
right: PropTypes.bool,
|
||||||
|
left: PropTypes.bool,
|
||||||
items: PropTypes.arrayOf(PropTypes.shape({
|
items: PropTypes.arrayOf(PropTypes.shape({
|
||||||
action: PropTypes.func,
|
action: PropTypes.func,
|
||||||
icon: PropTypes.func,
|
icon: PropTypes.func,
|
||||||
|
@ -81,6 +84,8 @@ Dropdown.propTypes = {
|
||||||
|
|
||||||
Dropdown.defaultProps = {
|
Dropdown.defaultProps = {
|
||||||
items: [],
|
items: [],
|
||||||
|
right: false,
|
||||||
|
left: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Dropdown;
|
export default Dropdown;
|
||||||
|
|
|
@ -1,29 +1,8 @@
|
||||||
import React, { useRef, useEffect } from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { createPortal } from 'react-dom';
|
import { createPortal } from 'react-dom';
|
||||||
|
|
||||||
import Dropdown from './Dropdown';
|
|
||||||
|
|
||||||
import { PreferencesIcon } from '../common/icons';
|
|
||||||
import { useModalBehavior } from '../utils/custom-hooks';
|
|
||||||
|
|
||||||
|
|
||||||
const OverlayManager = ({ overlay, hideOverlay }) => {
|
const OverlayManager = ({ overlay, hideOverlay }) => {
|
||||||
const headerNavOptions = [
|
|
||||||
{
|
|
||||||
icon: PreferencesIcon,
|
|
||||||
title: 'Preferences',
|
|
||||||
href: '/mobile/preferences',
|
|
||||||
},
|
|
||||||
{ icon: PreferencesIcon, title: 'Examples', href: '/mobile/examples' },
|
|
||||||
{
|
|
||||||
icon: PreferencesIcon,
|
|
||||||
title: 'Original Editor',
|
|
||||||
href: '/mobile/preferences',
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
// const setRef = useModalBehavior(hideOverlay);
|
|
||||||
// const [visible, trigger, setRef] = useModalBehavior();
|
// const [visible, trigger, setRef] = useModalBehavior();
|
||||||
|
|
||||||
const jsx = (
|
const jsx = (
|
||||||
|
|
|
@ -31,7 +31,9 @@ const HeaderDiv = styled.div`
|
||||||
|
|
||||||
const IconContainer = styled.div`
|
const IconContainer = styled.div`
|
||||||
margin-left: ${props => (props.leftButton ? remSize(32) : remSize(4))};
|
margin-left: ${props => (props.leftButton ? remSize(32) : remSize(4))};
|
||||||
|
list-style: none;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
flex-direction: horizontal;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,8 @@ class App extends React.Component {
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div className="app">
|
<div className="app">
|
||||||
{this.state.isMounted && !window.devToolsExtension && getConfig('NODE_ENV') === 'development' && <DevTools />}
|
{/* FIXME: remove false */}
|
||||||
|
{false && this.state.isMounted && !window.devToolsExtension && getConfig('NODE_ENV') === 'development' && <DevTools />}
|
||||||
{this.props.children}
|
{this.props.children}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
@ -67,13 +67,9 @@ const MobileIDEView = (props) => {
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
const [tmController, setTmController] = useState(null); // eslint-disable-line
|
const [tmController, setTmController] = useState(null); // eslint-disable-line
|
||||||
const [overlayName, setOverlay] = useState(null); // eslint-disable-line
|
|
||||||
|
|
||||||
// TODO: Move this to OverlayController (?)
|
|
||||||
const hideOverlay = () => setOverlay(null);
|
|
||||||
// const overlayRef = useRef({});
|
|
||||||
|
|
||||||
const [triggerNavDropdown, NavDropDown] = useAsModal(<Dropdown items={headerNavOptions} />);
|
const [triggerNavDropdown, NavDropDown] = useAsModal(<Dropdown right items={headerNavOptions} />);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Screen fullscreen>
|
<Screen fullscreen>
|
||||||
|
@ -84,12 +80,17 @@ const MobileIDEView = (props) => {
|
||||||
<IconButton to="/mobile" icon={ExitIcon} aria-label="Return to original editor" />
|
<IconButton to="/mobile" icon={ExitIcon} aria-label="Return to original editor" />
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<IconButton
|
<li style={{ position: 'relative' }}>
|
||||||
onClick={triggerNavDropdown}
|
<IconButton
|
||||||
icon={MoreIcon}
|
onClick={triggerNavDropdown}
|
||||||
aria-label="Options"
|
icon={MoreIcon}
|
||||||
/>
|
aria-label="Options"
|
||||||
<IconButton to="/mobile/preview" onClick={() => { startSketch(); }} icon={PlayIcon} aria-label="Run sketch" />
|
/>
|
||||||
|
<NavDropDown />
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<IconButton to="/mobile/preview" onClick={() => { startSketch(); }} icon={PlayIcon} aria-label="Run sketch" />
|
||||||
|
</li>
|
||||||
</Header>
|
</Header>
|
||||||
|
|
||||||
<IDEWrapper>
|
<IDEWrapper>
|
||||||
|
@ -107,9 +108,7 @@ const MobileIDEView = (props) => {
|
||||||
editorOptionsVisible={ide.editorOptionsVisible}
|
editorOptionsVisible={ide.editorOptionsVisible}
|
||||||
showEditorOptions={showEditorOptions}
|
showEditorOptions={showEditorOptions}
|
||||||
closeEditorOptions={closeEditorOptions}
|
closeEditorOptions={closeEditorOptions}
|
||||||
showKeyboardShortcutModal={showKeyboardShortcutModal}
|
showKeyboard={ide.isPlaying}
|
||||||
setUnsavedChanges={setUnsavedChanges}
|
|
||||||
isPlaying={ide.isPlaying}
|
|
||||||
theme={preferences.theme}
|
theme={preferences.theme}
|
||||||
startRefreshSketch={startRefreshSketch}
|
startRefreshSketch={startRefreshSketch}
|
||||||
stopSketch={stopSketch}
|
stopSketch={stopSketch}
|
||||||
|
@ -133,12 +132,6 @@ const MobileIDEView = (props) => {
|
||||||
{ide.consoleIsExpanded && <Expander expanded><Console /></Expander>}
|
{ide.consoleIsExpanded && <Expander expanded><Console /></Expander>}
|
||||||
<ActionStrip />
|
<ActionStrip />
|
||||||
</Footer>
|
</Footer>
|
||||||
<NavDropDown />
|
|
||||||
{/* <OverlayManager
|
|
||||||
// ref={overlayRef}
|
|
||||||
overlay={overlayName}
|
|
||||||
hideOverlay={hideOverlay}
|
|
||||||
/> */}
|
|
||||||
</Screen>
|
</Screen>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue