mirror of
https://github.com/gosticks/react-bootstrap-table2.git
synced 2026-06-28 21:20:04 +00:00
examples enhance
* utils for products generator * load test for each *.test.js file in packages folder * [test] unit test for utils/common * refactor all products with productGenerator for all examples * refactor folder structure * move component <Code /> to src/components/common * rename component file name
This commit is contained in:
26
packages/react-bootstrap-table2-example/src/components/common/code-block.js
vendored
Normal file
26
packages/react-bootstrap-table2-example/src/components/common/code-block.js
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
import React, { Component } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
export default class extends Component {
|
||||
static propTypes = {
|
||||
children: PropTypes.string
|
||||
}
|
||||
static defaultProps = {
|
||||
children: ''
|
||||
}
|
||||
componentDidMount() {
|
||||
// code-prettify
|
||||
// run the PR.prettyPrint() function once your page has finished loading
|
||||
if (typeof (PR) !== 'undefined') PR.prettyPrint(); // eslint-disable-line no-undef
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div className="highlight-text-html-basic">
|
||||
<pre className="prettyprint lang-js">
|
||||
{ this.props.children }
|
||||
</pre>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
21
packages/react-bootstrap-table2-example/src/utils/common.js
vendored
Normal file
21
packages/react-bootstrap-table2-example/src/utils/common.js
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* products generator for stories
|
||||
*
|
||||
* @param {Number} quantity - quantity of products
|
||||
* @param {Function} callback - callback func which is similiar to 'mapFunction'
|
||||
* aims to customize product format
|
||||
*
|
||||
* @return {Array} - products array
|
||||
*/
|
||||
export const productsGenerator = (quantity = 5, callback) => {
|
||||
if (callback) return Array.from({ length: quantity }, callback);
|
||||
|
||||
// if no given callback, retrun default product format.
|
||||
return (
|
||||
Array.from({ length: quantity }, (value, index) => ({
|
||||
id: index,
|
||||
name: `Item name ${index}`,
|
||||
price: 2100 + index
|
||||
}))
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user