@widergy/mobile-ui 1.4.5 → 1.5.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 CHANGED
@@ -1,3 +1,17 @@
1
+ # [1.5.0](https://github.com/widergy/mobile-ui/compare/v1.4.6...v1.5.0) (2024-04-25)
2
+
3
+
4
+ ### Features
5
+
6
+ * added labelBackgroundColor prop for autocomplete ([#279](https://github.com/widergy/mobile-ui/issues/279)) ([293bba9](https://github.com/widergy/mobile-ui/commit/293bba930ae4d18c94a401b642ff9c8d2a316e4f))
7
+
8
+ ## [1.4.6](https://github.com/widergy/mobile-ui/compare/v1.4.5...v1.4.6) (2024-04-22)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * allow autocomplete custom behaviour ([#273](https://github.com/widergy/mobile-ui/issues/273)) ([775faf0](https://github.com/widergy/mobile-ui/commit/775faf02c9ed0f184a150d735735dd0a40cd8753))
14
+
1
15
  ## [1.4.5](https://github.com/widergy/mobile-ui/compare/v1.4.4...v1.4.5) (2024-04-22)
2
16
 
3
17
 
@@ -1,4 +1,4 @@
1
- import { arrayOf, bool, func, oneOf, shape, string } from 'prop-types';
1
+ import { arrayOf, bool, element, func, oneOf, shape, string } from 'prop-types';
2
2
  import React, { useMemo } from 'react';
3
3
  import { View } from 'react-native';
4
4
 
@@ -8,9 +8,20 @@ import UTTextInput from '../UTTextInput';
8
8
 
9
9
  import styles from './styles';
10
10
 
11
- const UTAutocomplete = ({ input, options, disabled, label, error, variant, autoCompletePlaceholder }) => {
11
+ const UTAutocomplete = ({
12
+ input,
13
+ options,
14
+ disabled,
15
+ label,
16
+ labelBackgroundColor,
17
+ error,
18
+ variant,
19
+ autoCompletePlaceholder,
20
+ MenuOptionComponent,
21
+ filterOptions
22
+ }) => {
12
23
  const selectedOption = useMemo(
13
- () => options.find(option => option.value === input.value),
24
+ () => options?.find(option => option.value === input.value),
14
25
  [options, input.value]
15
26
  );
16
27
 
@@ -29,14 +40,18 @@ const UTAutocomplete = ({ input, options, disabled, label, error, variant, autoC
29
40
  onOpen={input.onFocus}
30
41
  onClose={input.onBlur}
31
42
  disabled={disabled}
43
+ onQueryChange={input.onQueryChange}
32
44
  autoCompletePlaceholder={autoCompletePlaceholder}
33
45
  maxHeight={WINDOW_HEIGHT * 0.25}
46
+ MenuOptionComponent={MenuOptionComponent}
47
+ filterOptions={filterOptions}
34
48
  >
35
49
  <UTTextInput
36
50
  variant={variant}
37
51
  value={selectedOption?.label}
38
52
  error={error}
39
53
  label={label}
54
+ labelBackgroundColor={labelBackgroundColor}
40
55
  RightIcon={{ type: 'font-awesome', name: 'caret-down' }}
41
56
  onChange={() => {}}
42
57
  disabled={disabled}
@@ -62,9 +77,12 @@ UTAutocomplete.propTypes = {
62
77
  ),
63
78
  disabled: bool,
64
79
  label: string,
80
+ labelBackgroundColor: string,
65
81
  error: oneOf([bool, string]),
66
82
  variant: string,
67
- autoCompletePlaceholder: string
83
+ autoCompletePlaceholder: string,
84
+ MenuOptionComponent: element,
85
+ filterOptions: bool
68
86
  };
69
87
 
70
88
  export default UTAutocomplete;
@@ -27,6 +27,8 @@ const UTMenu = ({
27
27
  maxHeight,
28
28
  isMultiple,
29
29
  autoCompletePlaceholder,
30
+ onQueryChange,
31
+ filterOptions = true,
30
32
  withAutocomplete
31
33
  }) => {
32
34
  const [isOpen, setIsOpen] = useState(false);
@@ -37,10 +39,11 @@ const UTMenu = ({
37
39
  const [menuDimentions, setMenuDimentions] = useState({ width: 0, height: 0 });
38
40
  const [query, setQuery] = useState('');
39
41
  const searchTextInputRef = useRef();
40
- const filteredOptions = useMemo(
41
- () => options.filter(option => !query || option.label.toUpperCase().includes(query.toUpperCase())),
42
- [query, options]
43
- );
42
+ const filteredOptions = useMemo(() => {
43
+ return filterOptions
44
+ ? options.filter(option => !query || option.label.toUpperCase().includes(query.toUpperCase()))
45
+ : options;
46
+ }, [query, options, filterOptions]);
44
47
 
45
48
  const { height: windowHeight, width: windowWidth } = Dimensions.get('window');
46
49
 
@@ -97,6 +100,11 @@ const UTMenu = ({
97
100
 
98
101
  const focusSearchInput = () => withAutocomplete && searchTextInputRef.current?.focus();
99
102
 
103
+ const handleQueryChange = value => {
104
+ setQuery(value);
105
+ onQueryChange(value);
106
+ };
107
+
100
108
  return (
101
109
  <>
102
110
  <TouchableOpacity
@@ -129,7 +137,7 @@ const UTMenu = ({
129
137
  <UTTextInput
130
138
  InputRef={searchTextInputRef}
131
139
  value={query}
132
- onChange={setQuery}
140
+ onChange={handleQueryChange}
133
141
  placeholder={autoCompletePlaceholder}
134
142
  onSubmitEditing={
135
143
  query && filteredOptions[0]
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.4.5",
5
+ "version": "1.5.0",
6
6
  "repository": "https://github.com/widergy/mobile-ui.git",
7
7
  "main": "lib/index.js",
8
8
  "files": [