UNPKG

@sendbird/uikit-react-native-foundation

Version:

A foundational UI kit for building chat-enabled React Native apps.

73 lines 2.37 kB
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); } import React from 'react'; import { I18nManager, Text as RNText, StyleSheet } from 'react-native'; import { isStartsWithRTL } from '@sendbird/uikit-utils'; import useUIKitTheme from '../../theme/useUIKitTheme'; const Text = ({ children, color, style, supportRTLAlign = true, originalText, ...props }) => { const { colors } = useUIKitTheme(); const typoStyle = useTypographyFilter(props); const textStyle = 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 (I18nManager.isRTL && supportRTLAlign) { if (originalText && isStartsWithRTL(originalText) || typeof children === 'string' && isStartsWithRTL(children)) { return I18nManager.doLeftAndRightSwapInRTL ? 'left' : 'right'; } else { return I18nManager.doLeftAndRightSwapInRTL ? 'right' : 'left'; } } if (textStyle.textAlign) return textStyle.textAlign; return undefined; })(); return /*#__PURE__*/React.createElement(RNText, _extends({ style: [textStyle, { textAlign }] }, props), children); }; const useTypographyFilter = ({ h1, h2, subtitle1, subtitle2, body1, body2, body3, button, caption1, caption2, caption3, caption4 }) => { const { typography } = useUIKitTheme(); 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 {}; }; export default Text; //# sourceMappingURL=index.js.map