@zohodesk/components
Version:
Dot UI is a customizable React component library built to deliver a clean, accessible, and developer-friendly UI experience. It offers a growing set of reusable components designed to align with modern design systems and streamline application development
399 lines (328 loc) • 16.8 kB
JavaScript
"use strict";
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = exports.CardHeader = exports.CardFooter = exports.CardContent = void 0;
var _react = _interopRequireWildcard(require("react"));
var _propTypes = require("./props/propTypes");
var _defaultProps = require("./props/defaultProps");
var _Layout = require("../Layout");
var _Config = require("../Provider/Config");
var _CardModule = _interopRequireDefault(require("./Card.module.css"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
/* eslint-disable react/forbid-component-props */
/*
isscroll header border change use ref
scroll logic remove from here
scroll logic move to virtualizer list
*/
/* performance handling pending in card component moving to ref instead of setState */
var CardHeader = /*#__PURE__*/function (_Component) {
_inherits(CardHeader, _Component);
var _super = _createSuper(CardHeader);
function CardHeader(props) {
var _this;
_classCallCheck(this, CardHeader);
_this = _super.call(this, props);
_this.getCardHeaderDom = _this.getCardHeaderDom.bind(_assertThisInitialized(_this));
_this.cardHeader = null;
return _this;
}
_createClass(CardHeader, [{
key: "getCardHeaderDom",
value: function getCardHeaderDom(ele) {
this.cardHeader = ele;
}
}, {
key: "setScrollClassName",
value: function setScrollClassName() {
if (!this.cardHeader) {
return null;
}
}
}, {
key: "render",
value: function render() {
var _this$props = this.props,
isScroll = _this$props.isScroll,
children = _this$props.children,
dataId = _this$props.dataId,
dataSelectorId = _this$props.dataSelectorId,
customClass = _this$props.customClass;
return /*#__PURE__*/_react["default"].createElement(_Layout.Box, {
className: "".concat(isScroll ? _CardModule["default"].scroll : _CardModule["default"].notScroll, " ").concat(customClass),
eleRef: this.getCardHeaderDom,
dataId: dataId,
dataSelectorId: dataSelectorId
}, children);
}
}]);
return CardHeader;
}(_react.Component);
exports.CardHeader = CardHeader;
CardHeader.propTypes = _propTypes.CardHeader_propTypes;
CardHeader.defaultProps = _defaultProps.CardHeader_defaultProps;
var CardContent = /*#__PURE__*/function (_Component2) {
_inherits(CardContent, _Component2);
var _super2 = _createSuper(CardContent);
function CardContent() {
_classCallCheck(this, CardContent);
return _super2.apply(this, arguments);
}
_createClass(CardContent, [{
key: "render",
value: function render() {
var _this$props2 = this.props,
onScroll = _this$props2.onScroll,
eleRef = _this$props2.eleRef,
children = _this$props2.children,
scroll = _this$props2.scroll,
isScrollAttribute = _this$props2.isScrollAttribute,
dataId = _this$props2.dataId,
dataSelectorId = _this$props2.dataSelectorId,
shrink = _this$props2.shrink,
customClass = _this$props2.customClass,
preventParentScroll = _this$props2.preventParentScroll;
return /*#__PURE__*/_react["default"].createElement(_Layout.Box, {
flexible: true,
onScroll: onScroll,
eleRef: eleRef,
scroll: scroll,
preventParentScroll: preventParentScroll,
isScrollAttribute: isScrollAttribute,
dataId: dataId,
shrink: shrink,
className: customClass,
dataSelectorId: dataSelectorId
}, children);
}
}]);
return CardContent;
}(_react.Component);
exports.CardContent = CardContent;
CardContent.propTypes = _propTypes.CardContent_propTypes;
CardContent.defaultProps = _defaultProps.CardContent_defaultProps;
var Card = /*#__PURE__*/function (_Component3) {
_inherits(Card, _Component3);
var _super3 = _createSuper(Card);
function Card(props) {
var _this2;
_classCallCheck(this, Card);
_this2 = _super3.call(this, props);
_this2.state = {
isScroll: false
};
var from = props.from,
limit = props.limit;
_this2.from = from;
_this2.limit = limit;
_this2.to = from + 3 * limit;
_this2.isFetching = false;
_this2.lastScrollTop = 0;
_this2.onScroll = _this2.onScroll.bind(_assertThisInitialized(_this2));
_this2.setScrollRef = _this2.setScrollRef.bind(_assertThisInitialized(_this2));
_this2.childEleRef = null; //this.onSetScroll = debounce(this.setScroll.bind(this, true), 10, true);
//this.onClearScroll = debounce(this.setScroll.bind(this, false), 500);
return _this2;
}
_createClass(Card, [{
key: "UNSAFE_componentWillReceiveProps",
value: function UNSAFE_componentWillReceiveProps(nextProps) {
if (this.from !== nextProps.from) {
this.from = nextProps.from;
}
}
}, {
key: "onScroll",
value: function onScroll(e) {
var _this3 = this;
var scrollContainerObj = e.currentTarget;
var scrollHeight = scrollContainerObj.scrollHeight;
var scrollTop = scrollContainerObj.scrollTop;
var offsetHeight = scrollContainerObj.offsetHeight;
var onScroll = this.props.onScroll;
onScroll && onScroll(e);
var _this$props3 = this.props,
fetchData = _this$props3.fetchData,
noMoreData = _this$props3.noMoreData,
scrollAt = _this$props3.scrollAt,
noNeedUpScroll = _this$props3.noNeedUpScroll,
isPercentageScroll = _this$props3.isPercentageScroll,
scrollDirection = _this$props3.scrollDirection;
var scrollLimitHeight = scrollHeight - scrollAt;
var currentVisibleBottom = scrollTop + offsetHeight;
if (scrollTop > this.lastScrollTop) {
this.scrollingDirection = 'down';
} else {
this.scrollingDirection = 'up';
}
this.lastScrollTop = scrollTop;
if (fetchData && !this.isFetching) {
var fetchDirection = scrollDirection === 'bottomToTop' ? 'up' : 'down';
if (this.scrollingDirection === fetchDirection && !noMoreData) {
var prefetch = false;
if (isPercentageScroll) {
var scrollingPercentage = scrollDirection === 'bottomToTop' ? (scrollHeight - scrollTop) / scrollLimitHeight * 100 : currentVisibleBottom / scrollLimitHeight * 100;
prefetch = scrollingPercentage >= (0, _Config.getLibraryConfig)('scrollFetchLimit');
} else {
prefetch = scrollDirection === 'bottomToTop' ? scrollTop <= scrollAt : scrollLimitHeight <= currentVisibleBottom;
}
if (prefetch) {
this.isFetching = true;
fetchData(this.from + this.limit, this.limit + this.to, this.scrollingDirection).then(function () {
_this3.to = _this3.limit + _this3.to;
_this3.isFetching = false;
}, function () {
_this3.isFetching = false;
});
}
} else {
var _prefetch = scrollDirection === 'bottomToTop' ? scrollLimitHeight <= currentVisibleBottom : 0 >= scrollTop - scrollAt;
if (_prefetch && this.from !== 0 && !noNeedUpScroll) {
this.isFetching = true;
fetchData(this.from - this.limit, this.to - this.limit, this.scrollingDirection).then(function () {
_this3.to = _this3.to - _this3.limit;
_this3.isFetching = false;
}, function () {
_this3.isFetching = false;
});
}
}
}
if (fetchData && !noNeedUpScroll) {
var topFetch = scrollDirection === 'bottomToTop' ? !noMoreData : !noNeedUpScroll && this.from !== 0;
var bottomFetch = scrollDirection === 'bottomToTop' ? !noNeedUpScroll && this.from !== 0 : !noMoreData;
if (scrollTop === 0 && topFetch) {
scrollContainerObj.scrollTop = scrollTop + offsetHeight / 3;
} else if (scrollHeight === currentVisibleBottom && bottomFetch) {
scrollContainerObj.scrollTop = scrollTop - offsetHeight / 2;
}
} // if (isScrollShadow) {
// this.onSetScroll();
// }
} // setScroll(isScroll) {
// let { isScroll: stateIsScroll } = this.state;
// if (isScroll && !stateIsScroll) {
// this.setState({ isScroll: true }, () => {
// this.onClearScroll();
// });
// } else if (!isScroll && stateIsScroll) {
// this.setState({ isScroll: false });
// }
// }
}, {
key: "setScrollRef",
value: function setScrollRef(el) {
var _this$props4 = this.props,
scrollAt = _this$props4.scrollAt,
scrollDirection = _this$props4.scrollDirection;
if (el && scrollDirection === 'bottomToTop') {
requestAnimationFrame(function () {
el.scrollTop = el.scrollHeight + Number(scrollAt);
});
}
this.childEleRef && this.childEleRef(el);
}
}, {
key: "render",
value: function render() {
var _this4 = this;
var _this$props5 = this.props,
onClick = _this$props5.onClick,
children = _this$props5.children,
isScrollAttribute = _this$props5.isScrollAttribute,
dataId = _this$props5.dataId,
eleRef = _this$props5.eleRef,
_this$props5$customCl = _this$props5.customClass,
customClass = _this$props5$customCl === void 0 ? '' : _this$props5$customCl,
htmlId = _this$props5.htmlId,
a11y = _this$props5.a11y;
var isScroll = this.state.isScroll;
var role = a11y.role;
return /*#__PURE__*/_react["default"].createElement(_Layout.Container, {
className: "".concat(customClass),
isScrollAttribute: isScrollAttribute,
onClick: onClick,
dataId: dataId,
eleRef: eleRef
}, _react["default"].Children.map(children, function (child) {
if (!child) {
return child;
}
if (child.type === CardHeader || _this4.props.childTypes && child.type === _this4.props.childTypes.cardHeader) {
return /*#__PURE__*/_react["default"].cloneElement(child, {
isScroll: isScroll
});
} else if (child.type === CardContent || _this4.props.childTypes && child.type === _this4.props.childTypes.cardContent) {
_this4.childEleRef = child.props.eleRef;
return /*#__PURE__*/_react["default"].createElement(_Layout.Box, {
id: htmlId,
role: role,
flexible: true,
scroll: child.props.scroll,
preventParentScroll: child.props.preventParentScroll,
onScroll: _this4.onScroll,
eleRef: _this4.setScrollRef,
isScrollAttribute: child.props.isScrollAttribute,
dataId: child.props.dataId,
shrink: child.props.shrink,
className: child.props.customClass,
dataSelectorId: child.props.dataSelectorId
}, child.props.children);
}
return child;
}));
}
}]);
return Card;
}(_react.Component);
exports["default"] = Card;
Card.propTypes = _propTypes.Card_propTypes;
Card.defaultProps = _defaultProps.Card_defaultProps; // if (__DOCS__) {
// Card.docs = {
// componentGroup: 'Template',
// folderName: 'Style Guide',
// external: true,
// description: ' '
// };
// }
var CardFooter = /*#__PURE__*/function (_Component4) {
_inherits(CardFooter, _Component4);
var _super4 = _createSuper(CardFooter);
function CardFooter() {
_classCallCheck(this, CardFooter);
return _super4.apply(this, arguments);
}
_createClass(CardFooter, [{
key: "render",
value: function render() {
var _this$props6 = this.props,
children = _this$props6.children,
dataId = _this$props6.dataId,
customClass = _this$props6.customClass,
dataSelectorId = _this$props6.dataSelectorId;
return /*#__PURE__*/_react["default"].createElement(_Layout.Box, {
className: "".concat(customClass),
dataId: dataId,
dataSelectorId: dataSelectorId
}, children);
}
}]);
return CardFooter;
}(_react.Component);
exports.CardFooter = CardFooter;
CardFooter.propTypes = _propTypes.CardFooter_propTypes;
CardFooter.defaultProps = _defaultProps.CardFooter_defaultProps;