@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.
72 lines (68 loc) • 5.03 kB
JavaScript
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import * as React from "react";
import styled from "styled-components";
import defaultTheme from "../defaultTheme";
import { ELEMENT_OPTIONS, TYPE_OPTIONS, TOKENS } from "./consts";
import getSpacingToken from "../common/getSpacingToken";
export 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, TOKENS.weightHeading, (_TOKENS$weightHeading = {}, _defineProperty(_TOKENS$weightHeading, TYPE_OPTIONS.DISPLAY, theme.orbit.fontWeightHeadingDisplay), _defineProperty(_TOKENS$weightHeading, TYPE_OPTIONS.DISPLAYSUBTITLE, theme.orbit.fontWeightHeadingDisplaySubtitle), _defineProperty(_TOKENS$weightHeading, TYPE_OPTIONS.TITLE1, theme.orbit.fontWeightHeadingTitle1), _defineProperty(_TOKENS$weightHeading, TYPE_OPTIONS.TITLE2, theme.orbit.fontWeightHeadingTitle2), _defineProperty(_TOKENS$weightHeading, TYPE_OPTIONS.TITLE3, theme.orbit.fontWeightHeadingTitle3), _defineProperty(_TOKENS$weightHeading, TYPE_OPTIONS.TITLE4, theme.orbit.fontWeightHeadingTitle4), _defineProperty(_TOKENS$weightHeading, TYPE_OPTIONS.TITLE5, theme.orbit.fontWeightHeadingTitle5), _TOKENS$weightHeading)), _defineProperty(_tokens, TOKENS.sizeHeading, (_TOKENS$sizeHeading = {}, _defineProperty(_TOKENS$sizeHeading, TYPE_OPTIONS.DISPLAY, theme.orbit.fontSizeHeadingDisplay), _defineProperty(_TOKENS$sizeHeading, TYPE_OPTIONS.DISPLAYSUBTITLE, theme.orbit.fontSizeHeadingDisplaySubtitle), _defineProperty(_TOKENS$sizeHeading, TYPE_OPTIONS.TITLE1, theme.orbit.fontSizeHeadingTitle1), _defineProperty(_TOKENS$sizeHeading, TYPE_OPTIONS.TITLE2, theme.orbit.fontSizeHeadingTitle2), _defineProperty(_TOKENS$sizeHeading, TYPE_OPTIONS.TITLE3, theme.orbit.fontSizeHeadingTitle3), _defineProperty(_TOKENS$sizeHeading, TYPE_OPTIONS.TITLE4, theme.orbit.fontSizeHeadingTitle4), _defineProperty(_TOKENS$sizeHeading, TYPE_OPTIONS.TITLE5, theme.orbit.fontSizeHeadingTitle5), _TOKENS$sizeHeading)), _defineProperty(_tokens, TOKENS.lineHeight, (_TOKENS$lineHeight = {}, _defineProperty(_TOKENS$lineHeight, TYPE_OPTIONS.DISPLAY, theme.orbit.lineHeightHeadingDisplay), _defineProperty(_TOKENS$lineHeight, TYPE_OPTIONS.DISPLAYSUBTITLE, theme.orbit.lineHeightHeadingDisplaySubtitle), _defineProperty(_TOKENS$lineHeight, TYPE_OPTIONS.TITLE1, theme.orbit.lineHeightHeadingTitle1), _defineProperty(_TOKENS$lineHeight, TYPE_OPTIONS.TITLE2, theme.orbit.lineHeightHeadingTitle2), _defineProperty(_TOKENS$lineHeight, TYPE_OPTIONS.TITLE3, theme.orbit.lineHeightHeadingTitle3), _defineProperty(_TOKENS$lineHeight, TYPE_OPTIONS.TITLE4, theme.orbit.lineHeightHeadingTitle4), _defineProperty(_TOKENS$lineHeight, TYPE_OPTIONS.TITLE5, theme.orbit.lineHeightHeadingTitle5), _TOKENS$lineHeight)), _tokens);
return tokens[name][type];
};
};
export var StyledHeading = styled(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(TOKENS.sizeHeading), getHeadingToken(TOKENS.weightHeading), function (_ref4) {
var theme = _ref4.theme,
inverted = _ref4.inverted;
return inverted ? theme.orbit.colorHeadingInverted : theme.orbit.colorHeading;
}, getHeadingToken(TOKENS.lineHeight), function (_ref5) {
var type = _ref5.type;
return type === TYPE_OPTIONS.TITLE5 && "uppercase";
}, getSpacingToken); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198
StyledHeading.defaultProps = {
theme: defaultTheme
};
var Heading = function Heading(_ref6) {
var children = _ref6.children,
_ref6$type = _ref6.type,
type = _ref6$type === void 0 ? TYPE_OPTIONS.TITLE1 : _ref6$type,
_ref6$as = _ref6.as,
as = _ref6$as === void 0 ? 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);
};
export default Heading;