@viktorvojtek/react-native-simple-components
Version:
Collection of essential UI components based on react-native components
62 lines (61 loc) • 3.45 kB
JavaScript
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
const react_1 = __importStar(require("react"));
const react_native_1 = require("react-native");
const react_native_responsive_fontsize_1 = require("react-native-responsive-fontsize");
const ThemeProvider_1 = require("../../ThemeProvider");
const Text = (props) => {
var _a, _b;
const { children, fontSize: fontSizeProp, fontWeight: fontWeightProp, letterSpacing: letterSpacingProp, numberOfLines, color } = props, restStyleProps = __rest(props, ["children", "fontSize", "fontWeight", "letterSpacing", "numberOfLines", "color"]);
const theme = (0, ThemeProvider_1.useTheme)();
const colorValue = (0, react_1.useMemo)(() => {
var _a, _b;
if (!color)
return undefined;
const isThemeColor = Object.keys((_a = theme === null || theme === void 0 ? void 0 : theme.colors) !== null && _a !== void 0 ? _a : {}).includes(color);
if (isThemeColor) {
return (_b = theme === null || theme === void 0 ? void 0 : theme.colors) === null || _b === void 0 ? void 0 : _b[color];
}
return color;
}, [theme, color]);
const fontSize = (0, react_1.useMemo)(() => (0, react_native_responsive_fontsize_1.RFValue)(+(fontSizeProp !== null && fontSizeProp !== void 0 ? fontSizeProp : 14)), [fontSizeProp]);
const fontWeight = fontWeightProp !== null && fontWeightProp !== void 0 ? fontWeightProp : "500";
const computedStyle = Object.assign({ fontSize,
fontWeight, fontFamily: (_b = (_a = theme === null || theme === void 0 ? void 0 : theme.fonts) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : "System", color: colorValue }, restStyleProps);
return (react_1.default.createElement(react_native_1.Text, { numberOfLines: numberOfLines, style: Object.assign({}, computedStyle) }, children));
};
exports.default = (0, react_1.memo)(Text);
;