react-show-more-list
Version:
A unopinionated component to handle showing more results
3 lines (2 loc) • 1.98 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):e.reactShowMoreList=t(e.react)}(this,function(e){"use strict";var t=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},n=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),r=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t},o=function(o){function u(e){t(this,u);var n=r(this,(u.__proto__||Object.getPrototypeOf(u)).call(this,e));return n.getNext=function(){return[n.props.replace?n.state.current[1]+1:0,n.state.current[1]+n.props.by]},n.onMore=function(){n.setState(function(e){return{current:n.getNext()}})},n.getItemsChunk=function(e){return function(t){return t.slice(e[0],e[1]+1)}},n.isLastChunk=function(e){return function(e){var t=n.props.onEnd,r=e[1]>=n.props.items.length-1;return r&&"function"==typeof t&&t(),r}},n.state={current:[0,e.by-1]},n}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(u,e.Component),n(u,[{key:"render",value:function(){var e=this.onMore,t=this.state.current,n=this.props,r=n.children,o=n.items,u=n.by,i=(n.onEnd,this.getItemsChunk(t)(o)),c=this.isLastChunk(u)(t);return"function"==typeof r?r({current:i,by:u,all:o,onMore:c?null:e}):null}}]),u}();return o.defaultProps={by:1,onEnd:null,replace:!1,items:[]},o});
//# sourceMappingURL=react-show-more-list.min.js.map