@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.
247 lines (197 loc) • 10.2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = exports.StyledCardSection = void 0;
var React = _interopRequireWildcard(require("react"));
var _styledComponents = _interopRequireDefault(require("styled-components"));
var _defaultTokens = _interopRequireDefault(require("../../defaultTokens"));
var _ChevronDown = _interopRequireDefault(require("../../icons/ChevronDown"));
var _index = _interopRequireDefault(require("../../Heading/index"));
var _index2 = _interopRequireDefault(require("../../Text/index"));
var _Icon = require("../../Icon");
var _consts = require("../../Icon/consts");
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 StyledCardSectionIconRight = (0, _styledComponents.default)(_ChevronDown.default).withConfig({
displayName: "CardSection__StyledCardSectionIconRight",
componentId: "o8zdxr-0"
})(["align-self:center;transition:", ";"], function (_ref) {
var theme = _ref.theme;
return theme.orbit.durationFast;
});
StyledCardSectionIconRight.defaultProps = {
theme: _defaultTokens.default
};
var StyledCardSectionContent = _styledComponents.default.div.withConfig({
displayName: "CardSection__StyledCardSectionContent",
componentId: "o8zdxr-1"
})(["font-size:", ";line-height:", ";color:", ";border-top:", ";padding-top:", ";transition:max-height ", " linear,padding ", " linear,border-top ", " linear;overflow:hidden;"], function (_ref2) {
var theme = _ref2.theme;
return theme.orbit.fontSizeTextNormal;
}, function (_ref3) {
var theme = _ref3.theme;
return theme.orbit.lineHeightText;
}, function (_ref4) {
var theme = _ref4.theme;
return theme.orbit.colorTextPrimary;
}, function (_ref5) {
var theme = _ref5.theme,
expanded = _ref5.expanded;
return expanded ? "1px solid ".concat(theme.orbit.paletteCloudNormal) : "0px solid ".concat(theme.orbit.paletteCloudNormal);
}, function (_ref6) {
var theme = _ref6.theme,
expanded = _ref6.expanded;
return expanded && "".concat(theme.orbit.spaceMedium);
}, function (_ref7) {
var theme = _ref7.theme;
return theme.orbit.durationFast;
}, function (_ref8) {
var theme = _ref8.theme;
return theme.orbit.durationFast;
}, function (_ref9) {
var theme = _ref9.theme;
return theme.orbit.durationFast;
});
StyledCardSectionContent.defaultProps = {
theme: _defaultTokens.default
};
var getMaxHeight = function getMaxHeight(_ref10) {
var expandable = _ref10.expandable,
expanded = _ref10.expanded,
contentHeight = _ref10.contentHeight;
if (expandable) {
if (expanded) {
return "".concat(contentHeight, "px");
}
return 0;
}
return "auto";
};
var StyledCardSection = _styledComponents.default.div.withConfig({
displayName: "CardSection__StyledCardSection",
componentId: "o8zdxr-2"
})(["width:100%;padding:", ";box-sizing:border-box;position:relative;background:", ";", "{transform:", ";}", "{max-height:", ";}"], function (_ref11) {
var theme = _ref11.theme;
return theme.orbit.spaceLarge;
}, function (_ref12) {
var theme = _ref12.theme;
return theme.orbit.backgroundCard;
}, StyledCardSectionIconRight, function (_ref13) {
var expanded = _ref13.expanded;
return expanded && "rotate(-180deg)";
}, StyledCardSectionContent, getMaxHeight);
exports.StyledCardSection = StyledCardSection;
StyledCardSection.defaultProps = {
theme: _defaultTokens.default
};
var StyledCardSectionHeader = _styledComponents.default.div.withConfig({
displayName: "CardSection__StyledCardSectionHeader",
componentId: "o8zdxr-3"
})(["margin-bottom:", ";display:flex;flex-direction:row;transition:margin ", " linear;cursor:pointer;position:relative;min-height:", ";"], function (_ref14) {
var theme = _ref14.theme,
expanded = _ref14.expanded;
return expanded && theme.orbit.spaceMedium;
}, function (_ref15) {
var theme = _ref15.theme;
return theme.orbit.durationFast;
}, function (_ref16) {
var expandable = _ref16.expandable;
return expandable && (0, _Icon.getSize)(_consts.ICON_SIZES.MEDIUM);
});
StyledCardSectionHeader.defaultProps = {
theme: _defaultTokens.default
};
var StyledTitleAndSubtitle = _styledComponents.default.div.withConfig({
displayName: "CardSection__StyledTitleAndSubtitle",
componentId: "o8zdxr-4"
})(["flex:1;padding-right:", ";"], function (_ref17) {
var theme = _ref17.theme;
return theme.orbit.spaceMedium;
});
StyledTitleAndSubtitle.defaultProps = {
theme: _defaultTokens.default
};
var CardSection =
/*#__PURE__*/
function (_React$Component) {
_inherits(CardSection, _React$Component);
function CardSection() {
var _getPrototypeOf2;
var _this;
_classCallCheck(this, CardSection);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(CardSection)).call.apply(_getPrototypeOf2, [this].concat(args)));
_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", 0);
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "node", React.createRef());
return _this;
}
_createClass(CardSection, [{
key: "componentDidMount",
value: function componentDidMount() {
var expandable = this.props.expandable;
if (expandable) {
setTimeout(this.setHeight, 250); // Prevent showing children on initial render
}
}
}, {
key: "componentDidUpdate",
value: function componentDidUpdate() {
var expandable = this.props.expandable;
if (expandable) {
this.setHeight(); // Prevent showing children on initial render
}
}
}, {
key: "render",
value: function render() {
var _this$props = this.props,
title = _this$props.title,
subTitle = _this$props.subTitle,
children = _this$props.children,
dataTest = _this$props.dataTest,
expandable = _this$props.expandable,
expanded = _this$props.expanded,
onClick = _this$props.onClick;
return React.createElement(StyledCardSection, {
"data-test": dataTest,
expandable: expandable,
expanded: expanded,
contentHeight: this.contentHeight
}, React.createElement(StyledCardSectionHeader, {
expandable: expandable,
expanded: expanded,
onClick: onClick
}, React.createElement(StyledTitleAndSubtitle, null, title && React.createElement(_index.default, {
type: "title3",
element: "h3"
}, title), subTitle && React.createElement(_index2.default, null, subTitle)), expandable && React.createElement(StyledCardSectionIconRight, {
size: "medium",
color: "secondary"
})), React.createElement(StyledCardSectionContent, {
expanded: expanded
}, React.createElement("div", {
ref: this.node
}, children)));
}
}]);
return CardSection;
}(React.Component);
var _default = CardSection;
exports.default = _default;