@widergy/mobile-ui 1.13.5 → 1.14.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 +14 -0
- package/lib/components/Surface/propTypes.js +3 -2
- package/lib/components/UTBaseInputField/README.md +179 -0
- package/lib/components/UTBaseInputField/components/ActionAdornment/index.js +41 -0
- package/lib/components/UTBaseInputField/components/IconAdornment/constants.js +1 -0
- package/lib/components/UTBaseInputField/components/IconAdornment/index.js +32 -0
- package/lib/components/UTBaseInputField/components/IconAdornment/utils.js +2 -0
- package/lib/components/UTBaseInputField/components/PrefixAdornment/index.js +16 -0
- package/lib/components/UTBaseInputField/components/SuffixAdornment/index.js +12 -0
- package/lib/components/UTBaseInputField/components/TooltipAdornment/index.js +19 -0
- package/lib/components/UTBaseInputField/constants.js +34 -0
- package/lib/components/UTBaseInputField/index.js +191 -0
- package/lib/components/{UTTextInput/versions/V1/components/TextInputField → UTBaseInputField}/theme.js +3 -2
- package/lib/components/UTButton/README.md +1 -1
- package/lib/components/UTButton/index.js +8 -2
- package/lib/components/UTCheckBox/README.md +15 -17
- package/lib/components/UTCheckBox/constants.js +2 -0
- package/lib/components/UTCheckBox/index.js +50 -24
- package/lib/components/UTCheckBox/proptypes.js +7 -10
- package/lib/components/UTCheckBox/theme.js +26 -15
- package/lib/components/UTCheckList/constants.js +1 -0
- package/lib/components/UTCheckList/index.js +43 -46
- package/lib/components/UTCheckList/styles.js +8 -11
- package/lib/components/UTCheckList/utils.js +5 -0
- package/lib/components/{UTRequiredLabel → UTFieldLabel}/index.js +3 -3
- package/lib/components/UTIcon/README.md +10 -10
- package/lib/components/UTIcon/index.js +6 -8
- package/lib/components/UTIcon/theme.js +1 -5
- package/lib/components/UTRoundView/index.js +22 -9
- package/lib/components/UTRoundView/propTypes.js +4 -2
- package/lib/components/UTRoundView/styles.js +8 -0
- package/lib/components/UTRoundView/utils.js +14 -0
- package/lib/components/UTSelect/index.js +5 -4
- package/lib/components/UTTextArea/constants.js +3 -1
- package/lib/components/UTTextArea/index.js +4 -4
- package/lib/components/UTTextInput/versions/V0/components/BaseInput/index.js +1 -1
- package/lib/components/UTTextInput/versions/V1/README.md +6 -15
- package/lib/components/UTTextInput/versions/V1/components/TextInputField/index.js +67 -201
- package/lib/components/UTTextInput/versions/V1/constants.js +1 -1
- package/lib/components/UTTextInput/versions/V1/index.js +5 -5
- package/lib/components/UTValidation/README.md +9 -6
- package/lib/components/UTValidation/index.js +8 -6
- package/lib/components/UTValidation/utils.js +4 -0
- package/package.json +4 -3
- package/lib/components/UTTextInput/versions/V1/components/TextInputField/constants.js +0 -12
- package/lib/components/UTTextInput/versions/V1/components/TextInputField/utils.js +0 -13
- package/lib/components/UTTextInput/versions/V1/utils.js +0 -1
- /package/lib/components/{UTRequiredLabel → UTFieldLabel}/constants.js +0 -0
- /package/lib/components/{UTRequiredLabel → UTFieldLabel}/styles.js +0 -0
- /package/lib/components/{UTButton → UTIcon}/utils.js +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## [1.14.1](https://github.com/widergy/mobile-ui/compare/v1.14.0...v1.14.1) (2024-07-19)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* components fixes and utbaseinputfield ([#314](https://github.com/widergy/mobile-ui/issues/314)) ([02378b1](https://github.com/widergy/mobile-ui/commit/02378b1e71edecb4f6dddcad2872d65dab95fe31))
|
|
7
|
+
|
|
8
|
+
# [1.14.0](https://github.com/widergy/mobile-ui/compare/v1.13.5...v1.14.0) (2024-07-17)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* add background gradient to UTRoundView ([#301](https://github.com/widergy/mobile-ui/issues/301)) ([b56dc81](https://github.com/widergy/mobile-ui/commit/b56dc81bfec89696048e7e7bf8e5458c08300203))
|
|
14
|
+
|
|
1
15
|
## [1.13.5](https://github.com/widergy/mobile-ui/compare/v1.13.4...v1.13.5) (2024-07-17)
|
|
2
16
|
|
|
3
17
|
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { ViewPropTypes } from 'deprecated-react-native-prop-types';
|
|
2
|
-
import { number } from 'prop-types';
|
|
2
|
+
import { number, string } from 'prop-types';
|
|
3
3
|
|
|
4
4
|
export default {
|
|
5
|
-
elevation: number
|
|
5
|
+
elevation: number,
|
|
6
|
+
position: string,
|
|
6
7
|
style: ViewPropTypes.style
|
|
7
8
|
};
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
# UTBaseInputField
|
|
2
|
+
|
|
3
|
+
## Description
|
|
4
|
+
|
|
5
|
+
`UTBaseInputField` is a flexible and customizable input field component that supports various input types, adornments, and styles. It can be used to create text inputs with additional functionality such as icons, prefixes, suffixes, and action buttons.
|
|
6
|
+
|
|
7
|
+
## Props
|
|
8
|
+
|
|
9
|
+
| Name | Type | Default | Description |
|
|
10
|
+
| --------------------- | ------ | ------- | --------------------------------------------------------- |
|
|
11
|
+
| alwaysShowPlaceholder | bool | | Whether to always show the placeholder text. |
|
|
12
|
+
| disabled | bool | | Whether the input field is disabled. |
|
|
13
|
+
| error | string | | Error message to display. |
|
|
14
|
+
| inputSize | string | | Size of the input field. |
|
|
15
|
+
| leftAdornments | array | | Elements to display on the left side of the input field. |
|
|
16
|
+
| maxCount | number | | Maximum number of characters allowed. |
|
|
17
|
+
| maxRows | number | | Maximum number of rows for multiline input. |
|
|
18
|
+
| onBlur | func | | Callback function to handle blur event. |
|
|
19
|
+
| onChange | func | | Callback function to handle change event. |
|
|
20
|
+
| onFocus | func | | Callback function to handle focus event. |
|
|
21
|
+
| onSubmitEditing | func | | Callback function to handle submit editing event. |
|
|
22
|
+
| placeholder | string | | Placeholder text for the input field. |
|
|
23
|
+
| readOnly | bool | | Whether the input field is read-only. |
|
|
24
|
+
| returnKeyType | string | | Type of return key to display on the keyboard. |
|
|
25
|
+
| rightAdornments | array | | Elements to display on the right side of the input field. |
|
|
26
|
+
| style | object | | Custom styles to apply to the component. |
|
|
27
|
+
| type | string | | Type of the input field (e.g., email, numeric, password). |
|
|
28
|
+
| value | string | | Value of the input field. |
|
|
29
|
+
|
|
30
|
+
## Input Types
|
|
31
|
+
|
|
32
|
+
The `type` prop can be one of these values:
|
|
33
|
+
|
|
34
|
+
- `email`
|
|
35
|
+
- `numeric`
|
|
36
|
+
- `password`
|
|
37
|
+
|
|
38
|
+
## Adornments
|
|
39
|
+
|
|
40
|
+
The `leftAdornments` and `rightAdornments` props are arrays of objects representing elements to be displayed on the left and right sides of the input field, respectively. Each object must have a `name` and `props` to be passed to the component.
|
|
41
|
+
|
|
42
|
+
### Example
|
|
43
|
+
|
|
44
|
+
```javascript
|
|
45
|
+
const leftAdornments = [
|
|
46
|
+
{
|
|
47
|
+
name: 'Prefix',
|
|
48
|
+
props: { text: 'Prefix Text' }
|
|
49
|
+
}
|
|
50
|
+
];
|
|
51
|
+
|
|
52
|
+
const rightAdornments = [
|
|
53
|
+
{
|
|
54
|
+
name: 'Suffix',
|
|
55
|
+
props: { text: 'Suffix Text' }
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
name: 'Icon',
|
|
59
|
+
props: { Icon: 'IconName', changeOnError: true }
|
|
60
|
+
}
|
|
61
|
+
];
|
|
62
|
+
|
|
63
|
+
const inputProps = {
|
|
64
|
+
leftAdornments,
|
|
65
|
+
placeholder: 'Enter text',
|
|
66
|
+
rightAdornments
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
<UTBaseInputField {...inputProps} />;
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Adornment Components
|
|
73
|
+
|
|
74
|
+
`UTBaseInputField` supports several adornments that can be placed on the left or right side of the input field. These adornments enhance the input field with additional functionality and visual elements. Below are the details of each adornment, including the props they expect.
|
|
75
|
+
|
|
76
|
+
#### PrefixAdornment
|
|
77
|
+
|
|
78
|
+
Displays a prefix text before the input field.
|
|
79
|
+
|
|
80
|
+
- **Props passed to PrefixAdornment:**
|
|
81
|
+
- `text` (string): The text to display as a prefix.
|
|
82
|
+
|
|
83
|
+
**Example Usage:**
|
|
84
|
+
|
|
85
|
+
```javascript
|
|
86
|
+
<UTBaseInputField leftAdornments={[{ name: 'Prefix', props: { text: 'https://' } }]} />
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
#### SuffixAdornment
|
|
90
|
+
|
|
91
|
+
Displays a suffix text after the input field.
|
|
92
|
+
|
|
93
|
+
- **Props passed to PrefixAdornment:**
|
|
94
|
+
- `text` (string): The text to display as a suffix.
|
|
95
|
+
|
|
96
|
+
**Example Usage:**
|
|
97
|
+
|
|
98
|
+
```javascript
|
|
99
|
+
<UTBaseInputField rightAdornments={[{ name: 'Suffix', props: { text: '.com' } }]} />
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
#### IconAdornment
|
|
103
|
+
|
|
104
|
+
Displays an icon, with an optional change on error.
|
|
105
|
+
|
|
106
|
+
- **Props passed to IconAdornment:**
|
|
107
|
+
- `Icon` (elementType): The icon to display.
|
|
108
|
+
- `error` (string): The error message (received from UTBaseInputField if an error occurs).
|
|
109
|
+
- `inputStyle` (object): The style of the input field (received from UTBaseInputField).
|
|
110
|
+
- `changeOnError` (bool): Whether to change the icon on error (default is false).
|
|
111
|
+
|
|
112
|
+
**Example Usage:**
|
|
113
|
+
|
|
114
|
+
```javascript
|
|
115
|
+
<UTBaseInputField rightAdornments={[{ name: 'Icon', props: { Icon: 'search', changeOnError: true } }]} />
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
#### ActionAdornment
|
|
119
|
+
|
|
120
|
+
Displays an action button.
|
|
121
|
+
|
|
122
|
+
- **Props passed to ActionAdornment:**
|
|
123
|
+
- `action` (object): The action object containing:
|
|
124
|
+
- `colorTheme` (string): The color theme of the button.
|
|
125
|
+
- `icon` (func): The icon to display in the button.
|
|
126
|
+
- `onPress` (func): The function to call when the button is pressed.
|
|
127
|
+
- `text` (string): The text to display in the button.
|
|
128
|
+
- `disabled` (bool): Whether the action button is disabled (received from `UTBaseInputField`).
|
|
129
|
+
- `actionStyle` (object): The style of the action button (received from `UTBaseInputField`).
|
|
130
|
+
|
|
131
|
+
**Example Usage:**
|
|
132
|
+
|
|
133
|
+
```javascript
|
|
134
|
+
<UTBaseInputField
|
|
135
|
+
rightAdornments={[{ name: 'Action', props: { action: { text: 'Go', onPress: handlePress } } }]}
|
|
136
|
+
/>
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
#### TooltipAdornment
|
|
140
|
+
|
|
141
|
+
Displays a tooltip with an icon.
|
|
142
|
+
|
|
143
|
+
- **Props passed to TooltipAdornment:**
|
|
144
|
+
- `tooltip` (string): The text to display in the tooltip.
|
|
145
|
+
|
|
146
|
+
**Example Usage:**
|
|
147
|
+
|
|
148
|
+
```javascript
|
|
149
|
+
<UTBaseInputField rightAdornments={[{ name: 'Tooltip', props: { tooltip: 'Tooltip Text' } }]} />
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### Example Usages:
|
|
153
|
+
|
|
154
|
+
```javascript
|
|
155
|
+
// Example of PrefixAdornment usage
|
|
156
|
+
<UTBaseInputField
|
|
157
|
+
leftAdornments={[{ name: 'Prefix', props: { text: 'Prefix Text' } }]}
|
|
158
|
+
/>
|
|
159
|
+
|
|
160
|
+
// Example of SuffixAdornment usage
|
|
161
|
+
<UTBaseInputField
|
|
162
|
+
rightAdornments={[{ name: 'Suffix', props: { text: 'Suffix Text' } }]}
|
|
163
|
+
/>
|
|
164
|
+
|
|
165
|
+
// Example of IconAdornment usage
|
|
166
|
+
<UTBaseInputField
|
|
167
|
+
rightAdornments={[{ name: 'Icon', props: { Icon: 'IconActivity', changeOnError: true } }]}
|
|
168
|
+
/>
|
|
169
|
+
|
|
170
|
+
// Example of ActionAdornment usage
|
|
171
|
+
<UTBaseInputField
|
|
172
|
+
rightAdornments={[{ name: 'Action', props: { action: { text: 'Go', onPress: handlePress } } }]}
|
|
173
|
+
/>
|
|
174
|
+
|
|
175
|
+
// Example of TooltipAdornment usage
|
|
176
|
+
<UTBaseInputField
|
|
177
|
+
rightAdornments={[{ name: 'Tooltip', props: { tooltip: 'Tooltip Text' } }]}
|
|
178
|
+
/>
|
|
179
|
+
```
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { string, bool, shape, func } from 'prop-types';
|
|
3
|
+
import { ViewPropTypes } from 'deprecated-react-native-prop-types';
|
|
4
|
+
|
|
5
|
+
import UTButton from '../../../UTButton';
|
|
6
|
+
|
|
7
|
+
const ActionAdornment = ({ action, disabled, actionStyle }) => {
|
|
8
|
+
if (!action) return null;
|
|
9
|
+
|
|
10
|
+
return (
|
|
11
|
+
<UTButton
|
|
12
|
+
colorTheme={action.colorTheme}
|
|
13
|
+
disabled={disabled}
|
|
14
|
+
Icon={action.icon}
|
|
15
|
+
onPress={action.onPress}
|
|
16
|
+
style={actionStyle}
|
|
17
|
+
variant="text"
|
|
18
|
+
>
|
|
19
|
+
{action.text}
|
|
20
|
+
</UTButton>
|
|
21
|
+
);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
ActionAdornment.propTypes = {
|
|
25
|
+
action: shape({
|
|
26
|
+
colorTheme: string,
|
|
27
|
+
icon: func,
|
|
28
|
+
onPress: func,
|
|
29
|
+
text: string
|
|
30
|
+
}),
|
|
31
|
+
actionStyle: ViewPropTypes.style,
|
|
32
|
+
disabled: bool
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
ActionAdornment.defaultProps = {
|
|
36
|
+
action: null,
|
|
37
|
+
actionStyle: {},
|
|
38
|
+
disabled: false
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export default ActionAdornment;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const ERROR_ICON = 'IconInfoCircle';
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { shape, string, elementType, bool } from 'prop-types';
|
|
3
|
+
import { TextPropTypes } from 'deprecated-react-native-prop-types';
|
|
4
|
+
|
|
5
|
+
import { isUTIcon } from '../../../UTIcon/utils';
|
|
6
|
+
import UTIcon from '../../../UTIcon';
|
|
7
|
+
|
|
8
|
+
import { ERROR_ICON } from './constants';
|
|
9
|
+
import { getIconColorProps } from './utils';
|
|
10
|
+
|
|
11
|
+
const IconAdornment = ({ Icon, error, inputStyle, changeOnError = false }) => {
|
|
12
|
+
const IconToRender = error && changeOnError ? ERROR_ICON : Icon;
|
|
13
|
+
|
|
14
|
+
if (!IconToRender) return null;
|
|
15
|
+
|
|
16
|
+
return isUTIcon(IconToRender) ? (
|
|
17
|
+
<UTIcon name={IconToRender} {...getIconColorProps(error, changeOnError)} />
|
|
18
|
+
) : (
|
|
19
|
+
<IconToRender fill={inputStyle.root.color} />
|
|
20
|
+
);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
IconAdornment.propTypes = {
|
|
24
|
+
error: string,
|
|
25
|
+
Icon: elementType,
|
|
26
|
+
inputStyle: shape({
|
|
27
|
+
root: TextPropTypes.style
|
|
28
|
+
}),
|
|
29
|
+
changeOnError: bool
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export default IconAdornment;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { string } from 'prop-types';
|
|
3
|
+
|
|
4
|
+
import UTLabel from '../../../UTLabel';
|
|
5
|
+
|
|
6
|
+
const PrefixAdornment = ({ text }) => (
|
|
7
|
+
<UTLabel colorTheme="gray" variant="small" weight="medium">
|
|
8
|
+
{text}
|
|
9
|
+
</UTLabel>
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
PrefixAdornment.propTypes = {
|
|
13
|
+
text: string
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export default PrefixAdornment;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { string } from 'prop-types';
|
|
3
|
+
|
|
4
|
+
import UTLabel from '../../../UTLabel';
|
|
5
|
+
|
|
6
|
+
const SuffixAdornment = ({ text }) => <UTLabel colorTheme="gray">{text}</UTLabel>;
|
|
7
|
+
|
|
8
|
+
SuffixAdornment.propTypes = {
|
|
9
|
+
text: string
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export default SuffixAdornment;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { string } from 'prop-types';
|
|
3
|
+
|
|
4
|
+
import UTTooltip from '../../../UTTooltip';
|
|
5
|
+
import UTIcon from '../../../UTIcon';
|
|
6
|
+
import UTLabel from '../../../UTLabel';
|
|
7
|
+
|
|
8
|
+
const TooltipAdornment = ({ tooltip }) =>
|
|
9
|
+
tooltip ? (
|
|
10
|
+
<UTTooltip content={<UTLabel>{tooltip}</UTLabel>}>
|
|
11
|
+
<UTIcon name="IconInfoCircle" colorTheme="gray" />
|
|
12
|
+
</UTTooltip>
|
|
13
|
+
) : undefined;
|
|
14
|
+
|
|
15
|
+
TooltipAdornment.propTypes = {
|
|
16
|
+
tooltip: string
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export default TooltipAdornment;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import ActionAdornment from './components/ActionAdornment';
|
|
2
|
+
import IconAdornment from './components/IconAdornment';
|
|
3
|
+
import PrefixAdornment from './components/PrefixAdornment';
|
|
4
|
+
import SuffixAdornment from './components/SuffixAdornment';
|
|
5
|
+
import TooltipAdornment from './components/TooltipAdornment';
|
|
6
|
+
|
|
7
|
+
export const TYPES = {
|
|
8
|
+
EMAIL: 'email',
|
|
9
|
+
NUMERIC: 'numeric',
|
|
10
|
+
PASSWORD: 'password'
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const KEYBOARD_BY_TYPE = {
|
|
14
|
+
[TYPES.EMAIL]: 'email-address',
|
|
15
|
+
[TYPES.NUMERIC]: 'numeric'
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const COMPONENT_KEYS = {
|
|
19
|
+
ACTION: 'Action',
|
|
20
|
+
ICON: 'Icon',
|
|
21
|
+
PREFIX: 'Prefix',
|
|
22
|
+
SUFFIX: 'Suffix',
|
|
23
|
+
TOOLTIP: 'Tooltip'
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const SMALL = 'small';
|
|
27
|
+
|
|
28
|
+
export const COMPONENTS_MAPPER = {
|
|
29
|
+
[COMPONENT_KEYS.ACTION]: ActionAdornment,
|
|
30
|
+
[COMPONENT_KEYS.ICON]: IconAdornment,
|
|
31
|
+
[COMPONENT_KEYS.PREFIX]: PrefixAdornment,
|
|
32
|
+
[COMPONENT_KEYS.SUFFIX]: SuffixAdornment,
|
|
33
|
+
[COMPONENT_KEYS.TOOLTIP]: TooltipAdornment
|
|
34
|
+
};
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import React, { forwardRef, useCallback, useEffect, useLayoutEffect, useState } from 'react';
|
|
2
|
+
import { bool, func, number, string, arrayOf, shape } from 'prop-types';
|
|
3
|
+
import { View, TextInput } from 'react-native';
|
|
4
|
+
import { ViewPropTypes } from 'deprecated-react-native-prop-types';
|
|
5
|
+
|
|
6
|
+
import { useTheme } from '../../theming';
|
|
7
|
+
import UTLabel from '../UTLabel';
|
|
8
|
+
|
|
9
|
+
import { KEYBOARD_BY_TYPE, TYPES, COMPONENTS_MAPPER } from './constants';
|
|
10
|
+
import { retrieveStyle } from './theme';
|
|
11
|
+
|
|
12
|
+
const UTBaseInputField = forwardRef(
|
|
13
|
+
(
|
|
14
|
+
{
|
|
15
|
+
alwaysShowPlaceholder,
|
|
16
|
+
disabled,
|
|
17
|
+
error,
|
|
18
|
+
inputSize,
|
|
19
|
+
leftAdornments,
|
|
20
|
+
maxCount,
|
|
21
|
+
maxRows,
|
|
22
|
+
onBlur,
|
|
23
|
+
onChange,
|
|
24
|
+
onFocus,
|
|
25
|
+
onSubmitEditing,
|
|
26
|
+
placeholder,
|
|
27
|
+
readOnly,
|
|
28
|
+
returnKeyType,
|
|
29
|
+
rightAdornments,
|
|
30
|
+
style,
|
|
31
|
+
type,
|
|
32
|
+
value
|
|
33
|
+
},
|
|
34
|
+
ref
|
|
35
|
+
) => {
|
|
36
|
+
const [displayValue, setDisplayValue] = useState(value);
|
|
37
|
+
const [focused, setFocused] = useState(false);
|
|
38
|
+
const [inputWidth, setInputWidth] = useState(null);
|
|
39
|
+
|
|
40
|
+
const theme = useTheme();
|
|
41
|
+
const multiline = maxRows > 1;
|
|
42
|
+
|
|
43
|
+
const handleFocus = useCallback(
|
|
44
|
+
event => {
|
|
45
|
+
setFocused(true);
|
|
46
|
+
if (!multiline) setDisplayValue(value);
|
|
47
|
+
onFocus?.(event);
|
|
48
|
+
},
|
|
49
|
+
[onFocus, value, multiline]
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
const truncateText = useCallback(
|
|
53
|
+
text => {
|
|
54
|
+
if (!inputWidth || !text) return text;
|
|
55
|
+
const charWidth = 8;
|
|
56
|
+
const maxCharsPerLine = Math.floor(inputWidth / charWidth);
|
|
57
|
+
const maxLength = maxCharsPerLine;
|
|
58
|
+
return text.length > maxLength ? `${text.substring(0, maxLength - 3)}...` : text;
|
|
59
|
+
},
|
|
60
|
+
[inputWidth]
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
const handleBlur = useCallback(
|
|
64
|
+
event => {
|
|
65
|
+
setFocused(false);
|
|
66
|
+
if (!multiline) setDisplayValue(truncateText(value));
|
|
67
|
+
onBlur?.(event);
|
|
68
|
+
},
|
|
69
|
+
[truncateText, value, multiline, onBlur]
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
const { actionStyle, containerStyle, inputRowStyle, inputStyle, textLengthRowStyle } = retrieveStyle({
|
|
73
|
+
disabled,
|
|
74
|
+
error,
|
|
75
|
+
focused,
|
|
76
|
+
inputSize,
|
|
77
|
+
maxRows,
|
|
78
|
+
multiline,
|
|
79
|
+
readOnly,
|
|
80
|
+
style,
|
|
81
|
+
theme
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
setDisplayValue(value);
|
|
86
|
+
}, [value]);
|
|
87
|
+
|
|
88
|
+
useLayoutEffect(() => {
|
|
89
|
+
if (ref?.current) {
|
|
90
|
+
ref.current.measure((_x, _y, width) => {
|
|
91
|
+
setInputWidth(width);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}, [focused]);
|
|
95
|
+
|
|
96
|
+
const secureTextEntry = type === TYPES.PASSWORD;
|
|
97
|
+
const autoCapitalize = type === TYPES.EMAIL ? 'none' : 'sentences';
|
|
98
|
+
const keyboardType = KEYBOARD_BY_TYPE[type] || 'default';
|
|
99
|
+
|
|
100
|
+
const renderElement = useCallback(element => {
|
|
101
|
+
const Component = COMPONENTS_MAPPER[element.name];
|
|
102
|
+
return Component ? (
|
|
103
|
+
<Component
|
|
104
|
+
actionStyle={actionStyle}
|
|
105
|
+
disabled={disabled}
|
|
106
|
+
error={error}
|
|
107
|
+
inputStyle={inputStyle}
|
|
108
|
+
key={element.name}
|
|
109
|
+
{...element.props}
|
|
110
|
+
/>
|
|
111
|
+
) : null;
|
|
112
|
+
}, []);
|
|
113
|
+
|
|
114
|
+
return (
|
|
115
|
+
<View style={containerStyle}>
|
|
116
|
+
<View style={inputRowStyle}>
|
|
117
|
+
{leftAdornments.map(renderElement)}
|
|
118
|
+
<TextInput
|
|
119
|
+
autoCapitalize={autoCapitalize}
|
|
120
|
+
autoCorrect={false}
|
|
121
|
+
editable={!disabled && !readOnly}
|
|
122
|
+
keyboardType={keyboardType}
|
|
123
|
+
maxLength={maxCount}
|
|
124
|
+
multiline={multiline}
|
|
125
|
+
numberOfLines={maxRows}
|
|
126
|
+
onChangeText={onChange}
|
|
127
|
+
onEndEditing={handleBlur}
|
|
128
|
+
onFocus={handleFocus}
|
|
129
|
+
onSubmitEditing={onSubmitEditing}
|
|
130
|
+
placeholder={!focused && !alwaysShowPlaceholder ? '' : placeholder}
|
|
131
|
+
placeholderTextColor={inputStyle.placeholderTextColor}
|
|
132
|
+
ref={ref}
|
|
133
|
+
returnKeyType={returnKeyType}
|
|
134
|
+
secureTextEntry={secureTextEntry}
|
|
135
|
+
selectionColor={inputStyle.selectionColor}
|
|
136
|
+
style={inputStyle.root}
|
|
137
|
+
type={type}
|
|
138
|
+
value={focused || multiline ? value : displayValue}
|
|
139
|
+
/>
|
|
140
|
+
{rightAdornments.map(renderElement)}
|
|
141
|
+
</View>
|
|
142
|
+
{maxCount && (
|
|
143
|
+
<View style={textLengthRowStyle}>
|
|
144
|
+
<UTLabel colorTheme="gray" variant="small">
|
|
145
|
+
{value?.length || 0}/{maxCount}
|
|
146
|
+
</UTLabel>
|
|
147
|
+
</View>
|
|
148
|
+
)}
|
|
149
|
+
</View>
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
UTBaseInputField.displayName = 'UTBaseInputField';
|
|
155
|
+
|
|
156
|
+
UTBaseInputField.propTypes = {
|
|
157
|
+
alwaysShowPlaceholder: bool,
|
|
158
|
+
disabled: bool,
|
|
159
|
+
error: string,
|
|
160
|
+
inputSize: string,
|
|
161
|
+
leftAdornments: arrayOf(
|
|
162
|
+
shape({
|
|
163
|
+
name: string.isRequired,
|
|
164
|
+
props: shape({})
|
|
165
|
+
})
|
|
166
|
+
),
|
|
167
|
+
maxCount: number,
|
|
168
|
+
maxRows: number,
|
|
169
|
+
onBlur: func,
|
|
170
|
+
onChange: func,
|
|
171
|
+
onFocus: func,
|
|
172
|
+
onSubmitEditing: func,
|
|
173
|
+
placeholder: string,
|
|
174
|
+
readOnly: bool,
|
|
175
|
+
returnKeyType: string,
|
|
176
|
+
rightAdornments: arrayOf(
|
|
177
|
+
shape({
|
|
178
|
+
name: string.isRequired,
|
|
179
|
+
props: shape({})
|
|
180
|
+
})
|
|
181
|
+
),
|
|
182
|
+
style: shape({
|
|
183
|
+
container: ViewPropTypes.style,
|
|
184
|
+
input: ViewPropTypes.style,
|
|
185
|
+
root: ViewPropTypes.style
|
|
186
|
+
}),
|
|
187
|
+
type: string,
|
|
188
|
+
value: string
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
export default UTBaseInputField;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
## Description
|
|
4
4
|
|
|
5
|
-
`UTButton` is a versatile button component that can be customized with various themes, sizes, icons, and loading states.
|
|
5
|
+
`UTButton` is a versatile button component that can be customized with various themes, sizes, icons, and loading states.
|
|
6
6
|
|
|
7
7
|
## Props
|
|
8
8
|
|
|
@@ -3,13 +3,13 @@ import { bool, func, elementType, string, shape } from 'prop-types';
|
|
|
3
3
|
import { Pressable, View } from 'react-native';
|
|
4
4
|
import { ViewPropTypes } from 'deprecated-react-native-prop-types';
|
|
5
5
|
|
|
6
|
+
import { isUTIcon } from '../UTIcon/utils';
|
|
6
7
|
import { useTheme } from '../../theming';
|
|
7
8
|
import UTIcon from '../UTIcon';
|
|
8
9
|
import UTLabel from '../UTLabel';
|
|
9
10
|
import UTLoading from '../UTLoading';
|
|
10
11
|
|
|
11
12
|
import { DEFAULT_PROPS, ICON_PLACEMENTS } from './constants';
|
|
12
|
-
import { isUTIcon } from './utils';
|
|
13
13
|
import { retrieveStyle } from './theme';
|
|
14
14
|
|
|
15
15
|
const UTButton = ({
|
|
@@ -54,8 +54,14 @@ const UTButton = ({
|
|
|
54
54
|
(isUTIcon(Icon) ? (
|
|
55
55
|
(() => {
|
|
56
56
|
const { fontSize, color, ...remainingIconStyles } = iconStyles;
|
|
57
|
+
|
|
57
58
|
return (
|
|
58
|
-
<UTIcon
|
|
59
|
+
<UTIcon
|
|
60
|
+
colorTheme={textStyles.colorTheme}
|
|
61
|
+
name={Icon}
|
|
62
|
+
size={fontSize}
|
|
63
|
+
style={remainingIconStyles}
|
|
64
|
+
/>
|
|
59
65
|
);
|
|
60
66
|
})()
|
|
61
67
|
) : (
|
|
@@ -6,15 +6,17 @@
|
|
|
6
6
|
|
|
7
7
|
## Props
|
|
8
8
|
|
|
9
|
-
| Name | Type
|
|
10
|
-
| ------------- |
|
|
11
|
-
| checked | bool
|
|
12
|
-
| disabled | bool
|
|
13
|
-
| indeterminate | bool
|
|
14
|
-
| label | string
|
|
15
|
-
| onPress | func
|
|
16
|
-
|
|
|
17
|
-
|
|
|
9
|
+
| Name | Type | Default | Description |
|
|
10
|
+
| ------------- | ------ | ------- | ------------------------------------------------------- |
|
|
11
|
+
| checked | bool | false | Indicates if the checkbox is checked. |
|
|
12
|
+
| disabled | bool | false | Disables the checkbox, making it unclickable. |
|
|
13
|
+
| indeterminate | bool | false | Indicates if the checkbox is in an indeterminate state. |
|
|
14
|
+
| label | string | | Label to display next to the checkbox. |
|
|
15
|
+
| onPress | func | | Function to call when the checkbox is pressed. |
|
|
16
|
+
| required | bool | false | Indicates if the checkbox is required. |
|
|
17
|
+
| reversed | bool | false | If true, reverses the order of label and checkbox. |
|
|
18
|
+
| spacing | string | | If "small", reduces the column gap from 16 to 8. |
|
|
19
|
+
| style | shape | {} | Custom styles to apply to the checkbox container. |
|
|
18
20
|
|
|
19
21
|
## Usage
|
|
20
22
|
|
|
@@ -31,7 +33,7 @@ const Example = () => {
|
|
|
31
33
|
};
|
|
32
34
|
|
|
33
35
|
export default Example;
|
|
34
|
-
|
|
36
|
+
```
|
|
35
37
|
|
|
36
38
|
### Custom Styles Example
|
|
37
39
|
|
|
@@ -40,12 +42,8 @@ import React from 'react';
|
|
|
40
42
|
import UTCheckBox from './UTCheckBox';
|
|
41
43
|
|
|
42
44
|
const customStyles = {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
touchable: {
|
|
46
|
-
root: { margin: 5 },
|
|
47
|
-
pressed: { opacity: 0.5 }
|
|
48
|
-
}
|
|
45
|
+
padding: 10,
|
|
46
|
+
backgroundColor: 'lightgrey'
|
|
49
47
|
};
|
|
50
48
|
|
|
51
49
|
const Example = () => {
|
|
@@ -57,10 +55,10 @@ const Example = () => {
|
|
|
57
55
|
label="Check me"
|
|
58
56
|
onPress={() => setChecked(!checked)}
|
|
59
57
|
style={customStyles}
|
|
58
|
+
spacing="small"
|
|
60
59
|
/>
|
|
61
60
|
);
|
|
62
61
|
};
|
|
63
62
|
|
|
64
63
|
export default Example;
|
|
65
|
-
|
|
66
64
|
```
|