respond-framework
Version:
create as fast you think
70 lines (69 loc) • 1.88 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _react = require("react");
var React = _react;
var _reactNative = require("react-native");
var _styles = require("../styles.js");
var _default = exports.default = /*#__PURE__*/(0, _react.memo)(/*#__PURE__*/(0, _react.forwardRef)(({
event,
name = 'value',
value: v,
formatIn = v => v,
format = v => v,
formatOut = format,
style,
placeholder,
placeholderStyle,
disabled,
returnKeyType = 'done',
zIndex = style?.zIndex ?? 1
}, ref) => {
const value = typeof v === 'object' // replayed from saved test, where strings/json transformed to objects
? Object.keys(v).length === 0 ? '' : JSON.stringify(v, null, 2) : String(formatIn(v) || '');
const onChangeText = v => {
if (disabled) return;
const next = formatOut(v) || '';
if (next === value) return;
event.trigger({
[name]: next
}, {
name,
input: true
});
};
return /*#__PURE__*/React.createElement(_reactNative.TextInput, {
ref,
style: [s.input, style, !value && s.placeholder, !value && placeholderStyle, disabled && s.disabled, {
zIndex
}],
placeholder: placeholder || name,
placeholderTextColor: placeholderStyle?.color || s.placeholder.color,
value,
onChangeText: (0, _react.useCallback)(onChangeText, [event, name, value, disabled]),
returnKeyType,
editable: !disabled
});
}));
const s = _reactNative.StyleSheet.create({
input: {
fontSize: 15,
height: 35,
paddingLeft: 12,
color: _styles.colors.tan,
backgroundColor: _styles.colors.navy,
borderRadius: 3,
marginTop: 9,
verticalAlign: 'middle',
paddingTop: 0,
paddingBottom: 0
},
placeholder: {
color: _styles.colors.greyLight
},
disabled: {
backgroundColor: 'rgb(238, 238, 238)'
}
});