@kiwicom/orbit-components
Version:
Orbit-components is a React component library which provides developers with the easiest possible way of building Kiwi.com’s products.
152 lines (118 loc) • 7 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var React = _interopRequireWildcard(require("react"));
var _styledComponents = _interopRequireWildcard(require("styled-components"));
var _Slide = _interopRequireDefault(require("../../utils/Slide"));
var _defaultTheme = _interopRequireDefault(require("../../defaultTheme"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
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); return Constructor; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
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 } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
var StyledTileExpandable = _styledComponents.default.div.withConfig({
displayName: "TileExpandable__StyledTileExpandable",
componentId: "notqy1-0"
})(["border-top:", ";padding:", ";margin:0 ", ";", ";font-size:", ";line-height:", ";color:", ";"], function (_ref) {
var theme = _ref.theme,
expanded = _ref.expanded;
return expanded ? "1px solid ".concat(theme.orbit.paletteCloudNormal) : "0px solid ".concat(theme.orbit.paletteCloudNormal);
}, function (_ref2) {
var theme = _ref2.theme,
expanded = _ref2.expanded;
return expanded && "".concat(theme.orbit.spaceMedium, " 0");
}, function (_ref3) {
var theme = _ref3.theme;
return theme.orbit.spaceMedium;
}, function (_ref4) {
var initialExpanded = _ref4.initialExpanded,
theme = _ref4.theme;
return !initialExpanded && (0, _styledComponents.css)(["transition:max-height ", " ease-in-out,padding ", " ease-in-out,border-top ", " ease-in-out;"], theme.orbit.durationFast, theme.orbit.durationFast, theme.orbit.durationFast);
}, function (_ref5) {
var theme = _ref5.theme;
return theme.orbit.fontSizeTextNormal;
}, function (_ref6) {
var theme = _ref6.theme;
return theme.orbit.lineHeightText;
}, function (_ref7) {
var theme = _ref7.theme;
return theme.orbit.colorTextPrimary;
});
StyledTileExpandable.defaultProps = {
theme: _defaultTheme.default
};
var TileExpandable =
/*#__PURE__*/
function (_React$PureComponent) {
_inherits(TileExpandable, _React$PureComponent);
function TileExpandable(props) {
var _this;
_classCallCheck(this, TileExpandable);
_this = _possibleConstructorReturn(this, _getPrototypeOf(TileExpandable).call(this, props));
_defineProperty(_assertThisInitialized(_this), "setHeight", function () {
var _this$node$current;
var contentHeight = (_this$node$current = _this.node.current) === null || _this$node$current === void 0 ? void 0 : _this$node$current.clientHeight;
_this.setState({
contentHeight: contentHeight
});
});
_defineProperty(_assertThisInitialized(_this), "timeout", void 0);
_defineProperty(_assertThisInitialized(_this), "node", void 0);
_this.node = React.createRef();
_this.state = {
contentHeight: 0
};
return _this;
}
_createClass(TileExpandable, [{
key: "componentDidMount",
value: function componentDidMount() {
this.timeout = setTimeout(this.setHeight, 250); // Prevent showing children on initial render
window.addEventListener("resize", this.setHeight);
}
}, {
key: "componentDidUpdate",
value: function componentDidUpdate() {
// Calculate height on expand - for dynamic components like TripSector
this.setHeight();
}
}, {
key: "componentWillUnmount",
value: function componentWillUnmount() {
if (this.timeout) {
clearTimeout(this.timeout);
}
window.removeEventListener("resize", this.setHeight);
}
}, {
key: "render",
value: function render() {
var _this$props = this.props,
expanded = _this$props.expanded,
children = _this$props.children,
initialExpanded = _this$props.initialExpanded;
return React.createElement(StyledTileExpandable, {
expanded: expanded,
contentHeight: this.state.contentHeight,
initialExpanded: initialExpanded
}, React.createElement(_Slide.default, {
maxHeight: this.state.contentHeight,
expanded: expanded
}, React.createElement("div", {
ref: this.node
}, children)));
}
}]);
return TileExpandable;
}(React.PureComponent);
var _default = TileExpandable;
exports.default = _default;