muba-input-text 3.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/InputText.js ADDED
@@ -0,0 +1,250 @@
1
+ import React from 'react';
2
+ import { TextInput, View, TouchableOpacity } from 'react-native';
3
+ import { inputTextStyles } from './InputTextStyles';
4
+ import OutputText from 'muba-output-text';
5
+ import { strings, isRTL, loadLocaleData } from 'muba-i18n';
6
+ import { addFontList } from 'muba-font';
7
+ import { createIconSetFromFontello } from 'react-native-vector-icons';
8
+ import fontelloConfig from './fonts/config.json';
9
+ const FontAwesomeIcon = createIconSetFromFontello(fontelloConfig);
10
+
11
+ const keyboardTypeMap = {
12
+ default: 'default',
13
+ email: 'email-address',
14
+ number: 'numeric',
15
+ phone: 'phone-pad'
16
+ };
17
+
18
+ export default class InputText extends React.Component {
19
+ constructor(props) {
20
+ super(props);
21
+
22
+ loadLocaleData({
23
+ ar: require('./locales/ar.json'),
24
+ en: require('./locales/en.json'),
25
+ es: require('./locales/es.json'),
26
+ fr: require('./locales/fr.json'),
27
+ it: require('./locales/it.json'),
28
+ nl: require('./locales/nl.json')
29
+ });
30
+
31
+ this.state = {
32
+ fieldError: false,
33
+ requiredError: false,
34
+ onlyNumbersError: false,
35
+ maxValueError: false,
36
+ emailBadFormat: false,
37
+ customizedError: false,
38
+ customizedErrorMessage: undefined,
39
+ inputFont: props.inputFont,
40
+ noteFont: props.noteFont,
41
+ fontLoaded: false
42
+ };
43
+ }
44
+
45
+ async componentDidMount() {
46
+ await addFontList([
47
+ {
48
+ name: 'InputTextRegular',
49
+ source: require('./fonts/Poppins/Poppins-Regular.ttf')
50
+ },
51
+ {
52
+ name: 'InputTextFontAwesome',
53
+ source: require('./fonts/Font-Awesome.ttf')
54
+ }
55
+ ]);
56
+ this.setState({ fontLoaded: true });
57
+ }
58
+
59
+ onSubmitValidate() {
60
+ this.setState({
61
+ fieldError: false,
62
+ requiredError: false,
63
+ onlyNumbersError: false,
64
+ maxValueError: false,
65
+ emailBadFormat: false
66
+ });
67
+
68
+ if (this.props.required && (this.props.value == null || this.props.value.toString().trim() === '')) {
69
+ if (this.props.scroll) {
70
+ this.props.scroll(this.inputTextView);
71
+ }
72
+
73
+ this.setState({ fieldError: true, requiredError: true });
74
+ return false;
75
+ }
76
+ return this.validateType();
77
+ }
78
+
79
+ showError() {
80
+ if (this.props.scroll) {
81
+ this.props.scroll(this.inputTextView);
82
+ }
83
+
84
+ this.setState({ fieldError: true });
85
+ }
86
+
87
+ hideError() {
88
+ this.setState({ fieldError: false });
89
+ }
90
+
91
+ validateType() {
92
+ if (this.props.type === 'email') {
93
+ return this.isValidEmail();
94
+ } else if (this.props.type === 'number') {
95
+ return this.isValidNumber();
96
+ }
97
+ return true;
98
+ }
99
+
100
+ isValidEmail() {
101
+ const EMAIL_ALLOWED_LENGTH = 50;
102
+ if (this.props.value != null) {
103
+ if (!this.props.value.length) {
104
+ // It's empty
105
+ this.showError();
106
+ return false;
107
+ } else {
108
+ if (this.props.value.length > EMAIL_ALLOWED_LENGTH || this.props.value.split('@').length !== 2) {
109
+ // It's invalid
110
+ this.showError();
111
+ this.setState({ emailBadFormat: true });
112
+ return false;
113
+ } else {
114
+ const pattern = new RegExp("[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])", 'i');
115
+ const success = !!pattern.test(this.props.value);
116
+
117
+ if (!success) {
118
+ // It's invalid
119
+ this.showError();
120
+ this.setState({ emailBadFormat: true });
121
+ return false;
122
+ }
123
+ }
124
+ }
125
+ }
126
+ // It's valid
127
+ return true;
128
+ }
129
+
130
+ isValidNumber() {
131
+ if (/\D/.test(this.props.value)) {
132
+ this.showError();
133
+ this.setState({ onlyNumbersError: true });
134
+ return false;
135
+ } else if (this.props.maxValue && parseInt(this.props.value) > this.props.maxValue) {
136
+ this.showError();
137
+ this.setState({ maxValueError: true });
138
+ return false;
139
+ }
140
+ return true;
141
+ }
142
+
143
+ showCustomizedError(messageError) {
144
+ this.setState({ fieldError: true, customizedError: true, customizedErrorMessage: messageError });
145
+ }
146
+
147
+ onChangeText(text) {
148
+ if (text === '') {
149
+ text = null;
150
+ }
151
+ this.setState({
152
+ fieldError: false,
153
+ requiredError: false,
154
+ onlyNumbersError: false,
155
+ maxValueError: false,
156
+ emailBadFormat: false,
157
+ customizedError: false,
158
+ customizedErrorMessage: undefined
159
+ });
160
+
161
+ if (this.props.onChangeText) {
162
+ this.props.onChangeText(text);
163
+ }
164
+ }
165
+
166
+ onChange(event) {
167
+ if (this.props.onChange) {
168
+ this.props.onChange(event);
169
+ }
170
+ }
171
+
172
+ onSubmitEditing(event) {
173
+ if (this.props.onSubmitEditing) {
174
+ this.props.onSubmitEditing(event);
175
+ }
176
+ }
177
+
178
+ focus = async () => {
179
+ this.input.focus();
180
+ }
181
+
182
+ render() {
183
+ return (
184
+ this.state.fontLoaded ?
185
+ <View
186
+ style={[this.state.fieldError && this.props.label ? inputTextStyles.fieldErrorView : '', this.props.textContainerStyle]}
187
+ ref={(element) => this.inputTextView = element}>
188
+ {this.props.label || ((this.props.showErrorText == null || this.props.showErrorText) && this.state.fieldError) ?
189
+ <View style={[this.props.label || this.state.fieldError ? { marginBottom: 10 } : '', this.props.inLineError ? inputTextStyles.row : '']}>
190
+ {this.props.label ?
191
+ <View style={inputTextStyles.row}>
192
+ <OutputText style={[inputTextStyles.progressbarField, this.props.labelStyle]}>{this.props.label}</OutputText>
193
+ {this.props.required ? <OutputText style={inputTextStyles.redText}> *</OutputText> : <OutputText />}
194
+ </View>
195
+ :
196
+ <View />
197
+ }
198
+ {this.state.requiredError && (this.props.showErrorText == null || this.props.showErrorText) ? <OutputText style={[inputTextStyles.subNote, inputTextStyles.redText]}> {strings('requiredField')}</OutputText> : null}
199
+ {this.state.onlyNumbersError && (this.props.showErrorText == null || this.props.showErrorText) ? <OutputText style={[inputTextStyles.subNote, inputTextStyles.redText]}> {strings('onlyNumbers')}</OutputText> : null}
200
+ {this.state.maxValueError && (this.props.showErrorText == null || this.props.showErrorText) ? <OutputText style={[inputTextStyles.subNote, inputTextStyles.redText]}> {strings('maxValueError', { maxValue: this.props.maxValue })}</OutputText> : null}
201
+ {this.state.emailBadFormat && (this.props.showErrorText == null || this.props.showErrorText) ? <OutputText style={[inputTextStyles.subNote, inputTextStyles.redText]}> {strings('emailBadFormat')}</OutputText> : null}
202
+ {this.state.maxCharacters && (this.props.showErrorText == null || this.props.showErrorText) ? <OutputText style={[inputTextStyles.subNote, inputTextStyles.redText]}> {strings('maxCharacters', { maxCharacters: this.props.maxCharacters })}</OutputText> : null}
203
+ {this.state.customizedError && (this.props.showErrorText == null || this.props.showErrorText) ? <OutputText style={[inputTextStyles.subNote, inputTextStyles.redText]}> {this.state.customizedErrorMessage}</OutputText> : null}
204
+ </View>
205
+ :
206
+ <View style={{ marginTop: 10 }} />
207
+ }
208
+
209
+ <View style={inputTextStyles.row} collapsable={false}>
210
+ <TextInput
211
+ ref={(input) => { this.input = input; }}
212
+ style={[inputTextStyles.textInputField, inputTextStyles.textField, this.props.style, { textAlign: isRTL() || this.props.language == 'AR' ? 'right' : 'left' }, this.state.fieldError && !this.props.label ? inputTextStyles.fieldError : '', this.props.disabled ? inputTextStyles.disabled : '', this.props.multiline ? { paddingTop: 5 } : '']}
213
+ underlineColorAndroid='transparent'
214
+ keyboardType={this.props.keyboardType ? this.props.keyboardType : keyboardTypeMap[this.props.type ? this.props.type : 'default']}
215
+ onChangeText={(text) => this.onChangeText(text)}
216
+ onChange={(event) => this.onChange(event)}
217
+ editable={this.props.disabled ? false : this.props.editable}
218
+ value={this.props.value != null ? this.props.value.toString() : this.props.value}
219
+ placeholder={this.props.placeholder ? (this.props.required && this.props.turnRequiredSign && isRTL() ? '* ' : '') + this.props.placeholder + (this.props.required && !this.props.turnRequiredSign ? ' *' : '') : ''}
220
+ placeholderTextColor={this.props.placeholderTextColor ? this.props.placeholderTextColor : inputTextStyles.placeholderTextColor.color}
221
+ returnKeyType={this.props.returnKeyType}
222
+ onSubmitEditing={() => { this.onSubmitEditing() }}
223
+ autoCapitalize={this.props.autoCapitalize ? this.props.autoCapitalize : null}
224
+ secureTextEntry={this.props.secureTextEntry ? this.props.secureTextEntry : false}
225
+ multiline={this.props.multiline}
226
+ autoComplete={this.props.autoComplete}
227
+ selection={this.props.selection}
228
+ selectionColor={this.props.selectionColor}
229
+ numberOfLines={this.props.numberOfLines}
230
+ maxLength={this.props.maxLength}
231
+ autoFocus={this.props.autoFocus} />
232
+ {this.props.children}
233
+
234
+ {this.props.value != null && !this.props.hideCancel ?
235
+ this.props.disabled ?
236
+ <View />
237
+ :
238
+ <TouchableOpacity style={[inputTextStyles.deleteTextInput, inputTextStyles.justifyCenter, this.props.iconContainerStyle]} onPress={() => { this.onChangeText('') }}>
239
+ <FontAwesomeIcon style={[inputTextStyles.deleteTextIcon, this.props.iconStyle]} name='input-text-cancel' />
240
+ </TouchableOpacity>
241
+ :
242
+ <View />
243
+ }
244
+ </View>
245
+ </View >
246
+ :
247
+ <View />
248
+ )
249
+ }
250
+ }
@@ -0,0 +1,85 @@
1
+ import { StyleSheet } from 'react-native';
2
+
3
+ const Fonts = {
4
+ Input: 'InputTextRegular',
5
+ Note: 'InputTextRegular',
6
+ }
7
+
8
+ export const inputTextStyles = StyleSheet.create({
9
+
10
+ row: {
11
+ flexDirection: 'row'
12
+ },
13
+
14
+ progressbarField: {
15
+ fontFamily: Fonts.Note,
16
+ fontSize: 12,
17
+ color: '#333',
18
+ },
19
+
20
+ redText: {
21
+ color: '#cf1b1b'
22
+ },
23
+
24
+ subNote: {
25
+ fontSize: 11,
26
+ color: '#858585',
27
+ fontFamily: Fonts.Note,
28
+ textAlign: 'left'
29
+ },
30
+
31
+ fieldErrorView: {
32
+ borderWidth: 2,
33
+ borderColor: '#f1d8d8',
34
+ borderRadius: 5,
35
+ backgroundColor: '#f1d8d8'
36
+ },
37
+
38
+ fieldError: {
39
+ borderWidth: 1,
40
+ borderColor: '#ff0000'
41
+ },
42
+
43
+ disabled: {
44
+ opacity: 0.4
45
+ },
46
+
47
+ placeholderTextColor: {
48
+ color: '#bbbbbb'
49
+ },
50
+
51
+ deleteTextInput: {
52
+ position: 'absolute',
53
+ paddingRight: 10,
54
+ paddingLeft: 10,
55
+ right: 0,
56
+ top: 8
57
+ },
58
+
59
+ deleteTextIcon: {
60
+ fontSize: 16,
61
+ color: '#858585'
62
+ },
63
+
64
+ justifyCenter: {
65
+ justifyContent: 'center'
66
+ },
67
+
68
+ textField: {
69
+ fontSize: 14,
70
+ fontFamily: Fonts.Input,
71
+ width: '100%',
72
+ display: 'flex',
73
+ height: 35,
74
+ backgroundColor: '#eff0f1',
75
+ color: '#333',
76
+ paddingLeft: 15,
77
+ borderRadius: 5
78
+ },
79
+
80
+ textInputField: {
81
+ paddingRight: 25,
82
+ }
83
+ });
84
+
85
+ export default inputTextStyles
Binary file
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "InputTextFontAwesome",
3
+ "css_prefix_text": "icon-",
4
+ "css_use_suffix": false,
5
+ "hinting": true,
6
+ "units_per_em": 1000,
7
+ "ascent": 850,
8
+ "glyphs": [
9
+ {
10
+ "uid": "5211af474d3a9848f67f945e2ccaf143",
11
+ "css": "input-text-cancel",
12
+ "code": 59409,
13
+ "src": "fontawesome"
14
+ }
15
+ ]
16
+ }
package/index.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ /// <reference types="muba" />
2
+
3
+ declare module "muba-input-text" {
4
+ export { default as InputText } from './InputText';
5
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "requiredField": "الحقول المطلوبة",
3
+ "onlyNumbers": "استخدم الأرقام فقط",
4
+ "maxValueError": "الحد الأقصى للقيمة المسموح بها هو {{maxValue}}",
5
+ "emailBadFormat": "رجاء قم بإدخال بريد إكتروني صحيح",
6
+ "maxCharacters": "الحد الأقصى للحروف {{maxCharacters}}"
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "requiredField": "Required field",
3
+ "onlyNumbers": "Use numbers only",
4
+ "maxValueError": "The maximum value allowed is {{maxValue}}",
5
+ "emailBadFormat": "Please enter a valid email address",
6
+ "maxCharacters": "{{maxCharacters}} characters max."
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "requiredField": "Campo obligatorio",
3
+ "onlyNumbers": "Utiliza sólo números",
4
+ "maxValueError": "El valor máximo permitido es {{maxValue}}",
5
+ "emailBadFormat": "Por favor, introduce una dirección de correo electrónico válida",
6
+ "maxCharacters": "{{maxCharacters}} caracteres máx."
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "requiredField": "Champs requis",
3
+ "onlyNumbers": "Utiliser des chiffres seulement",
4
+ "maxValueError": "La valeur maximale autorisée est {{maxValue}}",
5
+ "emailBadFormat": "S'il vous plaît, mettez une adresse email valide",
6
+ "maxCharacters": "{{maxCharacters}} caractères max."
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "requiredField": "Campo obbligatorio",
3
+ "onlyNumbers": "Usa solo numeri",
4
+ "maxValueError": "Il valore massimo permesso è {{maxValue}}",
5
+ "emailBadFormat": "Inserisci un indirizzo e-mail valido",
6
+ "maxCharacters": "{{maxCharacters}} caratteri massimi"
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "requiredField": "Verplicht veld",
3
+ "onlyNumbers": "Gebruik alleen cijfers",
4
+ "maxValueError": "De maximale toegestane waarde is {maxValue}}",
5
+ "emailBadFormat": "Voer een geldig e-mailadres in",
6
+ "maxCharacters": "Maximaal {{maxCharacters} tekens"
7
+ }
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "muba-input-text",
3
+ "version": "3.0.2",
4
+ "description": "Input text",
5
+ "main": "InputText.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/Mubawab/muba-input-text.git"
12
+ },
13
+ "author": "Mubawab",
14
+ "license": "ISC",
15
+ "bugs": {
16
+ "url": "https://github.com/Mubawab/muba-input-text/issues"
17
+ },
18
+ "homepage": "https://github.com/Mubawab/muba-input-text#readme",
19
+ "dependencies": {
20
+ "muba-font": "3",
21
+ "muba-i18n": "3",
22
+ "muba-output-text": "3"
23
+ }
24
+ }