@widergy/mobile-ui 1.15.0 → 1.15.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 +7 -0
- package/lib/components/Button/index.js +1 -1
- package/lib/components/UTBadge/index.js +2 -2
- package/lib/components/UTBadge/theme.js +9 -6
- package/lib/components/UTBaseInputField/README.md +45 -31
- package/lib/components/UTBaseInputField/components/ActionAdornment/index.js +5 -16
- package/lib/components/UTBaseInputField/components/BadgeAdornment/index.js +13 -0
- package/lib/components/UTBaseInputField/components/IconAdornment/constants.js +2 -0
- package/lib/components/UTBaseInputField/components/IconAdornment/index.js +20 -15
- package/lib/components/UTBaseInputField/components/IconAdornment/proptypes.js +20 -0
- package/lib/components/UTBaseInputField/components/IconAdornment/utils.js +7 -2
- package/lib/components/UTBaseInputField/constants.js +12 -1
- package/lib/components/UTBaseInputField/index.js +69 -72
- package/lib/components/UTBaseInputField/proptypes.js +60 -0
- package/lib/components/UTBaseInputField/theme.js +72 -32
- package/lib/components/UTBottomSheet/README.md +53 -0
- package/lib/components/UTBottomSheet/index.js +139 -0
- package/lib/components/UTBottomSheet/styles.js +46 -0
- package/lib/components/UTButton/constants.js +5 -14
- package/lib/components/UTButton/index.js +6 -22
- package/lib/components/UTButton/proptypes.js +29 -0
- package/lib/components/UTButton/theme.js +6 -5
- package/lib/components/UTCheckBox/README.md +4 -30
- package/lib/components/UTCheckBox/constants.js +4 -1
- package/lib/components/UTCheckBox/index.js +33 -22
- package/lib/components/UTCheckBox/proptypes.js +12 -3
- package/lib/components/UTCheckBox/styles.js +7 -0
- package/lib/components/UTCheckBox/theme.js +98 -54
- package/lib/components/UTCheckList/README.MD +14 -10
- package/lib/components/UTCheckList/constants.js +6 -1
- package/lib/components/UTCheckList/index.js +44 -66
- package/lib/components/UTCheckList/proptypes.js +48 -0
- package/lib/components/UTCheckList/styles.js +10 -5
- package/lib/components/UTCheckList/utils.js +5 -0
- package/lib/components/UTFieldLabel/index.js +4 -3
- package/lib/components/UTLabel/constants.js +11 -11
- package/lib/components/UTLabel/index.js +3 -17
- package/lib/components/UTLabel/proptypes.js +19 -0
- package/lib/components/UTLabel/theme.js +2 -2
- package/lib/components/UTMenu/index.js +1 -1
- package/lib/components/UTPasswordField/versions/V0/components/PasswordValidations/styles.js +1 -0
- package/lib/components/UTPasswordField/versions/V1/index.js +3 -2
- package/lib/components/UTSearchField/README.md +42 -0
- package/lib/components/UTSearchField/index.js +59 -0
- package/lib/components/UTSearchField/proptypes.js +28 -0
- package/lib/components/UTSelect/index.js +10 -97
- package/lib/components/UTSelect/{componentes → versions/V0/componentes}/MultipleItem/index.js +1 -1
- package/lib/components/UTSelect/versions/V0/index.js +103 -0
- package/lib/components/UTSelect/versions/V1/README.md +82 -0
- package/lib/components/UTSelect/versions/V1/index.js +171 -0
- package/lib/components/UTSelect/versions/V1/proptypes.js +45 -0
- package/lib/components/UTSelect/versions/V1/styles.js +18 -0
- package/lib/components/UTTextArea/index.js +1 -1
- package/lib/components/UTTextInput/versions/V0/components/BaseInput/index.js +3 -3
- package/lib/components/UTTextInput/versions/V1/README.md +36 -35
- package/lib/components/UTTextInput/versions/V1/components/TextInputField/index.js +18 -12
- package/lib/components/UTTextInput/versions/V1/constants.js +3 -5
- package/lib/components/UTTextInput/versions/V1/index.js +21 -18
- package/lib/components/UTTextInput/versions/V1/proptypes.js +23 -6
- package/lib/index.js +47 -52
- package/package.json +2 -2
- /package/lib/components/UTSelect/{componentes → versions/V0/componentes}/MultipleItem/styles.js +0 -0
- /package/lib/components/UTSelect/{proptypes.js → versions/V0/proptypes.js} +0 -0
- /package/lib/components/UTSelect/{styles.js → versions/V0/styles.js} +0 -0
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import React, { useState, useCallback, useRef } from 'react';
|
|
2
|
+
import { View, Pressable, ScrollView } from 'react-native';
|
|
3
|
+
import isEmpty from 'lodash/isEmpty';
|
|
4
|
+
|
|
5
|
+
import { COMPONENT_KEYS } from '../../../UTBaseInputField/constants';
|
|
6
|
+
import UTBaseInputField from '../../../UTBaseInputField';
|
|
7
|
+
import UTBottomSheet from '../../../UTBottomSheet';
|
|
8
|
+
import UTCheckList from '../../../UTCheckList';
|
|
9
|
+
import UTFieldLabel from '../../../UTFieldLabel';
|
|
10
|
+
import UTLabel from '../../../UTLabel';
|
|
11
|
+
import UTSearchField from '../../../UTSearchField';
|
|
12
|
+
|
|
13
|
+
import { defaultProps, propTypes } from './proptypes';
|
|
14
|
+
import styles from './styles';
|
|
15
|
+
|
|
16
|
+
const UTSelect = ({
|
|
17
|
+
action,
|
|
18
|
+
alwaysShowPlaceholder,
|
|
19
|
+
closeButtonText,
|
|
20
|
+
helpText,
|
|
21
|
+
input,
|
|
22
|
+
isMultiple,
|
|
23
|
+
label,
|
|
24
|
+
noMatchesText,
|
|
25
|
+
options,
|
|
26
|
+
placeholder,
|
|
27
|
+
prefix,
|
|
28
|
+
required,
|
|
29
|
+
searchPlaceholder,
|
|
30
|
+
selectAllLabel,
|
|
31
|
+
showSelectAll,
|
|
32
|
+
style,
|
|
33
|
+
suffix
|
|
34
|
+
}) => {
|
|
35
|
+
const [bottomSheetVisible, setBottomSheetVisible] = useState(false);
|
|
36
|
+
const [searchTerm, setSearchTerm] = useState('');
|
|
37
|
+
const [selectedOptions, setSelectedOptions] = useState(input.value || []);
|
|
38
|
+
const [sortedOptions, setSortedOptions] = useState(options);
|
|
39
|
+
const inputFieldRef = useRef(null);
|
|
40
|
+
|
|
41
|
+
const sortOptions = useCallback(() => {
|
|
42
|
+
const selectedOptionsList = options.filter(option => selectedOptions.includes(option.value));
|
|
43
|
+
const unselectedOptionsList = options.filter(option => !selectedOptions.includes(option.value));
|
|
44
|
+
setSortedOptions([...selectedOptionsList, ...unselectedOptionsList]);
|
|
45
|
+
}, [options, selectedOptions]);
|
|
46
|
+
|
|
47
|
+
const handleOpenBottomSheet = () => {
|
|
48
|
+
sortOptions();
|
|
49
|
+
setBottomSheetVisible(true);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const handleCloseBottomSheet = () => {
|
|
53
|
+
if (inputFieldRef.current) {
|
|
54
|
+
inputFieldRef.current.truncate();
|
|
55
|
+
}
|
|
56
|
+
setBottomSheetVisible(false);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const clearSelectedOptions = () => {
|
|
60
|
+
setSelectedOptions([]);
|
|
61
|
+
input.onChange([]);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const handleSelect = useCallback(
|
|
65
|
+
newValues => {
|
|
66
|
+
setSelectedOptions(newValues);
|
|
67
|
+
input.onChange(newValues);
|
|
68
|
+
if (!isMultiple) handleCloseBottomSheet();
|
|
69
|
+
},
|
|
70
|
+
[input, isMultiple]
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
const displayValue = selectedOptions
|
|
74
|
+
.map(optionValue => {
|
|
75
|
+
const option = options.find(o => o.value === optionValue);
|
|
76
|
+
return option ? option.label : '';
|
|
77
|
+
})
|
|
78
|
+
.join(', ');
|
|
79
|
+
|
|
80
|
+
const filteredOptions = sortedOptions.filter(option =>
|
|
81
|
+
option.label.toLowerCase().includes(searchTerm.toLowerCase())
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
const clearAction = {
|
|
85
|
+
Icon: 'IconX',
|
|
86
|
+
onPress: clearSelectedOptions,
|
|
87
|
+
size: 'small'
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const leftAdornments = [
|
|
91
|
+
...(isMultiple && !isEmpty(selectedOptions)
|
|
92
|
+
? [{ name: COMPONENT_KEYS.BADGE, props: { text: selectedOptions.length, colorTheme: 'identity' } }]
|
|
93
|
+
: []),
|
|
94
|
+
{ name: COMPONENT_KEYS.PREFIX, props: { text: prefix } }
|
|
95
|
+
];
|
|
96
|
+
|
|
97
|
+
const rightAdornments = [
|
|
98
|
+
{ name: COMPONENT_KEYS.SUFFIX, props: { text: suffix } },
|
|
99
|
+
...(displayValue ? [{ name: COMPONENT_KEYS.ACTION, props: { action: clearAction } }] : []),
|
|
100
|
+
{ name: COMPONENT_KEYS.ICON, props: { Icon: 'IconChevronDown' } },
|
|
101
|
+
{ name: COMPONENT_KEYS.ACTION, props: { action } }
|
|
102
|
+
];
|
|
103
|
+
|
|
104
|
+
return (
|
|
105
|
+
<View>
|
|
106
|
+
<View style={[styles.container, style]}>
|
|
107
|
+
{label && (
|
|
108
|
+
<UTFieldLabel required={required} variant="body">
|
|
109
|
+
{label}
|
|
110
|
+
</UTFieldLabel>
|
|
111
|
+
)}
|
|
112
|
+
<Pressable onPress={handleOpenBottomSheet}>
|
|
113
|
+
<UTBaseInputField
|
|
114
|
+
ref={inputFieldRef}
|
|
115
|
+
alwaysShowPlaceholder={alwaysShowPlaceholder}
|
|
116
|
+
editable={false}
|
|
117
|
+
leftAdornments={leftAdornments}
|
|
118
|
+
placeholder={placeholder}
|
|
119
|
+
rightAdornments={rightAdornments}
|
|
120
|
+
input={{ value: displayValue }}
|
|
121
|
+
variant="button"
|
|
122
|
+
/>
|
|
123
|
+
</Pressable>
|
|
124
|
+
{helpText && (
|
|
125
|
+
<UTLabel colorTheme="gray" variant="small">
|
|
126
|
+
{helpText}
|
|
127
|
+
</UTLabel>
|
|
128
|
+
)}
|
|
129
|
+
</View>
|
|
130
|
+
<UTBottomSheet
|
|
131
|
+
title={label}
|
|
132
|
+
description={helpText}
|
|
133
|
+
visible={bottomSheetVisible}
|
|
134
|
+
onClose={handleCloseBottomSheet}
|
|
135
|
+
buttonText={closeButtonText}
|
|
136
|
+
>
|
|
137
|
+
<View style={styles.bottomSheetBodyContainer}>
|
|
138
|
+
<UTSearchField
|
|
139
|
+
input={{
|
|
140
|
+
value: searchTerm,
|
|
141
|
+
onChange: setSearchTerm
|
|
142
|
+
}}
|
|
143
|
+
placeholder={searchPlaceholder}
|
|
144
|
+
variant="gray"
|
|
145
|
+
/>
|
|
146
|
+
{isEmpty(filteredOptions) ? (
|
|
147
|
+
<UTLabel colorTheme="gray" style={styles.noMatchesText}>
|
|
148
|
+
{noMatchesText}
|
|
149
|
+
</UTLabel>
|
|
150
|
+
) : (
|
|
151
|
+
<ScrollView keyboardShouldPersistTaps="handled">
|
|
152
|
+
<UTCheckList
|
|
153
|
+
showSelectAll={showSelectAll}
|
|
154
|
+
input={{ value: selectedOptions, onChange: handleSelect }}
|
|
155
|
+
options={filteredOptions}
|
|
156
|
+
isSimple={!isMultiple}
|
|
157
|
+
selectAllLabel={selectAllLabel}
|
|
158
|
+
variant="button"
|
|
159
|
+
/>
|
|
160
|
+
</ScrollView>
|
|
161
|
+
)}
|
|
162
|
+
</View>
|
|
163
|
+
</UTBottomSheet>
|
|
164
|
+
</View>
|
|
165
|
+
);
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
UTSelect.defaultProps = defaultProps;
|
|
169
|
+
UTSelect.propTypes = propTypes;
|
|
170
|
+
|
|
171
|
+
export default UTSelect;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { arrayOf, bool, func, number, oneOfType, shape, string } from 'prop-types';
|
|
2
|
+
import { ViewPropTypes } from 'deprecated-react-native-prop-types';
|
|
3
|
+
|
|
4
|
+
export const defaultProps = {
|
|
5
|
+
alwaysShowPlaceholder: true,
|
|
6
|
+
input: {
|
|
7
|
+
value: [],
|
|
8
|
+
onChange: () => {}
|
|
9
|
+
},
|
|
10
|
+
showSelectAll: false,
|
|
11
|
+
isMultiple: false,
|
|
12
|
+
style: {}
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const propTypes = {
|
|
16
|
+
action: shape({
|
|
17
|
+
Icon: string,
|
|
18
|
+
onPress: func,
|
|
19
|
+
size: string
|
|
20
|
+
}),
|
|
21
|
+
alwaysShowPlaceholder: bool,
|
|
22
|
+
closeButtonText: string,
|
|
23
|
+
helpText: string,
|
|
24
|
+
input: shape({
|
|
25
|
+
value: arrayOf(oneOfType([string, number])),
|
|
26
|
+
onChange: func
|
|
27
|
+
}),
|
|
28
|
+
isMultiple: bool,
|
|
29
|
+
label: string,
|
|
30
|
+
noMatchesText: string,
|
|
31
|
+
options: arrayOf(
|
|
32
|
+
shape({
|
|
33
|
+
label: string,
|
|
34
|
+
value: oneOfType([string, number])
|
|
35
|
+
})
|
|
36
|
+
),
|
|
37
|
+
placeholder: string,
|
|
38
|
+
prefix: string,
|
|
39
|
+
required: bool,
|
|
40
|
+
searchPlaceholder: string,
|
|
41
|
+
selectAllLabel: string,
|
|
42
|
+
showSelectAll: bool,
|
|
43
|
+
style: ViewPropTypes.style,
|
|
44
|
+
suffix: string
|
|
45
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { StyleSheet } from 'react-native';
|
|
2
|
+
|
|
3
|
+
const styles = StyleSheet.create({
|
|
4
|
+
bottomSheetBodyContainer: {
|
|
5
|
+
height: '100%',
|
|
6
|
+
rowGap: 16
|
|
7
|
+
},
|
|
8
|
+
container: {
|
|
9
|
+
rowGap: 8
|
|
10
|
+
},
|
|
11
|
+
noMatchesText: {
|
|
12
|
+
alignSelf: 'center',
|
|
13
|
+
paddingHorizontal: 16,
|
|
14
|
+
paddingVertical: 24
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
export default styles;
|
|
@@ -8,7 +8,7 @@ import React, {
|
|
|
8
8
|
Fragment
|
|
9
9
|
} from 'react';
|
|
10
10
|
import _ from 'lodash';
|
|
11
|
-
import { bool, elementType, func,
|
|
11
|
+
import { bool, elementType, func, number, oneOfType, shape, string } from 'prop-types';
|
|
12
12
|
import { TextInput } from 'react-native';
|
|
13
13
|
import { ViewPropTypes } from 'deprecated-react-native-prop-types';
|
|
14
14
|
|
|
@@ -129,8 +129,8 @@ BaseInput.propTypes = {
|
|
|
129
129
|
onChange: func.isRequired,
|
|
130
130
|
disabled: bool,
|
|
131
131
|
value: string,
|
|
132
|
-
id: string,
|
|
133
|
-
RightIcon:
|
|
132
|
+
id: oneOfType([number, string]),
|
|
133
|
+
RightIcon: oneOfType([shape({ name: string, type: string, color: string }), elementType]),
|
|
134
134
|
hiddenInput: bool,
|
|
135
135
|
onRightIconPress: func,
|
|
136
136
|
placeholder: string,
|
|
@@ -1,39 +1,41 @@
|
|
|
1
1
|
# UTTextInput
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## Description
|
|
4
|
+
|
|
5
|
+
`UTTextInput` is a customizable text input component that supports various customization options such as icons, validation messages, and action buttons.
|
|
4
6
|
|
|
5
7
|
## Props
|
|
6
8
|
|
|
7
|
-
| Name | Type
|
|
8
|
-
| --------------------- |
|
|
9
|
-
| action | object
|
|
10
|
-
| alwaysShowPlaceholder | bool
|
|
11
|
-
| disabled | bool
|
|
12
|
-
| error | string
|
|
13
|
-
| helpText | string
|
|
14
|
-
|
|
|
15
|
-
|
|
|
16
|
-
|
|
|
17
|
-
|
|
|
18
|
-
|
|
|
19
|
-
|
|
|
20
|
-
|
|
|
21
|
-
|
|
|
22
|
-
|
|
|
23
|
-
|
|
|
24
|
-
|
|
|
25
|
-
|
|
|
26
|
-
|
|
|
27
|
-
|
|
|
28
|
-
|
|
|
29
|
-
|
|
|
30
|
-
|
|
|
31
|
-
|
|
|
32
|
-
|
|
|
33
|
-
|
|
|
34
|
-
|
|
|
35
|
-
|
|
|
36
|
-
|
|
|
9
|
+
| Name | Type | Default | Description |
|
|
10
|
+
| --------------------- | ------------------------------------------------------------------------- | --------- | -------------------------------------------------------------------------------------------------------- |
|
|
11
|
+
| action | object | | Action button configuration object. |
|
|
12
|
+
| alwaysShowPlaceholder | bool | false | Whether to always show the placeholder. |
|
|
13
|
+
| disabled | bool | false | Disables the input field. |
|
|
14
|
+
| error | string | | Error message to be displayed. |
|
|
15
|
+
| helpText | string | | Help text to be displayed below the input field. |
|
|
16
|
+
| id | oneOfType([number, string]) | | Unique identifier for the input field. |
|
|
17
|
+
| inputRef | func | | Reference to the input field. |
|
|
18
|
+
| input | shape({ value: string.isRequired, onChange: func.isRequired }).isRequired | | Input object containing the value and onChange handler. |
|
|
19
|
+
| inputSize | string | 'large' | Size of the input field. One of: `small`, `large`. |
|
|
20
|
+
| label | string | | Label text for the input field. |
|
|
21
|
+
| labelVariant | string | 'large' | Variant of the label. |
|
|
22
|
+
| LeftIcon | elementType | | Icon to be displayed on the left side of the input field. |
|
|
23
|
+
| maxCount | number | | Maximum number of characters allowed in the input field. |
|
|
24
|
+
| maxRows | number | 1 | Maximum number of rows allowed in the input field. |
|
|
25
|
+
| onBlur | func | | Function to call when the input field loses focus. |
|
|
26
|
+
| onFocus | func | | Function to call when the input field gains focus. |
|
|
27
|
+
| onSubmitEditing | func | | Function to call when the input field is submitted. |
|
|
28
|
+
| placeholder | string | | Placeholder text for the input field. |
|
|
29
|
+
| prefix | string | | Prefix text to be displayed inside the input field. |
|
|
30
|
+
| readOnly | bool | false | Makes the input field read-only. |
|
|
31
|
+
| required | bool | false | Whether the input field is required. |
|
|
32
|
+
| returnKeyType | string | 'done' | Determines the return key type on the keyboard. |
|
|
33
|
+
| RightIcon | elementType | | Icon to be displayed on the right side of the input field. |
|
|
34
|
+
| style | shape({ container: object, input: object, root: object }) | | Style object to customize the input field. Can contain `root`, `container`, `input`, or `action` styles. |
|
|
35
|
+
| suffix | string | | Suffix text to be displayed inside the input field. |
|
|
36
|
+
| tooltip | string | | Tooltip text to be displayed. |
|
|
37
|
+
| type | string | 'default' | Type of input (e.g., 'text', 'password', 'email'). |
|
|
38
|
+
| validations | array | | Array of validation rules to be applied to the input field. |
|
|
37
39
|
|
|
38
40
|
### action
|
|
39
41
|
|
|
@@ -69,7 +71,7 @@ It must be one of these:
|
|
|
69
71
|
- "password"
|
|
70
72
|
- "numeric"
|
|
71
73
|
|
|
72
|
-
### Methods via `
|
|
74
|
+
### Methods via `inputRef`
|
|
73
75
|
|
|
74
76
|
| Name | Description |
|
|
75
77
|
| -------- | ------------------------------------ |
|
|
@@ -93,8 +95,7 @@ If a RightIcon is provided and an error occurs, the RightIcon will be replaced b
|
|
|
93
95
|
|
|
94
96
|
### Structure of validations
|
|
95
97
|
|
|
96
|
-
The validations prop expects an array of objects, where each object can have a title, status, and an items array. Each item in the items array represents a specific validation rule with a status and text.
|
|
97
|
-
It is no neccesary to indicate status value if it is "default".
|
|
98
|
+
The validations prop expects an array of objects, where each object can have a title, status, and an items array. Each item in the items array represents a specific validation rule with a status and text. It is not necessary to indicate status value if it is "default".
|
|
98
99
|
|
|
99
100
|
#### Example structure:
|
|
100
101
|
|
|
@@ -140,7 +141,7 @@ const validationData = [
|
|
|
140
141
|
Errors can be displayed below the input field using either the `error` prop or the `validations` prop.
|
|
141
142
|
|
|
142
143
|
- **error**: A string that represents a general error message.
|
|
143
|
-
- **validations**: An array of validation rules, where each rule is an object containing a `
|
|
144
|
+
- **validations**: An array of validation rules, where each rule is an object containing a `status` and a `text`.
|
|
144
145
|
|
|
145
146
|
If both `error` and `validations` are provided, `validations` will take precedence, and its messages will be displayed.
|
|
146
147
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { bool, elementType, func, number, shape, string } from 'prop-types';
|
|
2
|
+
import { bool, elementType, func, instanceOf, number, oneOfType, shape, string } from 'prop-types';
|
|
3
3
|
import { ViewPropTypes } from 'deprecated-react-native-prop-types';
|
|
4
4
|
|
|
5
5
|
import UTBaseInputField from '../../../../../UTBaseInputField';
|
|
@@ -8,15 +8,17 @@ import { COMPONENT_KEYS } from '../../../../../UTBaseInputField/constants';
|
|
|
8
8
|
const TextInputField = ({
|
|
9
9
|
action,
|
|
10
10
|
alwaysShowPlaceholder,
|
|
11
|
+
blurOnSubmit,
|
|
11
12
|
disabled,
|
|
12
13
|
error,
|
|
13
|
-
|
|
14
|
+
id,
|
|
15
|
+
input,
|
|
16
|
+
inputRef,
|
|
14
17
|
inputSize,
|
|
15
18
|
LeftIcon,
|
|
16
19
|
maxLength,
|
|
17
20
|
maxRows,
|
|
18
21
|
onBlur,
|
|
19
|
-
onChange,
|
|
20
22
|
onFocus,
|
|
21
23
|
onSubmitEditing,
|
|
22
24
|
placeholder,
|
|
@@ -28,8 +30,7 @@ const TextInputField = ({
|
|
|
28
30
|
style,
|
|
29
31
|
suffix,
|
|
30
32
|
tooltip,
|
|
31
|
-
type
|
|
32
|
-
value
|
|
33
|
+
type
|
|
33
34
|
}) => {
|
|
34
35
|
const leftAdornments = [
|
|
35
36
|
{ name: COMPONENT_KEYS.ICON, props: { Icon: LeftIcon } },
|
|
@@ -46,25 +47,26 @@ const TextInputField = ({
|
|
|
46
47
|
return (
|
|
47
48
|
<UTBaseInputField
|
|
48
49
|
alwaysShowPlaceholder={alwaysShowPlaceholder}
|
|
50
|
+
blurOnSubmit={blurOnSubmit}
|
|
49
51
|
disabled={disabled}
|
|
50
52
|
error={error}
|
|
53
|
+
id={id}
|
|
54
|
+
input={input}
|
|
51
55
|
inputSize={inputSize}
|
|
52
56
|
leftAdornments={leftAdornments}
|
|
53
57
|
maxLength={maxLength}
|
|
54
58
|
maxRows={maxRows}
|
|
55
59
|
onBlur={onBlur}
|
|
56
|
-
onChange={onChange}
|
|
57
60
|
onFocus={onFocus}
|
|
58
61
|
onSubmitEditing={onSubmitEditing}
|
|
59
62
|
placeholder={placeholder}
|
|
60
63
|
readOnly={readOnly}
|
|
61
|
-
ref={
|
|
64
|
+
ref={inputRef}
|
|
62
65
|
returnKeyType={returnKeyType}
|
|
63
66
|
rightAdornments={rightAdornments}
|
|
64
67
|
showCharacterCount={showCharacterCount}
|
|
65
68
|
style={style}
|
|
66
69
|
type={type}
|
|
67
|
-
value={value}
|
|
68
70
|
/>
|
|
69
71
|
);
|
|
70
72
|
};
|
|
@@ -74,15 +76,20 @@ TextInputField.displayName = 'TextInputField';
|
|
|
74
76
|
TextInputField.propTypes = {
|
|
75
77
|
action: shape({ icon: elementType, action: func, colorTheme: string, text: string }),
|
|
76
78
|
alwaysShowPlaceholder: bool,
|
|
79
|
+
blurOnSubmit: bool,
|
|
77
80
|
disabled: bool,
|
|
78
81
|
error: string,
|
|
79
|
-
|
|
82
|
+
id: oneOfType([number, string]),
|
|
83
|
+
input: shape({
|
|
84
|
+
value: string,
|
|
85
|
+
onChange: func
|
|
86
|
+
}),
|
|
87
|
+
inputRef: oneOfType([func, instanceOf(Object)]),
|
|
80
88
|
inputSize: string,
|
|
81
89
|
LeftIcon: elementType,
|
|
82
90
|
maxLength: number,
|
|
83
91
|
maxRows: number,
|
|
84
92
|
onBlur: func,
|
|
85
|
-
onChange: func,
|
|
86
93
|
onFocus: func,
|
|
87
94
|
onSubmitEditing: func,
|
|
88
95
|
placeholder: string,
|
|
@@ -98,8 +105,7 @@ TextInputField.propTypes = {
|
|
|
98
105
|
}),
|
|
99
106
|
suffix: string,
|
|
100
107
|
tooltip: string,
|
|
101
|
-
type: string
|
|
102
|
-
value: string
|
|
108
|
+
type: string
|
|
103
109
|
};
|
|
104
110
|
|
|
105
111
|
export default TextInputField;
|
|
@@ -1,23 +1,26 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
2
|
import { View } from 'react-native';
|
|
3
3
|
|
|
4
4
|
import { formatErrorToValidation } from '../../../UTValidation/utils';
|
|
5
|
-
import UTLabel from '../../../UTLabel';
|
|
6
5
|
import UTFieldLabel from '../../../UTFieldLabel';
|
|
6
|
+
import UTLabel from '../../../UTLabel';
|
|
7
7
|
import UTValidation from '../../../UTValidation';
|
|
8
8
|
|
|
9
|
-
import {
|
|
10
|
-
import
|
|
9
|
+
import { defaultProps, propTypes } from './proptypes';
|
|
10
|
+
import { SIZES } from './constants';
|
|
11
11
|
import styles from './styles';
|
|
12
12
|
import TextInputField from './components/TextInputField';
|
|
13
13
|
|
|
14
14
|
const UTTextInput = ({
|
|
15
15
|
action,
|
|
16
16
|
alwaysShowPlaceholder,
|
|
17
|
+
blurOnSubmit,
|
|
17
18
|
disabled,
|
|
18
19
|
error,
|
|
19
20
|
helpText,
|
|
20
|
-
|
|
21
|
+
id,
|
|
22
|
+
input,
|
|
23
|
+
inputRef,
|
|
21
24
|
inputSize,
|
|
22
25
|
label,
|
|
23
26
|
labelVariant,
|
|
@@ -25,7 +28,6 @@ const UTTextInput = ({
|
|
|
25
28
|
maxLength,
|
|
26
29
|
maxRows,
|
|
27
30
|
onBlur,
|
|
28
|
-
onChange,
|
|
29
31
|
onFocus,
|
|
30
32
|
onSubmitEditing,
|
|
31
33
|
placeholder,
|
|
@@ -39,12 +41,15 @@ const UTTextInput = ({
|
|
|
39
41
|
suffix,
|
|
40
42
|
tooltip,
|
|
41
43
|
type,
|
|
42
|
-
validations
|
|
43
|
-
value
|
|
44
|
+
validations
|
|
44
45
|
}) => {
|
|
45
46
|
const labelColorTheme = readOnly ? 'gray' : 'dark';
|
|
46
|
-
const labelComponentVariant = labelVariant === SMALL ? 'small' : 'body';
|
|
47
|
-
|
|
47
|
+
const labelComponentVariant = labelVariant === SIZES.SMALL ? 'small' : 'body';
|
|
48
|
+
|
|
49
|
+
const validationData = useMemo(
|
|
50
|
+
() => validations || (error && formatErrorToValidation(error)),
|
|
51
|
+
[error, validations]
|
|
52
|
+
);
|
|
48
53
|
|
|
49
54
|
return (
|
|
50
55
|
<View style={[styles.container, style.root]}>
|
|
@@ -56,15 +61,17 @@ const UTTextInput = ({
|
|
|
56
61
|
<TextInputField
|
|
57
62
|
action={action}
|
|
58
63
|
alwaysShowPlaceholder={alwaysShowPlaceholder}
|
|
64
|
+
blurOnSubmit={blurOnSubmit}
|
|
59
65
|
disabled={disabled}
|
|
60
66
|
error={error}
|
|
61
|
-
|
|
67
|
+
id={id}
|
|
68
|
+
input={input}
|
|
69
|
+
inputRef={inputRef}
|
|
62
70
|
inputSize={inputSize}
|
|
63
71
|
LeftIcon={LeftIcon}
|
|
64
72
|
maxLength={maxLength}
|
|
65
73
|
maxRows={maxRows}
|
|
66
74
|
onBlur={onBlur}
|
|
67
|
-
onChange={onChange}
|
|
68
75
|
onFocus={onFocus}
|
|
69
76
|
onSubmitEditing={onSubmitEditing}
|
|
70
77
|
placeholder={placeholder}
|
|
@@ -77,7 +84,6 @@ const UTTextInput = ({
|
|
|
77
84
|
suffix={suffix}
|
|
78
85
|
tooltip={tooltip}
|
|
79
86
|
type={type}
|
|
80
|
-
value={value}
|
|
81
87
|
/>
|
|
82
88
|
{helpText && (
|
|
83
89
|
<UTLabel colorTheme="gray" variant="small">
|
|
@@ -89,10 +95,7 @@ const UTTextInput = ({
|
|
|
89
95
|
);
|
|
90
96
|
};
|
|
91
97
|
|
|
92
|
-
UTTextInput.defaultProps =
|
|
93
|
-
|
|
94
|
-
UTTextInput.propTypes = {
|
|
95
|
-
...propTypes
|
|
96
|
-
};
|
|
98
|
+
UTTextInput.defaultProps = defaultProps;
|
|
99
|
+
UTTextInput.propTypes = propTypes;
|
|
97
100
|
|
|
98
101
|
export default UTTextInput;
|
|
@@ -1,15 +1,34 @@
|
|
|
1
|
-
import { bool, elementType, func, number, shape, string } from 'prop-types';
|
|
1
|
+
import { bool, elementType, func, instanceOf, number, oneOfType, shape, string } from 'prop-types';
|
|
2
2
|
import { ViewPropTypes } from 'deprecated-react-native-prop-types';
|
|
3
3
|
|
|
4
4
|
import { validationDataProptypes } from '../../../UTValidation/constants';
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
import { SIZES } from './constants';
|
|
7
|
+
|
|
8
|
+
export const defaultProps = {
|
|
9
|
+
input: {
|
|
10
|
+
value: [],
|
|
11
|
+
onChange: () => {}
|
|
12
|
+
},
|
|
13
|
+
inputSize: SIZES.LARGE,
|
|
14
|
+
labelVariant: SIZES.LARGE,
|
|
15
|
+
maxRows: 1,
|
|
16
|
+
style: {}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const propTypes = {
|
|
7
20
|
action: shape({ icon: elementType, action: func, colorTheme: string, text: string }),
|
|
8
21
|
alwaysShowPlaceholder: bool,
|
|
22
|
+
blurOnSubmit: bool,
|
|
9
23
|
disabled: bool,
|
|
10
24
|
error: string,
|
|
11
25
|
helpText: string,
|
|
12
|
-
|
|
26
|
+
id: oneOfType([number, string]),
|
|
27
|
+
input: shape({
|
|
28
|
+
value: string,
|
|
29
|
+
onChange: func
|
|
30
|
+
}),
|
|
31
|
+
inputRef: oneOfType([func, instanceOf(Object)]),
|
|
13
32
|
inputSize: string,
|
|
14
33
|
label: string,
|
|
15
34
|
labelVariant: string,
|
|
@@ -17,7 +36,6 @@ export default {
|
|
|
17
36
|
maxLength: number,
|
|
18
37
|
maxRows: number,
|
|
19
38
|
onBlur: func,
|
|
20
|
-
onChange: func,
|
|
21
39
|
onFocus: func,
|
|
22
40
|
onSubmitEditing: func,
|
|
23
41
|
placeholder: string,
|
|
@@ -35,6 +53,5 @@ export default {
|
|
|
35
53
|
suffix: string,
|
|
36
54
|
tooltip: string,
|
|
37
55
|
type: string,
|
|
38
|
-
validations: validationDataProptypes
|
|
39
|
-
value: string
|
|
56
|
+
validations: validationDataProptypes
|
|
40
57
|
};
|