UNPKG

@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.

336 lines (286 loc) 14.2 kB
"use strict"; var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized")); var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties")); 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 _handleKeyDown = _interopRequireDefault(require("../../utils/handleKeyDown")); function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } 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: "mo8kks-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: "mo8kks-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: "mo8kks-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: "mo8kks-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: "mo8kks-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: "mo8kks-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: "mo8kks-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: "mo8kks-7" })(["transform:", ";"], function (_ref11) { var isReturn = _ref11.isReturn; return isReturn && "rotate(180deg)"; }); var StyledDestination = _styledComponents.default.div.withConfig({ displayName: "DestinationCard__StyledDestination", componentId: "mo8kks-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 = (0, _objectWithoutProperties2.default)(_ref13, ["height", "imageURL", "theme"]); return /*#__PURE__*/React.createElement("div", props); }).withConfig({ displayName: "DestinationCard__StyledDestinationCard", componentId: "mo8kks-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 /*#__PURE__*/React.createElement(_Text.default, { type: "white", as: "div", size: "small", weight: "bold" }, children); }; var DestinationCard = /*#__PURE__*/function (_React$PureComponent) { (0, _inherits2.default)(DestinationCard, _React$PureComponent); var _super = _createSuper(DestinationCard); function DestinationCard() { var _this; (0, _classCallCheck2.default)(this, DestinationCard); for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } _this = _super.call.apply(_super, [this].concat(args)); (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "state", { hiddenContentHeight: 0 }); (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "hiddenContent", /*#__PURE__*/React.createRef()); (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "cardID", (0, _randomID.default)("destinationCardID")); (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "setHeight", function () { var _assertThisInitialize = (0, _assertThisInitialized2.default)(_this), hiddenContent = _assertThisInitialize.hiddenContent; if (hiddenContent.current) { _this.setState({ hiddenContentHeight: hiddenContent.current.clientHeight }); } }); return _this; } (0, _createClass2.default)(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 /*#__PURE__*/React.createElement(StyledDestinationCard, { "data-test": dataTest, onClick: onClick, onKeyDown: (0, _handleKeyDown.default)(onClick), height: height >= _consts.SMALLEST_HEIGHT ? height : _consts.SMALLEST_HEIGHT, tabIndex: tabIndex, role: "link", "aria-labelledby": this.cardID }, /*#__PURE__*/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 }), /*#__PURE__*/React.createElement(StyledOverlay, null), /*#__PURE__*/React.createElement(StyledOverlayHover, null), /*#__PURE__*/React.createElement(StyledDestinationCardContent, { hiddenContentHeight: hiddenContentHeight }, /*#__PURE__*/React.createElement(StyledDestinationCardHeader, { id: this.cardID }, /*#__PURE__*/React.createElement(Shown, null, /*#__PURE__*/React.createElement(_Stack.default, { flex: true, align: "center", justify: "start", spacing: "extraTight" }, /*#__PURE__*/React.createElement(_Heading.default, { type: "title3", inverted: true }, departureCity), /*#__PURE__*/React.createElement(ArrowUp, { customColor: "#fff", size: "small" }))), /*#__PURE__*/React.createElement(StyledDestination, null, /*#__PURE__*/React.createElement(_Heading.default, { type: "title1", inverted: true }, destinationCity)), /*#__PURE__*/React.createElement(Shown, null, /*#__PURE__*/React.createElement(_Heading.default, { type: "title4", inverted: true }, destinationCountry))), /*#__PURE__*/React.createElement(_Stack.default, { flex: true, justify: "between", spaceAfter: "small", align: "end" }, /*#__PURE__*/React.createElement(_Heading.default, { type: "title3", inverted: true }, price), timeOfStay && /*#__PURE__*/React.createElement(_Heading.default, { type: "title4", inverted: true }, timeOfStay)), /*#__PURE__*/React.createElement(StyledDestinationCardHiddenContent, { ref: this.hiddenContent }, /*#__PURE__*/React.createElement(_Stack.default, { direction: "row", justify: "between" }, /*#__PURE__*/React.createElement(SmallHeading, null, outbound.text ? outbound.text : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(FlightDirect, { size: "small" }), outbound.date)), /*#__PURE__*/React.createElement(SmallHeading, null, outbound.type, "\xA0\u2022\xA0", outbound.duration)), inbound && /*#__PURE__*/React.createElement(_Stack.default, { direction: "row", justify: "between" }, /*#__PURE__*/React.createElement(SmallHeading, null, /*#__PURE__*/React.createElement(FlightDirect, { size: "small", isReturn: true }), inbound.date), /*#__PURE__*/React.createElement(SmallHeading, null, inbound.type, "\xA0\u2022\xA0", inbound.duration))))); } }]); return DestinationCard; }(React.PureComponent); var _default = DestinationCard; exports.default = _default;