@widergy/mobile-ui 1.12.5 → 1.12.7
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/UTAutocomplete/index.js +6 -2
- package/lib/components/UTBadge/README.md +17 -26
- package/lib/components/UTBadge/index.js +6 -5
- package/lib/components/UTButton/README.md +78 -26
- package/lib/components/UTButton/index.js +4 -4
- package/lib/components/UTIcon/README.md +53 -51
- package/lib/components/UTIcon/index.js +5 -3
- package/lib/components/UTLabel/README.md +62 -39
- package/lib/components/UTLabel/index.js +14 -6
- package/lib/components/UTLabel/theme.js +24 -9
- package/lib/components/UTMenu/components/ListView/index.js +1 -1
- package/lib/components/UTMenu/index.js +8 -7
- package/lib/components/UTMenu/styles.js +0 -1
- package/lib/components/UTPasswordField/index.js +9 -42
- package/lib/components/UTPasswordField/{components → versions/V0/components}/PasswordValidations/components/ErrorMessage/index.js +3 -3
- package/lib/components/UTPasswordField/{components → versions/V0/components}/PasswordValidations/components/Validation/index.js +3 -3
- package/lib/components/UTPasswordField/{components → versions/V0/components}/PasswordValidations/index.js +1 -1
- package/lib/components/UTPasswordField/{components → versions/V0/components}/PasswordValidations/styles.js +1 -2
- package/lib/components/UTPasswordField/versions/V0/index.js +49 -0
- package/lib/components/UTPasswordField/versions/V1/README.md +23 -0
- package/lib/components/UTPasswordField/versions/V1/constants.js +7 -0
- package/lib/components/UTPasswordField/versions/V1/index.js +32 -0
- package/lib/components/UTTextArea/README.md +32 -0
- package/lib/components/UTTextInput/versions/V0/components/BaseInput/index.js +1 -1
- package/lib/components/UTTextInput/versions/V1/README.md +236 -0
- package/lib/components/UTTextInput/versions/V1/components/TextInputField/index.js +179 -148
- package/lib/components/UTTextInput/versions/V1/components/TextInputField/theme.js +30 -27
- package/lib/components/UTTextInput/versions/V1/components/TextInputField/utils.js +7 -5
- package/lib/components/UTTextInput/versions/V1/index.js +13 -5
- package/lib/components/UTTextInput/versions/V1/proptypes.js +3 -0
- package/lib/components/UTValidation/README.md +33 -18
- package/lib/components/UTValidation/index.js +8 -6
- package/package.json +1 -1
- /package/lib/components/UTPasswordField/{components → versions/V0/components}/PasswordValidations/components/ErrorMessage/styles.js +0 -0
- /package/lib/components/UTPasswordField/{components → versions/V0/components}/PasswordValidations/components/Validation/styles.js +0 -0
- /package/lib/components/UTPasswordField/{proptypes.js → versions/V0/proptypes.js} +0 -0
|
@@ -15,9 +15,21 @@ const variantsColorTheme = (colorTheme, shade, theme) => {
|
|
|
15
15
|
return colorThemeDefinition[colorShade] || '#000';
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
const getFontFamily = (theme, weight) =>
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
export const getFontFamily = (theme, weight) =>
|
|
19
|
+
weight === WEIGHTS[DEFAULT_PROPS.weight] || IS_IOS
|
|
20
|
+
? theme.fonts.fontFamily
|
|
21
|
+
: theme.fonts?.customVariants?.[weight]?.fontFamily;
|
|
22
|
+
|
|
23
|
+
export const getFontSize = variant => VARIANTS_SIZES[variant] || VARIANTS_SIZES[DEFAULT_PROPS.variant];
|
|
24
|
+
|
|
25
|
+
export const getFontWeight = weight => (IS_IOS ? WEIGHTS[weight] || WEIGHTS[DEFAULT_PROPS.weight] : null);
|
|
26
|
+
|
|
27
|
+
export const getFontStyles = ({ theme, variant, weight }) => {
|
|
28
|
+
const fontFamily = getFontFamily(theme, weight);
|
|
29
|
+
const fontSize = getFontSize(variant);
|
|
30
|
+
const fontWeight = getFontWeight(weight);
|
|
31
|
+
|
|
32
|
+
return { fontFamily, fontSize, fontWeight };
|
|
21
33
|
};
|
|
22
34
|
|
|
23
35
|
export const retrieveStyle = ({ colorTheme, field, shade, theme, variant, weight }) => ({
|
|
@@ -26,10 +38,13 @@ export const retrieveStyle = ({ colorTheme, field, shade, theme, variant, weight
|
|
|
26
38
|
field?.configuration?.shade ?? shade,
|
|
27
39
|
theme
|
|
28
40
|
),
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
41
|
+
...getFontStyles({
|
|
42
|
+
theme,
|
|
43
|
+
variant: field?.configuration?.variant ?? variant,
|
|
44
|
+
weight: field?.configuration?.weight ?? weight
|
|
45
|
+
}),
|
|
46
|
+
includeFontPadding: false,
|
|
47
|
+
margin: 0,
|
|
48
|
+
paddingVertical: 0,
|
|
49
|
+
textAlignVertical: 'center'
|
|
35
50
|
});
|
|
@@ -28,7 +28,7 @@ class ListView extends PureComponent {
|
|
|
28
28
|
|
|
29
29
|
handleOnPress = item => {
|
|
30
30
|
const { handleOptionPress, onPress } = this.props;
|
|
31
|
-
return handleOptionPress(item.action || (() => onPress(item)));
|
|
31
|
+
return handleOptionPress(item.action || (() => onPress(item)), item?.value);
|
|
32
32
|
};
|
|
33
33
|
|
|
34
34
|
renderItem = ({ item }) => {
|
|
@@ -3,6 +3,7 @@ import { Dimensions, Keyboard, KeyboardAvoidingView, Modal, TouchableOpacity, Vi
|
|
|
3
3
|
|
|
4
4
|
import useKeyboardHeight from '../../hooks/useKeyboardHeight';
|
|
5
5
|
import UTTextInput from '../UTTextInput';
|
|
6
|
+
import Surface from '../Surface';
|
|
6
7
|
|
|
7
8
|
import MenuOption from './components/MenuOption';
|
|
8
9
|
import ListView from './components/ListView';
|
|
@@ -101,15 +102,15 @@ const UTMenu = ({
|
|
|
101
102
|
setTimeout(() => setIsOpen(true), 20);
|
|
102
103
|
if (onOpen) onOpen();
|
|
103
104
|
};
|
|
104
|
-
const closeMenu =
|
|
105
|
+
const closeMenu = value => {
|
|
105
106
|
setIsOpen(false);
|
|
106
107
|
setQuery('');
|
|
107
|
-
if (onClose) onClose();
|
|
108
|
+
if (onClose) onClose(value);
|
|
108
109
|
};
|
|
109
110
|
|
|
110
|
-
const handleOptionPress = action => {
|
|
111
|
+
const handleOptionPress = (action, value) => {
|
|
111
112
|
action();
|
|
112
|
-
if (!isMultiple) closeMenu();
|
|
113
|
+
if (!isMultiple) closeMenu(value);
|
|
113
114
|
};
|
|
114
115
|
|
|
115
116
|
const focusSearchInput = () => withAutocomplete && searchTextInputRef.current?.focus();
|
|
@@ -140,14 +141,14 @@ const UTMenu = ({
|
|
|
140
141
|
<TouchableOpacity onPress={closeMenu} style={styles.overlayTouchable}>
|
|
141
142
|
<View style={styles.overlay} />
|
|
142
143
|
</TouchableOpacity>
|
|
143
|
-
<
|
|
144
|
+
<Surface
|
|
144
145
|
style={[styles.menu, position, fullWidth && { width: anchorMeasure?.width }, propStyles?.menu]}
|
|
145
146
|
ref={menuRef}
|
|
146
147
|
onLayout={handleMenuLayout}
|
|
147
148
|
>
|
|
148
149
|
<KeyboardAvoidingView behavior="height">
|
|
149
150
|
{withAutocomplete && (
|
|
150
|
-
<View style={styles.searchContainer}>
|
|
151
|
+
<View style={[styles.searchContainer, propStyles?.searchContainer]}>
|
|
151
152
|
<UTTextInput
|
|
152
153
|
InputRef={searchTextInputRef}
|
|
153
154
|
value={query}
|
|
@@ -177,7 +178,7 @@ const UTMenu = ({
|
|
|
177
178
|
isMultiple={isMultiple}
|
|
178
179
|
/>
|
|
179
180
|
</KeyboardAvoidingView>
|
|
180
|
-
</
|
|
181
|
+
</Surface>
|
|
181
182
|
</Modal>
|
|
182
183
|
</Fragment>
|
|
183
184
|
);
|
|
@@ -1,49 +1,16 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { string } from 'prop-types';
|
|
3
3
|
|
|
4
|
-
import
|
|
4
|
+
import V0 from './versions/V0';
|
|
5
|
+
import V1 from './versions/V1';
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const UTPasswordField = ({
|
|
10
|
-
style,
|
|
11
|
-
disabled,
|
|
12
|
-
input,
|
|
13
|
-
error,
|
|
14
|
-
disableCaptionLabel,
|
|
15
|
-
passwordValidations,
|
|
16
|
-
showValidations,
|
|
17
|
-
shouldShowError,
|
|
18
|
-
errorTextProps,
|
|
19
|
-
...props
|
|
20
|
-
}) => {
|
|
21
|
-
const { value, onChange } = input;
|
|
22
|
-
|
|
23
|
-
return (
|
|
24
|
-
<View>
|
|
25
|
-
<UTTextInput
|
|
26
|
-
{...props}
|
|
27
|
-
value={value}
|
|
28
|
-
onChange={onChange}
|
|
29
|
-
error={showValidations ? !!error : error}
|
|
30
|
-
errorTextProps={errorTextProps}
|
|
31
|
-
hiddenInput
|
|
32
|
-
/>
|
|
33
|
-
{!!showValidations && !!passwordValidations && (
|
|
34
|
-
<PasswordValidations
|
|
35
|
-
disabled={disabled}
|
|
36
|
-
value={value}
|
|
37
|
-
style={style}
|
|
38
|
-
error={error}
|
|
39
|
-
passwordValidations={passwordValidations}
|
|
40
|
-
shouldShowError={shouldShowError}
|
|
41
|
-
/>
|
|
42
|
-
)}
|
|
43
|
-
</View>
|
|
44
|
-
);
|
|
7
|
+
const UTPasswordField = ({ version = 'V0', ...props }) => {
|
|
8
|
+
const Component = { V0, V1 }[version];
|
|
9
|
+
return <Component {...props} />;
|
|
45
10
|
};
|
|
46
11
|
|
|
47
|
-
UTPasswordField.propTypes =
|
|
12
|
+
UTPasswordField.propTypes = {
|
|
13
|
+
version: string
|
|
14
|
+
};
|
|
48
15
|
|
|
49
16
|
export default UTPasswordField;
|
|
@@ -3,9 +3,9 @@ import { bool, string, func } from 'prop-types';
|
|
|
3
3
|
import { View } from 'react-native';
|
|
4
4
|
import _ from 'lodash';
|
|
5
5
|
|
|
6
|
-
import
|
|
7
|
-
import Icon from '
|
|
8
|
-
import
|
|
6
|
+
import { useTheme } from '../../../../../../../../theming';
|
|
7
|
+
import Icon from '../../../../../../../Icon';
|
|
8
|
+
import Label from '../../../../../../../Label';
|
|
9
9
|
|
|
10
10
|
import ownStyles from './styles';
|
|
11
11
|
|
|
@@ -3,9 +3,9 @@ import { string, bool, element } from 'prop-types';
|
|
|
3
3
|
import { View } from 'react-native';
|
|
4
4
|
import _ from 'lodash';
|
|
5
5
|
|
|
6
|
-
import
|
|
7
|
-
import Icon from '
|
|
8
|
-
import
|
|
6
|
+
import { useTheme } from '../../../../../../../../theming';
|
|
7
|
+
import Icon from '../../../../../../../Icon';
|
|
8
|
+
import Label from '../../../../../../../Label';
|
|
9
9
|
|
|
10
10
|
import ownStyles from './styles';
|
|
11
11
|
|
|
@@ -4,7 +4,7 @@ import { ViewPropTypes } from 'deprecated-react-native-prop-types';
|
|
|
4
4
|
import { View } from 'react-native';
|
|
5
5
|
import _ from 'lodash';
|
|
6
6
|
|
|
7
|
-
import { useTheme } from '
|
|
7
|
+
import { useTheme } from '../../../../../../theming';
|
|
8
8
|
|
|
9
9
|
import Validation from './components/Validation';
|
|
10
10
|
import ErrorMessage from './components/ErrorMessage';
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { View } from 'react-native';
|
|
3
|
+
|
|
4
|
+
import UTTextInput from '../../../UTTextInput';
|
|
5
|
+
|
|
6
|
+
import PasswordValidations from './components/PasswordValidations';
|
|
7
|
+
import passwordFieldProptypes from './proptypes';
|
|
8
|
+
|
|
9
|
+
const UTPasswordField = ({
|
|
10
|
+
style,
|
|
11
|
+
disabled,
|
|
12
|
+
input,
|
|
13
|
+
error,
|
|
14
|
+
disableCaptionLabel,
|
|
15
|
+
passwordValidations,
|
|
16
|
+
showValidations,
|
|
17
|
+
shouldShowError,
|
|
18
|
+
errorTextProps,
|
|
19
|
+
...props
|
|
20
|
+
}) => {
|
|
21
|
+
const { value, onChange } = input;
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<View>
|
|
25
|
+
<UTTextInput
|
|
26
|
+
{...props}
|
|
27
|
+
value={value}
|
|
28
|
+
onChange={onChange}
|
|
29
|
+
error={showValidations ? !!error : error}
|
|
30
|
+
errorTextProps={errorTextProps}
|
|
31
|
+
hiddenInput
|
|
32
|
+
/>
|
|
33
|
+
{!!showValidations && !!passwordValidations && (
|
|
34
|
+
<PasswordValidations
|
|
35
|
+
disabled={disabled}
|
|
36
|
+
value={value}
|
|
37
|
+
style={style}
|
|
38
|
+
error={error}
|
|
39
|
+
passwordValidations={passwordValidations}
|
|
40
|
+
shouldShowError={shouldShowError}
|
|
41
|
+
/>
|
|
42
|
+
)}
|
|
43
|
+
</View>
|
|
44
|
+
);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
UTPasswordField.propTypes = passwordFieldProptypes;
|
|
48
|
+
|
|
49
|
+
export default UTPasswordField;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# UTPasswordField
|
|
2
|
+
|
|
3
|
+
## Description
|
|
4
|
+
|
|
5
|
+
`UTPasswordField` is a component that provides a password input field with an optional toggle to show or hide the password. It builds on the `UTTextInput` component and adds functionality specific to password inputs.
|
|
6
|
+
|
|
7
|
+
## Props
|
|
8
|
+
|
|
9
|
+
`UTPasswordField` inherits all the props from `UTTextInput` and adds custom behavior for handling password visibility.
|
|
10
|
+
|
|
11
|
+
| Name | Type | Default | Description |
|
|
12
|
+
| ---- | ---- | ------- | -------------------------------------- |
|
|
13
|
+
| ... | ... | ... | Inherits all props from `UTTextInput`. |
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```javascript
|
|
18
|
+
<UTPasswordField placeholder="Enter your password" />
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Notes
|
|
22
|
+
|
|
23
|
+
For more detailed information on inherited props, refer to the documentation for `UTTextInput`.
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import propTypes from '../../../UTTextInput/versions/V1/proptypes';
|
|
4
|
+
import UTTextInput from '../../../UTTextInput';
|
|
5
|
+
|
|
6
|
+
import { ICON_EYE, ICON_EYE_OFF, INPUT_TYPE } from './constants';
|
|
7
|
+
|
|
8
|
+
const UTPasswordField = props => {
|
|
9
|
+
const [isPasswordVisible, setIsPasswordVisible] = useState(false);
|
|
10
|
+
|
|
11
|
+
const toggleVisibility = () => {
|
|
12
|
+
setIsPasswordVisible(!isPasswordVisible);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const action = {
|
|
16
|
+
icon: isPasswordVisible ? ICON_EYE : ICON_EYE_OFF,
|
|
17
|
+
onPress: toggleVisibility
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<UTTextInput
|
|
22
|
+
action={action}
|
|
23
|
+
type={isPasswordVisible ? INPUT_TYPE.TEXT : INPUT_TYPE.PASSWORD}
|
|
24
|
+
version="V1"
|
|
25
|
+
{...props}
|
|
26
|
+
/>
|
|
27
|
+
);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
UTPasswordField.propTypes = propTypes;
|
|
31
|
+
|
|
32
|
+
export default UTPasswordField;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# UTTextArea
|
|
2
|
+
|
|
3
|
+
## Description
|
|
4
|
+
|
|
5
|
+
`UTTextArea` is a component that provides a multi-line text input field, building on the `UTTextInput` component with additional customization for handling multiple rows of text.
|
|
6
|
+
|
|
7
|
+
## Props
|
|
8
|
+
|
|
9
|
+
`UTTextArea` inherits all the props from `UTTextInput` and adds an additional prop specific to the number of rows.
|
|
10
|
+
|
|
11
|
+
| Name | Type | Default | Description |
|
|
12
|
+
| ------- | ------ | ------- | ----------------------------------------------------- |
|
|
13
|
+
| maxRows | number | 4 | The maximum number of rows the text area can display. |
|
|
14
|
+
| ... | ... | ... | Inherits all props from `UTTextInput`. |
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
### Basic Example
|
|
19
|
+
|
|
20
|
+
```javascript
|
|
21
|
+
<UTTextArea placeholder="Enter your text here..." />
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### Example with Custom Rows
|
|
25
|
+
|
|
26
|
+
```javascript
|
|
27
|
+
<UTTextArea maxRows={6} placeholder="Enter a longer text here..." />
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Notes
|
|
31
|
+
|
|
32
|
+
For more detailed information on inherited props, refer to the documentation for `UTTextInput`.
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
# UTTextInput
|
|
2
|
+
|
|
3
|
+
Component used for displaying a text input field with various customization options.
|
|
4
|
+
|
|
5
|
+
## Props
|
|
6
|
+
|
|
7
|
+
| Name | Type | Default | Description |
|
|
8
|
+
| --------------------- | ----------- | --------- | -------------------------------------------------------------------------------------------------------- |
|
|
9
|
+
| action | object | | Action button configuration object. |
|
|
10
|
+
| alwaysShowPlaceholder | bool | false | Whether to always show the placeholder. |
|
|
11
|
+
| disabled | bool | false | Disables the input field. |
|
|
12
|
+
| error | string | | Error message to be displayed. |
|
|
13
|
+
| helpText | string | | Help text to be displayed below the input field. |
|
|
14
|
+
| InputRef | ref | | Reference to the input field. |
|
|
15
|
+
| inputSize | string | 'l' | Size of the input field. |
|
|
16
|
+
| label | string | | Label text for the input field. |
|
|
17
|
+
| labelVariant | string | 'l' | Variant of the label. |
|
|
18
|
+
| LeftIcon | elementType | | Icon to be displayed on the left side of the input field. |
|
|
19
|
+
| maxCount | number | | Maximum number of characters allowed in the input field. |
|
|
20
|
+
| maxRows | number | 1 | Maximum number of rows allowed in the input field. |
|
|
21
|
+
| onBlur | func | | Function to call when the input field loses focus. |
|
|
22
|
+
| onChange | func | | Function to call when the input field value changes. |
|
|
23
|
+
| onFocus | func | | Function to call when the input field gains focus. |
|
|
24
|
+
| onSubmitEditing | func | | Function to call when the input field is submitted. |
|
|
25
|
+
| placeholder | string | | Placeholder text for the input field. |
|
|
26
|
+
| prefix | string | | Prefix text to be displayed inside the input field. |
|
|
27
|
+
| readOnly | bool | false | Makes the input field read-only. |
|
|
28
|
+
| required | bool | false | Whether the input field is required. |
|
|
29
|
+
| returnKeyType | string | 'done' | Determines the return key type on the keyboard. |
|
|
30
|
+
| RightIcon | elementType | | Icon to be displayed on the right side of the input field. |
|
|
31
|
+
| style | object | | Style object to customize the input field. Can contain `root`, `container`, `input`, or `action` styles. |
|
|
32
|
+
| suffix | string | | Suffix text to be displayed inside the input field. |
|
|
33
|
+
| tooltip | string | | Tooltip text to be displayed. |
|
|
34
|
+
| type | string | 'default' | Type of input (e.g., 'text', 'password', 'email'). |
|
|
35
|
+
| validations | array | | Array of validation rules to be applied to the input field. |
|
|
36
|
+
| value | string | '' | Value of the input field. |
|
|
37
|
+
|
|
38
|
+
### action
|
|
39
|
+
|
|
40
|
+
Configuration object for the action button.
|
|
41
|
+
|
|
42
|
+
| Name | Type | Description |
|
|
43
|
+
| ---------- | ----------- | --------------------------------------------------- |
|
|
44
|
+
| icon | elementType | Icon to be displayed in the action button. |
|
|
45
|
+
| onPress | func | Function to call when the action button is pressed. |
|
|
46
|
+
| colorTheme | string | Color theme of the action button. |
|
|
47
|
+
| text | string | Text to be displayed in the action button. |
|
|
48
|
+
|
|
49
|
+
### labelVariant
|
|
50
|
+
|
|
51
|
+
It must be one of these:
|
|
52
|
+
|
|
53
|
+
- "s": small
|
|
54
|
+
- "l": large
|
|
55
|
+
|
|
56
|
+
### inputSize
|
|
57
|
+
|
|
58
|
+
It must be one of these:
|
|
59
|
+
|
|
60
|
+
- "s": small
|
|
61
|
+
- "l": large
|
|
62
|
+
|
|
63
|
+
### type
|
|
64
|
+
|
|
65
|
+
It must be one of these:
|
|
66
|
+
|
|
67
|
+
- "default"
|
|
68
|
+
- "email"
|
|
69
|
+
- "password"
|
|
70
|
+
- "numeric"
|
|
71
|
+
|
|
72
|
+
### Methods via `InputRef`
|
|
73
|
+
|
|
74
|
+
| Name | Description |
|
|
75
|
+
| -------- | ------------------------------------ |
|
|
76
|
+
| focus | Focuses the input field. |
|
|
77
|
+
| blur | Blurs the input field. |
|
|
78
|
+
| setValue | Sets the value of the input field. |
|
|
79
|
+
| clear | Clears the value of the input field. |
|
|
80
|
+
|
|
81
|
+
### style
|
|
82
|
+
|
|
83
|
+
The `style` prop is an object that can contain the following keys to customize the appearance of the input field:
|
|
84
|
+
|
|
85
|
+
- `root`: Style for the root of the component.
|
|
86
|
+
- `container`: Style for the container of the input field.
|
|
87
|
+
- `input`: Style for the input field itself.
|
|
88
|
+
- `action`: Style for the action button.
|
|
89
|
+
|
|
90
|
+
### Right Icon
|
|
91
|
+
|
|
92
|
+
If a RightIcon is provided and an error occurs, the RightIcon will be replaced by an error icon.
|
|
93
|
+
|
|
94
|
+
### Structure of validations
|
|
95
|
+
|
|
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
|
+
|
|
99
|
+
#### Example structure:
|
|
100
|
+
|
|
101
|
+
```jsx
|
|
102
|
+
const validationData = [
|
|
103
|
+
{
|
|
104
|
+
items: [
|
|
105
|
+
{
|
|
106
|
+
status: 'success',
|
|
107
|
+
text: 'Must be at least 8 characters long.'
|
|
108
|
+
}
|
|
109
|
+
]
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
items: [
|
|
113
|
+
{
|
|
114
|
+
status: 'error',
|
|
115
|
+
text: 'Must be at most 16 characters long.'
|
|
116
|
+
}
|
|
117
|
+
]
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
title: 'Must meet at least one of the following conditions:',
|
|
121
|
+
status: 'error',
|
|
122
|
+
items: [
|
|
123
|
+
{
|
|
124
|
+
text: 'At least one lowercase letter.'
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
text: 'At least one uppercase letter.'
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
status: 'success',
|
|
131
|
+
text: 'At least one number.'
|
|
132
|
+
}
|
|
133
|
+
]
|
|
134
|
+
}
|
|
135
|
+
];
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Handling Errors
|
|
139
|
+
|
|
140
|
+
Errors can be displayed below the input field using either the `error` prop or the `validations` prop.
|
|
141
|
+
|
|
142
|
+
- **error**: A string that represents a general error message.
|
|
143
|
+
- **validations**: An array of validation rules, where each rule is an object containing a `rule` and a `message`.
|
|
144
|
+
|
|
145
|
+
If both `error` and `validations` are provided, `validations` will take precedence, and its messages will be displayed.
|
|
146
|
+
|
|
147
|
+
#### Example usage with `error`:
|
|
148
|
+
|
|
149
|
+
```jsx
|
|
150
|
+
<UTTextInput
|
|
151
|
+
label="Username"
|
|
152
|
+
placeholder="Enter your username"
|
|
153
|
+
error="This username is already taken"
|
|
154
|
+
/>
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
#### Example usage with validations:
|
|
158
|
+
|
|
159
|
+
```jsx
|
|
160
|
+
const validations = [
|
|
161
|
+
{
|
|
162
|
+
items: [
|
|
163
|
+
{
|
|
164
|
+
status: 'success',
|
|
165
|
+
text: 'Must be at least 8 characters long.'
|
|
166
|
+
}
|
|
167
|
+
]
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
items: [
|
|
171
|
+
{
|
|
172
|
+
status: 'error',
|
|
173
|
+
text: 'Must be at most 16 characters long.'
|
|
174
|
+
}
|
|
175
|
+
]
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
title: 'Must meet at least one of the following conditions:',
|
|
179
|
+
status: 'error',
|
|
180
|
+
items: [
|
|
181
|
+
{
|
|
182
|
+
text: 'At least one lowercase letter.'
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
text: 'At least one uppercase letter.'
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
status: 'success',
|
|
189
|
+
text: 'At least one number.'
|
|
190
|
+
}
|
|
191
|
+
]
|
|
192
|
+
}
|
|
193
|
+
];
|
|
194
|
+
|
|
195
|
+
<UTTextInput
|
|
196
|
+
label="Email"
|
|
197
|
+
placeholder="Enter your email"
|
|
198
|
+
validations={validations}
|
|
199
|
+
/>
|
|
200
|
+
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
## Usage
|
|
204
|
+
|
|
205
|
+
```jsx
|
|
206
|
+
<UTTextInput
|
|
207
|
+
label="Password"
|
|
208
|
+
placeholder="Enter your password"
|
|
209
|
+
type="password"
|
|
210
|
+
required
|
|
211
|
+
onChange={text => console.log(text)}
|
|
212
|
+
validations={[
|
|
213
|
+
{
|
|
214
|
+
title: 'Must meet at least two of the following conditions:',
|
|
215
|
+
items: [
|
|
216
|
+
{
|
|
217
|
+
text: 'At least one lowercase letter.'
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
text: 'At least one uppercase letter.'
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
status: 'success',
|
|
224
|
+
text: 'At least one number.'
|
|
225
|
+
}
|
|
226
|
+
]
|
|
227
|
+
}
|
|
228
|
+
]}
|
|
229
|
+
style={{
|
|
230
|
+
root: { padding: 5 },
|
|
231
|
+
container: { margin: 10 },
|
|
232
|
+
input: { borderColor: 'blue' },
|
|
233
|
+
action: { backgroundColor: 'green' }
|
|
234
|
+
}}
|
|
235
|
+
/>
|
|
236
|
+
```
|