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.

83 lines (69 loc) 4.53 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = exports.StyledHeading = void 0; var React = _interopRequireWildcard(require("react")); var _styledComponents = _interopRequireDefault(require("styled-components")); var _defaultTokens = _interopRequireDefault(require("../defaultTokens")); var _consts = require("./consts"); var _getSpacingToken = _interopRequireDefault(require("../common/getSpacingToken")); 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 _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 getToken = function getToken(name) { return function (_ref) { var _TOKENS$weightHeading, _TOKENS$sizeHeading, _tokens; var theme = _ref.theme, type = _ref.type; var tokens = (_tokens = {}, _defineProperty(_tokens, _consts.TOKENS.weightHeading, (_TOKENS$weightHeading = {}, _defineProperty(_TOKENS$weightHeading, _consts.TYPE_OPTIONS.DISPLAY, theme.orbit.fontWeightHeadingDisplay), _defineProperty(_TOKENS$weightHeading, _consts.TYPE_OPTIONS.TITLE1, theme.orbit.fontWeightHeadingTitle1), _defineProperty(_TOKENS$weightHeading, _consts.TYPE_OPTIONS.TITLE2, theme.orbit.fontWeightHeadingTitle2), _defineProperty(_TOKENS$weightHeading, _consts.TYPE_OPTIONS.TITLE3, theme.orbit.fontWeightHeadingTitle3), _defineProperty(_TOKENS$weightHeading, _consts.TYPE_OPTIONS.TITLE4, theme.orbit.fontWeightMedium), _TOKENS$weightHeading)), _defineProperty(_tokens, _consts.TOKENS.sizeHeading, (_TOKENS$sizeHeading = {}, _defineProperty(_TOKENS$sizeHeading, _consts.TYPE_OPTIONS.DISPLAY, theme.orbit.fontSizeHeadingDisplay), _defineProperty(_TOKENS$sizeHeading, _consts.TYPE_OPTIONS.TITLE1, theme.orbit.fontSizeHeadingTitle1), _defineProperty(_TOKENS$sizeHeading, _consts.TYPE_OPTIONS.TITLE2, theme.orbit.fontSizeHeadingTitle2), _defineProperty(_TOKENS$sizeHeading, _consts.TYPE_OPTIONS.TITLE3, theme.orbit.fontSizeHeadingTitle3), _defineProperty(_TOKENS$sizeHeading, _consts.TYPE_OPTIONS.TITLE4, theme.orbit.fontSizeTextNormal), _TOKENS$sizeHeading)), _tokens); return tokens[name][type]; }; }; var StyledHeading = (0, _styledComponents.default)(function (_ref2) { var Component = _ref2.element, className = _ref2.className, children = _ref2.children, dataTest = _ref2.dataTest; return React.createElement(Component, { className: className, "data-test": dataTest }, children); }).withConfig({ displayName: "Heading__StyledHeading", componentId: "sc-1b8cso5-0" })(["font-family:", ";font-size:", ";font-weight:", ";color:", ";line-height:", ";margin:0;margin-bottom:", ";"], function (_ref3) { var theme = _ref3.theme; return theme.orbit.fontFamily; }, getToken(_consts.TOKENS.sizeHeading), getToken(_consts.TOKENS.weightHeading), function (_ref4) { var theme = _ref4.theme, inverted = _ref4.inverted; return inverted ? theme.orbit.colorHeadingInverted : theme.orbit.colorHeading; }, function (_ref5) { var theme = _ref5.theme; return theme.orbit.lineHeightHeading; }, _getSpacingToken.default); exports.StyledHeading = StyledHeading; StyledHeading.defaultProps = { theme: _defaultTokens.default }; var Heading = function Heading(_ref6) { var children = _ref6.children, _ref6$type = _ref6.type, type = _ref6$type === void 0 ? _consts.TYPE_OPTIONS.TITLE1 : _ref6$type, _ref6$element = _ref6.element, element = _ref6$element === void 0 ? _consts.ELEMENT_OPTIONS.H1 : _ref6$element, dataTest = _ref6.dataTest, _ref6$inverted = _ref6.inverted, inverted = _ref6$inverted === void 0 ? false : _ref6$inverted, spaceAfter = _ref6.spaceAfter; return React.createElement(StyledHeading, { type: type, element: element, inverted: inverted, dataTest: dataTest, spaceAfter: spaceAfter }, children); }; var _default = Heading; exports.default = _default;