@viktorvojtek/react-native-simple-components
Version:
Collection of essential UI components based on react-native components
147 lines (146 loc) • 6.71 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;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const react_1 = __importStar(require("react"));
const react_native_1 = require("react-native");
const utils_1 = require("../utils");
const Text_1 = __importDefault(require("./Text/Text"));
const useColoredProps_1 = __importDefault(require("../hooks/useColoredProps"));
const TextInput = (0, react_1.forwardRef)((props, ref) => {
const coloredPropItems = (0, useColoredProps_1.default)(props);
const { label, allowFontScaling, autoCapitalize, autoComplete, // Android
autoCorrect, autoFocus, blurOnSubmit, caretHidden, clearButtonMode, // iOS
clearTextOnFocus, // iOS
contextMenuHidden, dataDetectorTypes, // iOS
defaultValue, cursorColor, // Android
disableFullscreenUI, // Android
editable, enablesReturnKeyAutomatically, // iOS
importantForAutofill, // Android
inlineImageLeft, // Android
inlineImagePadding, // Android
inputAccessoryViewID, // iOS
keyboardAppearance, // iOS
keyboardType, maxFontSizeMultiplier, maxLength, multiline = true, numberOfLines = 5, // Android
onBlur, onChange, onChangeText, onContentSizeChange, onEndEditing, onPressIn, onPressOut, onFocus, onKeyPress, onLayout, onScroll, onSelectionChange, onSubmitEditing, placeholder, placeholderTextColor, returnKeyLabel, // Android
returnKeyType, rejectResponderTermination, // iOS
scrollEnabled, // iOS
secureTextEntry, selection, selectionColor, selectTextOnFocus, showSoftInputOnFocus, spellCheck, // iOS
textAlign, textContentType, // iOS
passwordRules, // iOS
color, style } = props, restStyleProps = __rest(props, ["label", "allowFontScaling", "autoCapitalize", "autoComplete", "autoCorrect", "autoFocus", "blurOnSubmit", "caretHidden", "clearButtonMode", "clearTextOnFocus", "contextMenuHidden", "dataDetectorTypes", "defaultValue", "cursorColor", "disableFullscreenUI", "editable", "enablesReturnKeyAutomatically", "importantForAutofill", "inlineImageLeft", "inlineImagePadding", "inputAccessoryViewID", "keyboardAppearance", "keyboardType", "maxFontSizeMultiplier", "maxLength", "multiline", "numberOfLines", "onBlur", "onChange", "onChangeText", "onContentSizeChange", "onEndEditing", "onPressIn", "onPressOut", "onFocus", "onKeyPress", "onLayout", "onScroll", "onSelectionChange", "onSubmitEditing", "placeholder", "placeholderTextColor", "returnKeyLabel", "returnKeyType", "rejectResponderTermination", "scrollEnabled", "secureTextEntry", "selection", "selectionColor", "selectTextOnFocus", "showSoftInputOnFocus", "spellCheck", "textAlign", "textContentType", "passwordRules", "color", "style"]);
const restProps = {
allowFontScaling,
autoCapitalize,
autoComplete,
autoCorrect,
autoFocus,
blurOnSubmit,
caretHidden,
clearButtonMode,
clearTextOnFocus,
contextMenuHidden,
dataDetectorTypes,
defaultValue,
cursorColor,
disableFullscreenUI,
editable,
enablesReturnKeyAutomatically,
importantForAutofill,
inlineImageLeft,
inlineImagePadding,
inputAccessoryViewID,
keyboardAppearance,
keyboardType,
maxFontSizeMultiplier,
maxLength,
multiline,
numberOfLines,
onBlur,
onChange,
onChangeText,
onContentSizeChange,
onEndEditing,
onPressIn,
onPressOut,
onFocus,
onKeyPress,
onLayout,
onScroll,
onSelectionChange,
onSubmitEditing,
placeholder,
// placeholderTextColor,
returnKeyLabel,
returnKeyType,
rejectResponderTermination,
scrollEnabled,
secureTextEntry,
selection,
selectionColor,
selectTextOnFocus,
showSoftInputOnFocus,
spellCheck,
textAlign,
textContentType,
passwordRules, // iOS
};
const computedStyle = (0, react_1.useMemo)(() => (0, utils_1.mapShortStyleProps)(restStyleProps), [restStyleProps]);
// TODO: Test this out for label
// const space = label ? 8 : 0;
return (react_1.default.createElement(react_1.default.Fragment, null,
label && react_1.default.createElement(Text_1.default, null, label),
react_1.default.createElement(react_native_1.TextInput, Object.assign({ ref: ref, style: [
style,
{
backgroundColor: "#fff",
borderWidth: 2,
borderColor: "#000",
borderTopLeftRadius: 5,
borderTopRightRadius: 5,
borderBottomLeftRadius: 5,
borderBottomRightRadius: 5,
paddingHorizontal: 10,
paddingVertical: 5,
flexGrow: 1,
},
...computedStyle,
...coloredPropItems,
] }, restProps))));
});
exports.default = (0, react_1.memo)(TextInput);