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.

176 lines (157 loc) 6.87 kB
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck"; import _createClass from "@babel/runtime/helpers/esm/createClass"; import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized"; import _inherits from "@babel/runtime/helpers/esm/inherits"; import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn"; import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf"; import _defineProperty from "@babel/runtime/helpers/esm/defineProperty"; function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(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; } } import * as React from "react"; import styled, { css } from "styled-components"; import defaultTheme from "../../../defaultTheme"; import media from "../../../utils/mediaQuery"; import CardSectionContext from "./CardSectionContext"; import ChevronDown from "../../../icons/ChevronDown"; import { getSize } from "../../../Icon"; import { ICON_SIZES } from "../../../Icon/consts"; var StyledCardSectionIconRight = styled(ChevronDown).withConfig({ displayName: "CardSection__StyledCardSectionIconRight", componentId: "sc-1bqkvxi-0" })(["align-self:center;transition:", ";"], function (_ref) { var theme = _ref.theme; return theme.orbit.durationFast; }); StyledCardSectionIconRight.defaultProps = { theme: defaultTheme }; var StyledCardSectionContent = styled.div.withConfig({ displayName: "CardSection__StyledCardSectionContent", componentId: "sc-1bqkvxi-1" })(["font-family:", ";font-size:", ";line-height:", ";color:", ";border-top:", ";padding-top:", ";overflow:hidden;"], function (_ref2) { var theme = _ref2.theme; return theme.orbit.fontFamily; }, function (_ref3) { var theme = _ref3.theme; return theme.orbit.fontSizeTextNormal; }, function (_ref4) { var theme = _ref4.theme; return theme.orbit.lineHeightTextNormal; }, function (_ref5) { var theme = _ref5.theme; return theme.orbit.colorTextPrimary; }, function (_ref6) { var theme = _ref6.theme, expanded = _ref6.expanded; return expanded ? "1px solid ".concat(theme.orbit.paletteCloudNormal) : "0px solid ".concat(theme.orbit.paletteCloudNormal); }, function (_ref7) { var theme = _ref7.theme, expanded = _ref7.expanded; return expanded && "".concat(theme.orbit.spaceMedium); }); StyledCardSectionContent.defaultProps = { theme: defaultTheme }; var StyledCardSectionHeader = styled.div.withConfig({ displayName: "CardSection__StyledCardSectionHeader", componentId: "sc-1bqkvxi-2" })(["margin-bottom:", ";display:flex;flex-direction:row;cursor:pointer;position:relative;min-height:", ";"], function (_ref8) { var theme = _ref8.theme, expanded = _ref8.expanded; return expanded && theme.orbit.spaceMedium; }, function (_ref9) { var expandable = _ref9.expandable; return expandable && getSize(ICON_SIZES.MEDIUM); }); StyledCardSectionHeader.defaultProps = { theme: defaultTheme }; export var StyledCardSection = styled.div.withConfig({ displayName: "CardSection__StyledCardSection", componentId: "sc-1bqkvxi-3" })(["width:100%;padding:", ";box-sizing:border-box;position:relative;background:", ";", ""], function (_ref10) { var theme = _ref10.theme; return theme.orbit.spaceMedium; }, function (_ref11) { var theme = _ref11.theme; return theme.orbit.backgroundCard; }, media.desktop(css(["padding:", ";"], function (_ref12) { var theme = _ref12.theme; return theme.orbit.spaceLarge; }))); StyledCardSection.defaultProps = { theme: defaultTheme }; var CardSection = /*#__PURE__*/function (_React$Component) { _inherits(CardSection, _React$Component); var _super = _createSuper(CardSection); function CardSection() { var _this; _classCallCheck(this, CardSection); 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)); _defineProperty(_assertThisInitialized(_this), "injectCallbackAndToggleSection", function () { var _this$props = _this.props, handleToggleSection = _this$props.handleToggleSection, onClose = _this$props.onClose, onExpand = _this$props.onExpand, expanded = _this$props.expanded; handleToggleSection(); // First do toggle if (expanded && onClose) { // If is expanded -> action is closing onClose(); } if (!expanded && onExpand) { // if is closed > action is expanding onExpand(); } }); _defineProperty(_assertThisInitialized(_this), "handleKeyDown", function (ev) { if (ev.keyCode === 13 || ev.keyCode === 32) { ev.preventDefault(); _this.injectCallbackAndToggleSection(); } }); return _this; } _createClass(CardSection, [{ key: "componentDidMount", value: function componentDidMount() { var _this$props2 = this.props, handleToggleSection = _this$props2.handleToggleSection, initialExpanded = _this$props2.initialExpanded, setInitialExpandedSection = _this$props2.setInitialExpandedSection; if (initialExpanded) { handleToggleSection(); setInitialExpandedSection(); } } }, { key: "render", value: function render() { var _this$props3 = this.props, children = _this$props3.children, dataTest = _this$props3.dataTest, expandable = _this$props3.expandable, expanded = _this$props3.expanded; return /*#__PURE__*/React.createElement(StyledCardSection, { "data-test": dataTest, expandable: expandable, expanded: expanded }, /*#__PURE__*/React.createElement(CardSectionContext.Provider, { value: { expandable: expandable, expanded: expanded, handleToggleSection: this.injectCallbackAndToggleSection, onKeyDownHandler: this.handleKeyDown } }, children)); } }]); return CardSection; }(React.Component); export default CardSection; export { default as CardSectionHeader } from "./CardSectionHeader"; export { default as CardSectionContent } from "./CardSectionContent";