@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.
120 lines (118 loc) • 3.89 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = exports.StyledText = void 0;
var React = _interopRequireWildcard(require("react"));
var _styledComponents = _interopRequireWildcard(require("styled-components"));
var _orbitDesignTokens = require("@kiwicom/orbit-design-tokens");
var _defaultTheme = _interopRequireDefault(require("../../defaultTheme"));
var _consts = require("../consts");
var _rtl = require("../../utils/rtl");
var _deprecated = require("../../TextLink/deprecated");
var _common = require("../../utils/common");
const getTypeToken = ({
theme,
type
}) => {
const typeTokens = {
[_consts.TYPE_OPTIONS.PRIMARY]: theme.orbit.colorTextPrimary,
[_consts.TYPE_OPTIONS.SECONDARY]: theme.orbit.colorTextSecondary,
[_consts.TYPE_OPTIONS.INFO]: theme.orbit.colorTextInfo,
[_consts.TYPE_OPTIONS.SUCCESS]: theme.orbit.colorTextSuccess,
[_consts.TYPE_OPTIONS.WARNING]: theme.orbit.colorTextWarning,
[_consts.TYPE_OPTIONS.CRITICAL]: theme.orbit.colorTextCritical,
[_consts.TYPE_OPTIONS.WHITE]: theme.orbit.colorTextWhite
};
return typeTokens[type];
};
const getWeightToken = ({
theme,
weight
}) => {
const weightTokens = {
[_consts.WEIGHT_OPTIONS.NORMAL]: theme.orbit.fontWeightNormal,
[_consts.WEIGHT_OPTIONS.MEDIUM]: theme.orbit.fontWeightMedium,
[_consts.WEIGHT_OPTIONS.BOLD]: theme.orbit.fontWeightBold
};
if (!weight) return null;
return weightTokens[weight];
};
const getSizeToken = ({
theme,
size
}) => {
const sizeTokens = {
[_consts.SIZE_OPTIONS.EXTRA_LARGE]: theme.orbit.fontSizeTextExtraLarge,
[_consts.SIZE_OPTIONS.LARGE]: theme.orbit.fontSizeTextLarge,
[_consts.SIZE_OPTIONS.NORMAL]: theme.orbit.fontSizeTextNormal,
[_consts.SIZE_OPTIONS.SMALL]: theme.orbit.fontSizeTextSmall
};
if (!size) return null;
return sizeTokens[size];
};
const getLineHeightToken = ({
theme,
size
}) => {
const lineHeightTokens = {
[_consts.SIZE_OPTIONS.EXTRA_LARGE]: theme.orbit.lineHeightTextExtraLarge,
[_consts.SIZE_OPTIONS.LARGE]: theme.orbit.lineHeightTextLarge,
[_consts.SIZE_OPTIONS.NORMAL]: theme.orbit.lineHeightTextNormal,
[_consts.SIZE_OPTIONS.SMALL]: theme.orbit.lineHeightTextSmall
};
if (!size) return null;
return lineHeightTokens[size];
};
/**
* @deprecated use .orbit-text selector instead
*/
const StyledText = (0, _styledComponents.default)(({
element: TextElement = _consts.ELEMENT_OPTIONS.P,
children,
className,
dataTest,
id
}) => /*#__PURE__*/React.createElement(TextElement, {
className: className,
"data-test": dataTest,
id: id
}, children)).withConfig({
displayName: "deprecated__StyledText",
componentId: "sc-11myi7a-0"
})(["", ""], ({
theme,
align,
uppercase,
size,
weight,
strikeThrough,
$type,
italic,
withBackground,
margin
}) => (0, _styledComponents.css)(["font-family:", ";background:", ";font-size:", ";font-weight:", ";color:", ";line-height:", ";text-align:", ";text-transform:", ";text-decoration:", ";font-style:", ";margin:0;", ";a:not(.orbit-text-link){", ";}"], theme.orbit.fontFamily, withBackground && (0, _orbitDesignTokens.convertHexToRgba)(getTypeToken({
theme,
type: $type
}), 10), getSizeToken({
theme,
size
}), getWeightToken({
theme,
weight
}), getTypeToken({
theme,
type: $type
}), getLineHeightToken({
theme,
size
}), (0, _rtl.textAlign)(align), uppercase && `uppercase`, strikeThrough && `line-through`, italic && `italic`, (0, _common.spacingUtility)(margin), (0, _deprecated.getLinkStyle)({
theme,
$type
})));
exports.StyledText = StyledText;
StyledText.defaultProps = {
theme: _defaultTheme.default
};
var _default = StyledText;
exports.default = _default;