@widergy/mobile-ui 1.29.0 → 1.29.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [1.29.1](https://github.com/widergy/mobile-ui/compare/v1.29.0...v1.29.1) (2024-10-22)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * update read mes and components to match the web ones ([#365](https://github.com/widergy/mobile-ui/issues/365)) ([ca5569a](https://github.com/widergy/mobile-ui/commit/ca5569a150fdb3ccab38517c33983c6309785d9a))
7
+
1
8
  # [1.29.0](https://github.com/widergy/mobile-ui/compare/v1.28.3...v1.29.0) (2024-10-21)
2
9
 
3
10
 
@@ -6,34 +6,37 @@
6
6
 
7
7
  ## Props
8
8
 
9
- | Name | Type | Default | Description |
10
- | --------------------- | --------------------------------------------------------- | -------- | --------------------------------------------------------- |
11
- | alwaysShowPlaceholder | bool | false | Whether to always show the placeholder text. |
12
- | disabled | bool | | Whether the input field is disabled. |
13
- | error | string | | Error message to display. |
14
- | id | oneOfType([number, string]) | | Unique identifier for the input field. |
15
- | value | string | '' | The value of the input field. |
16
- | onChange | func.isRequired | () => {} | Callback function to handle change event. |
17
- | inputSize | string | 'large' | Size of the input field. One of: `small`, `large`. |
18
- | leftAdornments | arrayOf(shape({ name: string, props: object })) | | Elements to display on the left side of the input field. |
19
- | maxCount | number | | Maximum number of characters allowed. |
20
- | maxRows | number | | Maximum number of rows for multiline input. |
21
- | onBlur | func | | Callback function to handle blur event. |
22
- | onFocus | func | | Callback function to handle focus event. |
23
- | onSubmitEditing | func | | Callback function to handle submit editing event. |
24
- | placeholder | string | | Placeholder text for the input field. |
25
- | readOnly | bool | | Whether the input field is read-only. |
26
- | returnKeyType | string | | Type of return key to display on the keyboard. |
27
- | rightAdornments | arrayOf(shape({ name: string, props: object })) | | Elements to display on the right side of the input field. |
28
- | style | shape({ container: object, input: object, root: object }) | {} | Custom styles to apply to the component. |
29
- | type | string | | Type of the input field (e.g., email, numeric, password). |
30
- | variant | string | 'white' | Variant of the input field. One of: `white`, `gray`. |
31
- | editable | bool | true | Whether the input field is editable. |
9
+ | Name | Type | Default | Description |
10
+ | --------------------- | --------------------------------------------------------- | -------- | ----------------------------------------------------------------------------------------------- |
11
+ | alwaysShowPlaceholder | bool | false | Whether to always show the placeholder text, even when the field is focused. |
12
+ | blurOnSubmit | bool | | If true, the input will be blurred when the user submits the text. |
13
+ | disabled | bool | | Whether the input field is disabled. |
14
+ | editable | bool | true | Whether the input field is editable. If false, it behaves like a disabled field. |
15
+ | error | oneOfType([bool, string]) | | Error message to display, or `true` to indicate an error state without a message. |
16
+ | id | oneOfType([number, string]) | | Unique identifier for the input field. |
17
+ | value | oneOfType([string, number]) | null | The value of the input field. |
18
+ | onChange | func | () => {} | Callback function to handle change events. |
19
+ | inputSize | string | 'large' | Size of the input field. One of: `small`, `large`. |
20
+ | leftAdornments | arrayOf(shape({ name: string, props: object })) | [] | Elements to display on the left side of the input field (e.g., prefix, icons). |
21
+ | maxLength | number | | Maximum number of characters allowed in the input. |
22
+ | maxRows | number | 1 | Maximum number of rows for multiline input. |
23
+ | onBlur | func | | Callback function to handle blur events. |
24
+ | onFocus | func | | Callback function to handle focus events. |
25
+ | onSubmitEditing | func | | Callback function to handle submit events. |
26
+ | placeholder | string | | Placeholder text for the input field. |
27
+ | readOnly | bool | | Whether the input field is read-only. |
28
+ | returnKeyType | string | | Type of return key to display on the keyboard. |
29
+ | rightAdornments | arrayOf(shape({ name: string, props: object })) | [] | Elements to display on the right side of the input field (e.g., suffix, icons, action buttons). |
30
+ | showCharacterCount | bool | | Whether to display the character count. |
31
+ | style | shape({ container: object, input: object, root: object }) | {} | Custom styles to apply to the component. |
32
+ | type | string | | Type of the input field (e.g., text, email, numeric, password). |
33
+ | variant | string | 'white' | Variant of the input field. One of: `white`, `gray`. |
32
34
 
33
35
  ## Input Types
34
36
 
35
37
  The `type` prop can be one of these values:
36
38
 
39
+ - `text`
37
40
  - `email`
38
41
  - `numeric`
39
42
  - `password`
@@ -93,7 +96,7 @@ Displays a prefix text before the input field.
93
96
 
94
97
  Displays a suffix text after the input field.
95
98
 
96
- - **Props passed to PrefixAdornment:**
99
+ - **Props passed to SuffixAdornment:**
97
100
  - `text` (string): The text to display as a suffix.
98
101
 
99
102
  **Example Usage:**
@@ -1,11 +1,12 @@
1
1
  import React from 'react';
2
+ import { shape, string, elementType, bool, oneOfType } from 'prop-types';
3
+ import { TextPropTypes } from 'deprecated-react-native-prop-types';
2
4
 
3
5
  import { isUTIcon } from '../../../UTIcon/utils';
4
6
  import UTIcon from '../../../UTIcon';
5
7
 
6
8
  import { ERROR_ICON, ICON_SIZE } from './constants';
7
9
  import { getIconColorProps } from './utils';
8
- import { defaultProps, propTypes } from './proptypes';
9
10
 
10
11
  const IconAdornment = ({
11
12
  changeOnError,
@@ -31,7 +32,17 @@ const IconAdornment = ({
31
32
  );
32
33
  };
33
34
 
34
- IconAdornment.propTypes = propTypes;
35
- IconAdornment.defaultProps = defaultProps;
35
+ IconAdornment.propTypes = {
36
+ changeOnError: bool,
37
+ changeOnFocus: bool,
38
+ colorTheme: string,
39
+ error: oneOfType([bool, string]),
40
+ focused: bool,
41
+ Icon: elementType,
42
+ inputStyle: shape({
43
+ root: TextPropTypes.style
44
+ }),
45
+ shade: string
46
+ };
36
47
 
37
48
  export default IconAdornment;
@@ -15,9 +15,10 @@ export const TYPES = {
15
15
  EMAIL: 'email',
16
16
  NUMBER: 'number',
17
17
  NUMERIC: 'numeric',
18
- PASSWORD: 'password',
19
18
  PASSWORD_NUMERIC: 'password_numeric',
20
- PHONE: 'phone'
19
+ PASSWORD: 'password',
20
+ PHONE: 'phone',
21
+ TEXT: 'text'
21
22
  };
22
23
 
23
24
  export const KEYBOARD_BY_TYPE = {
@@ -10,41 +10,41 @@ import React, {
10
10
  } from 'react';
11
11
  import { View, TextInput } from 'react-native';
12
12
  import debounce from 'lodash/debounce';
13
+ import { arrayOf, bool, func, number, object, oneOfType, shape, string } from 'prop-types';
13
14
 
14
15
  import { useTheme } from '../../theming';
15
16
  import UTLabel from '../UTLabel';
16
17
 
17
18
  import { COMPONENTS_MAPPER, DEBOUNCE_CONFIG, DEBOUNCE_DELAY } from './constants';
18
- import { defaultProps, propTypes } from './proptypes';
19
19
  import { getPropsByType } from './utils';
20
20
  import { CONTAINER, LINE_HEIGHT, retrieveStyle } from './theme';
21
21
 
22
22
  const UTBaseInputField = forwardRef(
23
23
  (
24
24
  {
25
- alwaysShowPlaceholder,
25
+ alwaysShowPlaceholder = false,
26
26
  blurOnSubmit,
27
27
  disabled,
28
- editable,
28
+ editable = true,
29
29
  error,
30
30
  id,
31
- inputSize,
32
- leftAdornments,
31
+ inputSize = 'large',
32
+ leftAdornments = [],
33
33
  maxLength,
34
- maxRows,
34
+ maxRows = 1,
35
35
  onBlur,
36
- onChange,
36
+ onChange = () => {},
37
37
  onFocus,
38
38
  onSubmitEditing,
39
39
  placeholder,
40
40
  readOnly,
41
41
  returnKeyType,
42
- rightAdornments,
42
+ rightAdornments = [],
43
43
  showCharacterCount,
44
44
  style,
45
45
  type,
46
- value,
47
- variant
46
+ value = null,
47
+ variant = 'white'
48
48
  },
49
49
  ref
50
50
  ) => {
@@ -54,6 +54,7 @@ const UTBaseInputField = forwardRef(
54
54
 
55
55
  const theme = useTheme();
56
56
  const multiline = maxRows > 1;
57
+ const hasCharactersCount = showCharacterCount && maxLength && !disabled && !readOnly;
57
58
 
58
59
  const { secureTextEntry, autoCapitalize, keyboardType } = getPropsByType(type);
59
60
 
@@ -205,7 +206,7 @@ const UTBaseInputField = forwardRef(
205
206
  />
206
207
  {rightAdornments.map(renderElement)}
207
208
  </View>
208
- {maxLength && showCharacterCount && (
209
+ {hasCharactersCount && (
209
210
  <View style={textLengthRowStyle}>
210
211
  <UTLabel colorTheme="gray" variant="small">
211
212
  {value?.length || 0}/{maxLength}
@@ -218,7 +219,40 @@ const UTBaseInputField = forwardRef(
218
219
  );
219
220
 
220
221
  UTBaseInputField.displayName = 'UTBaseInputField';
221
- UTBaseInputField.defaultProps = defaultProps;
222
- UTBaseInputField.propTypes = propTypes;
222
+
223
+ UTBaseInputField.propTypes = {
224
+ alwaysShowPlaceholder: bool,
225
+ blurOnSubmit: bool,
226
+ disabled: bool,
227
+ editable: bool,
228
+ error: oneOfType([bool, string]),
229
+ id: oneOfType([number, string]),
230
+ value: oneOfType([string, number]),
231
+ onChange: func,
232
+ inputSize: string,
233
+ leftAdornments: arrayOf(shape({ name: string.isRequired, props: shape({}) })),
234
+ maxLength: number,
235
+ maxRows: number,
236
+ onBlur: func,
237
+ onFocus: func,
238
+ onSubmitEditing: func,
239
+ placeholder: string,
240
+ readOnly: bool,
241
+ returnKeyType: string,
242
+ rightAdornments: arrayOf(
243
+ shape({
244
+ name: string.isRequired,
245
+ props: shape({})
246
+ })
247
+ ),
248
+ showCharacterCount: bool,
249
+ style: shape({
250
+ container: object,
251
+ input: object,
252
+ root: object
253
+ }),
254
+ type: string,
255
+ variant: string
256
+ };
223
257
 
224
258
  export default UTBaseInputField;
@@ -39,6 +39,7 @@ const COLORS = {
39
39
  TEXT: {
40
40
  CURSOR: theme => theme.Palette.accent['04'],
41
41
  INPUT: theme => theme.Palette.dark['05'],
42
+ DISABLED_INPUT: theme => theme.Palette.gray['04'],
42
43
  PLACEHOLDER: theme => theme.Palette.gray['02'],
43
44
  SELECTION: theme => theme.Palette.accent['02']
44
45
  }
@@ -124,7 +125,10 @@ const conditionalContainerStyle = (disabled, error, focused, inputSize, readOnly
124
125
  })
125
126
  });
126
127
 
127
- const conditionalInputStyle = (maxRows, multiline) => ({
128
+ const conditionalInputStyle = (disabled, maxRows, multiline, theme) => ({
129
+ ...(disabled && {
130
+ color: COLORS.TEXT.DISABLED_INPUT(theme)
131
+ }),
128
132
  ...(multiline && {
129
133
  height: maxRows * LINE_HEIGHT,
130
134
  textAlignVertical: 'top'
@@ -154,7 +158,7 @@ export const retrieveStyle = ({
154
158
  const inputStyle = {
155
159
  root: {
156
160
  ...baseTheme.input.root,
157
- ...conditionalInputStyle(maxRows, multiline),
161
+ ...conditionalInputStyle(disabled, maxRows, multiline, theme),
158
162
  ...style.input
159
163
  },
160
164
  cursorColor: baseTheme.input.cursorColor,
@@ -1,11 +1,2 @@
1
- export const INPUT_TYPE = {
2
- NUMERIC: 'numeric',
3
- PASSWORD: 'password',
4
- PASSWORD_NUMERIC: 'password_numeric',
5
- TEXT: 'text'
6
- };
7
-
8
- export const KEYBOARD_TYPE_NUMERIC = 'numeric';
9
-
10
1
  export const ICON_EYE = 'IconEye';
11
2
  export const ICON_EYE_OFF = 'IconEyeOff';
@@ -1,11 +1,12 @@
1
1
  import React, { useState } from 'react';
2
2
 
3
- import { propTypes, defaultProps } from '../../../UTTextInput/versions/V1/proptypes';
3
+ import { propTypes as textInputPropTypes } from '../../../UTTextInput/versions/V1';
4
+ import { TYPES } from '../../../UTBaseInputField/constants';
4
5
  import UTTextInput from '../../../UTTextInput';
5
6
 
6
- import { ICON_EYE, ICON_EYE_OFF, INPUT_TYPE, KEYBOARD_TYPE_NUMERIC } from './constants';
7
+ import { ICON_EYE, ICON_EYE_OFF } from './constants';
7
8
 
8
- const UTPasswordField = ({ keyboardType, ...props }) => {
9
+ const UTPasswordField = ({ type, ...props }) => {
9
10
  const [isPasswordVisible, setIsPasswordVisible] = useState(false);
10
11
 
11
12
  const toggleVisibility = () => setIsPasswordVisible(!isPasswordVisible);
@@ -16,17 +17,14 @@ const UTPasswordField = ({ keyboardType, ...props }) => {
16
17
  };
17
18
 
18
19
  const textInputType = isPasswordVisible
19
- ? keyboardType === KEYBOARD_TYPE_NUMERIC
20
- ? INPUT_TYPE.NUMERIC
21
- : INPUT_TYPE.TEXT
22
- : keyboardType === KEYBOARD_TYPE_NUMERIC
23
- ? INPUT_TYPE.PASSWORD_NUMERIC
24
- : INPUT_TYPE.PASSWORD;
20
+ ? type
21
+ : type === TYPES.NUMERIC
22
+ ? TYPES.PASSWORD_NUMERIC
23
+ : TYPES.PASSWORD;
25
24
 
26
25
  return <UTTextInput {...props} action={action} type={textInputType} version="V1" />;
27
26
  };
28
27
 
29
- UTPasswordField.defaultProps = defaultProps;
30
- UTPasswordField.propTypes = propTypes;
28
+ UTPasswordField.propTypes = textInputPropTypes;
31
29
 
32
30
  export default UTPasswordField;
@@ -2,16 +2,17 @@
2
2
 
3
3
  ## Description
4
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.
5
+ `UTTextArea` is a multi-line text input component that extends `UTTextInput`. It is pre-configured to handle multiple rows of text and automatically displays the character count.
6
6
 
7
7
  ## Props
8
8
 
9
- `UTTextArea` inherits all the props from `UTTextInput` and adds an additional prop specific to the number of rows.
9
+ `UTTextArea` inherits all the props from `UTTextInput` and predefines some of them for convenience.
10
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`. |
11
+ | Name | Type | Default | Description |
12
+ | ------------------ | ------ | ------- | ----------------------------------------------------------------- |
13
+ | maxRows | number | 4 | The number of rows the text area will display. |
14
+ | showCharacterCount | bool | true | Whether to display the character count. Always `true` by default. |
15
+ | ... | ... | ... | Inherits all other props from `UTTextInput`. |
15
16
 
16
17
  ## Usage
17
18
 
@@ -1,16 +1,10 @@
1
1
  import React from 'react';
2
2
 
3
3
  import UTTextInput from '../UTTextInput';
4
- import { propTypes } from '../UTTextInput/versions/V1/proptypes';
4
+ import { propTypes as TextInputPropTypes } from '../UTTextInput/versions/V1';
5
5
 
6
- import { DEFAULT_PROPS } from './constants';
6
+ const UTTextArea = props => <UTTextInput showCharacterCount maxRows={4} version="V1" {...props} />;
7
7
 
8
- const UTTextArea = ({ maxRows, ...props }) => (
9
- <UTTextInput showCharacterCount maxRows={maxRows} version="V1" {...props} />
10
- );
11
-
12
- UTTextArea.defaultProps = DEFAULT_PROPS;
13
-
14
- UTTextArea.propTypes = propTypes;
8
+ UTTextArea.propTypes = TextInputPropTypes;
15
9
 
16
10
  export default UTTextArea;
@@ -9,63 +9,65 @@
9
9
  | Name | Type | Default | Description |
10
10
  | --------------------- | --------------------------------------------------------- | --------- | -------------------------------------------------------------------------------------------------------- |
11
11
  | action | object | | Action button configuration object. |
12
- | alwaysShowPlaceholder | bool | false | Whether to always show the placeholder. |
12
+ | alwaysShowPlaceholder | bool | false | Whether to always show the placeholder, even when the field is focused. |
13
+ | blurOnSubmit | bool | false | Whether the input should lose focus after submitting. |
13
14
  | disabled | bool | false | Disables the input field. |
14
- | error | string | | Error message to be displayed. |
15
+ | error | string | | Error message to be displayed below the input field. |
15
16
  | helpText | string | | Help text to be displayed below the input field. |
16
17
  | id | oneOfType([number, string]) | | Unique identifier for the input field. |
17
- | inputRef | func | | Reference to the input field. |
18
+ | inputRef | oneOfType([func, instanceOf(Object)]) | | Reference to the input field to access methods like `focus`, `blur`, or `clear`. |
18
19
  | inputSize | string | 'large' | Size of the input field. One of: `small`, `large`. |
19
20
  | title | string | | Title text for the input field. |
20
- | titleVariant | string | 'large' | Variant of the title. |
21
+ | titleVariant | string | 'large' | Variant of the title. Either `small` or `large`. |
21
22
  | LeftIcon | elementType | | Icon to be displayed on the left side of the input field. |
22
- | maxCount | number | | Maximum number of characters allowed in the input field. |
23
+ | maxLength | number | | Maximum number of characters allowed in the input field. |
23
24
  | maxRows | number | 1 | Maximum number of rows allowed in the input field. |
24
25
  | onBlur | func | | Function to call when the input field loses focus. |
25
26
  | onChange | func | | Function to call when the input field value changes. |
26
27
  | onFocus | func | | Function to call when the input field gains focus. |
27
- | onSubmitEditing | func | | Function to call when the input field is submitted. |
28
+ | onSubmitEditing | func | | Function to call when the input field is submitted (e.g., pressing Enter on a keyboard). |
28
29
  | placeholder | string | | Placeholder text for the input field. |
29
- | prefix | string | | Prefix text to be displayed inside the input field. |
30
+ | prefix | string | | Prefix text to be displayed inside the input field before the entered value. |
30
31
  | 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. |
32
+ | required | bool | false | Marks the input field as required. |
33
+ | returnKeyType | string | 'done' | Determines the return key type on the keyboard (e.g., `done`, `next`). |
33
34
  | RightIcon | elementType | | Icon to be displayed on the right side of the input field. |
35
+ | showCharacterCount | bool | false | Whether the character count should be displayed (if `maxLength` is defined). |
34
36
  | 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. |
39
- | value | string | '' | The value of the input field. |
37
+ | suffix | string | | Suffix text to be displayed inside the input field after the entered value. |
38
+ | tooltip | string | | Tooltip text to be displayed next to the input field. |
39
+ | type | string | 'default' | Type of input field (e.g., 'text', 'password', 'email', 'numeric'). |
40
+ | validations | validationDataProptypes | | Array of validation rules to be applied to the input field. |
41
+ | value | string | '' | The current value of the input field. |
40
42
 
41
43
  ### action
42
44
 
43
- Configuration object for the action button.
45
+ The `action` object allows configuring the action button that appears inside the input field, such as a clear or submit icon.
44
46
 
45
- | Name | Type | Description |
46
- | ---------- | ----------- | --------------------------------------------------- |
47
- | icon | elementType | Icon to be displayed in the action button. |
48
- | onPress | func | Function to call when the action button is pressed. |
49
- | colorTheme | string | Color theme of the action button. |
50
- | text | string | Text to be displayed in the action button. |
47
+ | Name | Type | Description |
48
+ | ---------- | ----------- | ------------------------------------------------------ |
49
+ | icon | elementType | Icon to be displayed in the action button. |
50
+ | onPress | func | Function called when the action button is pressed. |
51
+ | colorTheme | string | Color theme of the action button. |
52
+ | text | string | Text to be displayed inside the action button, if any. |
51
53
 
52
54
  ### titleVariant
53
55
 
54
- It must be one of these:
56
+ The value of `titleVariant` must be one of the following:
55
57
 
56
- - "small": small
57
- - "large": large
58
+ - "small"
59
+ - "large"
58
60
 
59
61
  ### inputSize
60
62
 
61
- It must be one of these:
63
+ The value of `inputSize` must be one of the following:
62
64
 
63
- - "small": small
64
- - "large": large
65
+ - "small"
66
+ - "large"
65
67
 
66
68
  ### type
67
69
 
68
- It must be one of these:
70
+ The value of `type` must be one of the following:
69
71
 
70
72
  - "default"
71
73
  - "email"
@@ -96,134 +98,8 @@ If a RightIcon is provided and an error occurs, the RightIcon will be replaced b
96
98
 
97
99
  ### Structure of validations
98
100
 
99
- 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".
100
-
101
- #### Example structure:
102
-
103
- ```jsx
104
- const validationData = [
105
- {
106
- items: [
107
- {
108
- status: 'success',
109
- text: 'Must be at least 8 characters long.'
110
- }
111
- ]
112
- },
113
- {
114
- items: [
115
- {
116
- status: 'error',
117
- text: 'Must be at most 16 characters long.'
118
- }
119
- ]
120
- },
121
- {
122
- title: 'Must meet at least one of the following conditions:',
123
- status: 'error',
124
- items: [
125
- {
126
- text: 'At least one lowercase letter.'
127
- },
128
- {
129
- text: 'At least one uppercase letter.'
130
- },
131
- {
132
- status: 'success',
133
- text: 'At least one number.'
134
- }
135
- ]
136
- }
137
- ];
138
- ```
101
+ For detailed information about the structure of validations, please refer to the UTValidation component documentation.
139
102
 
140
103
  ### Handling Errors
141
104
 
142
105
  Errors can be displayed below the input field using either the `error` prop or the `validations` prop.
143
-
144
- - **error**: A string that represents a general error message.
145
- - **validations**: An array of validation rules, where each rule is an object containing a `status` and a `text`.
146
-
147
- If both `error` and `validations` are provided, `validations` will take precedence, and its messages will be displayed.
148
-
149
- #### Example usage with `error`:
150
-
151
- ```jsx
152
- <UTTextInput title="Username" placeholder="Enter your username" error="This username is already taken" />
153
- ```
154
-
155
- #### Example usage with validations:
156
-
157
- ```jsx
158
- const validations = [
159
- {
160
- items: [
161
- {
162
- status: 'success',
163
- text: 'Must be at least 8 characters long.'
164
- }
165
- ]
166
- },
167
- {
168
- items: [
169
- {
170
- status: 'error',
171
- text: 'Must be at most 16 characters long.'
172
- }
173
- ]
174
- },
175
- {
176
- title: 'Must meet at least one of the following conditions:',
177
- status: 'error',
178
- items: [
179
- {
180
- text: 'At least one lowercase letter.'
181
- },
182
- {
183
- text: 'At least one uppercase letter.'
184
- },
185
- {
186
- status: 'success',
187
- text: 'At least one number.'
188
- }
189
- ]
190
- }
191
- ];
192
-
193
- <UTTextInput title="Email" placeholder="Enter your email" validations={validations} />;
194
- ```
195
-
196
- ## Usage
197
-
198
- ```jsx
199
- <UTTextInput
200
- title="Password"
201
- placeholder="Enter your password"
202
- type="password"
203
- required
204
- onChange={text => console.log(text)}
205
- validations={[
206
- {
207
- title: 'Must meet at least two of the following conditions:',
208
- items: [
209
- {
210
- text: 'At least one lowercase letter.'
211
- },
212
- {
213
- text: 'At least one uppercase letter.'
214
- },
215
- {
216
- status: 'success',
217
- text: 'At least one number.'
218
- }
219
- ]
220
- }
221
- ]}
222
- style={{
223
- root: { padding: 5 },
224
- container: { margin: 10 },
225
- input: { borderColor: 'blue' },
226
- action: { backgroundColor: 'green' }
227
- }}
228
- />
229
- ```
@@ -1,13 +1,13 @@
1
1
  import React, { useMemo } from 'react';
2
+ import { bool, elementType, func, instanceOf, number, object, oneOfType, shape, string } from 'prop-types';
2
3
  import { View } from 'react-native';
3
4
 
4
5
  import { formatErrorToValidation } from '../../../UTValidation/utils';
6
+ import { TITLE_VARIANTS } from '../../../../constants/inputs';
5
7
  import UTFieldLabel from '../../../UTFieldLabel';
6
8
  import UTLabel from '../../../UTLabel';
7
- import UTValidation from '../../../UTValidation';
9
+ import UTValidation, { validationDataProptypes } from '../../../UTValidation';
8
10
 
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
 
@@ -20,14 +20,12 @@ const UTTextInput = ({
20
20
  helpText,
21
21
  id,
22
22
  inputRef,
23
- inputSize,
24
- title,
25
- titleVariant,
23
+ inputSize = 'large',
26
24
  LeftIcon,
27
25
  maxLength,
28
- maxRows,
26
+ maxRows = 1,
29
27
  onBlur,
30
- onChange,
28
+ onChange = () => {},
31
29
  onFocus,
32
30
  onSubmitEditing,
33
31
  placeholder,
@@ -37,15 +35,16 @@ const UTTextInput = ({
37
35
  returnKeyType,
38
36
  RightIcon,
39
37
  showCharacterCount,
40
- style,
38
+ style = {},
41
39
  suffix,
40
+ title,
41
+ titleVariant = 'large',
42
42
  tooltip,
43
43
  type,
44
44
  validations,
45
- value
45
+ value = null
46
46
  }) => {
47
47
  const titleColorTheme = readOnly ? 'gray' : 'dark';
48
- const titleComponentVariant = titleVariant === SIZES.SMALL ? 'small' : 'body';
49
48
 
50
49
  const validationData = useMemo(
51
50
  () => validations || (error && formatErrorToValidation(error)),
@@ -55,7 +54,7 @@ const UTTextInput = ({
55
54
  return (
56
55
  <View style={[styles.container, style.root]}>
57
56
  {title && (
58
- <UTFieldLabel colorTheme={titleColorTheme} required={required} variant={titleComponentVariant}>
57
+ <UTFieldLabel colorTheme={titleColorTheme} required={required} variant={TITLE_VARIANTS[titleVariant]}>
59
58
  {title}
60
59
  </UTFieldLabel>
61
60
  )}
@@ -97,7 +96,49 @@ const UTTextInput = ({
97
96
  );
98
97
  };
99
98
 
100
- UTTextInput.defaultProps = defaultProps;
99
+ export const propTypes = {
100
+ action: shape({
101
+ action: func,
102
+ colorTheme: string,
103
+ icon: elementType,
104
+ text: string
105
+ }),
106
+ alwaysShowPlaceholder: bool,
107
+ blurOnSubmit: bool,
108
+ disabled: bool,
109
+ error: string,
110
+ helpText: string,
111
+ id: oneOfType([number, string]),
112
+ inputRef: oneOfType([func, instanceOf(Object)]),
113
+ inputSize: string,
114
+ LeftIcon: elementType,
115
+ maxLength: number,
116
+ maxRows: number,
117
+ onBlur: func,
118
+ onChange: func,
119
+ onFocus: func,
120
+ onSubmitEditing: func,
121
+ placeholder: string,
122
+ prefix: string,
123
+ readOnly: bool,
124
+ required: bool,
125
+ returnKeyType: string,
126
+ RightIcon: elementType,
127
+ showCharacterCount: bool,
128
+ style: shape({
129
+ container: object,
130
+ input: object,
131
+ root: object
132
+ }),
133
+ suffix: string,
134
+ title: string,
135
+ titleVariant: string,
136
+ tooltip: string,
137
+ type: string,
138
+ validations: validationDataProptypes,
139
+ value: string
140
+ };
141
+
101
142
  UTTextInput.propTypes = propTypes;
102
143
 
103
144
  export default UTTextInput;
@@ -18,10 +18,10 @@ The `validationData` prop is an array of objects, each representing a validation
18
18
  ### Structure of validationData
19
19
 
20
20
  - **title** (optional): A string that represents the title of the validation group.
21
- - **status** (required): A string indicating the status of the validation group. Possible values are `success`, `error`, and `default`.
21
+ - **status** (optional): A string indicating the status of the validation group. Possible values are `success`, `error`, and `default`. If not provided, it defaults to `default`.
22
22
  - **items** (required): An array of objects, each representing an individual validation item.
23
23
  - **text** (required): A string containing the validation message.
24
- - **status** (required): A string indicating the status of the validation item. Possible values are `success`, `error`, and `default`.
24
+ - **status** (optional): A string indicating the status of the validation item. Possible values are `success`, `error`, and `default`. If not provided, it defaults to `default`.
25
25
  - **withIcon** (optional): A boolean indicating whether to display an icon next to the validation message. Defaults to `true`.
26
26
 
27
27
  ### Example
@@ -32,24 +32,24 @@ const validationData = [
32
32
  items: [
33
33
  {
34
34
  status: 'success',
35
- text: 'Debe tener como mínimo 8 caracteres.',
35
+ text: 'Must be at least 8 characters long.',
36
36
  withIcon: true // Optional, defaults to true
37
37
  }
38
38
  ]
39
39
  },
40
40
  {
41
- title: 'Debe cumplir con al menos 2 de las siguientes condiciones:',
41
+ title: 'Must meet at least 2 of the following conditions:',
42
42
  status: 'error',
43
43
  items: [
44
44
  {
45
- text: 'Al menos 1 letra minúscula.' // Defaults to "default" and "withIcon" to true
45
+ text: 'At least 1 lowercase letter.' // Defaults to "default" and "withIcon" to true
46
46
  },
47
47
  {
48
- text: 'Al menos 1 letra mayúscula.' // Defaults to "default" and "withIcon" to true
48
+ text: 'At least 1 uppercase letter.' // Defaults to "default" and "withIcon" to true
49
49
  },
50
50
  {
51
51
  status: 'success',
52
- text: 'Al menos 1 número.',
52
+ text: 'At least 1 number.',
53
53
  withIcon: false // Will not display an icon
54
54
  }
55
55
  ]
@@ -66,9 +66,3 @@ The `status` prop can be one of these values:
66
66
  - `default`
67
67
 
68
68
  If `status` is not provided, it defaults to `default`.
69
-
70
- ## Usage
71
-
72
- ```javascript
73
- <UTValidation validationData={validationData} />
74
- ```
@@ -1,5 +1,3 @@
1
- import { arrayOf, shape, string } from 'prop-types';
2
-
3
1
  export const STATUSES = {
4
2
  success: 'success',
5
3
  error: 'error',
@@ -26,20 +24,3 @@ export const ICON_MAPPER = {
26
24
  export const STATUSES_WITH_ICON = [STATUSES.success, STATUSES.error];
27
25
 
28
26
  export const ICON_SIZE = 15;
29
-
30
- export const DEFAULT_PROPS = {
31
- validationData: {}
32
- };
33
-
34
- export const validationDataProptypes = arrayOf(
35
- shape({
36
- items: arrayOf(
37
- shape({
38
- text: string,
39
- status: string
40
- })
41
- ),
42
- status: string,
43
- title: string
44
- })
45
- );
@@ -1,26 +1,18 @@
1
1
  import React from 'react';
2
+ import { arrayOf, bool, object, shape, string } from 'prop-types';
2
3
  import { isEmpty } from 'lodash';
3
4
  import { View } from 'react-native';
4
- import { object } from 'prop-types';
5
5
 
6
6
  import { useTheme } from '../../theming';
7
7
  import UTIcon from '../UTIcon';
8
8
  import UTLabel from '../UTLabel';
9
9
 
10
- import {
11
- DEFAULT_PROPS,
12
- ICON_MAPPER,
13
- ICON_SIZE,
14
- STATUS_COLOR_MAPPER,
15
- STATUSES_WITH_ICON,
16
- STATUSES,
17
- validationDataProptypes
18
- } from './constants';
10
+ import { ICON_MAPPER, ICON_SIZE, STATUS_COLOR_MAPPER, STATUSES_WITH_ICON, STATUSES } from './constants';
19
11
  import { retrieveStyle } from './theme';
20
12
  import styles from './styles';
21
13
  import { generateItemKey, generateKey } from './utils';
22
14
 
23
- const UTValidation = ({ style, validationData }) => {
15
+ const UTValidation = ({ style, validationData = [] }) => {
24
16
  const theme = useTheme();
25
17
 
26
18
  if (isEmpty(validationData)) return null;
@@ -63,7 +55,19 @@ const UTValidation = ({ style, validationData }) => {
63
55
  );
64
56
  };
65
57
 
66
- UTValidation.defaultProps = DEFAULT_PROPS;
58
+ export const validationDataProptypes = arrayOf(
59
+ shape({
60
+ items: arrayOf(
61
+ shape({
62
+ text: string,
63
+ status: string,
64
+ withIcon: bool
65
+ })
66
+ ),
67
+ status: string,
68
+ title: string
69
+ })
70
+ );
67
71
 
68
72
  UTValidation.propTypes = {
69
73
  style: object,
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@widergy/mobile-ui",
3
3
  "description": "Widergy Mobile Components",
4
4
  "author": "widergy",
5
- "version": "1.29.0",
5
+ "version": "1.29.1",
6
6
  "repository": "https://github.com/widergy/mobile-ui.git",
7
7
  "main": "lib/index.js",
8
8
  "files": [
@@ -1,20 +0,0 @@
1
- import { shape, string, elementType, bool, oneOfType } from 'prop-types';
2
- import { TextPropTypes } from 'deprecated-react-native-prop-types';
3
-
4
- export const propTypes = {
5
- changeOnError: bool,
6
- changeOnFocus: bool,
7
- colorTheme: string,
8
- error: oneOfType([bool, string]),
9
- focused: bool,
10
- Icon: elementType,
11
- inputStyle: shape({
12
- root: TextPropTypes.style
13
- }),
14
- shade: string
15
- };
16
-
17
- export const defaultProps = {
18
- changeOnError: false,
19
- changeOnFocus: false
20
- };
@@ -1,50 +0,0 @@
1
- import { arrayOf, bool, func, number, object, oneOfType, shape, string } from 'prop-types';
2
-
3
- import { VARIANT, SIZES } from './constants';
4
-
5
- export const defaultProps = {
6
- alwaysShowPlaceholder: false,
7
- editable: true,
8
- inputSize: SIZES.LARGE,
9
- leftAdornments: [],
10
- maxRows: 1,
11
- onChange: () => {},
12
- rightAdornments: [],
13
- value: null,
14
- variant: VARIANT.WHITE
15
- };
16
-
17
- export const propTypes = {
18
- alwaysShowPlaceholder: bool,
19
- blurOnSubmit: bool,
20
- disabled: bool,
21
- editable: bool,
22
- error: oneOfType([bool, string]),
23
- id: oneOfType([number, string]),
24
- value: oneOfType([string, number]),
25
- onChange: func,
26
- inputSize: string,
27
- leftAdornments: arrayOf(shape({ name: string.isRequired, props: shape({}) })),
28
- maxLength: number,
29
- maxRows: number,
30
- onBlur: func,
31
- onFocus: func,
32
- onSubmitEditing: func,
33
- placeholder: string,
34
- readOnly: bool,
35
- returnKeyType: string,
36
- rightAdornments: arrayOf(
37
- shape({
38
- name: string.isRequired,
39
- props: shape({})
40
- })
41
- ),
42
- showCharacterCount: bool,
43
- style: shape({
44
- container: object,
45
- input: object,
46
- root: object
47
- }),
48
- type: string,
49
- variant: string
50
- };
@@ -1,3 +0,0 @@
1
- const DEFAULT_MAX_ROWS = 4;
2
-
3
- export const DEFAULT_PROPS = { maxRows: DEFAULT_MAX_ROWS };
@@ -1,4 +0,0 @@
1
- export const SIZES = {
2
- SMALL: 'small',
3
- LARGE: 'large'
4
- };
@@ -1,58 +0,0 @@
1
- import { bool, elementType, func, instanceOf, number, object, oneOfType, shape, string } from 'prop-types';
2
-
3
- import { validationDataProptypes } from '../../../UTValidation/constants';
4
-
5
- import { SIZES } from './constants';
6
-
7
- export const defaultProps = {
8
- inputSize: SIZES.LARGE,
9
- maxRows: 1,
10
- onChange: () => {},
11
- style: {},
12
- titleVariant: SIZES.LARGE,
13
- value: null
14
- };
15
-
16
- export const propTypes = {
17
- action: shape({
18
- action: func,
19
- colorTheme: string,
20
- icon: elementType,
21
- text: string
22
- }),
23
- alwaysShowPlaceholder: bool,
24
- blurOnSubmit: bool,
25
- disabled: bool,
26
- error: string,
27
- helpText: string,
28
- id: oneOfType([number, string]),
29
- inputRef: oneOfType([func, instanceOf(Object)]),
30
- inputSize: string,
31
- keyboardType: string,
32
- LeftIcon: elementType,
33
- maxLength: number,
34
- maxRows: number,
35
- onBlur: func,
36
- onChange: func,
37
- onFocus: func,
38
- onSubmitEditing: func,
39
- placeholder: string,
40
- prefix: string,
41
- readOnly: bool,
42
- required: bool,
43
- returnKeyType: string,
44
- RightIcon: elementType,
45
- showCharacterCount: bool,
46
- style: shape({
47
- container: object,
48
- input: object,
49
- root: object
50
- }),
51
- suffix: string,
52
- title: string,
53
- titleVariant: string,
54
- tooltip: string,
55
- type: string,
56
- validations: validationDataProptypes,
57
- value: string
58
- };