Skip to content

Commit

Permalink
[docs] Fix the latest regressions (#461)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari authored Sep 1, 2018
1 parent 01f419c commit eb19f50
Show file tree
Hide file tree
Showing 21 changed files with 218 additions and 306 deletions.
1 change: 0 additions & 1 deletion docs/src/modules/components/Demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ const styles = theme => ({
borderRadius: theme.shape.borderRadius,
backgroundColor:
theme.palette.type === 'light' ? theme.palette.grey[200] : theme.palette.grey[900],
display: 'flex',
justifyContent: 'center',
paddingTop: theme.spacing.unit * 2,
paddingBottom: theme.spacing.unit * 2,
Expand Down
2 changes: 1 addition & 1 deletion docs/src/modules/components/MarkdownDocs.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const styles = theme => ({

const demoRegexp = /^"demo": "(.*)"/;
const SOURCE_CODE_ROOT_URL =
'https://github.com/oliviertassinari/react-swipeable-views/tree/master/';
'https://github.com/oliviertassinari/react-swipeable-views/tree/master';

function MarkdownDocs(props, context) {
const { classes, demos, disableAd, markdown, markdownLocation: markdownLocationProp } = props;
Expand Down
30 changes: 0 additions & 30 deletions docs/src/modules/components/SupportTouch.js

This file was deleted.

44 changes: 9 additions & 35 deletions docs/src/modules/components/withRoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import React from 'react';
import PropTypes from 'prop-types';
import find from 'lodash/find';
import { withRouter } from 'next/router';
import pure from 'recompose/pure';
import wrapDisplayName from 'recompose/wrapDisplayName';
import AppWrapper from 'docs/src/modules/components/AppWrapper';

const pages = [
Expand Down Expand Up @@ -52,7 +50,7 @@ const pages = [
function findActivePage(currentPages, router) {
const activePage = find(currentPages, page => {
if (page.children) {
return router.pathname.indexOf(page.pathname) === 0;
return router.pathname.indexOf(`${page.pathname}/`) === 0;
}

// Should be an exact match if no children
Expand All @@ -71,10 +69,7 @@ function findActivePage(currentPages, router) {
return activePage;
}

function withRoot(BaseComponent) {
// Prevent rerendering
const PureBaseComponent = pure(BaseComponent);

function withRoot(Component) {
class WithRoot extends React.Component {
getChildContext() {
const { router } = this.props;
Expand All @@ -93,48 +88,27 @@ function withRoot(BaseComponent) {
}

render() {
const { sheetsRegistry, ...other } = this.props;

const { pageContext, ...other } = this.props;
return (
<AppWrapper sheetsRegistry={sheetsRegistry}>
<PureBaseComponent initialProps={other} />
</AppWrapper>
<React.StrictMode>
<AppWrapper pageContext={pageContext}>
<Component initialProps={other} />
</AppWrapper>
</React.StrictMode>
);
}
}

WithRoot.propTypes = {
pageContext: PropTypes.object,
router: PropTypes.object.isRequired,
sheetsRegistry: PropTypes.object,
};

WithRoot.childContextTypes = {
pages: PropTypes.array,
activePage: PropTypes.object,
};

WithRoot.getInitialProps = ctx => {
let initialProps = {};

if (BaseComponent.getInitialProps) {
const baseComponentInitialProps = BaseComponent.getInitialProps(ctx);
initialProps = {
...baseComponentInitialProps,
...initialProps,
};
}

if (process.browser) {
return initialProps;
}

return initialProps;
};

if (process.env.NODE_ENV !== 'production') {
WithRoot.displayName = wrapDisplayName(BaseComponent, 'withRoot');
}

return withRouter(WithRoot);
}

Expand Down
24 changes: 18 additions & 6 deletions docs/src/modules/utils/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ export function titleize(string) {

return string
.split('-')
.map(word => word.split(''))
.map(letters => {
const first = letters.shift();
return [first.toUpperCase(), ...letters].join('');
})
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
.join(' ');
}

Expand All @@ -25,9 +21,25 @@ export function pageToTitle(page) {

const name = page.pathname.replace(/.*\//, '');

if (page.pathname.indexOf('/api') === 0) {
if (page.pathname.indexOf('/api/') !== -1) {
return upperFirst(camelCase(name));
}

return titleize(name);
}

export function getDependencies(raw) {
const deps = {
'react-dom': 'latest',
react: 'latest',
};
const re = /^import\s.*\sfrom\s+'([^']+)'/gm;
let m;
// eslint-disable-next-line no-cond-assign
while ((m = re.exec(raw))) {
// handle scope names
const name = m[1].charAt(0) === '@' ? m[1].split('/', 2).join('/') : m[1].split('/', 1)[0];
deps[name] = deps[name] || 'latest';
}
return deps;
}
25 changes: 11 additions & 14 deletions docs/src/pages/demos/DemoAnimateHeight.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import SwipeableViews from 'react-swipeable-views';
import SupportTouch from 'docs/src/modules/components/SupportTouch';

const styles = {
slide: {
Expand Down Expand Up @@ -68,19 +67,17 @@ Slide4.contextTypes = {

function DemoAnimateHeight() {
return (
<SupportTouch>
<SwipeableViews animateHeight>
<div style={Object.assign({}, styles.slide, styles.slide1)}>{list.slice(0, 10)}</div>
<div style={Object.assign({}, styles.slide, styles.slide2)}>
{'This slide has a max-height limit:'}
<br />
<br />
{list.slice(0, 7)}
</div>
<div style={Object.assign({}, styles.slide, styles.slide3)}>{list.slice(0, 7)}</div>
<Slide4 />
</SwipeableViews>
</SupportTouch>
<SwipeableViews animateHeight>
<div style={Object.assign({}, styles.slide, styles.slide1)}>{list.slice(0, 10)}</div>
<div style={Object.assign({}, styles.slide, styles.slide2)}>
{'This slide has a max-height limit:'}
<br />
<br />
{list.slice(0, 7)}
</div>
<div style={Object.assign({}, styles.slide, styles.slide3)}>{list.slice(0, 7)}</div>
<Slide4 />
</SwipeableViews>
);
}

Expand Down
19 changes: 8 additions & 11 deletions docs/src/pages/demos/DemoAutoPlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React from 'react';
import SwipeableViews from 'react-swipeable-views';
import { autoPlay } from 'react-swipeable-views-utils';
import Pagination from 'docs/src/modules/components/Pagination';
import SupportTouch from 'docs/src/modules/components/SupportTouch';

const AutoPlaySwipeableViews = autoPlay(SwipeableViews);

Expand Down Expand Up @@ -41,16 +40,14 @@ class DemoAutoPlay extends React.Component {
const { index } = this.state;

return (
<SupportTouch>
<div style={styles.root}>
<AutoPlaySwipeableViews index={index} onChangeIndex={this.handleChangeIndex}>
<div style={Object.assign({}, styles.slide, styles.slide1)}>slide n°1</div>
<div style={Object.assign({}, styles.slide, styles.slide2)}>slide n°2</div>
<div style={Object.assign({}, styles.slide, styles.slide3)}>slide n°3</div>
</AutoPlaySwipeableViews>
<Pagination dots={3} index={index} onChangeIndex={this.handleChangeIndex} />
</div>
</SupportTouch>
<div style={styles.root}>
<AutoPlaySwipeableViews index={index} onChangeIndex={this.handleChangeIndex}>
<div style={Object.assign({}, styles.slide, styles.slide1)}>slide n°1</div>
<div style={Object.assign({}, styles.slide, styles.slide2)}>slide n°2</div>
<div style={Object.assign({}, styles.slide, styles.slide3)}>slide n°3</div>
</AutoPlaySwipeableViews>
<Pagination dots={3} index={index} onChangeIndex={this.handleChangeIndex} />
</div>
);
}
}
Expand Down
17 changes: 7 additions & 10 deletions docs/src/pages/demos/DemoAxis.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import SwipeableViews from 'react-swipeable-views';
import SupportTouch from 'docs/src/modules/components/SupportTouch';

const styles = {
slideContainer: {
Expand Down Expand Up @@ -29,15 +28,13 @@ const styles = {

function DemoAxis() {
return (
<SupportTouch>
<SwipeableViews containerStyle={styles.slideContainer} axis="y" resistance>
<div style={Object.assign({}, styles.slide, styles.slide1)}>slide n°1</div>
<div style={Object.assign({}, styles.slide, styles.slide2)}>slide n°2</div>
<div style={styles.scroll}>
<div style={Object.assign({}, styles.slide, styles.slide3)}>slide n°3</div>
</div>
</SwipeableViews>
</SupportTouch>
<SwipeableViews containerStyle={styles.slideContainer} axis="y" resistance>
<div style={Object.assign({}, styles.slide, styles.slide1)}>slide n°1</div>
<div style={Object.assign({}, styles.slide, styles.slide2)}>slide n°2</div>
<div style={styles.scroll}>
<div style={Object.assign({}, styles.slide, styles.slide3)}>slide n°3</div>
</div>
</SwipeableViews>
);
}

Expand Down
7 changes: 1 addition & 6 deletions docs/src/pages/demos/DemoCircular.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React from 'react';
import SwipeableViews from 'react-swipeable-views';
import { virtualize } from 'react-swipeable-views-utils';
import { mod } from 'react-swipeable-views-core';
import SupportTouch from 'docs/src/modules/components/SupportTouch';

const VirtualizeSwipeableViews = virtualize(SwipeableViews);

Expand Down Expand Up @@ -54,11 +53,7 @@ function slideRenderer(params) {
}

function DemoSimple() {
return (
<SupportTouch>
<VirtualizeSwipeableViews slideRenderer={slideRenderer} />
</SupportTouch>
);
return <VirtualizeSwipeableViews slideRenderer={slideRenderer} />;
}

export default DemoSimple;
Loading

0 comments on commit eb19f50

Please sign in to comment.