@widergy/mobile-ui 1.15.0 → 1.16.0
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 +14 -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/UTIcon/README.md +46 -7
- package/lib/components/UTIcon/components/EnergyIcons/EnergyIconCar.svg +17 -0
- package/lib/components/UTIcon/components/EnergyIcons/EnergyIconCart.svg +6 -0
- package/lib/components/UTIcon/components/EnergyIcons/EnergyIconHome.svg +5 -0
- package/lib/components/UTIcon/components/EnergyIcons/EnergyIconTruck.svg +7 -0
- package/lib/components/UTIcon/constants.js +14 -0
- package/lib/components/UTIcon/index.js +19 -8
- package/lib/components/UTIcon/utils.js +34 -0
- 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,103 @@
|
|
|
1
|
+
import React, { useState, useMemo } from 'react';
|
|
2
|
+
import { isEmpty } from '@widergy/web-utils/lib/array';
|
|
3
|
+
import { View } from 'react-native';
|
|
4
|
+
|
|
5
|
+
import Label from '../../../Label';
|
|
6
|
+
import UTMenu from '../../../UTMenu';
|
|
7
|
+
import UTTextInput from '../../../UTTextInput';
|
|
8
|
+
|
|
9
|
+
import MultipleItem from './componentes/MultipleItem';
|
|
10
|
+
import styles from './styles';
|
|
11
|
+
import UTSelectTypes from './proptypes';
|
|
12
|
+
|
|
13
|
+
const UTSelect = ({
|
|
14
|
+
options = [],
|
|
15
|
+
value,
|
|
16
|
+
onChange,
|
|
17
|
+
error,
|
|
18
|
+
UTMenuProps,
|
|
19
|
+
label,
|
|
20
|
+
styles: propStyles,
|
|
21
|
+
variant,
|
|
22
|
+
disabled,
|
|
23
|
+
UTTextInputProps,
|
|
24
|
+
isMultiple,
|
|
25
|
+
verticalOffset = 5,
|
|
26
|
+
title,
|
|
27
|
+
titleProps,
|
|
28
|
+
changeOnClose
|
|
29
|
+
}) => {
|
|
30
|
+
const [focused, setFocused] = useState(false);
|
|
31
|
+
|
|
32
|
+
const selectedOption = useMemo(
|
|
33
|
+
() => (!isMultiple ? options.find(option => option.value === value) : value || []),
|
|
34
|
+
[isMultiple, options, value]
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
const handleChange = option => {
|
|
38
|
+
if (!changeOnClose) onChange(option.value);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const handleChangeMultiple = newValue => {
|
|
42
|
+
const newValues = !selectedOption?.find?.(elem => elem === newValue.value)
|
|
43
|
+
? [...(selectedOption || []), newValue.value]
|
|
44
|
+
: selectedOption?.filter(elem => elem !== newValue.value);
|
|
45
|
+
|
|
46
|
+
const finalValue = isEmpty(newValues) ? null : newValues;
|
|
47
|
+
if (!changeOnClose) {
|
|
48
|
+
onChange(finalValue);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const handleOpen = () => setFocused(true);
|
|
53
|
+
// eslint-disable-next-line consistent-return
|
|
54
|
+
const handleClose = () => {
|
|
55
|
+
setFocused(false);
|
|
56
|
+
if (changeOnClose) {
|
|
57
|
+
return isMultiple
|
|
58
|
+
? onChange(selectedOption)
|
|
59
|
+
: onChange(options.find(_option => _option.id === selectedOption.id).value);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
<View style={[styles.container, propStyles]}>
|
|
65
|
+
{title && (
|
|
66
|
+
<Label medium primary {...titleProps}>
|
|
67
|
+
{title}
|
|
68
|
+
</Label>
|
|
69
|
+
)}
|
|
70
|
+
<UTMenu
|
|
71
|
+
options={options}
|
|
72
|
+
selectedOption={isMultiple ? selectedOption : selectedOption?.id}
|
|
73
|
+
fullWidth
|
|
74
|
+
verticalOffset={verticalOffset}
|
|
75
|
+
disabled={disabled}
|
|
76
|
+
onPress={isMultiple ? handleChangeMultiple : handleChange}
|
|
77
|
+
onOpen={handleOpen}
|
|
78
|
+
onClose={handleClose}
|
|
79
|
+
withoutOpacity
|
|
80
|
+
MenuOptionComponent={isMultiple && MultipleItem}
|
|
81
|
+
isMultiple={isMultiple}
|
|
82
|
+
{...UTMenuProps}
|
|
83
|
+
>
|
|
84
|
+
<UTTextInput
|
|
85
|
+
variant={variant}
|
|
86
|
+
value={isMultiple ? value?.join(', ') || '' : selectedOption?.label || selectedOption?.value || ''}
|
|
87
|
+
error={error}
|
|
88
|
+
label={label}
|
|
89
|
+
select
|
|
90
|
+
controlledFocus={focused}
|
|
91
|
+
disabled={disabled}
|
|
92
|
+
version="V0"
|
|
93
|
+
RightIcon={{ type: 'font-awesome', name: 'caret-down' }}
|
|
94
|
+
{...UTTextInputProps}
|
|
95
|
+
/>
|
|
96
|
+
</UTMenu>
|
|
97
|
+
</View>
|
|
98
|
+
);
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
UTSelect.propTypes = UTSelectTypes;
|
|
102
|
+
|
|
103
|
+
export default UTSelect;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# UTSelect
|
|
2
|
+
|
|
3
|
+
## Description
|
|
4
|
+
|
|
5
|
+
`UTSelect` is a customizable dropdown select component that allows users to select single or multiple options from a provided list. It includes features like search, select all, and dynamic option filtering.
|
|
6
|
+
|
|
7
|
+
## Props
|
|
8
|
+
|
|
9
|
+
| Name | Type | Default | Description |
|
|
10
|
+
| --------------------- | ------ | ------- | ---------------------------------------------------------------------------------------------------- |
|
|
11
|
+
| action | shape | | Action object containing `Icon`, `onPress`, and `size` for the action button. |
|
|
12
|
+
| alwaysShowPlaceholder | bool | true | Determines if the placeholder should always be shown. |
|
|
13
|
+
| helpText | string | | Help text displayed below the input field. |
|
|
14
|
+
| noMatchesText | string | | Text to display when no matches are found in the search. |
|
|
15
|
+
| input | shape | | Input configuration object containing `value` and `onChange`. |
|
|
16
|
+
| isMultiple | bool | false | Allows multiple selection if true. |
|
|
17
|
+
| label | string | | Label for the select field. |
|
|
18
|
+
| options | array | | Array of options to be displayed in the dropdown. Each option is an object with `label` and `value`. |
|
|
19
|
+
| placeholder | string | | Placeholder text for the select field. |
|
|
20
|
+
| prefix | string | | Text to display as a prefix inside the input field. |
|
|
21
|
+
| required | bool | false | Indicates if the select field is required. |
|
|
22
|
+
| searchPlaceholder | string | | Placeholder text for the search field. |
|
|
23
|
+
| selectAllLabel | string | | Label for the "Select All" checkbox. |
|
|
24
|
+
| showSelectAll | bool | false | Determines whether to show the "Select All" checkbox. |
|
|
25
|
+
| style | shape | {} | Custom styles to apply to the select field. Can contain `root`, `noMatchesText`, `scrollview`. |
|
|
26
|
+
| suffix | string | | Text to display as a suffix inside the input field. |
|
|
27
|
+
|
|
28
|
+
### Input Object
|
|
29
|
+
|
|
30
|
+
The `input` prop is an object that should contain the following keys:
|
|
31
|
+
|
|
32
|
+
| Name | Type | Description |
|
|
33
|
+
| -------- | ----------------------- | -------------------------------------------- |
|
|
34
|
+
| value | arrayOf(string, number) | Array of selected values. |
|
|
35
|
+
| onChange | func | Function to call when the selection changes. |
|
|
36
|
+
|
|
37
|
+
### Option Object
|
|
38
|
+
|
|
39
|
+
The `options` prop is an array of objects, each representing an option:
|
|
40
|
+
|
|
41
|
+
| Name | Type | Description |
|
|
42
|
+
| ----- | -------------- | -------------------------------- |
|
|
43
|
+
| label | string | Label to display for the option. |
|
|
44
|
+
| value | string, number | Value of the option. |
|
|
45
|
+
|
|
46
|
+
## Usage
|
|
47
|
+
|
|
48
|
+
```jsx
|
|
49
|
+
import React, { useState } from 'react';
|
|
50
|
+
import { View, Text } from 'react-native';
|
|
51
|
+
import UTSelect from './UTSelect';
|
|
52
|
+
|
|
53
|
+
const options = [
|
|
54
|
+
{ label: 'Option 1', value: '1' },
|
|
55
|
+
{ label: 'Option 2', value: '2' },
|
|
56
|
+
{ label: 'Option 3', value: '3' }
|
|
57
|
+
];
|
|
58
|
+
|
|
59
|
+
const UTSelectExample = () => {
|
|
60
|
+
const [selectedOptions, setSelectedOptions] = useState([]);
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<View style={{ padding: 20 }}>
|
|
64
|
+
<UTSelect
|
|
65
|
+
label="Select Options"
|
|
66
|
+
options={options}
|
|
67
|
+
input={{
|
|
68
|
+
value: selectedOptions,
|
|
69
|
+
onChange: setSelectedOptions
|
|
70
|
+
}}
|
|
71
|
+
placeholder="Select an option"
|
|
72
|
+
searchPlaceholder="Search options"
|
|
73
|
+
selectAllLabel="Select All"
|
|
74
|
+
noMatchesText="No matches found"
|
|
75
|
+
/>
|
|
76
|
+
<Text>Selected Options: {selectedOptions.join(', ')}</Text>
|
|
77
|
+
</View>
|
|
78
|
+
);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export default UTSelectExample;
|
|
82
|
+
```
|
|
@@ -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;
|