@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.
143 lines (110 loc) • 7.24 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var React = _interopRequireWildcard(require("react"));
var _styledComponents = _interopRequireWildcard(require("styled-components"));
var _index = _interopRequireDefault(require("../../utils/toggleDown/index"));
var _index2 = _interopRequireDefault(require("../../utils/toggleUp/index"));
var _defaultTokens = _interopRequireDefault(require("../../defaultTokens"));
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 _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 _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
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 getAnimation = function getAnimation(_ref) {
var theme = _ref.theme,
expanded = _ref.expanded,
contentHeight = _ref.contentHeight;
return expanded ? (0, _styledComponents.css)(["", " ", " linear;"], theme.orbit.durationFast, (0, _index.default)(contentHeight)) : (0, _styledComponents.css)(["", " ", " linear;"], theme.orbit.durationFast, (0, _index2.default)(contentHeight));
};
var StyledTileExpandable = _styledComponents.default.div.withConfig({
displayName: "TileExpandable__StyledTileExpandable",
componentId: "notqy1-0"
})(["border-top:", ";padding:", ";margin:0 ", ";max-height:", ";transition:", ";overflow:hidden;animation:", ";font-size:", ";line-height:", ";color:", ";"], function (_ref2) {
var theme = _ref2.theme,
expanded = _ref2.expanded;
return expanded ? "1px solid ".concat(theme.orbit.paletteCloudNormal) : "0px solid ".concat(theme.orbit.paletteCloudNormal);
}, function (_ref3) {
var theme = _ref3.theme,
expanded = _ref3.expanded;
return expanded && "".concat(theme.orbit.spaceMedium, " 0");
}, function (_ref4) {
var theme = _ref4.theme;
return theme.orbit.spaceMedium;
}, function (_ref5) {
var contentHeight = _ref5.contentHeight,
expanded = _ref5.expanded,
initialExpanded = _ref5.initialExpanded;
return !initialExpanded && (expanded ? "".concat(contentHeight, "px") : "0");
}, function (_ref6) {
var initialExpanded = _ref6.initialExpanded,
theme = _ref6.theme;
return !initialExpanded && "\n max-height ".concat(theme.orbit.durationFast, " linear,\n padding ").concat(theme.orbit.durationFast, " linear,\n border-top ").concat(theme.orbit.durationFast, " linear\n ");
}, function (_ref7) {
var initialExpanded = _ref7.initialExpanded;
return !initialExpanded && getAnimation;
}, function (_ref8) {
var theme = _ref8.theme;
return theme.orbit.fontSizeTextNormal;
}, function (_ref9) {
var theme = _ref9.theme;
return theme.orbit.lineHeightText;
}, function (_ref10) {
var theme = _ref10.theme;
return theme.orbit.colorTextPrimary;
});
StyledTileExpandable.defaultProps = {
theme: _defaultTokens.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(_assertThisInitialized(_this)), "setHeight", function () {
var _this$node;
_this.contentHeight = (_this$node = _this.node) === null || _this$node === void 0 ? void 0 : _this$node.current.clientHeight;
});
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "contentHeight", void 0);
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "node", void 0);
_this.contentHeight = 0;
_this.node = React.createRef();
return _this;
}
_createClass(TileExpandable, [{
key: "componentDidMount",
value: function componentDidMount() {
setTimeout(this.setHeight, 250); // Prevent showing children on initial render
}
}, {
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.contentHeight,
initialExpanded: initialExpanded
}, React.createElement("div", {
ref: this.node
}, children));
}
}]);
return TileExpandable;
}(React.PureComponent);
var _default = TileExpandable;
exports.default = _default;