@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.
367 lines (306 loc) • 16.1 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var React = _interopRequireWildcard(require("react"));
var _styledComponents = _interopRequireWildcard(require("styled-components"));
var _Heading = _interopRequireDefault(require("../Heading"));
var _Stack = _interopRequireDefault(require("../Stack"));
var _ArrowUp = _interopRequireDefault(require("../icons/ArrowUp"));
var _defaultTheme = _interopRequireDefault(require("../defaultTheme"));
var _FlightDirect = _interopRequireDefault(require("../icons/FlightDirect"));
var _consts = require("./consts");
var _LazyImage = _interopRequireDefault(require("../LazyImage"));
var _Text = _interopRequireDefault(require("../Text"));
var _randomID = _interopRequireDefault(require("../utils/randomID"));
var _keyMaps = _interopRequireDefault(require("../common/keyMaps"));
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; }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
var overlayCss = (0, _styledComponents.css)(["position:absolute;top:0;left:0;z-index:1;width:100%;height:100%;border-radius:", ";transition:opacity ", " ease-in-out;"], function (_ref) {
var theme = _ref.theme;
return theme.orbit.borderRadiusNormal;
}, function (_ref2) {
var theme = _ref2.theme;
return theme.orbit.durationNormal;
});
var StyledOverlay = _styledComponents.default.div.withConfig({
displayName: "DestinationCard__StyledOverlay",
componentId: "x4idx5-0"
})(["", ";opacity:1;background:linear-gradient( to bottom,rgba(0,0,0,0) 0%,rgba(0,0,0,0) 50%,rgba(0,0,0,0.13) 65%,rgba(0,0,0,0.3) 75%,rgba(0,0,0,0.8) 100% );"], overlayCss);
StyledOverlay.defaultProps = {
theme: _defaultTheme.default
};
var StyledOverlayHover = _styledComponents.default.div.withConfig({
displayName: "DestinationCard__StyledOverlayHover",
componentId: "x4idx5-1"
})(["", ";opacity:0;background:rgba(0,0,0,0.8);"], overlayCss);
StyledOverlayHover.defaultProps = {
theme: _defaultTheme.default
};
var StyledDestinationCardContent = _styledComponents.default.div.withConfig({
displayName: "DestinationCard__StyledDestinationCardContent",
componentId: "x4idx5-2"
})(["position:relative;z-index:2;display:flex;flex-direction:column;padding:", ";width:100%;transition:bottom ", " ease-in-out;bottom:", ";"], function (_ref3) {
var theme = _ref3.theme;
return theme.orbit.spaceSmall;
}, function (_ref4) {
var theme = _ref4.theme;
return theme.orbit.durationFast;
}, function (_ref5) {
var hiddenContentHeight = _ref5.hiddenContentHeight,
theme = _ref5.theme;
return "-".concat(hiddenContentHeight + parseInt(theme.orbit.spaceSmall, 10), "px");
});
StyledDestinationCardContent.defaultProps = {
theme: _defaultTheme.default
};
var StyledDestinationCardHeader = _styledComponents.default.div.withConfig({
displayName: "DestinationCard__StyledDestinationCardHeader",
componentId: "x4idx5-3"
})(["margin-bottom:", ";"], function (_ref6) {
var theme = _ref6.theme;
return theme.orbit.spaceXSmall;
});
StyledDestinationCardHeader.defaultProps = {
theme: _defaultTheme.default
};
var Shown = _styledComponents.default.div.withConfig({
displayName: "DestinationCard__Shown",
componentId: "x4idx5-4"
})(["transition:all ", " ease-in-out;opacity:0;position:relative;top:\"-50%\";margin-bottom:", ";"], function (_ref7) {
var theme = _ref7.theme;
return theme.orbit.durationFast;
}, function (_ref8) {
var theme = _ref8.theme;
return theme.orbit.spaceXXSmall;
});
Shown.defaultProps = {
theme: _defaultTheme.default
};
var ArrowUp = (0, _styledComponents.default)(_ArrowUp.default).withConfig({
displayName: "DestinationCard__ArrowUp",
componentId: "x4idx5-5"
})(["transform:rotate(90deg);margin-left:", ";"], function (_ref9) {
var theme = _ref9.theme;
return theme.orbit.spaceXXSmall;
});
ArrowUp.defaultProps = {
theme: _defaultTheme.default
};
var StyledDestinationCardHiddenContent = _styledComponents.default.div.withConfig({
displayName: "DestinationCard__StyledDestinationCardHiddenContent",
componentId: "x4idx5-6"
})(["padding:", " 0 0;border-top:1px solid rgba(255,255,255,0.3);"], function (_ref10) {
var theme = _ref10.theme;
return theme.orbit.spaceSmall;
});
StyledDestinationCardHiddenContent.defaultProps = {
theme: _defaultTheme.default
};
var FlightDirect = (0, _styledComponents.default)(_FlightDirect.default).withConfig({
displayName: "DestinationCard__FlightDirect",
componentId: "x4idx5-7"
})(["transform:", ";"], function (_ref11) {
var isReturn = _ref11.isReturn;
return isReturn && "rotate(180deg)";
});
var StyledDestination = _styledComponents.default.div.withConfig({
displayName: "DestinationCard__StyledDestination",
componentId: "x4idx5-8"
})(["position:relative;transition:top ", " ease-in-out;top:16px;"], function (_ref12) {
var theme = _ref12.theme;
return theme.orbit.durationFast;
});
StyledDestination.defaultProps = {
theme: _defaultTheme.default
};
var StyledDestinationCard = (0, _styledComponents.default)(function (_ref13) {
var height = _ref13.height,
imageURL = _ref13.imageURL,
theme = _ref13.theme,
props = _objectWithoutProperties(_ref13, ["height", "imageURL", "theme"]);
return React.createElement("div", props);
}).withConfig({
displayName: "DestinationCard__StyledDestinationCard",
componentId: "x4idx5-9"
})(["width:100%;height:", ";display:flex;align-items:flex-end;position:relative;box-sizing:border-box;border-radius:", ";overflow:hidden;cursor:pointer;&:hover{", "{opacity:0;}", "{top:0;}", "{opacity:1;}", "{bottom:0;}", "{opacity:1;top:0;}}&:focus{outline:none;box-shadow:0 0 1px 1px ", ",0 0 1px 3px rgba(1,118,210,0.6);}"], function (_ref14) {
var height = _ref14.height;
return height ? "".concat(height, "px") : "100%";
}, function (_ref15) {
var theme = _ref15.theme;
return theme.orbit.borderRadiusNormal;
}, StyledOverlay, StyledDestination, StyledOverlayHover, StyledDestinationCardContent, Shown, function (_ref16) {
var theme = _ref16.theme;
return theme.orbit.colorTextButtonWhiteBordered;
});
StyledDestinationCard.defaultProps = {
theme: _defaultTheme.default
};
var SmallHeading = function SmallHeading(_ref17) {
var children = _ref17.children;
return React.createElement(_Text.default, {
type: "white",
element: "div",
size: "small",
weight: "bold"
}, children);
};
var DestinationCard =
/*#__PURE__*/
function (_React$PureComponent) {
_inherits(DestinationCard, _React$PureComponent);
function DestinationCard() {
var _getPrototypeOf2;
var _this;
_classCallCheck(this, DestinationCard);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(DestinationCard)).call.apply(_getPrototypeOf2, [this].concat(args)));
_defineProperty(_assertThisInitialized(_this), "state", {
hiddenContentHeight: 0
});
_defineProperty(_assertThisInitialized(_this), "hiddenContent", React.createRef());
_defineProperty(_assertThisInitialized(_this), "cardID", (0, _randomID.default)("destinationCardID"));
_defineProperty(_assertThisInitialized(_this), "setHeight", function () {
var _assertThisInitialize = _assertThisInitialized(_this),
hiddenContent = _assertThisInitialize.hiddenContent;
if (hiddenContent.current) {
_this.setState({
hiddenContentHeight: hiddenContent.current.clientHeight
});
}
});
_defineProperty(_assertThisInitialized(_this), "handleKeyDown", function (ev) {
var onClick = _this.props.onClick;
if (onClick) {
if (ev.keyCode === _keyMaps.default.ENTER) {
onClick();
} else if (ev.keyCode === _keyMaps.default.SPACE) {
ev.preventDefault();
onClick();
}
}
});
return _this;
}
_createClass(DestinationCard, [{
key: "componentDidMount",
value: function componentDidMount() {
this.setHeight();
}
}, {
key: "componentDidUpdate",
value: function componentDidUpdate(prevProps) {
if (prevProps !== this.props) {
this.setHeight();
}
}
}, {
key: "render",
value: function render() {
var _this$props = this.props,
dataTest = _this$props.dataTest,
departureCity = _this$props.departureCity,
destinationCity = _this$props.destinationCity,
destinationCountry = _this$props.destinationCountry,
price = _this$props.price,
timeOfStay = _this$props.timeOfStay,
outbound = _this$props.outbound,
inbound = _this$props.inbound,
_this$props$height = _this$props.height,
height = _this$props$height === void 0 ? 300 : _this$props$height,
onClick = _this$props.onClick,
_this$props$tabIndex = _this$props.tabIndex,
tabIndex = _this$props$tabIndex === void 0 ? "0" : _this$props$tabIndex;
var hiddenContentHeight = this.state.hiddenContentHeight;
var image = this.props.image.toLowerCase();
return React.createElement(StyledDestinationCard, {
"data-test": dataTest,
onClick: onClick,
onKeyDown: this.handleKeyDown,
height: height >= _consts.SMALLEST_HEIGHT ? height : _consts.SMALLEST_HEIGHT,
tabIndex: tabIndex,
role: "link",
"aria-labelledby": this.cardID
}, React.createElement(_LazyImage.default, {
original: {
webp: " ".concat(_consts.BASE_URL, "/photos/385x320/").concat(image, ".webp"),
jpg: "".concat(_consts.BASE_URL, "/photos/385x320/").concat(image, ".jpg")
},
placeholder: {
webp: " ".concat(_consts.BASE_URL, "/photos/30x30/").concat(image, ".webp"),
jpg: "".concat(_consts.BASE_URL, "/photos/30x30/").concat(image, ".jpg")
} // Add that to images kiwi
,
name: destinationCity
}), React.createElement(StyledOverlay, null), React.createElement(StyledOverlayHover, null), React.createElement(StyledDestinationCardContent, {
hiddenContentHeight: hiddenContentHeight
}, React.createElement(StyledDestinationCardHeader, {
id: this.cardID
}, React.createElement(Shown, null, React.createElement(_Stack.default, {
flex: true,
align: "center",
justify: "start",
spacing: "extraTight"
}, React.createElement(_Heading.default, {
type: "title3",
element: "div",
inverted: true
}, departureCity), React.createElement(ArrowUp, {
customColor: "#fff",
size: "small"
}))), React.createElement(StyledDestination, null, React.createElement(_Heading.default, {
type: "title1",
element: "div",
inverted: true
}, destinationCity)), React.createElement(Shown, null, React.createElement(_Heading.default, {
type: "title4",
element: "div",
inverted: true
}, destinationCountry))), React.createElement(_Stack.default, {
flex: true,
justify: "between",
spaceAfter: "small",
align: "end"
}, React.createElement(_Heading.default, {
type: "title3",
element: "div",
inverted: true
}, price), timeOfStay && React.createElement(_Heading.default, {
type: "title4",
element: "div",
inverted: true
}, timeOfStay)), React.createElement(StyledDestinationCardHiddenContent, {
ref: this.hiddenContent
}, React.createElement(_Stack.default, {
direction: "row",
justify: "between"
}, React.createElement(SmallHeading, null, outbound.text ? outbound.text : React.createElement(React.Fragment, null, React.createElement(FlightDirect, {
size: "small"
}), outbound.date)), React.createElement(SmallHeading, null, outbound.type, "\xA0\u2022\xA0", outbound.duration)), inbound && React.createElement(_Stack.default, {
direction: "row",
justify: "between"
}, React.createElement(SmallHeading, null, React.createElement(FlightDirect, {
size: "small",
isReturn: true
}), inbound.date), React.createElement(SmallHeading, null, inbound.type, "\xA0\u2022\xA0", inbound.duration)))));
}
}]);
return DestinationCard;
}(React.PureComponent);
var _default = DestinationCard;
exports.default = _default;