@razorpay/blade
Version:
The Design System that powers Razorpay
135 lines (132 loc) • 5.01 kB
JavaScript
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
import React__default from 'react';
import '../BaseText/index.js';
import { useValidateAsProp } from '../utils.js';
import '../../Box/styledProps/index.js';
import '../../../utils/assignWithoutSideEffects/index.js';
import '../../../utils/logger/index.js';
import { jsx } from 'react/jsx-runtime';
import { throwBladeError } from '../../../utils/logger/logger.js';
import { BaseText } from '../BaseText/BaseText.web.js';
import { getStyledProps } from '../../Box/styledProps/getStyledProps.js';
import { assignWithoutSideEffects } from '../../../utils/assignWithoutSideEffects/assignWithoutSideEffects.js';
var _excluded = ["as", "variant", "weight", "size", "truncateAfterLines", "children", "color", "testID", "textAlign", "textDecorationLine", "wordBreak"];
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var validAsValues = ['p', 'span', 'div', 'abbr', 'figcaption', 'cite', 'q', 'label'];
var getTextProps = function getTextProps(_ref) {
var variant = _ref.variant,
weight = _ref.weight,
size = _ref.size,
_ref$color = _ref.color,
color = _ref$color === void 0 ? 'surface.text.gray.normal' : _ref$color,
testID = _ref.testID,
textAlign = _ref.textAlign,
textDecorationLine = _ref.textDecorationLine;
var props = {
color: color,
fontSize: 100,
fontWeight: weight !== null && weight !== void 0 ? weight : 'regular',
fontStyle: 'normal',
lineHeight: 100,
fontFamily: 'text',
componentName: 'text',
testID: testID,
textAlign: textAlign,
textDecorationLine: textDecorationLine
};
if (variant === 'caption') {
// variant of caption can only have size of small
if (size && size !== 'small' && size !== 'medium') {
if (true) {
throwBladeError({
moduleName: 'Text',
message: "size cannot be '".concat(size, "' when variant is 'caption'")
});
}
// Set size as small in case of invalid size
size = 'small';
}
} else if (variant !== 'caption' && !size) {
size = 'medium';
}
if (variant === 'body') {
if (size === 'xsmall') {
props.fontSize = 25;
props.lineHeight = 25;
}
if (size === 'small') {
props.fontSize = 75;
props.lineHeight = 75;
}
if (size === 'medium') {
props.fontSize = 100;
props.lineHeight = 100;
}
if (size === 'large') {
props.fontSize = 200;
props.lineHeight = 200;
}
}
if (variant === 'caption') {
if (size === 'small') {
props.fontSize = 50;
props.lineHeight = 50;
props.fontWeight = 'regular';
}
if (size === 'medium') {
props.fontSize = 100;
props.lineHeight = 50;
props.fontWeight = 'regular';
}
props.fontStyle = 'italic';
}
return props;
};
var _Text = function _Text(_ref2, ref) {
var _ref2$as = _ref2.as,
as = _ref2$as === void 0 ? 'p' : _ref2$as,
_ref2$variant = _ref2.variant,
variant = _ref2$variant === void 0 ? 'body' : _ref2$variant,
_ref2$weight = _ref2.weight,
weight = _ref2$weight === void 0 ? 'regular' : _ref2$weight,
size = _ref2.size,
truncateAfterLines = _ref2.truncateAfterLines,
children = _ref2.children,
color = _ref2.color,
testID = _ref2.testID,
textAlign = _ref2.textAlign,
textDecorationLine = _ref2.textDecorationLine,
wordBreak = _ref2.wordBreak,
styledProps = _objectWithoutProperties(_ref2, _excluded);
var props = _objectSpread({
as: as,
truncateAfterLines: truncateAfterLines,
wordBreak: wordBreak
}, getTextProps({
variant: variant,
weight: weight,
color: color,
size: size,
testID: testID,
textAlign: textAlign,
textDecorationLine: textDecorationLine
}));
useValidateAsProp({
componentName: 'Text',
as: as,
validAsValues: validAsValues
});
return /*#__PURE__*/jsx(BaseText, _objectSpread(_objectSpread(_objectSpread({
ref: ref
}, props), getStyledProps(styledProps)), {}, {
children: children
}));
};
var Text = /*#__PURE__*/assignWithoutSideEffects( /*#__PURE__*/React__default.forwardRef(_Text), {
displayName: 'Text',
componentId: 'Text'
});
export { Text, getTextProps };
//# sourceMappingURL=Text.js.map