@widergy/mobile-ui 1.50.0 → 1.50.1

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/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [1.50.1](https://github.com/widergy/mobile-ui/compare/v1.50.0...v1.50.1) (2025-09-18)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * [CX-1130] UTCuit Field Refactor ([#456](https://github.com/widergy/mobile-ui/issues/456)) ([19cce9d](https://github.com/widergy/mobile-ui/commit/19cce9dc619a04044b662cb3e359dd755c5c4715))
7
+
1
8
  # [1.50.0](https://github.com/widergy/mobile-ui/compare/v1.49.7...v1.50.0) (2025-08-12)
2
9
 
3
10
 
@@ -0,0 +1,8 @@
1
+ export const ID_CODE_REGEX = /(\d+)/gi;
2
+
3
+ export const PREFIX_LENGTH = 2;
4
+ export const DOCUMENT_LENGTH = 8;
5
+
6
+ export const PREFIX_REGEX = /^[23]\d$/;
7
+
8
+ export const TITLE = 'CUIT';
@@ -0,0 +1,191 @@
1
+ import React, { useState, useRef, useEffect } from 'react';
2
+ import { bool, func, oneOf, oneOfType, string } from 'prop-types';
3
+ import { View } from 'react-native';
4
+
5
+ import UTLabel from '../UTLabel';
6
+ import UTTextInput from '../UTTextInput';
7
+
8
+ import styles from './styles';
9
+ import { ID_CODE_REGEX, PREFIX_LENGTH, DOCUMENT_LENGTH, TITLE } from './constants';
10
+
11
+ const UTCuit = ({
12
+ blurOnSubmit,
13
+ defaultValue,
14
+ editable = true,
15
+ editableDocument = true,
16
+ formError,
17
+ onBlur,
18
+ onChange,
19
+ onFocus,
20
+ onSubmitEditing,
21
+ returnKeyType = 'done',
22
+ title,
23
+ value
24
+ }) => {
25
+ const prefixRef = useRef();
26
+ const documentNumberRef = useRef();
27
+ const suffixRef = useRef();
28
+
29
+ const [documentNumber, setDocumentNumber] = useState('');
30
+ const [prefix, setPrefix] = useState('');
31
+ const [suffix, setSuffix] = useState('');
32
+
33
+ const valuesRef = useRef({ prefix: '', documentNumber: '', suffix: '' });
34
+ const isInitialized = useRef(false);
35
+
36
+ useEffect(() => {
37
+ if (!isInitialized.current) {
38
+ const initialValue = value || defaultValue || '';
39
+ const code = initialValue.match(ID_CODE_REGEX);
40
+
41
+ let initialPrefix = '';
42
+ let initialDocNumber = '';
43
+ let initialSuffix = '';
44
+
45
+ if (code) {
46
+ if (code.length === 3) [initialPrefix, initialDocNumber, initialSuffix] = code;
47
+ else [initialDocNumber] = code;
48
+ }
49
+
50
+ const formattedDocumentNumber = !editableDocument
51
+ ? `${'0'.repeat(DOCUMENT_LENGTH - initialDocNumber.length)}${initialDocNumber}`
52
+ : initialDocNumber;
53
+
54
+ setDocumentNumber(formattedDocumentNumber);
55
+ setPrefix(initialPrefix);
56
+ setSuffix(initialSuffix);
57
+
58
+ valuesRef.current = {
59
+ prefix: initialPrefix,
60
+ documentNumber: formattedDocumentNumber,
61
+ suffix: initialSuffix
62
+ };
63
+
64
+ isInitialized.current = true;
65
+ }
66
+ }, [value, defaultValue, editableDocument]);
67
+
68
+ const changeDocumentNumber = newDocumentNumber => {
69
+ if (editableDocument) {
70
+ setDocumentNumber(newDocumentNumber);
71
+ valuesRef.current.documentNumber = newDocumentNumber;
72
+ if (onChange) {
73
+ onChange(`${valuesRef.current.prefix}-${newDocumentNumber}-${valuesRef.current.suffix}`);
74
+ }
75
+ }
76
+ };
77
+
78
+ const changePrefix = newPrefix => {
79
+ if (newPrefix.length === 1 && !['2', '3'].includes(newPrefix)) {
80
+ return;
81
+ }
82
+ if (newPrefix.length === 2 && !/^[23][0-9]$/.test(newPrefix)) {
83
+ return;
84
+ }
85
+
86
+ setPrefix(newPrefix);
87
+ valuesRef.current.prefix = newPrefix;
88
+ if (onChange) {
89
+ onChange(`${newPrefix}-${valuesRef.current.documentNumber}-${valuesRef.current.suffix}`);
90
+ }
91
+ };
92
+
93
+ const changeSuffix = newSuffix => {
94
+ setSuffix(newSuffix);
95
+ valuesRef.current.suffix = newSuffix;
96
+ if (onChange) {
97
+ onChange(`${valuesRef.current.prefix}-${valuesRef.current.documentNumber}-${newSuffix}`);
98
+ }
99
+ };
100
+
101
+ const handleBlur = () => {
102
+ if (onBlur) {
103
+ onBlur();
104
+ }
105
+ };
106
+
107
+ return (
108
+ <View style={styles.container}>
109
+ <UTLabel variant="medium" style={styles.title}>
110
+ {title || TITLE}
111
+ </UTLabel>
112
+ <View style={styles.fieldContainer}>
113
+ <View style={styles.input}>
114
+ <UTTextInput
115
+ alwaysShowPlaceholder
116
+ blurOnSubmit={blurOnSubmit}
117
+ disabled={!editable}
118
+ error={!!formError && ' '}
119
+ inputRef={prefixRef}
120
+ maxLength={PREFIX_LENGTH}
121
+ onBlur={handleBlur}
122
+ onChange={changePrefix}
123
+ onFocus={onFocus}
124
+ placeholder="XX"
125
+ returnKeyType={returnKeyType}
126
+ type="numeric"
127
+ value={prefix}
128
+ version="V1"
129
+ />
130
+ </View>
131
+ <View style={styles.documentContainer}>
132
+ <UTTextInput
133
+ alwaysShowPlaceholder
134
+ blurOnSubmit={blurOnSubmit}
135
+ disabled={!editable || !editableDocument}
136
+ error={!!formError && ' '}
137
+ inputRef={documentNumberRef}
138
+ maxLength={DOCUMENT_LENGTH}
139
+ onBlur={handleBlur}
140
+ onChange={changeDocumentNumber}
141
+ onFocus={onFocus}
142
+ placeholder="XXXXXXXX"
143
+ returnKeyType={returnKeyType}
144
+ type="numeric"
145
+ value={documentNumber}
146
+ version="V1"
147
+ />
148
+ </View>
149
+ <View style={styles.input}>
150
+ <UTTextInput
151
+ alwaysShowPlaceholder
152
+ blurOnSubmit={blurOnSubmit}
153
+ disabled={!editable}
154
+ error={!!formError && ' '}
155
+ inputRef={suffixRef}
156
+ maxLength={1}
157
+ onBlur={handleBlur}
158
+ onChange={changeSuffix}
159
+ onFocus={onFocus}
160
+ onSubmitEditing={onSubmitEditing}
161
+ placeholder="X"
162
+ returnKeyType={returnKeyType}
163
+ type="numeric"
164
+ value={suffix}
165
+ version="V1"
166
+ />
167
+ </View>
168
+ </View>
169
+ <UTLabel colorTheme="error" variant="xsmall" style={styles.error}>
170
+ {formError || ''}
171
+ </UTLabel>
172
+ </View>
173
+ );
174
+ };
175
+
176
+ UTCuit.propTypes = {
177
+ blurOnSubmit: bool,
178
+ defaultValue: string,
179
+ editable: bool,
180
+ editableDocument: bool,
181
+ formError: oneOfType([string, bool]),
182
+ onBlur: func,
183
+ onChange: func.isRequired,
184
+ onFocus: func,
185
+ onSubmitEditing: func,
186
+ returnKeyType: oneOf(['done', 'go', 'next', 'search']),
187
+ title: string,
188
+ value: string
189
+ };
190
+
191
+ export default UTCuit;
@@ -0,0 +1,33 @@
1
+ import { StyleSheet } from 'react-native';
2
+
3
+ export default StyleSheet.create({
4
+ container: {
5
+ flexDirection: 'column'
6
+ },
7
+ title: {
8
+ marginBottom: 8
9
+ },
10
+ fieldContainer: {
11
+ alignItems: 'flex-end',
12
+ flexDirection: 'row',
13
+ marginTop: 6
14
+ },
15
+ documentContainer: {
16
+ flex: 2,
17
+ paddingHorizontal: 4
18
+ },
19
+ input: {
20
+ flex: 1
21
+ },
22
+ inputContainer: {
23
+ flex: 1
24
+ },
25
+ message: {
26
+ paddingTop: 15,
27
+ marginBottom: -25
28
+ },
29
+ error: {
30
+ marginBottom: 12,
31
+ marginTop: 12
32
+ }
33
+ });
package/lib/index.js CHANGED
@@ -44,6 +44,7 @@ export { default as UTButton } from './components/UTButton';
44
44
  export { default as UTButtonGroup } from './components/UTButtonGroup';
45
45
  export { default as UTCBUInput } from './components/UTCBUInput';
46
46
  export { default as UTCheckBox } from './components/UTCheckBox';
47
+ export { default as UTCuit } from './components/UTCuit';
47
48
  export { default as UTCheckList } from './components/UTCheckList';
48
49
  export { default as UTDataCategory } from './components/UTDataCategory';
49
50
  export { default as UTDataElement } from './components/UTDataElement';
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@widergy/mobile-ui",
3
3
  "description": "Widergy Mobile Components",
4
4
  "author": "widergy",
5
- "version": "1.50.0",
5
+ "version": "1.50.1",
6
6
  "repository": "https://github.com/widergy/mobile-ui.git",
7
7
  "main": "lib/index.js",
8
8
  "files": [