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.1 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 = exports.StyledHeading = exports.getHeadingToken = void 0; var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); 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")); 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 = {}, (0, _defineProperty2.default)(_tokens, _consts.TOKENS.weightHeading, (_TOKENS$weightHeading = {}, (0, _defineProperty2.default)(_TOKENS$weightHeading, _consts.TYPE_OPTIONS.DISPLAY, theme.orbit.fontWeightHeadingDisplay), (0, _defineProperty2.default)(_TOKENS$weightHeading, _consts.TYPE_OPTIONS.DISPLAYSUBTITLE, theme.orbit.fontWeightHeadingDisplaySubtitle), (0, _defineProperty2.default)(_TOKENS$weightHeading, _consts.TYPE_OPTIONS.TITLE1, theme.orbit.fontWeightHeadingTitle1), (0, _defineProperty2.default)(_TOKENS$weightHeading, _consts.TYPE_OPTIONS.TITLE2, theme.orbit.fontWeightHeadingTitle2), (0, _defineProperty2.default)(_TOKENS$weightHeading, _consts.TYPE_OPTIONS.TITLE3, theme.orbit.fontWeightHeadingTitle3), (0, _defineProperty2.default)(_TOKENS$weightHeading, _consts.TYPE_OPTIONS.TITLE4, theme.orbit.fontWeightHeadingTitle4), (0, _defineProperty2.default)(_TOKENS$weightHeading, _consts.TYPE_OPTIONS.TITLE5, theme.orbit.fontWeightHeadingTitle5), _TOKENS$weightHeading)), (0, _defineProperty2.default)(_tokens, _consts.TOKENS.sizeHeading, (_TOKENS$sizeHeading = {}, (0, _defineProperty2.default)(_TOKENS$sizeHeading, _consts.TYPE_OPTIONS.DISPLAY, theme.orbit.fontSizeHeadingDisplay), (0, _defineProperty2.default)(_TOKENS$sizeHeading, _consts.TYPE_OPTIONS.DISPLAYSUBTITLE, theme.orbit.fontSizeHeadingDisplaySubtitle), (0, _defineProperty2.default)(_TOKENS$sizeHeading, _consts.TYPE_OPTIONS.TITLE1, theme.orbit.fontSizeHeadingTitle1), (0, _defineProperty2.default)(_TOKENS$sizeHeading, _consts.TYPE_OPTIONS.TITLE2, theme.orbit.fontSizeHeadingTitle2), (0, _defineProperty2.default)(_TOKENS$sizeHeading, _consts.TYPE_OPTIONS.TITLE3, theme.orbit.fontSizeHeadingTitle3), (0, _defineProperty2.default)(_TOKENS$sizeHeading, _consts.TYPE_OPTIONS.TITLE4, theme.orbit.fontSizeHeadingTitle4), (0, _defineProperty2.default)(_TOKENS$sizeHeading, _consts.TYPE_OPTIONS.TITLE5, theme.orbit.fontSizeHeadingTitle5), _TOKENS$sizeHeading)), (0, _defineProperty2.default)(_tokens, _consts.TOKENS.lineHeight, (_TOKENS$lineHeight = {}, (0, _defineProperty2.default)(_TOKENS$lineHeight, _consts.TYPE_OPTIONS.DISPLAY, theme.orbit.lineHeightHeadingDisplay), (0, _defineProperty2.default)(_TOKENS$lineHeight, _consts.TYPE_OPTIONS.DISPLAYSUBTITLE, theme.orbit.lineHeightHeadingDisplaySubtitle), (0, _defineProperty2.default)(_TOKENS$lineHeight, _consts.TYPE_OPTIONS.TITLE1, theme.orbit.lineHeightHeadingTitle1), (0, _defineProperty2.default)(_TOKENS$lineHeight, _consts.TYPE_OPTIONS.TITLE2, theme.orbit.lineHeightHeadingTitle2), (0, _defineProperty2.default)(_TOKENS$lineHeight, _consts.TYPE_OPTIONS.TITLE3, theme.orbit.lineHeightHeadingTitle3), (0, _defineProperty2.default)(_TOKENS$lineHeight, _consts.TYPE_OPTIONS.TITLE4, theme.orbit.lineHeightHeadingTitle4), (0, _defineProperty2.default)(_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 /*#__PURE__*/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$as = _ref6.as, as = _ref6$as === void 0 ? _consts.ELEMENT_OPTIONS.DIV : _ref6$as, 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 /*#__PURE__*/React.createElement(StyledHeading, { id: id, type: type, element: as, inverted: inverted, dataTest: dataTest, spaceAfter: spaceAfter, dataA11ySection: dataA11ySection }, children); }; var _default = Heading; exports.default = _default;