UNPKG

@enact/ui

Version:

A collection of simplified unstyled cross-platform UI components for Enact

554 lines (548 loc) 19.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.VirtualList = exports.VirtualGridList = void 0; Object.defineProperty(exports, "VirtualListBasic", { enumerable: true, get: function get() { return _VirtualListBasic.VirtualListBasic; } }); exports["default"] = void 0; Object.defineProperty(exports, "gridListItemSizeShape", { enumerable: true, get: function get() { return _VirtualListBasic.gridListItemSizeShape; } }); Object.defineProperty(exports, "itemSizesShape", { enumerable: true, get: function get() { return _VirtualListBasic.itemSizesShape; } }); var _util = require("@enact/core/util"); var _propTypes = _interopRequireDefault(require("prop-types")); var _Resizable = require("../Resizable"); var _useScroll3 = _interopRequireDefault(require("../useScroll")); var _Scrollbar = _interopRequireDefault(require("../useScroll/Scrollbar")); var _VirtualListBasic = require("./VirtualListBasic"); var _jsxRuntime = require("react/jsx-runtime"); function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; } function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /** * Unstyled virtual list components and behaviors to be customized by a theme or application. * * @module ui/VirtualList * @exports gridListImageSizeShape * @exports itemSizesShape * @exports VirtualGridList * @exports VirtualList * @exports VirtualListBasic */ var nop = function nop() {}; var virtualListDefaultProps = { cbScrollTo: nop, direction: 'vertical', horizontalScrollbar: 'auto', noScrollByDrag: false, noScrollByWheel: false, onScroll: nop, onScrollStart: nop, onScrollStop: nop, overscrollEffectOn: { drag: false, pageKey: false, wheel: false }, role: 'list', scrollMode: 'translate', verticalScrollbar: 'auto' }; /** * An unstyled scrollable virtual list component with touch support. * * @class VirtualList * @memberof ui/VirtualList * @extends ui/VirtualList.VirtualListBasic * @ui * @public */ var VirtualList = exports.VirtualList = function VirtualList(props) { // Hooks var virtualListProps = (0, _util.setDefaultProps)(props, virtualListDefaultProps); var _useScroll = (0, _useScroll3["default"])(virtualListProps), scrollContentHandle = _useScroll.scrollContentHandle, ScrollContentWrapper = _useScroll.scrollContentWrapper, isHorizontalScrollbarVisible = _useScroll.isHorizontalScrollbarVisible, isVerticalScrollbarVisible = _useScroll.isVerticalScrollbarVisible, resizeContextProps = _useScroll.resizeContextProps, scrollContainerProps = _useScroll.scrollContainerProps, scrollInnerContainerProps = _useScroll.scrollInnerContainerProps, scrollContentWrapperProps = _useScroll.scrollContentWrapperProps, scrollContentProps = _useScroll.scrollContentProps, verticalScrollbarProps = _useScroll.verticalScrollbarProps, horizontalScrollbarProps = _useScroll.horizontalScrollbarProps; // Render return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Resizable.ResizeContext, _objectSpread(_objectSpread({}, resizeContextProps), {}, { children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", _objectSpread(_objectSpread({}, scrollContainerProps), {}, { children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("div", _objectSpread(_objectSpread({}, scrollInnerContainerProps), {}, { children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(ScrollContentWrapper, _objectSpread(_objectSpread({}, scrollContentWrapperProps), {}, { children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_VirtualListBasic.VirtualListBasic, _objectSpread(_objectSpread({}, scrollContentProps), {}, { ref: scrollContentHandle })) })), isVerticalScrollbarVisible ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_Scrollbar["default"], _objectSpread({}, verticalScrollbarProps)) : null] })), isHorizontalScrollbarVisible ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_Scrollbar["default"], _objectSpread({}, horizontalScrollbarProps)) : null] })) })); }; VirtualList.displayName = 'ui:VirtualList'; VirtualList.propTypes = /** @lends ui/VirtualList.VirtualList.prototype */{ /** * A callback function that receives a reference to the `scrollTo` feature. * * Once received, the `scrollTo` method can be called as an imperative interface. * * The `scrollTo` function accepts the following parameters: * - {position: {x, y}} - Pixel value for x and/or y position * - {align} - Where the scroll area should be aligned. Values are: * `'left'`, `'right'`, `'top'`, `'bottom'`, * `'topleft'`, `'topright'`, `'bottomleft'`, and `'bottomright'`. * - {index} - Index of specific item. (`0` or positive integer) * This option is available for only `VirtualList` kind. * - {node} - Node to scroll into view * - {animate} - When `true`, scroll occurs with animation. When `false`, no * animation occurs. * - {focus} - When `true`, attempts to focus item after scroll. Only valid when scrolling * by `index` or `node`. * > Note: Only specify one of: `position`, `align`, `index` or `node` * * Example: * ``` * // If you set cbScrollTo prop like below; * cbScrollTo: (fn) => {this.scrollTo = fn;} * // You can simply call like below; * this.scrollTo({align: 'top'}); // scroll to the top * ``` * * @type {Function} * @public */ cbScrollTo: _propTypes["default"].func, /** * The layout direction of the list. * * Valid values are: * * `'horizontal'`, and * * `'vertical'`. * * @type {String} * @default 'vertical' * @public */ direction: _propTypes["default"].oneOf(['horizontal', 'vertical']), /** * Specifies how to show horizontal scrollbar. * * Valid values are: * * `'auto'`, * * `'visible'`, and * * `'hidden'`. * * @type {String} * @default 'auto' * @public */ horizontalScrollbar: _propTypes["default"].oneOf(['auto', 'visible', 'hidden']), /** * Prevents scroll by dragging or flicking on the list. * * @type {Boolean} * @default false * @private */ noScrollByDrag: _propTypes["default"].bool, /** * Prevents scroll by wheeling on the list. * * @type {Boolean} * @default false * @public */ noScrollByWheel: _propTypes["default"].bool, /** * Called when scrolling. * * Passes `scrollLeft`, `scrollTop`, and `moreInfo`. * It is not recommended to set this prop since it can cause performance degradation. * Use `onScrollStart` or `onScrollStop` instead. * * @type {Function} * @param {Object} event * @param {Number} event.scrollLeft Scroll left value. * @param {Number} event.scrollTop Scroll top value. * @param {Object} event.moreInfo The object including `firstVisibleIndex` and `lastVisibleIndex` properties. * @public */ onScroll: _propTypes["default"].func, /** * Called when scroll starts. * * Passes `scrollLeft`, `scrollTop`, and `moreInfo`. * You can get firstVisibleIndex and lastVisibleIndex from VirtualList with `moreInfo`. * * Example: * ``` * onScrollStart = ({scrollLeft, scrollTop, moreInfo}) => { * const {firstVisibleIndex, lastVisibleIndex} = moreInfo; * // do something with firstVisibleIndex and lastVisibleIndex * } * * render = () => ( * <VirtualList * ... * onScrollStart={this.onScrollStart} * ... * /> * ) * ``` * * @type {Function} * @param {Object} event * @param {Number} event.scrollLeft Scroll left value. * @param {Number} event.scrollTop Scroll top value. * @param {Object} event.moreInfo The object including `firstVisibleIndex` and `lastVisibleIndex` properties. * @public */ onScrollStart: _propTypes["default"].func, /** * Called when scroll stops. * * Passes `scrollLeft`, `scrollTop`, and `moreInfo`. * You can get firstVisibleIndex and lastVisibleIndex from VirtualList with `moreInfo`. * * Example: * ``` * onScrollStop = ({scrollLeft, scrollTop, moreInfo}) => { * const {firstVisibleIndex, lastVisibleIndex} = moreInfo; * // do something with firstVisibleIndex and lastVisibleIndex * } * * render = () => ( * <VirtualList * ... * onScrollStop={this.onScrollStop} * ... * /> * ) * ``` * * @type {Function} * @param {Object} event * @param {Number} event.scrollLeft Scroll left value. * @param {Number} event.scrollTop Scroll top value. * @param {Object} event.moreInfo The object including `firstVisibleIndex` and `lastVisibleIndex` properties. * @public */ onScrollStop: _propTypes["default"].func, /** * Specifies overscroll effects shows on which type of inputs. * * @type {Object} * @default {drag: false, pageKey: false, wheel: false} * @private */ overscrollEffectOn: _propTypes["default"].shape({ drag: _propTypes["default"].bool, pageKey: _propTypes["default"].bool, wheel: _propTypes["default"].bool }), /** * The ARIA role for the list. * * @type {String} * @default 'list' * @public */ role: _propTypes["default"].string, /** * Specifies how to scroll. * * Valid values are: * * `'translate'`, * * `'native'`. * * @type {String} * @default 'translate' * @public */ scrollMode: _propTypes["default"].string, /** * Specifies how to show vertical scrollbar. * * Valid values are: * * `'auto'`, * * `'visible'`, and * * `'hidden'`. * * @type {String} * @default 'auto' * @public */ verticalScrollbar: _propTypes["default"].oneOf(['auto', 'visible', 'hidden']) }; VirtualList.defaultPropValues = virtualListDefaultProps; var virtualGridListDefaultProps = { cbScrollTo: nop, direction: 'vertical', horizontalScrollbar: 'auto', noScrollByDrag: false, noScrollByWheel: false, onScroll: nop, onScrollStart: nop, onScrollStop: nop, overscrollEffectOn: { drag: false, pageKey: false, wheel: false }, role: 'list', scrollMode: 'translate', verticalScrollbar: 'auto' }; /** * An unstyled scrollable virtual grid list component with touch support. * * @class VirtualGridList * @memberof ui/VirtualList * @extends ui/VirtualList.VirtualListBasic * @ui * @public */ var VirtualGridList = exports.VirtualGridList = function VirtualGridList(props) { var virtualGridListProps = (0, _util.setDefaultProps)(props, virtualGridListDefaultProps); var _useScroll2 = (0, _useScroll3["default"])(virtualGridListProps), scrollContentHandle = _useScroll2.scrollContentHandle, ScrollContentWrapper = _useScroll2.scrollContentWrapper, isHorizontalScrollbarVisible = _useScroll2.isHorizontalScrollbarVisible, isVerticalScrollbarVisible = _useScroll2.isVerticalScrollbarVisible, resizeContextProps = _useScroll2.resizeContextProps, scrollContainerProps = _useScroll2.scrollContainerProps, scrollInnerContainerProps = _useScroll2.scrollInnerContainerProps, scrollContentWrapperProps = _useScroll2.scrollContentWrapperProps, scrollContentProps = _useScroll2.scrollContentProps, verticalScrollbarProps = _useScroll2.verticalScrollbarProps, horizontalScrollbarProps = _useScroll2.horizontalScrollbarProps; return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Resizable.ResizeContext, _objectSpread(_objectSpread({}, resizeContextProps), {}, { children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", _objectSpread(_objectSpread({}, scrollContainerProps), {}, { children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("div", _objectSpread(_objectSpread({}, scrollInnerContainerProps), {}, { children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(ScrollContentWrapper, _objectSpread(_objectSpread({}, scrollContentWrapperProps), {}, { children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_VirtualListBasic.VirtualListBasic, _objectSpread(_objectSpread({}, scrollContentProps), {}, { ref: scrollContentHandle })) })), isVerticalScrollbarVisible ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_Scrollbar["default"], _objectSpread({}, verticalScrollbarProps)) : null] })), isHorizontalScrollbarVisible ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_Scrollbar["default"], _objectSpread({}, horizontalScrollbarProps)) : null] })) })); }; VirtualGridList.displayName = 'ui:VirtualGridList'; VirtualGridList.propTypes = /** @lends ui/VirtualList.VirtualGridList.prototype */{ /** * A callback function that receives a reference to the `scrollTo` feature. * * Once received, the `scrollTo` method can be called as an imperative interface. * * The `scrollTo` function accepts the following parameters: * - {position: {x, y}} - Pixel value for x and/or y position * - {align} - Where the scroll area should be aligned. Values are: * `'left'`, `'right'`, `'top'`, `'bottom'`, * `'topleft'`, `'topright'`, `'bottomleft'`, and `'bottomright'`. * - {index} - Index of specific item. (`0` or positive integer) * This option is available for only `VirtualList` kind. * - {node} - Node to scroll into view * - {animate} - When `true`, scroll occurs with animation. When `false`, no * animation occurs. * - {focus} - When `true`, attempts to focus item after scroll. Only valid when scrolling * by `index` or `node`. * > Note: Only specify one of: `position`, `align`, `index` or `node` * * Example: * ``` * // If you set cbScrollTo prop like below; * cbScrollTo: (fn) => {this.scrollTo = fn;} * // You can simply call like below; * this.scrollTo({align: 'top'}); // scroll to the top * ``` * * @type {Function} * @public */ cbScrollTo: _propTypes["default"].func, /** * The layout direction of the list. * * Valid values are: * * `'horizontal'`, and * * `'vertical'`. * * @type {String} * @default 'vertical' * @public */ direction: _propTypes["default"].oneOf(['horizontal', 'vertical']), /** * Specifies how to show horizontal scrollbar. * * Valid values are: * * `'auto'`, * * `'visible'`, and * * `'hidden'`. * * @type {String} * @default 'auto' * @public */ horizontalScrollbar: _propTypes["default"].oneOf(['auto', 'visible', 'hidden']), /** * Prevents scroll by dragging or flicking on the list. * * @type {Boolean} * @default false * @private */ noScrollByDrag: _propTypes["default"].bool, /** * Prevents scroll by wheeling on the list. * * @type {Boolean} * @default false * @public */ noScrollByWheel: _propTypes["default"].bool, /** * Called when scrolling. * * Passes `scrollLeft`, `scrollTop`, and `moreInfo`. * It is not recommended to set this prop since it can cause performance degradation. * Use `onScrollStart` or `onScrollStop` instead. * * @type {Function} * @param {Object} event * @param {Number} event.scrollLeft Scroll left value. * @param {Number} event.scrollTop Scroll top value. * @param {Object} event.moreInfo The object including `firstVisibleIndex` and `lastVisibleIndex` properties. * @public */ onScroll: _propTypes["default"].func, /** * Called when scroll starts. * * Passes `scrollLeft`, `scrollTop`, and `moreInfo`. * You can get firstVisibleIndex and lastVisibleIndex from VirtualGridList with `moreInfo`. * * Example: * ``` * onScrollStart = ({scrollLeft, scrollTop, moreInfo}) => { * const {firstVisibleIndex, lastVisibleIndex} = moreInfo; * // do something with firstVisibleIndex and lastVisibleIndex * } * * render = () => ( * <VirtualGridList * ... * onScrollStart={this.onScrollStart} * ... * /> * ) * ``` * * @type {Function} * @param {Object} event * @param {Number} event.scrollLeft Scroll left value. * @param {Number} event.scrollTop Scroll top value. * @param {Object} event.moreInfo The object including `firstVisibleIndex` and `lastVisibleIndex` properties. * @public */ onScrollStart: _propTypes["default"].func, /** * Called when scroll stops. * * Passes `scrollLeft`, `scrollTop`, and `moreInfo`. * You can get firstVisibleIndex and lastVisibleIndex from VirtualList with `moreInfo`. * * Example: * ``` * onScrollStop = ({scrollLeft, scrollTop, moreInfo}) => { * const {firstVisibleIndex, lastVisibleIndex} = moreInfo; * // do something with firstVisibleIndex and lastVisibleIndex * } * * render = () => ( * <VirtualGridList * ... * onScrollStop={this.onScrollStop} * ... * /> * ) * ``` * * @type {Function} * @param {Object} event * @param {Number} event.scrollLeft Scroll left value. * @param {Number} event.scrollTop Scroll top value. * @param {Object} event.moreInfo The object including `firstVisibleIndex` and `lastVisibleIndex` properties. * @public */ onScrollStop: _propTypes["default"].func, /** * Specifies overscroll effects shows on which type of inputs. * * @type {Object} * @default {drag: false, pageKey: false, wheel: false} * @private */ overscrollEffectOn: _propTypes["default"].shape({ drag: _propTypes["default"].bool, pageKey: _propTypes["default"].bool, wheel: _propTypes["default"].bool }), /** * The ARIA role for the list. * * @type {String} * @default 'list' * @public */ role: _propTypes["default"].string, /** * Specifies how to scroll. * * Valid values are: * * `'translate'`, * * `'native'`. * * @type {String} * @default 'translate' * @public */ scrollMode: _propTypes["default"].string, /** * Specifies how to show vertical scrollbar. * * Valid values are: * * `'auto'`, * * `'visible'`, and * * `'hidden'`. * * @type {String} * @default 'auto' * @public */ verticalScrollbar: _propTypes["default"].oneOf(['auto', 'visible', 'hidden']) }; VirtualGridList.defaultPropValues = virtualGridListDefaultProps; var _default = exports["default"] = VirtualList;