@sendbird/uikit-react-native-foundation
Version:
A foundational UI kit for building chat-enabled React Native apps.
80 lines (79 loc) • 2.74 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _react = _interopRequireDefault(require("react"));
var _reactNative = require("react-native");
var _uikitUtils = require("@sendbird/uikit-utils");
var _useUIKitTheme = _interopRequireDefault(require("../../theme/useUIKitTheme"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
const Text = ({
children,
color,
style,
supportRTLAlign = true,
originalText,
...props
}) => {
const {
colors
} = (0, _useUIKitTheme.default)();
const typoStyle = useTypographyFilter(props);
const textStyle = _reactNative.StyleSheet.flatten([{
color: typeof color === 'string' ? color : (color === null || color === void 0 ? void 0 : color(colors)) ?? colors.text
}, typoStyle, style]);
const textAlign = (() => {
if (textStyle.textAlign && textStyle.textAlign !== 'left' && textStyle.textAlign !== 'right') {
return textStyle.textAlign;
}
if (_reactNative.I18nManager.isRTL && supportRTLAlign) {
if (originalText && (0, _uikitUtils.isStartsWithRTL)(originalText) || typeof children === 'string' && (0, _uikitUtils.isStartsWithRTL)(children)) {
return _reactNative.I18nManager.doLeftAndRightSwapInRTL ? 'left' : 'right';
} else {
return _reactNative.I18nManager.doLeftAndRightSwapInRTL ? 'right' : 'left';
}
}
if (textStyle.textAlign) return textStyle.textAlign;
return undefined;
})();
return /*#__PURE__*/_react.default.createElement(_reactNative.Text, _extends({
style: [textStyle, {
textAlign
}]
}, props), children);
};
const useTypographyFilter = ({
h1,
h2,
subtitle1,
subtitle2,
body1,
body2,
body3,
button,
caption1,
caption2,
caption3,
caption4
}) => {
const {
typography
} = (0, _useUIKitTheme.default)();
if (h1) return typography.h1;
if (h2) return typography.h2;
if (subtitle1) return typography.subtitle1;
if (subtitle2) return typography.subtitle2;
if (body1) return typography.body1;
if (body2) return typography.body2;
if (body3) return typography.body3;
if (button) return typography.button;
if (caption1) return typography.caption1;
if (caption2) return typography.caption2;
if (caption3) return typography.caption3;
if (caption4) return typography.caption4;
return {};
};
var _default = exports.default = Text;
//# sourceMappingURL=index.js.map