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.

92 lines (78 loc) 6.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = exports.StyledHeading = exports.getHeadingToken = void 0; var React = _interopRequireWildcard(require("react")); var _styledComponents = _interopRequireDefault(require("styled-components")); var _defaultTheme = _interopRequireDefault(require("../defaultTheme")); 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 getHeadingToken = function getHeadingToken(name) { return function (_ref) { var _TOKENS$weightHeading, _TOKENS$sizeHeading, _TOKENS$lineHeight, _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.DISPLAYSUBTITLE, theme.orbit.fontWeightHeadingDisplaySubtitle), _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.fontWeightHeadingTitle4), _defineProperty(_TOKENS$weightHeading, _consts.TYPE_OPTIONS.TITLE5, theme.orbit.fontWeightHeadingTitle5), _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.DISPLAYSUBTITLE, theme.orbit.fontSizeHeadingDisplaySubtitle), _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.fontSizeHeadingTitle4), _defineProperty(_TOKENS$sizeHeading, _consts.TYPE_OPTIONS.TITLE5, theme.orbit.fontSizeHeadingTitle5), _TOKENS$sizeHeading)), _defineProperty(_tokens, _consts.TOKENS.lineHeight, (_TOKENS$lineHeight = {}, _defineProperty(_TOKENS$lineHeight, _consts.TYPE_OPTIONS.DISPLAY, theme.orbit.lineHeightHeadingDisplay), _defineProperty(_TOKENS$lineHeight, _consts.TYPE_OPTIONS.DISPLAYSUBTITLE, theme.orbit.lineHeightHeadingDisplaySubtitle), _defineProperty(_TOKENS$lineHeight, _consts.TYPE_OPTIONS.TITLE1, theme.orbit.lineHeightHeadingTitle1), _defineProperty(_TOKENS$lineHeight, _consts.TYPE_OPTIONS.TITLE2, theme.orbit.lineHeightHeadingTitle2), _defineProperty(_TOKENS$lineHeight, _consts.TYPE_OPTIONS.TITLE3, theme.orbit.lineHeightHeadingTitle3), _defineProperty(_TOKENS$lineHeight, _consts.TYPE_OPTIONS.TITLE4, theme.orbit.lineHeightHeadingTitle4), _defineProperty(_TOKENS$lineHeight, _consts.TYPE_OPTIONS.TITLE5, theme.orbit.lineHeightHeadingTitle5), _TOKENS$lineHeight)), _tokens); return tokens[name][type]; }; }; exports.getHeadingToken = getHeadingToken; var StyledHeading = (0, _styledComponents.default)(function (_ref2) { var Component = _ref2.element, className = _ref2.className, children = _ref2.children, dataTest = _ref2.dataTest, dataA11ySection = _ref2.dataA11ySection, id = _ref2.id; return React.createElement(Component, { className: className, "data-test": dataTest, "data-a11y-section": dataA11ySection, id: id }, children); }).withConfig({ displayName: "Heading__StyledHeading", componentId: "sc-1b8cso5-0" })(["font-family:", ";font-size:", ";font-weight:", ";color:", ";line-height:", ";text-transform:", ";margin:0;margin-bottom:", ";"], function (_ref3) { var theme = _ref3.theme; return theme.orbit.fontFamily; }, getHeadingToken(_consts.TOKENS.sizeHeading), getHeadingToken(_consts.TOKENS.weightHeading), function (_ref4) { var theme = _ref4.theme, inverted = _ref4.inverted; return inverted ? theme.orbit.colorHeadingInverted : theme.orbit.colorHeading; }, getHeadingToken(_consts.TOKENS.lineHeight), function (_ref5) { var type = _ref5.type; return type === _consts.TYPE_OPTIONS.TITLE5 && "uppercase"; }, _getSpacingToken.default); exports.StyledHeading = StyledHeading; StyledHeading.defaultProps = { theme: _defaultTheme.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.DIV : _ref6$element, dataTest = _ref6.dataTest, _ref6$inverted = _ref6.inverted, inverted = _ref6$inverted === void 0 ? false : _ref6$inverted, spaceAfter = _ref6.spaceAfter, dataA11ySection = _ref6.dataA11ySection, id = _ref6.id; return React.createElement(StyledHeading, { id: id, type: type, element: element, inverted: inverted, dataTest: dataTest, spaceAfter: spaceAfter, dataA11ySection: dataA11ySection }, children); }; var _default = Heading; exports.default = _default;