diff --git a/plugin-api/beta/client/components/SortOption.js b/plugin-api/beta/client/components/SortOption.js index 31aa509c0..7c8b4d761 100644 --- a/plugin-api/beta/client/components/SortOption.js +++ b/plugin-api/beta/client/components/SortOption.js @@ -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, }; diff --git a/plugin-api/beta/client/factories/index.js b/plugin-api/beta/client/factories/index.js index 485651821..d413258c6 100644 --- a/plugin-api/beta/client/factories/index.js +++ b/plugin-api/beta/client/factories/index.js @@ -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); diff --git a/plugin-api/beta/client/hocs/withSortOption.js b/plugin-api/beta/client/hocs/withSortOption.js index 7870b668e..076d921e7 100644 --- a/plugin-api/beta/client/hocs/withSortOption.js +++ b/plugin-api/beta/client/hocs/withSortOption.js @@ -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 = () => {