woocommerce/plugins/woocommerce-admin/client/devdocs/docs.js

46 lines
831 B
JavaScript
Raw Normal View History

/** @format */
/**
* External dependencies
*/
import { Component } from '@wordpress/element';
import marked from 'marked';
import { Parser } from 'html-to-react';
const htmlToReactParser = new Parser();
class Docs extends Component {
state = {
readme: null,
};
componentDidMount() {
this.getReadme();
}
getReadme() {
2019-01-04 03:04:54 +00:00
const { filePath, docPath } = this.props;
const readme = require( `../../docs/components/${ docPath }/${ filePath }.md` );
if ( ! readme ) {
return;
}
const html = marked( readme );
this.setState( {
readme: htmlToReactParser.parse( html ),
} );
}
render() {
const { readme } = this.state;
if ( ! readme ) {
return null;
}
return <div className="woocommerce-devdocs__docs">{ readme }</div>;
}
}
2019-01-04 03:04:54 +00:00
Docs.defaultProps = {
docPath: 'packages',
};
export default Docs;