Skip to content

Commit

Permalink
let's merge
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Oct 31, 2018
1 parent 135bd69 commit 1ab3859
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 95 deletions.
42 changes: 20 additions & 22 deletions docs/src/modules/components/AppDrawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Hidden from '@material-ui/core/Hidden';
import AppDrawerNavItem from 'docs/src/modules/components/AppDrawerNavItem';
import Link from 'docs/src/modules/components/Link';
import { pageToTitle } from 'docs/src/modules/utils/helpers';
import Context from './context';
import PageContext from 'docs/src/modules/components/PageContext';

const styles = theme => ({
paper: {
Expand Down Expand Up @@ -97,30 +97,28 @@ function AppDrawer(props) {
const { classes, className, disablePermanent, mobileOpen, onClose, onOpen } = props;

const drawer = (
<Context.Consumer>
{({ activePage, pages }) => {
return (
<div className={classes.nav}>
<div className={classes.toolbarIe11}>
<div className={classes.toolbar}>
<Link className={classes.title} href="/" onClick={onClose}>
<Typography variant="h6" color="inherit">
Material-UI
</Typography>
<PageContext.Consumer>
{({ activePage, pages }) => (
<div className={classes.nav}>
<div className={classes.toolbarIe11}>
<div className={classes.toolbar}>
<Link className={classes.title} href="/" onClick={onClose}>
<Typography variant="h6" color="inherit">
Material-UI
</Typography>
</Link>
{process.env.LIB_VERSION ? (
<Link className={classes.anchor} href={_rewriteUrlForNextExport('/versions')}>
<Typography variant="caption">{`v${process.env.LIB_VERSION}`}</Typography>
</Link>
{process.env.LIB_VERSION ? (
<Link className={classes.anchor} href={_rewriteUrlForNextExport('/versions')}>
<Typography variant="caption">{`v${process.env.LIB_VERSION}`}</Typography>
</Link>
) : null}
</div>
) : null}
</div>
<Divider />
{renderNavItems({ props, pages, activePage, depth: 0 })}
</div>
);
}}
</Context.Consumer>
<Divider />
{renderNavItems({ props, pages, activePage, depth: 0 })}
</div>
)}
</PageContext.Consumer>
);

return (
Expand Down
6 changes: 3 additions & 3 deletions docs/src/modules/components/EditPage.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React from 'react';
import PropTypes from 'prop-types';
import Button from '@material-ui/core/Button';
import Context from './context';
import PageContext from 'docs/src/modules/components/PageContext';

function EditPage(props) {
const { markdownLocation, sourceCodeRootUrl } = props;

return (
<Context.Consumer>
<PageContext.Consumer>
{({ userLanguage }) => {
if (userLanguage === 'zh') {
return (
Expand All @@ -23,7 +23,7 @@ function EditPage(props) {
</Button>
);
}}
</Context.Consumer>
</PageContext.Consumer>
);
}

Expand Down
100 changes: 47 additions & 53 deletions docs/src/modules/components/MarkdownDocs.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,69 +34,63 @@ const demoRegexp = /^"demo": "(.*)"/;
const SOURCE_CODE_ROOT_URL = 'https://github.com/mui-org/material-ui/blob/master';

function MarkdownDocs(props) {
const { classes, demos, disableAd, markdown, markdownLocation } = props;
const { classes, demos, disableAd, markdown, markdownLocation: markdownLocationProp } = props;
const headers = getHeaders(markdown);

return (
<MarkdownDocsContents markdown={markdown} markdownLocation={markdownLocation}>
{contents => {
return (
<AppFrame>
<Head
title={`${headers.title || getTitle(markdown)} - Material-UI`}
description={headers.description || getDescription(markdown)}
/>
{disableAd ? null : (
<Portal container={() => document.querySelector('.description')}>
<Ad />
</Portal>
)}
<AppTableOfContents contents={contents} />
<AppContent className={classes.root}>
<div className={classes.header}>
<EditPage
markdownLocation={markdownLocation}
sourceCodeRootUrl={SOURCE_CODE_ROOT_URL}
/>
</div>
{contents.map((content, index) => {
const match = content.match(demoRegexp);
<MarkdownDocsContents markdown={markdown} markdownLocation={markdownLocationProp}>
{({ contents, markdownLocation }) => (
<AppFrame>
<Head
title={`${headers.title || getTitle(markdown)} - Material-UI`}
description={headers.description || getDescription(markdown)}
/>
<AppTableOfContents contents={contents} />
{disableAd ? null : (
<Portal container={() => document.querySelector('.description')}>
<Ad />
</Portal>
)}
<AppContent className={classes.root}>
<div className={classes.header}>
<EditPage
markdownLocation={markdownLocation}
sourceCodeRootUrl={SOURCE_CODE_ROOT_URL}
/>
</div>
{contents.map((content, index) => {
const match = content.match(demoRegexp);

if (match && demos) {
let demoOptions;
try {
demoOptions = JSON.parse(`{${content}}`);
} catch (err) {
console.error(err); // eslint-disable-line no-console
return null;
}

const name = demoOptions.demo;
warning(demos && demos[name], `Missing demo: ${name}.`);
return (
<Demo
key={content}
js={demos[name].js}
raw={demos[name].raw}
index={index}
demoOptions={demoOptions}
githubLocation={`${SOURCE_CODE_ROOT_URL}/docs/src/${name}`}
/>
);
if (match && demos) {
let demoOptions;
try {
demoOptions = JSON.parse(`{${content}}`);
} catch (err) {
console.error(err); // eslint-disable-line no-console
return null;
}

const name = demoOptions.demo;
warning(demos && demos[name], `Missing demo: ${name}.`);
return (
<MarkdownElement
className={classes.markdownElement}
<Demo
key={content}
text={content}
js={demos[name].js}
raw={demos[name].raw}
index={index}
demoOptions={demoOptions}
githubLocation={`${SOURCE_CODE_ROOT_URL}/docs/src/${name}`}
/>
);
})}
</AppContent>
</AppFrame>
);
}}
}

return (
<MarkdownElement className={classes.markdownElement} key={content} text={content} />
);
})}
</AppContent>
</AppFrame>
)}
</MarkdownDocsContents>
);
}
Expand Down
8 changes: 4 additions & 4 deletions docs/src/modules/components/MarkdownDocsContents.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import kebabCase from 'lodash/kebabCase';
import { _rewriteUrlForNextExport } from 'next/router';
import PropTypes from 'prop-types';
import { getHeaders, getContents } from 'docs/src/modules/utils/parseMarkdown';
import Context from './context';
import PageContext from 'docs/src/modules/components/PageContext';

function MarkdownDocsContents(props) {
const { children, markdownLocation: markdownLocationProp, markdown } = props;
const contents = getContents(markdown);
const headers = getHeaders(markdown);

return (
<Context.Consumer>
<PageContext.Consumer>
{({ activePage }) => {
let markdownLocation = markdownLocationProp || activePage.pathname;

Expand Down Expand Up @@ -43,9 +43,9 @@ ${headers.components
`);
}

return children(contents);
return children({ contents, markdownLocation });
}}
</Context.Consumer>
</PageContext.Consumer>
);
}

Expand Down
5 changes: 5 additions & 0 deletions docs/src/modules/components/PageContext.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import React from 'react';

const PageContext = React.createContext();

export default PageContext;
6 changes: 3 additions & 3 deletions docs/src/modules/components/PageTitle.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from 'react';
import PropTypes from 'prop-types';
import { pageToTitle } from 'docs/src/modules/utils/helpers';
import Context from './context';
import PageContext from 'docs/src/modules/components/PageContext';

// TODO: it really wants to be named useTitle but we're not quite there yet.
function PageTitle(props) {
return (
<Context.Consumer>
<PageContext.Consumer>
{({ activePage }) => {
if (!activePage) {
throw new Error('Missing activePage.');
Expand All @@ -15,7 +15,7 @@ function PageTitle(props) {
const title = activePage.title !== false ? pageToTitle(activePage) : null;
return props.children(title);
}}
</Context.Consumer>
</PageContext.Consumer>
);
}

Expand Down
7 changes: 0 additions & 7 deletions docs/src/modules/components/context.js

This file was deleted.

6 changes: 3 additions & 3 deletions docs/src/modules/components/withRoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import url from 'url';
import findPages from /* preval */ 'docs/src/modules/utils/findPages';
import { loadCSS } from 'fg-loadcss/src/loadCSS';
import acceptLanguage from 'accept-language';
import Context from './context';
import PageContext from 'docs/src/modules/components/PageContext';

acceptLanguage.languages(['en', 'zh']);

Expand Down Expand Up @@ -319,7 +319,7 @@ function withRoot(Component) {

return (
<React.StrictMode>
<Context.Provider value={{ activePage, pages, userLanguage }}>
<PageContext.Provider value={{ activePage, pages, userLanguage }}>
<Provider store={this.redux}>
<AppWrapper pageContext={pageContext}>
<Component
Expand All @@ -328,7 +328,7 @@ function withRoot(Component) {
/>
</AppWrapper>
</Provider>
</Context.Provider>
</PageContext.Provider>
</React.StrictMode>
);
}
Expand Down

0 comments on commit 1ab3859

Please sign in to comment.