Skip to content

Commit 7b23b39

Browse files
jimmyleeexpbot
authored andcommitted
removes routing based menu for a basic state managed menu
fbshipit-source-id: 4db2384
1 parent d069388 commit 7b23b39

File tree

6 files changed

+57
-121
lines changed

6 files changed

+57
-121
lines changed

components/DocumentationHeader.js

Lines changed: 19 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@ import DismissIcon from '~/components/icons/DismissIcon';
1010
import AlgoliaSearch from '~/components/plugins/AlgoliaSearch';
1111
import VersionSelector from '~/components/VersionSelector';
1212

13-
const STYLES_HIDE_MOBILE = css`
14-
@media screen and (max-width: ${Constants.breakpoints.mobile}) {
15-
display: none;
16-
}
17-
`;
18-
1913
const STYLES_LEFT = css`
2014
flex-shrink: 0;
2115
padding-right: 24px;
@@ -63,7 +57,6 @@ const STYLES_TITLE_TEXT = css`
6357
const STYLES_MENU_BUTTON = css`
6458
cursor: pointer;
6559
height: 100%;
66-
display: none;
6760
align-items: center;
6861
justify-content: center;
6962
padding-left: 24px;
@@ -81,36 +74,22 @@ const STYLES_MENU_BUTTON = css`
8174
}
8275
8376
@media screen and (max-width: ${Constants.breakpoints.mobile}) {
84-
display: flex;
8577
padding-left: 16px;
8678
}
8779
`;
8880

89-
const STYLES_DISMISS_BUTTON = css`
90-
cursor: pointer;
91-
height: 100%;
92-
display: flex;
93-
align-items: center;
94-
justify-content: center;
95-
padding-left: 24px;
96-
margin-left: 16px;
97-
border-left: 1px solid ${Constants.colors.border};
98-
text-decoration: none;
99-
color: ${Constants.colors.black};
100-
101-
:visited {
102-
color: ${Constants.colors.black};
103-
}
104-
105-
:hover {
106-
color: ${Constants.colors.expo};
107-
}
81+
const STYLES_MENU_BUTTON_IS_MOBILE = css`
82+
display: none;
10883
10984
@media screen and (max-width: ${Constants.breakpoints.mobile}) {
110-
padding-left: 16px;
85+
display: flex;
11186
}
11287
`;
11388

89+
const STYLES_MENU_BUTTON_VISIBLE = css`
90+
display: flex;
91+
`;
92+
11493
export default class DocumentationHeader extends React.PureComponent {
11594
render() {
11695
return (
@@ -124,33 +103,31 @@ export default class DocumentationHeader extends React.PureComponent {
124103

125104
<h1 className={STYLES_TITLE_TEXT}>Expo Docs</h1>
126105

127-
{!this.props.hideVersionSelector && (
106+
{!this.props.isVersionSelectorHidden && (
128107
<VersionSelector
129-
className={STYLES_HIDE_MOBILE}
130108
style={{ marginLeft: 16 }}
131-
activeVersion={this.props.activeVersion}
109+
version={this.props.version}
132110
onSetVersion={this.props.onSetVersion}
133111
/>
134112
)}
135113
</div>
136114
<div className={STYLES_RIGHT}>
137-
{!this.props.hideAlgoliaSearch && (
138-
<AlgoliaSearch router={this.props.router} activeVersion={this.props.activeVersion} />
115+
{!this.props.isAlogliaSearchHidden && (
116+
<AlgoliaSearch router={this.props.router} version={this.props.version} />
139117
)}
140118

141119
{!this.props.isMenuActive && (
142-
<Link
143-
prefetch
144-
href={`/mobile-navigation`}
145-
as={`/mobile-navigation/${this.props.activeVersion}`}>
146-
<a className={STYLES_MENU_BUTTON}>
147-
<MenuIcon />
148-
</a>
149-
</Link>
120+
<span
121+
className={`${STYLES_MENU_BUTTON} ${STYLES_MENU_BUTTON_IS_MOBILE}`}
122+
onClick={this.props.onShowMenu}>
123+
<MenuIcon />
124+
</span>
150125
)}
151126

152127
{this.props.isMenuActive && (
153-
<span className={STYLES_DISMISS_BUTTON} onClick={() => window.history.back()}>
128+
<span
129+
className={`${STYLES_MENU_BUTTON} ${STYLES_MENU_BUTTON_VISIBLE}`}
130+
onClick={this.props.onHideMenu}>
154131
<DismissIcon />
155132
</span>
156133
)}

components/DocumentationPage.js

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ const mutateRouteDataForRender = data => {
3737
};
3838

3939
export default class DocumentationPage extends React.Component {
40+
state = {
41+
isMenuActive: false,
42+
};
43+
4044
componentDidMount() {
4145
Router.onRouteChangeStart = () => {
4246
window.NProgress.start();
@@ -61,6 +65,18 @@ export default class DocumentationPage extends React.Component {
6165
}
6266
};
6367

68+
_handleShowMenu = () => {
69+
this.setState({
70+
isMenuActive: true,
71+
});
72+
};
73+
74+
_handleHideMenu = () => {
75+
this.setState({
76+
isMenuActive: false,
77+
});
78+
};
79+
6480
render() {
6581
const canonicalUrl = `https://docs.expo.io${Utilities.replaceVersionInUrl(
6682
this.props.url.pathname,
@@ -81,32 +97,38 @@ export default class DocumentationPage extends React.Component {
8197
const headerElement = (
8298
<DocumentationHeader
8399
pathname={this.props.url.pathname}
84-
activeVersion={this.version}
100+
version={this.version}
101+
isMenuActive={this.state.isMenuActive}
102+
isAlogiaSearchHidden={this.state.isMenuActive}
85103
onSetVersion={this._handleSetVersion}
104+
onShowMenu={this._handleShowMenu}
105+
onHideMenu={this._handleHideMenu}
86106
/>
87107
);
88108

89109
const sidebarElement = (
90-
<DocumentationSidebar
91-
url={this.props.url}
92-
asPath={this.props.asPath}
93-
routes={routes}
94-
activeVersion={this.version}
95-
/>
110+
<DocumentationSidebar url={this.props.url} asPath={this.props.asPath} routes={routes} />
96111
);
97112

98113
return (
99-
<DocumentationPageLayout header={headerElement} sidebar={sidebarElement}>
114+
<DocumentationPageLayout
115+
header={headerElement}
116+
sidebar={sidebarElement}
117+
isMenuActive={this.state.isMenuActive}>
100118
<Head title={`${this.props.title} - Expo Documentation`}>
101119
{version === 'unversioned' && <meta name="robots" content="noindex" />}
102120
{version !== 'unversioned' && <link rel="canonical" href={canonicalUrl} />}
103121
</Head>
104122

105-
<div className={STYLES_DOCUMENT}>
106-
<H1>{this.props.title}</H1>
107-
{this.props.children}
108-
<DocumentationFooter />
109-
</div>
123+
{!this.state.isMenuActive ? (
124+
<div className={STYLES_DOCUMENT}>
125+
<H1>{this.props.title}</H1>
126+
{this.props.children}
127+
<DocumentationFooter />
128+
</div>
129+
) : (
130+
<DocumentationSidebar url={this.props.url} asPath={this.props.asPath} routes={routes} />
131+
)}
110132
</DocumentationPageLayout>
111133
);
112134
}

components/DocumentationPageLayout.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export default props => {
4646
<div className={STYLES_CONTAINER}>
4747
<div className={STYLES_HEADER}>{props.header}</div>
4848
<div className={STYLES_CONTENT}>
49-
<div className={STYLES_LEFT}>{props.sidebar}</div>
49+
{!props.isMenuActive ? <div className={STYLES_LEFT}>{props.sidebar}</div> : undefined}
5050
<div className={STYLES_RIGHT}>{props.children}</div>
5151
</div>
5252
</div>

components/VersionSelector.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ export default class VersionSelector extends React.Component {
8080
return (
8181
<div className={STYLES_SELECT} style={this.props.style}>
8282
<label className={STYLES_SELECT_TEXT} htmlFor="version-menu">
83-
{this.props.activeVersion} <ChevronDownIcon style={{ marginLeft: 8 }} />
83+
{this.props.version} <ChevronDownIcon style={{ marginLeft: 8 }} />
8484
</label>
8585
<select
8686
className={STYLES_SELECT_ELEMENT}
8787
id="version-menu"
88-
value={this.props.activeVersion}
88+
value={this.props.version}
8989
onChange={e => this.props.onSetVersion(e.target.value)}>
9090
{orderVersions(VERSIONS)
9191
.map(version => {

pages/mobile-navigation.js

Lines changed: 0 additions & 59 deletions
This file was deleted.

server.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,6 @@ app.prepare().then(() => {
6565
server.use(compression());
6666
}
6767

68-
server.get('/mobile-navigation/:version', (req, res) => {
69-
app.render(req, res, '/mobile-navigation', { version: req.params.version });
70-
});
71-
7268
// NOTE(jim): Mutations have to line up with FS paths provided by mdjs.
7369
server.get('/versions/:version', (req, res) => {
7470
const { query } = parse(req.url, true);

0 commit comments

Comments
 (0)