react-native-ui-lib 7.38.0-snapshot.6221 → 7.38.0-snapshot.6240
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/package.json +1 -1
- package/src/components/index.js +0 -3
- package/src/components/picker/PickerItemsList.js +3 -1
- package/src/components/picker/helpers/usePickerDialogProps.d.ts +17 -0
- package/src/components/picker/helpers/usePickerDialogProps.js +49 -0
- package/src/components/picker/helpers/usePickerSelection.d.ts +2 -1
- package/src/components/picker/helpers/usePickerSelection.js +40 -4
- package/src/components/picker/index.js +22 -13
- package/src/components/picker/types.d.ts +18 -2
- package/src/index.d.ts +0 -1
- package/src/index.js +0 -35
- package/searchInput.d.ts +0 -2
- package/searchInput.js +0 -1
- package/src/components/searchInput/index.d.ts +0 -39
- package/src/components/searchInput/index.js +0 -220
- package/src/components/searchInput/searchInput.api.json +0 -60
- package/src/components/searchInput/types.d.ts +0 -70
- package/src/components/searchInput/types.js +0 -5
package/package.json
CHANGED
package/src/components/index.js
CHANGED
|
@@ -137,9 +137,6 @@ export default {
|
|
|
137
137
|
get ProgressiveImage() {
|
|
138
138
|
return require('./progressiveImage').default;
|
|
139
139
|
},
|
|
140
|
-
get SearchInput() {
|
|
141
|
-
return require('./searchInput').default;
|
|
142
|
-
},
|
|
143
140
|
get StateScreen() {
|
|
144
141
|
return require('./stateScreen').default;
|
|
145
142
|
},
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _isUndefined from "lodash/isUndefined";
|
|
1
2
|
import _times from "lodash/times";
|
|
2
3
|
import _throttle from "lodash/throttle";
|
|
3
4
|
import _isFunction from "lodash/isFunction";
|
|
@@ -33,6 +34,7 @@ const PickerItemsList = props => {
|
|
|
33
34
|
useDialog,
|
|
34
35
|
mode,
|
|
35
36
|
testID,
|
|
37
|
+
selectionValidation,
|
|
36
38
|
showLoader,
|
|
37
39
|
customLoaderElement,
|
|
38
40
|
renderCustomTopElement
|
|
@@ -116,7 +118,7 @@ const PickerItemsList = props => {
|
|
|
116
118
|
{doneLabel ?? 'Select'}
|
|
117
119
|
</Text>
|
|
118
120
|
</View>;
|
|
119
|
-
} else if (!useDialog || mode === PickerModes.MULTI) {
|
|
121
|
+
} else if (_isUndefined(selectionValidation) && (!useDialog || mode === PickerModes.MULTI)) {
|
|
120
122
|
return <Modal.TopBar testID={`${props.testID}.topBar`} {...topBarProps} />;
|
|
121
123
|
}
|
|
122
124
|
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { PickerProps } from '../types';
|
|
3
|
+
type HookProps = PickerProps & {
|
|
4
|
+
shouldDisableDoneButton?: boolean;
|
|
5
|
+
};
|
|
6
|
+
declare const usePickerDialogProps: (props: HookProps, onDone: any) => import("../../touchableOpacity").TouchableOpacityProps & import("../../../incubator/dialog/types")._DialogPropsOld & {
|
|
7
|
+
expandableContent?: React.ReactElement<any, string | React.JSXElementConstructor<any>> | undefined;
|
|
8
|
+
useDialog?: boolean | undefined;
|
|
9
|
+
modalProps?: import("../../modal").ModalProps | undefined;
|
|
10
|
+
showTopBar?: boolean | undefined;
|
|
11
|
+
topBarProps?: import("../../modal").ModalTopBarProps | undefined;
|
|
12
|
+
renderCustomOverlay?: ((props: import("../../../incubator/expandableOverlay").RenderCustomOverlayProps) => React.ReactElement<any, string | React.JSXElementConstructor<any>> | null | undefined) | undefined;
|
|
13
|
+
disabled?: boolean | undefined;
|
|
14
|
+
} & {
|
|
15
|
+
children?: React.ReactNode;
|
|
16
|
+
};
|
|
17
|
+
export default usePickerDialogProps;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { StyleSheet } from 'react-native';
|
|
3
|
+
import { PickerModes } from "../types";
|
|
4
|
+
import Button from "../../button";
|
|
5
|
+
import { Colors } from "../../../style";
|
|
6
|
+
const DIALOG_PROPS = {
|
|
7
|
+
bottom: true,
|
|
8
|
+
width: '100%',
|
|
9
|
+
useSafeArea: true
|
|
10
|
+
};
|
|
11
|
+
const usePickerDialogProps = (props, onDone) => {
|
|
12
|
+
const {
|
|
13
|
+
customPickerProps,
|
|
14
|
+
mode,
|
|
15
|
+
testID,
|
|
16
|
+
selectionOptions,
|
|
17
|
+
shouldDisableDoneButton
|
|
18
|
+
} = props;
|
|
19
|
+
const migrateDialog = customPickerProps?.migrateDialog;
|
|
20
|
+
const defaultProps = DIALOG_PROPS;
|
|
21
|
+
const {
|
|
22
|
+
validationMessage,
|
|
23
|
+
validationMessageStyle
|
|
24
|
+
} = selectionOptions || {};
|
|
25
|
+
const modifiedHeaderProps = migrateDialog && validationMessage && {
|
|
26
|
+
headerProps: {
|
|
27
|
+
trailingAccessory: validationMessage && <Button label="Save" link style={{
|
|
28
|
+
height: 30
|
|
29
|
+
}} onPress={mode === PickerModes.MULTI ? onDone : undefined} testID={`${testID}.dialog.header.save`} disabled={!shouldDisableDoneButton} />,
|
|
30
|
+
subtitle: !shouldDisableDoneButton && validationMessage,
|
|
31
|
+
subtitleStyle: [styles.validationMessage, validationMessageStyle],
|
|
32
|
+
...customPickerProps?.dialogProps?.headerProps
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const dialogProps = {
|
|
36
|
+
dialogProps: {
|
|
37
|
+
...defaultProps,
|
|
38
|
+
...customPickerProps?.dialogProps,
|
|
39
|
+
...modifiedHeaderProps
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
return dialogProps;
|
|
43
|
+
};
|
|
44
|
+
export default usePickerDialogProps;
|
|
45
|
+
const styles = StyleSheet.create({
|
|
46
|
+
validationMessage: {
|
|
47
|
+
color: Colors.red30
|
|
48
|
+
}
|
|
49
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { RefObject } from 'react';
|
|
2
2
|
import { PickerProps, PickerValue, PickerSingleValue, PickerMultiValue } from '../types';
|
|
3
|
-
interface UsePickerSelectionProps extends Pick<PickerProps, 'migrate' | 'value' | 'onChange' | 'getItemValue' | 'topBarProps' | 'mode'> {
|
|
3
|
+
interface UsePickerSelectionProps extends Pick<PickerProps, 'migrate' | 'value' | 'onChange' | 'getItemValue' | 'topBarProps' | 'mode' | 'selectionValidation' | 'selectionOptions' | 'useDialog'> {
|
|
4
4
|
pickerExpandableRef: RefObject<any>;
|
|
5
5
|
setSearchValue: (searchValue: string) => void;
|
|
6
6
|
}
|
|
@@ -9,5 +9,6 @@ declare const usePickerSelection: (props: UsePickerSelectionProps) => {
|
|
|
9
9
|
onDoneSelecting: (item: PickerValue) => void;
|
|
10
10
|
toggleItemSelection: (item: PickerSingleValue) => void;
|
|
11
11
|
cancelSelect: () => void;
|
|
12
|
+
shouldDisableDoneButton: boolean | undefined;
|
|
12
13
|
};
|
|
13
14
|
export default usePickerSelection;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import _xor from "lodash/xor";
|
|
2
2
|
import _xorBy from "lodash/xorBy";
|
|
3
|
+
import _isFunction from "lodash/isFunction";
|
|
4
|
+
import _isUndefined from "lodash/isUndefined";
|
|
3
5
|
import { useCallback, useState, useEffect } from 'react';
|
|
4
6
|
import { PickerModes } from "../types";
|
|
5
7
|
const usePickerSelection = props => {
|
|
@@ -11,22 +13,54 @@ const usePickerSelection = props => {
|
|
|
11
13
|
pickerExpandableRef,
|
|
12
14
|
getItemValue,
|
|
13
15
|
setSearchValue,
|
|
14
|
-
mode
|
|
16
|
+
mode,
|
|
17
|
+
selectionValidation,
|
|
18
|
+
selectionOptions,
|
|
19
|
+
useDialog
|
|
15
20
|
} = props;
|
|
21
|
+
const {
|
|
22
|
+
onValidationFailed,
|
|
23
|
+
validateOnStart,
|
|
24
|
+
onChangeValidity
|
|
25
|
+
} = selectionOptions || {};
|
|
16
26
|
const [multiDraftValue, setMultiDraftValue] = useState(value);
|
|
17
27
|
const [multiFinalValue, setMultiFinalValue] = useState(value);
|
|
28
|
+
const [isValid, setIsValid] = useState(undefined);
|
|
29
|
+
const _selectionValidation = item => {
|
|
30
|
+
if (useDialog) {
|
|
31
|
+
const isValid = selectionValidation?.(item);
|
|
32
|
+
if (!isValid) {
|
|
33
|
+
onValidationFailed?.(item);
|
|
34
|
+
}
|
|
35
|
+
setIsValid(isValid);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
18
38
|
useEffect(() => {
|
|
19
39
|
if (mode === PickerModes.MULTI && multiFinalValue !== value) {
|
|
20
40
|
setMultiDraftValue(value);
|
|
21
41
|
setMultiFinalValue(value);
|
|
22
42
|
}
|
|
23
43
|
}, [value]);
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
if (_isUndefined(selectionValidation)) {
|
|
46
|
+
setIsValid(true);
|
|
47
|
+
} else if (_isFunction(selectionValidation) && validateOnStart) {
|
|
48
|
+
_selectionValidation?.(value);
|
|
49
|
+
} else {
|
|
50
|
+
setIsValid(false);
|
|
51
|
+
}
|
|
52
|
+
}, []);
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
if (isValid !== undefined) {
|
|
55
|
+
onChangeValidity?.(isValid);
|
|
56
|
+
}
|
|
57
|
+
}, [isValid]);
|
|
24
58
|
const onDoneSelecting = useCallback(item => {
|
|
25
59
|
setSearchValue('');
|
|
26
60
|
setMultiFinalValue(item);
|
|
27
61
|
pickerExpandableRef.current?.closeExpandable?.();
|
|
28
62
|
onChange?.(item);
|
|
29
|
-
}, [onChange]);
|
|
63
|
+
}, [onChange, useDialog, selectionValidation]);
|
|
30
64
|
const toggleItemSelection = useCallback(item => {
|
|
31
65
|
let newValue;
|
|
32
66
|
const itemAsArray = [item];
|
|
@@ -35,8 +69,9 @@ const usePickerSelection = props => {
|
|
|
35
69
|
} else {
|
|
36
70
|
newValue = _xor(multiDraftValue, itemAsArray);
|
|
37
71
|
}
|
|
72
|
+
_selectionValidation(newValue);
|
|
38
73
|
setMultiDraftValue(newValue);
|
|
39
|
-
}, [multiDraftValue, getItemValue]);
|
|
74
|
+
}, [multiDraftValue, getItemValue, useDialog, _selectionValidation]);
|
|
40
75
|
const cancelSelect = useCallback(() => {
|
|
41
76
|
setSearchValue('');
|
|
42
77
|
setMultiDraftValue(multiFinalValue);
|
|
@@ -47,7 +82,8 @@ const usePickerSelection = props => {
|
|
|
47
82
|
multiDraftValue,
|
|
48
83
|
onDoneSelecting,
|
|
49
84
|
toggleItemSelection,
|
|
50
|
-
cancelSelect
|
|
85
|
+
cancelSelect,
|
|
86
|
+
shouldDisableDoneButton: isValid
|
|
51
87
|
};
|
|
52
88
|
};
|
|
53
89
|
export default usePickerSelection;
|
|
@@ -10,19 +10,16 @@ import TextField from "../textField";
|
|
|
10
10
|
import PickerItemsList from "./PickerItemsList";
|
|
11
11
|
import PickerItem from "./PickerItem";
|
|
12
12
|
import PickerContext from "./PickerContext";
|
|
13
|
-
import
|
|
14
|
-
import usePickerLabel from "./helpers/usePickerLabel";
|
|
15
|
-
import usePickerSearch from "./helpers/usePickerSearch";
|
|
16
|
-
import useImperativePickerHandle from "./helpers/useImperativePickerHandle";
|
|
13
|
+
// import usePickerMigrationWarnings from './helpers/usePickerMigrationWarnings';
|
|
17
14
|
import useFieldType from "./helpers/useFieldType";
|
|
15
|
+
import useImperativePickerHandle from "./helpers/useImperativePickerHandle";
|
|
18
16
|
import useNewPickerProps from "./helpers/useNewPickerProps";
|
|
19
|
-
|
|
17
|
+
import usePickerDialogProps from "./helpers/usePickerDialogProps";
|
|
18
|
+
import usePickerLabel from "./helpers/usePickerLabel";
|
|
19
|
+
import usePickerSearch from "./helpers/usePickerSearch";
|
|
20
|
+
import usePickerSelection from "./helpers/usePickerSelection";
|
|
20
21
|
import { extractPickerItems } from "./PickerPresenter";
|
|
21
22
|
import { PickerProps, PickerItemProps, PickerValue, PickerModes, PickerFieldTypes, PickerSearchStyle, RenderCustomModalProps, PickerItemsListProps, PickerMethods } from "./types";
|
|
22
|
-
const DEFAULT_DIALOG_PROPS = {
|
|
23
|
-
bottom: true,
|
|
24
|
-
width: '100%'
|
|
25
|
-
};
|
|
26
23
|
const Picker = React.forwardRef((props, ref) => {
|
|
27
24
|
const themeProps = useThemeProps(props, 'Picker');
|
|
28
25
|
const {
|
|
@@ -55,6 +52,8 @@ const Picker = React.forwardRef((props, ref) => {
|
|
|
55
52
|
accessibilityLabel,
|
|
56
53
|
accessibilityHint,
|
|
57
54
|
items: propItems,
|
|
55
|
+
selectionValidation,
|
|
56
|
+
selectionOptions,
|
|
58
57
|
showLoader,
|
|
59
58
|
customLoaderElement,
|
|
60
59
|
renderCustomTopElement,
|
|
@@ -101,7 +100,8 @@ const Picker = React.forwardRef((props, ref) => {
|
|
|
101
100
|
multiDraftValue,
|
|
102
101
|
onDoneSelecting,
|
|
103
102
|
toggleItemSelection,
|
|
104
|
-
cancelSelect
|
|
103
|
+
cancelSelect,
|
|
104
|
+
shouldDisableDoneButton
|
|
105
105
|
} = usePickerSelection({
|
|
106
106
|
migrate,
|
|
107
107
|
value,
|
|
@@ -110,8 +110,17 @@ const Picker = React.forwardRef((props, ref) => {
|
|
|
110
110
|
getItemValue,
|
|
111
111
|
topBarProps,
|
|
112
112
|
setSearchValue,
|
|
113
|
-
mode
|
|
113
|
+
mode,
|
|
114
|
+
selectionValidation,
|
|
115
|
+
selectionOptions,
|
|
116
|
+
useDialog
|
|
114
117
|
});
|
|
118
|
+
const {
|
|
119
|
+
dialogProps = {}
|
|
120
|
+
} = usePickerDialogProps({
|
|
121
|
+
...themeProps,
|
|
122
|
+
shouldDisableDoneButton
|
|
123
|
+
}, () => onDoneSelecting(multiDraftValue));
|
|
115
124
|
const {
|
|
116
125
|
label,
|
|
117
126
|
accessibilityInfo
|
|
@@ -201,12 +210,12 @@ const Picker = React.forwardRef((props, ref) => {
|
|
|
201
210
|
...topBarProps,
|
|
202
211
|
onCancel: cancelSelect,
|
|
203
212
|
onDone: mode === PickerModes.MULTI ? () => onDoneSelecting(multiDraftValue) : undefined
|
|
204
|
-
}} showSearch={showSearch} searchStyle={searchStyle} searchPlaceholder={searchPlaceholder} onSearchChange={_onSearchChange} renderCustomSearch={renderCustomSearch} renderHeader={renderHeader} listProps={listProps} useSafeArea={useSafeArea} showLoader={showLoader} customLoaderElement={customLoaderElement} renderCustomTopElement={renderCustomTopElement}>
|
|
213
|
+
}} showSearch={showSearch} searchStyle={searchStyle} searchPlaceholder={searchPlaceholder} onSearchChange={_onSearchChange} renderCustomSearch={renderCustomSearch} renderHeader={renderHeader} listProps={listProps} useSafeArea={useSafeArea} selectionValidation={selectionValidation} showLoader={showLoader} customLoaderElement={customLoaderElement} renderCustomTopElement={renderCustomTopElement}>
|
|
205
214
|
{filteredItems}
|
|
206
215
|
</PickerItemsList>;
|
|
207
216
|
}, [testID, mode, useDialog, selectedItemPosition, topBarProps, cancelSelect, onDoneSelecting, multiDraftValue, showSearch, searchStyle, searchPlaceholder, _onSearchChange, renderCustomSearch, renderHeader, listProps, filteredItems, useSafeArea, useWheelPicker, items, showLoader]);
|
|
208
217
|
return <PickerContext.Provider value={contextValue}>
|
|
209
|
-
{<ExpandableOverlay ref={pickerExpandable} useDialog={useDialog || useWheelPicker}
|
|
218
|
+
{<ExpandableOverlay ref={pickerExpandable} useDialog={useDialog || useWheelPicker} migrateDialog expandableContent={expandableModalContent} renderCustomOverlay={renderOverlay ? _renderOverlay : undefined} onPress={onPress} testID={testID} {...customPickerProps} dialogProps={dialogProps} disabled={themeProps.editable === false}>
|
|
210
219
|
{renderTextField()}
|
|
211
220
|
</ExpandableOverlay>}
|
|
212
221
|
</PickerContext.Provider>;
|
|
@@ -147,7 +147,23 @@ type PickerExpandableOverlayProps = {
|
|
|
147
147
|
*/
|
|
148
148
|
enableModalBlur?: boolean;
|
|
149
149
|
};
|
|
150
|
-
|
|
150
|
+
type PickerSelectionOptions = Pick<TextFieldProps, 'validateOnStart' | 'onChangeValidity' | 'validationMessage' | 'validationMessageStyle'> & {
|
|
151
|
+
/**
|
|
152
|
+
* Callback for when field validated and failed
|
|
153
|
+
*/
|
|
154
|
+
onValidationFailed?: (value: PickerValue) => void;
|
|
155
|
+
};
|
|
156
|
+
type PickerSelectionValidation = {
|
|
157
|
+
/**
|
|
158
|
+
* Callback for when selection was made
|
|
159
|
+
*/
|
|
160
|
+
selectionValidation?: (value: PickerValue) => boolean;
|
|
161
|
+
/**
|
|
162
|
+
* Selection validation options
|
|
163
|
+
*/
|
|
164
|
+
selectionOptions?: PickerSelectionOptions;
|
|
165
|
+
};
|
|
166
|
+
export type PickerBaseProps = Omit<TextFieldProps, 'value' | 'onChange'> & PickerPropsDeprecation & PickerExpandableOverlayProps & PickerListProps & PickerSelectionValidation & {
|
|
151
167
|
/**
|
|
152
168
|
* Use dialog instead of modal picker
|
|
153
169
|
*/
|
|
@@ -287,7 +303,7 @@ export interface PickerContextProps extends Pick<PickerProps, 'migrate' | 'value
|
|
|
287
303
|
onSelectedLayout: (event: any) => any;
|
|
288
304
|
selectionLimit: PickerProps['selectionLimit'];
|
|
289
305
|
}
|
|
290
|
-
export type PickerItemsListProps = Pick<PropsWithChildren<PickerProps>, 'topBarProps' | 'listProps' | 'renderHeader' | 'useSafeArea' | 'showLoader' | 'customLoaderElement' | 'renderCustomTopElement' | 'showSearch' | 'searchStyle' | 'searchPlaceholder' | 'onSearchChange' | 'renderCustomSearch' | 'children' | 'useWheelPicker' | 'useDialog' | 'mode' | 'testID'> & {
|
|
306
|
+
export type PickerItemsListProps = Pick<PropsWithChildren<PickerProps>, 'topBarProps' | 'listProps' | 'renderHeader' | 'useSafeArea' | 'showLoader' | 'customLoaderElement' | 'renderCustomTopElement' | 'showSearch' | 'searchStyle' | 'searchPlaceholder' | 'onSearchChange' | 'renderCustomSearch' | 'children' | 'useWheelPicker' | 'selectionValidation' | 'useDialog' | 'mode' | 'testID'> & {
|
|
291
307
|
items?: {
|
|
292
308
|
value: any;
|
|
293
309
|
label: any;
|
package/src/index.d.ts
CHANGED
|
@@ -76,7 +76,6 @@ export { default as RadioGroup, RadioGroupProps } from './components/radioGroup'
|
|
|
76
76
|
export type { RecorderProps } from './typings/recorderTypes';
|
|
77
77
|
export type { ComponentStatics } from './typings/common';
|
|
78
78
|
export { default as ScrollBar, ScrollBarProps } from './components/scrollBar';
|
|
79
|
-
export { default as SearchInput, SearchInputProps, SearchInputRef, SearchInputPresets } from './components/searchInput';
|
|
80
79
|
export { default as SectionsWheelPicker, SectionsWheelPickerProps } from './components/sectionsWheelPicker';
|
|
81
80
|
export { default as SegmentedControl, SegmentedControlProps, SegmentedControlItemProps, SegmentedControlPreset } from './components/segmentedControl';
|
|
82
81
|
export { default as SharedTransition } from './components/sharedTransition';
|
package/src/index.js
CHANGED
|
@@ -178,10 +178,6 @@ var _exportNames = {
|
|
|
178
178
|
RadioGroupProps: true,
|
|
179
179
|
ScrollBar: true,
|
|
180
180
|
ScrollBarProps: true,
|
|
181
|
-
SearchInput: true,
|
|
182
|
-
SearchInputProps: true,
|
|
183
|
-
SearchInputRef: true,
|
|
184
|
-
SearchInputPresets: true,
|
|
185
181
|
SectionsWheelPicker: true,
|
|
186
182
|
SectionsWheelPickerProps: true,
|
|
187
183
|
SegmentedControl: true,
|
|
@@ -1210,30 +1206,6 @@ Object.defineProperty(exports, "ScrollBarProps", {
|
|
|
1210
1206
|
return _scrollBar().ScrollBarProps;
|
|
1211
1207
|
}
|
|
1212
1208
|
});
|
|
1213
|
-
Object.defineProperty(exports, "SearchInput", {
|
|
1214
|
-
enumerable: true,
|
|
1215
|
-
get: function () {
|
|
1216
|
-
return _searchInput().default;
|
|
1217
|
-
}
|
|
1218
|
-
});
|
|
1219
|
-
Object.defineProperty(exports, "SearchInputPresets", {
|
|
1220
|
-
enumerable: true,
|
|
1221
|
-
get: function () {
|
|
1222
|
-
return _searchInput().SearchInputPresets;
|
|
1223
|
-
}
|
|
1224
|
-
});
|
|
1225
|
-
Object.defineProperty(exports, "SearchInputProps", {
|
|
1226
|
-
enumerable: true,
|
|
1227
|
-
get: function () {
|
|
1228
|
-
return _searchInput().SearchInputProps;
|
|
1229
|
-
}
|
|
1230
|
-
});
|
|
1231
|
-
Object.defineProperty(exports, "SearchInputRef", {
|
|
1232
|
-
enumerable: true,
|
|
1233
|
-
get: function () {
|
|
1234
|
-
return _searchInput().SearchInputRef;
|
|
1235
|
-
}
|
|
1236
|
-
});
|
|
1237
1209
|
Object.defineProperty(exports, "SectionsWheelPicker", {
|
|
1238
1210
|
enumerable: true,
|
|
1239
1211
|
get: function () {
|
|
@@ -2221,13 +2193,6 @@ function _scrollBar() {
|
|
|
2221
2193
|
};
|
|
2222
2194
|
return data;
|
|
2223
2195
|
}
|
|
2224
|
-
function _searchInput() {
|
|
2225
|
-
const data = _interopRequireWildcard(require("./components/searchInput"));
|
|
2226
|
-
_searchInput = function () {
|
|
2227
|
-
return data;
|
|
2228
|
-
};
|
|
2229
|
-
return data;
|
|
2230
|
-
}
|
|
2231
2196
|
function _sectionsWheelPicker() {
|
|
2232
2197
|
const data = _interopRequireWildcard(require("./components/sectionsWheelPicker"));
|
|
2233
2198
|
_sectionsWheelPicker = function () {
|
package/searchInput.d.ts
DELETED
package/searchInput.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require('./src/components/searchInput').default;
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { SearchInputPresets, SearchInputProps, SearchInputRef } from './types';
|
|
3
|
-
declare const SearchInput: React.ForwardRefExoticComponent<import("react-native").TextInputProps & {
|
|
4
|
-
onClear?: (() => void) | undefined;
|
|
5
|
-
onDismiss?: (() => void) | undefined;
|
|
6
|
-
cancelButtonProps?: import("../button").ButtonProps | undefined;
|
|
7
|
-
renderCustomRightElement?: (() => React.ReactElement<any, string | React.JSXElementConstructor<any>>) | undefined;
|
|
8
|
-
title?: string | undefined;
|
|
9
|
-
showLoader?: boolean | undefined;
|
|
10
|
-
loaderProps?: import("react-native").ActivityIndicatorProps | undefined;
|
|
11
|
-
renderLoaderElement?: (() => React.ReactElement<any, string | React.JSXElementConstructor<any>>) | undefined;
|
|
12
|
-
invertColors?: boolean | undefined;
|
|
13
|
-
inaccessible?: boolean | undefined;
|
|
14
|
-
useSafeArea?: boolean | undefined;
|
|
15
|
-
style?: import("react-native").StyleProp<import("react-native").ViewStyle>;
|
|
16
|
-
containerStyle?: import("react-native").StyleProp<import("react-native").TextStyle | import("react-native").ViewStyle>;
|
|
17
|
-
preset?: "default" | "prominent" | SearchInputPresets | undefined;
|
|
18
|
-
} & React.RefAttributes<any>>;
|
|
19
|
-
interface StaticMembers {
|
|
20
|
-
presets: typeof SearchInputPresets;
|
|
21
|
-
}
|
|
22
|
-
export { SearchInput, SearchInputProps, SearchInputRef, SearchInputPresets };
|
|
23
|
-
declare const _default: React.ForwardRefExoticComponent<import("react-native").TextInputProps & {
|
|
24
|
-
onClear?: (() => void) | undefined;
|
|
25
|
-
onDismiss?: (() => void) | undefined;
|
|
26
|
-
cancelButtonProps?: import("../button").ButtonProps | undefined;
|
|
27
|
-
renderCustomRightElement?: (() => React.ReactElement<any, string | React.JSXElementConstructor<any>>) | undefined;
|
|
28
|
-
title?: string | undefined;
|
|
29
|
-
showLoader?: boolean | undefined;
|
|
30
|
-
loaderProps?: import("react-native").ActivityIndicatorProps | undefined;
|
|
31
|
-
renderLoaderElement?: (() => React.ReactElement<any, string | React.JSXElementConstructor<any>>) | undefined;
|
|
32
|
-
invertColors?: boolean | undefined;
|
|
33
|
-
inaccessible?: boolean | undefined;
|
|
34
|
-
useSafeArea?: boolean | undefined;
|
|
35
|
-
style?: import("react-native").StyleProp<import("react-native").ViewStyle>;
|
|
36
|
-
containerStyle?: import("react-native").StyleProp<import("react-native").TextStyle | import("react-native").ViewStyle>;
|
|
37
|
-
preset?: "default" | "prominent" | SearchInputPresets | undefined;
|
|
38
|
-
} & React.RefAttributes<any>> & StaticMembers;
|
|
39
|
-
export default _default;
|
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
import _isEmpty from "lodash/isEmpty";
|
|
2
|
-
import React, { useImperativeHandle, forwardRef, useEffect, useRef, useState } from 'react';
|
|
3
|
-
import { StyleSheet, Animated, TextInput, ActivityIndicator } from 'react-native';
|
|
4
|
-
import { SearchInputPresets, SearchInputProps, SearchInputRef } from "./types";
|
|
5
|
-
import { Colors, BorderRadiuses, Spacings, Typography } from "../../style";
|
|
6
|
-
import { Constants, asBaseComponent } from "../../commons/new";
|
|
7
|
-
import Button from "../button";
|
|
8
|
-
import Icon from "../icon";
|
|
9
|
-
import View from "../view";
|
|
10
|
-
import Assets from "../../assets";
|
|
11
|
-
const ICON_SIZE = 24;
|
|
12
|
-
const INPUT_HEIGHT = 60;
|
|
13
|
-
const TOP_INPUT_HEIGHT = Constants.isIOS ? 40 : 56;
|
|
14
|
-
const PROMINENT_INPUT_HEIGHT = 48;
|
|
15
|
-
const INVERTED_TEXT_COLOR = Colors.$textDefaultLight;
|
|
16
|
-
const INVERTED_ICON_COLOR = Colors.$iconDefaultLight;
|
|
17
|
-
const HIT_SLOP_VALUE = 20;
|
|
18
|
-
const SearchInput = forwardRef((props, ref) => {
|
|
19
|
-
const {
|
|
20
|
-
preset = SearchInputPresets.DEFAULT,
|
|
21
|
-
onDismiss,
|
|
22
|
-
useSafeArea,
|
|
23
|
-
invertColors,
|
|
24
|
-
testID,
|
|
25
|
-
showLoader,
|
|
26
|
-
loaderProps,
|
|
27
|
-
value: controlledValue,
|
|
28
|
-
onChangeText,
|
|
29
|
-
onClear,
|
|
30
|
-
containerStyle,
|
|
31
|
-
renderCustomRightElement,
|
|
32
|
-
style,
|
|
33
|
-
inaccessible
|
|
34
|
-
} = props;
|
|
35
|
-
const currentAnimatedValue = useRef();
|
|
36
|
-
const searchInputRef = useRef(null);
|
|
37
|
-
const [hasValue, setHasValue] = useState(Boolean(controlledValue));
|
|
38
|
-
const [value, setValue] = useState(controlledValue);
|
|
39
|
-
const [valueState] = useState(new Animated.Value(_isEmpty(controlledValue) ? 0 : 1));
|
|
40
|
-
const [isAnimatingClearButton, setIsAnimatingClearButton] = useState(!_isEmpty(controlledValue));
|
|
41
|
-
useImperativeHandle(ref, () => {
|
|
42
|
-
return {
|
|
43
|
-
blur: () => searchInputRef.current?.blur(),
|
|
44
|
-
focus: () => searchInputRef.current?.focus(),
|
|
45
|
-
clear: () => {
|
|
46
|
-
searchInputRef.current?.clear();
|
|
47
|
-
onChangeText?.('');
|
|
48
|
-
onClear?.();
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
});
|
|
52
|
-
useEffect(() => {
|
|
53
|
-
if (controlledValue !== value) {
|
|
54
|
-
setValue(controlledValue);
|
|
55
|
-
setHasValue(Boolean(controlledValue));
|
|
56
|
-
}
|
|
57
|
-
}, [controlledValue]);
|
|
58
|
-
useEffect(() => {
|
|
59
|
-
if (hasValue) {
|
|
60
|
-
animatedValueState(1);
|
|
61
|
-
} else {
|
|
62
|
-
animatedValueState(0);
|
|
63
|
-
}
|
|
64
|
-
}, [hasValue]);
|
|
65
|
-
useEffect(() => {
|
|
66
|
-
return () => {
|
|
67
|
-
currentAnimatedValue.current?.stop();
|
|
68
|
-
};
|
|
69
|
-
}, []);
|
|
70
|
-
const animatedValueState = value => {
|
|
71
|
-
setIsAnimatingClearButton(true);
|
|
72
|
-
if (currentAnimatedValue.current) {
|
|
73
|
-
currentAnimatedValue.current.stop();
|
|
74
|
-
}
|
|
75
|
-
currentAnimatedValue.current = Animated.timing(valueState, {
|
|
76
|
-
toValue: value,
|
|
77
|
-
duration: 160,
|
|
78
|
-
useNativeDriver: true
|
|
79
|
-
});
|
|
80
|
-
currentAnimatedValue.current.start(() => {
|
|
81
|
-
if (!hasValue) {
|
|
82
|
-
setIsAnimatingClearButton(false);
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
};
|
|
86
|
-
const getHeight = () => {
|
|
87
|
-
const isProminent = preset === SearchInputPresets.PROMINENT;
|
|
88
|
-
if (isProminent) {
|
|
89
|
-
return PROMINENT_INPUT_HEIGHT;
|
|
90
|
-
}
|
|
91
|
-
return useSafeArea ? TOP_INPUT_HEIGHT : INPUT_HEIGHT;
|
|
92
|
-
};
|
|
93
|
-
const onChangeTextHandler = text => {
|
|
94
|
-
console.log(`onChangeTextHandler, text:`, text);
|
|
95
|
-
onChangeText?.(text);
|
|
96
|
-
setValue(text);
|
|
97
|
-
setHasValue(!_isEmpty(text));
|
|
98
|
-
};
|
|
99
|
-
const clearInput = () => {
|
|
100
|
-
searchInputRef?.current?.clear();
|
|
101
|
-
onChangeTextHandler('');
|
|
102
|
-
onClear?.();
|
|
103
|
-
};
|
|
104
|
-
const renderClearButton = () => {
|
|
105
|
-
const transform = [{
|
|
106
|
-
translateY: valueState.interpolate({
|
|
107
|
-
inputRange: [0, 1],
|
|
108
|
-
outputRange: [50, 1]
|
|
109
|
-
})
|
|
110
|
-
}];
|
|
111
|
-
const clearButtonStyle = !isDismissible() && isAnimatingClearButton && styles.clearButton;
|
|
112
|
-
const iconStyle = {
|
|
113
|
-
tintColor: invertColors ? INVERTED_ICON_COLOR : Colors.grey40,
|
|
114
|
-
width: 12,
|
|
115
|
-
height: 12
|
|
116
|
-
};
|
|
117
|
-
return <Animated.View style={[{
|
|
118
|
-
transform
|
|
119
|
-
}, clearButtonStyle]}>
|
|
120
|
-
<Button link grey10 text80 iconSource={Assets.icons.x} iconStyle={iconStyle} onPress={clearInput} hitSlop={HIT_SLOP_VALUE} accessible={Boolean(hasValue)} accessibilityLabel={'clear'} testID={`${testID}.clearButton`} />
|
|
121
|
-
</Animated.View>;
|
|
122
|
-
};
|
|
123
|
-
const renderCancelButton = () => {
|
|
124
|
-
const {
|
|
125
|
-
cancelButtonProps
|
|
126
|
-
} = props;
|
|
127
|
-
if (onDismiss) {
|
|
128
|
-
return <Button style={styles.cancelButton} link color={invertColors ? INVERTED_TEXT_COLOR : undefined} $textDefault text65M {...cancelButtonProps} onPress={onDismiss} testID={`${testID}.cancelButton`} />;
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
const renderTextInput = () => {
|
|
132
|
-
const {
|
|
133
|
-
placeholder
|
|
134
|
-
} = props;
|
|
135
|
-
const height = getHeight();
|
|
136
|
-
const placeholderTextColor = invertColors ? INVERTED_TEXT_COLOR : Colors.$textDefault;
|
|
137
|
-
const selectionColor = invertColors ? INVERTED_TEXT_COLOR : Colors.$textDefault;
|
|
138
|
-
return <View style={[styles.inputContainer, {
|
|
139
|
-
height
|
|
140
|
-
}]}>
|
|
141
|
-
<TextInput accessibilityRole={'search'} placeholder={placeholder} placeholderTextColor={placeholderTextColor} underlineColorAndroid="transparent" selectionColor={selectionColor} ref={searchInputRef} value={value} allowFontScaling={false} style={[styles.input, containerStyle, invertColors && {
|
|
142
|
-
color: INVERTED_TEXT_COLOR
|
|
143
|
-
}, (!isDismissible() || isAnimatingClearButton) && styles.emptyInput]} onChangeText={onChangeTextHandler} testID={testID} />
|
|
144
|
-
{isAnimatingClearButton && renderClearButton()}
|
|
145
|
-
{isDismissible() && renderCancelButton()}
|
|
146
|
-
{!isDismissible() && renderCustomRightElement && renderCustomRightElement()}
|
|
147
|
-
</View>;
|
|
148
|
-
};
|
|
149
|
-
const isDismissible = () => {
|
|
150
|
-
return typeof onDismiss !== 'undefined';
|
|
151
|
-
};
|
|
152
|
-
const renderIcon = (icon, left = true) => {
|
|
153
|
-
const invertedColor = invertColors ? {
|
|
154
|
-
tintColor: INVERTED_ICON_COLOR
|
|
155
|
-
} : undefined;
|
|
156
|
-
return <View>
|
|
157
|
-
<Icon tintColor={invertedColor?.tintColor} style={[styles.icon, invertedColor, left && styles.leftIcon]} source={icon} size={ICON_SIZE} />
|
|
158
|
-
</View>;
|
|
159
|
-
};
|
|
160
|
-
const renderLoader = () => {
|
|
161
|
-
const {
|
|
162
|
-
renderLoaderElement
|
|
163
|
-
} = props;
|
|
164
|
-
return <View>
|
|
165
|
-
{renderLoaderElement ? renderLoaderElement() : <ActivityIndicator style={styles.loader} {...loaderProps} />}
|
|
166
|
-
</View>;
|
|
167
|
-
};
|
|
168
|
-
const topInputTopMargin = useSafeArea && {
|
|
169
|
-
marginTop: Constants.isIOS ? Constants.statusBarHeight : 0
|
|
170
|
-
};
|
|
171
|
-
const isProminent = preset === SearchInputPresets.PROMINENT;
|
|
172
|
-
return <View inaccessible={inaccessible} row centerV style={[style, isProminent && styles.prominentContainer, topInputTopMargin]} testID={`${testID}.searchBox`}>
|
|
173
|
-
{showLoader ? renderLoader() : renderIcon(Assets.icons.search)}
|
|
174
|
-
{renderTextInput()}
|
|
175
|
-
</View>;
|
|
176
|
-
});
|
|
177
|
-
const styles = StyleSheet.create({
|
|
178
|
-
inputContainer: {
|
|
179
|
-
height: INPUT_HEIGHT,
|
|
180
|
-
flex: 1,
|
|
181
|
-
flexDirection: 'row',
|
|
182
|
-
alignItems: 'center',
|
|
183
|
-
overflow: 'hidden'
|
|
184
|
-
},
|
|
185
|
-
prominentContainer: {
|
|
186
|
-
borderWidth: 1,
|
|
187
|
-
borderColor: Colors.$outlineDefault,
|
|
188
|
-
borderRadius: BorderRadiuses.br20,
|
|
189
|
-
marginHorizontal: Spacings.s5
|
|
190
|
-
},
|
|
191
|
-
input: {
|
|
192
|
-
flex: 1,
|
|
193
|
-
...Typography.body,
|
|
194
|
-
lineHeight: undefined,
|
|
195
|
-
color: Colors.$textDefault,
|
|
196
|
-
textAlign: Constants.isRTL ? 'right' : 'left'
|
|
197
|
-
},
|
|
198
|
-
emptyInput: {
|
|
199
|
-
marginRight: Spacings.s4
|
|
200
|
-
},
|
|
201
|
-
cancelButton: {
|
|
202
|
-
marginLeft: Spacings.s4,
|
|
203
|
-
marginRight: Spacings.s4
|
|
204
|
-
},
|
|
205
|
-
clearButton: {
|
|
206
|
-
marginRight: Spacings.s4
|
|
207
|
-
},
|
|
208
|
-
icon: {
|
|
209
|
-
marginRight: Spacings.s4
|
|
210
|
-
},
|
|
211
|
-
leftIcon: {
|
|
212
|
-
marginLeft: Spacings.s4
|
|
213
|
-
},
|
|
214
|
-
loader: {
|
|
215
|
-
marginHorizontal: Spacings.s4
|
|
216
|
-
}
|
|
217
|
-
});
|
|
218
|
-
SearchInput.displayName = 'SearchInput';
|
|
219
|
-
export { SearchInput, SearchInputProps, SearchInputRef, SearchInputPresets };
|
|
220
|
-
export default asBaseComponent(SearchInput);
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "SearchInput",
|
|
3
|
-
"category": "form",
|
|
4
|
-
"description": "Search input for filtering purpose",
|
|
5
|
-
"example": "https://github.com/wix-private/wix-react-native-ui-lib/blob/master/example/screens/components/SearchInputScreen.tsx",
|
|
6
|
-
"extends": ["TextInput"],
|
|
7
|
-
"extendsLink": "https://reactnative.dev/docs/textinput",
|
|
8
|
-
"props": [
|
|
9
|
-
{"name": "onDismiss", "type": "() => void", "description": "callback for dismiss action"},
|
|
10
|
-
{"name": "onClear", "type": "() => void", "description": "On clear button callback."},
|
|
11
|
-
{"name": "title", "type": "string", "description": "Title prop."},
|
|
12
|
-
{"name": "showFilterIcon", "type": "boolean", "description": "Pass true to add filter icon on the right."},
|
|
13
|
-
{
|
|
14
|
-
"name": "showLoader",
|
|
15
|
-
"type": "boolean",
|
|
16
|
-
"description": "Whether to show a loader instead of the left search icon."
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
"name": "renderLoaderElement",
|
|
20
|
-
"type": " () => React.ReactElement",
|
|
21
|
-
"description": "custom loader element to render instead of the default loader"
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
"name": "renderLoaderElement",
|
|
25
|
-
"type": " () => React.ReactElement",
|
|
26
|
-
"description": "custom loader element to render instead of the default loader"
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
"name": "cancelButtonProps",
|
|
30
|
-
"type": "ButtonProps",
|
|
31
|
-
"description": "Props for the cancel button"
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
"name": "schemeColor",
|
|
35
|
-
"type": "string | null",
|
|
36
|
-
"description": "The SearchInput colors (affects the search icon color, the filter icon color when 'showFilterIcon' is passed and the cancel button color)"
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
"name": "inaccessible",
|
|
40
|
-
"type": "boolean",
|
|
41
|
-
"description": "Turn off accessibility for this view and its nested children"
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
"name": "useSafeArea",
|
|
45
|
-
"type": "boolean",
|
|
46
|
-
"description": "in case the SearchInput is rendered in a safe area (top of the screen)"
|
|
47
|
-
},
|
|
48
|
-
{"name": "containerStyle", "type": "ViewStyle", "description": "Override styles for the input"},
|
|
49
|
-
{"name": "style", "type": "ViewStyle", "description": "Override styles for container"}
|
|
50
|
-
],
|
|
51
|
-
"snippet": [
|
|
52
|
-
"<SearchInput",
|
|
53
|
-
" ref={searchInputRef$1}",
|
|
54
|
-
" testID={'searchInput'$2}",
|
|
55
|
-
" placeholder={'Search'$3}",
|
|
56
|
-
" onDismiss={onDismiss$4}",
|
|
57
|
-
" showFilterIcon={showFilterIcon$5}",
|
|
58
|
-
"/>"
|
|
59
|
-
]
|
|
60
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { TextInputProps, StyleProp, ViewStyle, TextStyle, ActivityIndicatorProps } from 'react-native';
|
|
3
|
-
import { ButtonProps } from '../button';
|
|
4
|
-
export declare enum SearchInputPresets {
|
|
5
|
-
DEFAULT = "default",
|
|
6
|
-
PROMINENT = "prominent"
|
|
7
|
-
}
|
|
8
|
-
export interface SearchInputRef {
|
|
9
|
-
blur: () => void;
|
|
10
|
-
clear: () => void;
|
|
11
|
-
focus: () => void;
|
|
12
|
-
}
|
|
13
|
-
export type SearchInputProps = TextInputProps & {
|
|
14
|
-
/**
|
|
15
|
-
* On clear button callback.
|
|
16
|
-
*/
|
|
17
|
-
onClear?: () => void;
|
|
18
|
-
/**
|
|
19
|
-
* callback for dismiss action
|
|
20
|
-
*/
|
|
21
|
-
onDismiss?: () => void;
|
|
22
|
-
/**
|
|
23
|
-
* Props for the cancel button
|
|
24
|
-
*/
|
|
25
|
-
cancelButtonProps?: ButtonProps;
|
|
26
|
-
/**
|
|
27
|
-
* Custom right element
|
|
28
|
-
*/
|
|
29
|
-
renderCustomRightElement?: () => React.ReactElement;
|
|
30
|
-
/**
|
|
31
|
-
* Title prop
|
|
32
|
-
*/
|
|
33
|
-
title?: string;
|
|
34
|
-
/**
|
|
35
|
-
* Whether to show a loader instead of the left search icon
|
|
36
|
-
*/
|
|
37
|
-
showLoader?: boolean;
|
|
38
|
-
/**
|
|
39
|
-
* Loader props
|
|
40
|
-
*/
|
|
41
|
-
loaderProps?: ActivityIndicatorProps;
|
|
42
|
-
/**
|
|
43
|
-
* custom loader element
|
|
44
|
-
*/
|
|
45
|
-
renderLoaderElement?: () => React.ReactElement;
|
|
46
|
-
/**
|
|
47
|
-
* converts the colors of the search's input elements, icons and button to white
|
|
48
|
-
*/
|
|
49
|
-
invertColors?: boolean;
|
|
50
|
-
/**
|
|
51
|
-
* Turn off accessibility for this view and its nested children
|
|
52
|
-
*/
|
|
53
|
-
inaccessible?: boolean;
|
|
54
|
-
/**
|
|
55
|
-
* in case the SearchInput is rendered in a safe area (top of the screen)
|
|
56
|
-
*/
|
|
57
|
-
useSafeArea?: boolean;
|
|
58
|
-
/**
|
|
59
|
-
* Override styles for container
|
|
60
|
-
*/
|
|
61
|
-
style?: StyleProp<ViewStyle>;
|
|
62
|
-
/**
|
|
63
|
-
* Override styles for the input
|
|
64
|
-
*/
|
|
65
|
-
containerStyle?: StyleProp<ViewStyle | TextStyle>;
|
|
66
|
-
/**
|
|
67
|
-
* The preset for the search input: default or prominent
|
|
68
|
-
*/
|
|
69
|
-
preset?: SearchInputPresets | `${SearchInputPresets}`;
|
|
70
|
-
};
|