|
1 | 1 | import {useEffect} from 'react';
|
2 |
| -import _ from 'lodash'; |
3 | 2 | import {LogService} from '../../../services';
|
4 |
| -import {PickerProps, PickerModes} from '../types'; |
| 3 | +import {PickerProps} from '../types'; |
5 | 4 |
|
6 |
| -// @ts-expect-error TODO: Remove this whole file when migration is completed |
7 |
| -type UsePickerMigrationWarnings = Pick<PickerProps, 'value' | 'mode' | 'useNativePicker'>; |
| 5 | +// TODO: Remove this whole file when migration is completed |
| 6 | +type UsePickerMigrationWarnings = Pick< |
| 7 | + PickerProps, |
| 8 | + 'children' | 'migrate' | 'getItemLabel' | 'getItemValue' | 'onShow' |
| 9 | +>; |
8 | 10 |
|
9 | 11 | const usePickerMigrationWarnings = (props: UsePickerMigrationWarnings) => {
|
10 |
| - const {value, mode, useNativePicker} = props; |
| 12 | + const {children, migrate, getItemLabel, getItemValue, onShow} = props; |
11 | 13 | useEffect(() => {
|
12 |
| - if (mode === PickerModes.SINGLE && Array.isArray(value)) { |
13 |
| - LogService.warn('Picker in SINGLE mode cannot accept an array for value'); |
| 14 | + if (children) { |
| 15 | + LogService.warn(`UILib Picker will stop supporting the 'children' prop in the next major version, please pass 'items' prop instead`); |
14 | 16 | }
|
15 |
| - if (mode === PickerModes.MULTI && !Array.isArray(value)) { |
16 |
| - LogService.warn('Picker in MULTI mode must accept an array for value'); |
| 17 | + |
| 18 | + if (migrate) { |
| 19 | + LogService.warn(`UILib Picker will stop supporting the 'migrate' prop in the next major version, please stop using it. The picker uses the new implementation by default.`); |
| 20 | + } |
| 21 | + |
| 22 | + if (getItemLabel) { |
| 23 | + LogService.warn(`UILib Picker will stop supporting the 'getItemLabel' prop in the next major version, please pass the 'getItemLabel' prop to the specific item instead`); |
17 | 24 | }
|
18 | 25 |
|
19 |
| - if (_.isPlainObject(value)) { |
20 |
| - LogService.warn('UILib Picker will stop supporting passing object as value in the next major version. Please use either string or a number as value'); |
| 26 | + if (getItemValue) { |
| 27 | + LogService.warn(`UILib Picker will stop supporting the 'getItemValue' prop in the next major version, please stop using it. The value will be extract from 'items' prop instead`); |
21 | 28 | }
|
22 | 29 |
|
23 |
| - if (useNativePicker) { |
24 |
| - LogService.warn(`UILib Picker will stop supporting the 'useNativePicker' prop soon, please pass instead the 'useWheelPicker' prop and handle relevant TextField migration if required to`); |
| 30 | + if (onShow) { |
| 31 | + LogService.warn(`UILib Picker will stop supporting the 'onShow' prop in the next major version, please pass the 'onShow' prop from the 'pickerModalProps' instead`); |
25 | 32 | }
|
26 | 33 | }, []);
|
27 | 34 | };
|
|
0 commit comments