File size: 935 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import PropTypes from 'prop-types';
import { PureComponent } from 'react';
import AsyncLoad from 'calypso/components/async-load';
import Placeholder from './placeholder';

export default class DevdocsAsyncLoad extends PureComponent {
	static defaultProps = {
		placeholderCount: 5,
	};
	static propTypes = {
		placeholderCount: PropTypes.number,
		require: PropTypes.oneOfType( [ PropTypes.func, PropTypes.string ] ).isRequired,
	};

	render() {
		const { placeholderCount, require, ...otherProps } = this.props;

		// If `component` is truthy, we're only rendering one component
		// (e.g. `/devdocs/blocks/login` not `/devdocs/blocks`), so we will
		// ignore the number of placeholders to render and just render one.
		const placeholders = this.props.component ? 1 : placeholderCount;

		return (
			<AsyncLoad
				placeholder={ <Placeholder count={ placeholders } /> }
				require={ require }
				{ ...otherProps }
			/>
		);
	}
}