2018-09-24 15:36:35 +00:00
|
|
|
/** @format */
|
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import classnames from 'classnames';
|
2019-08-29 14:47:27 +00:00
|
|
|
import { Component, Fragment } from '@wordpress/element';
|
2018-09-24 15:36:35 +00:00
|
|
|
import { find, get } from 'lodash';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import ComponentExample from './example';
|
|
|
|
import ComponentDocs from './docs';
|
|
|
|
import { Card, Link } from '@woocommerce/components';
|
|
|
|
import examples from './examples.json';
|
|
|
|
import './style.scss';
|
|
|
|
|
|
|
|
const camelCaseToSlug = name => {
|
|
|
|
return name.replace( /\.?([A-Z])/g, ( x, y ) => '-' + y.toLowerCase() ).replace( /^-/, '' );
|
|
|
|
};
|
|
|
|
|
|
|
|
const getExampleData = example => {
|
|
|
|
const componentName = get( example, 'component' );
|
|
|
|
const filePath = get( example, 'filePath', camelCaseToSlug( componentName ) );
|
|
|
|
|
|
|
|
return {
|
|
|
|
componentName,
|
|
|
|
filePath,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export default class extends Component {
|
|
|
|
render() {
|
2019-08-30 16:07:29 +00:00
|
|
|
const { query: { component } } = this.props;
|
2018-09-24 15:36:35 +00:00
|
|
|
const className = classnames( 'woocommerce_devdocs', {
|
|
|
|
'is-single': component,
|
|
|
|
'is-list': ! component,
|
|
|
|
} );
|
|
|
|
|
|
|
|
let exampleList = examples;
|
|
|
|
if ( component ) {
|
|
|
|
const example = find( examples, ex => component === camelCaseToSlug( ex.component ) );
|
|
|
|
exampleList = [ example ];
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={ className }>
|
|
|
|
{ exampleList.map( example => {
|
2019-08-29 21:41:21 +00:00
|
|
|
const { componentName, filePath } = getExampleData( example );
|
2018-09-24 15:36:35 +00:00
|
|
|
const cardClasses = classnames(
|
|
|
|
'woocommerce-devdocs__card',
|
2019-05-22 08:38:25 +00:00
|
|
|
`woocommerce-devdocs__card--${ filePath }`,
|
|
|
|
'woocommerce-analytics__card'
|
2018-09-24 15:36:35 +00:00
|
|
|
);
|
|
|
|
return (
|
2019-08-29 14:47:27 +00:00
|
|
|
<Fragment key={ componentName }>
|
|
|
|
<Card
|
|
|
|
key={ `${ componentName }-example` }
|
|
|
|
className={ cardClasses }
|
|
|
|
title={
|
|
|
|
component ? (
|
|
|
|
componentName
|
|
|
|
) : (
|
|
|
|
<Link
|
2019-08-30 16:07:29 +00:00
|
|
|
href={ `admin.php?page=wc-admin&path=/devdocs&component=${ filePath }` }
|
2019-08-29 14:47:27 +00:00
|
|
|
type="wc-admin"
|
|
|
|
>
|
|
|
|
{ componentName }
|
|
|
|
</Link>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
action={
|
|
|
|
component ? (
|
|
|
|
<Link href={ '?page=wc-admin&path=/devdocs' } type="wc-admin">
|
|
|
|
Full list
|
|
|
|
</Link>
|
|
|
|
) : null
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<ComponentExample
|
|
|
|
asyncName={ componentName }
|
|
|
|
component={ componentName }
|
|
|
|
filePath={ filePath }
|
|
|
|
/>
|
|
|
|
</Card>
|
2018-09-24 15:36:35 +00:00
|
|
|
{ component && (
|
2019-01-04 03:04:54 +00:00
|
|
|
<ComponentDocs
|
2019-08-29 14:47:27 +00:00
|
|
|
key={ `${ componentName }-readme` }
|
2019-01-04 03:04:54 +00:00
|
|
|
componentName={ componentName }
|
|
|
|
filePath={ filePath }
|
|
|
|
/>
|
2018-09-24 15:36:35 +00:00
|
|
|
) }
|
2019-08-29 14:47:27 +00:00
|
|
|
</Fragment>
|
2018-09-24 15:36:35 +00:00
|
|
|
);
|
|
|
|
} ) }
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|