Some docs

This commit is contained in:
Chi Vinh Le
2017-08-25 21:22:48 +07:00
parent 42951aaf0b
commit e3227322a5
3 changed files with 22 additions and 0 deletions
@@ -19,7 +19,13 @@ export default class SortOption extends React.Component {
}
SortOption.propTypes = {
// A simple callback to be called when clicking on this sort option.
setSort: PropTypes.func.isRequired,
// Whether or not this sort option is active.
active: PropTypes.bool.isRequired,
// Label to show next to the input control.
label: PropTypes.string.isRequired,
};
@@ -1,4 +1,12 @@
import withSortOption from '../hocs/withSortOption';
import SortOption from '../components/SortOption';
/**
* A factory creating a sort option component.
* @param {string|function} label label to display, can be a callback for lazy evaluation.
* @param {Object} sort sort parameters
* @param {string} sort.sortBy
* @param {string} sort.sortOrder
* @return {Object} Component
*/
export const createSortOption = (label, sort) => withSortOption({...sort, label})(SortOption);
@@ -18,6 +18,14 @@ const mapDispatchToProps = (dispatch) =>
dispatch
);
/**
* A HOC providing props to implement a sort option.
* Provides the props `active`, `setSort`, `label`.
* @param {Object} sort
* @param {Object} sort.sortBy
* @param {string} sort.sortOrder
* @return {Object} HOC
*/
export default ({sortBy = 'created_at', sortOrder = 'DESC', label}) => hoistStatics((WrappedComponent) => {
class WithSortOption extends React.Component {
setSort = () => {