From cd66f79518229d7ccad8312f530c7bc7189073b1 Mon Sep 17 00:00:00 2001 From: adids1221 Date: Wed, 4 Sep 2024 16:09:42 +0300 Subject: [PATCH] Picker dailog validation --- src/components/picker/PickerItemsList.tsx | 6 +- .../picker/helpers/usePickerDialogProps.tsx | 67 +++++++++++++++++++ .../picker/helpers/usePickerSelection.tsx | 55 +++++++++++++-- src/components/picker/index.tsx | 46 +++++++------ src/components/picker/types.ts | 26 ++++++- 5 files changed, 172 insertions(+), 28 deletions(-) create mode 100644 src/components/picker/helpers/usePickerDialogProps.tsx diff --git a/src/components/picker/PickerItemsList.tsx b/src/components/picker/PickerItemsList.tsx index 26db3b6e97..c3ba9a22ba 100644 --- a/src/components/picker/PickerItemsList.tsx +++ b/src/components/picker/PickerItemsList.tsx @@ -32,7 +32,8 @@ const PickerItemsList = (props: PickerItemsListProps) => { useSafeArea, useDialog, mode, - testID + testID, + migrateDialog } = props; const context = useContext(PickerContext); @@ -138,7 +139,8 @@ const PickerItemsList = (props: PickerItemsListProps) => { ); - } else if (!useDialog || mode === PickerModes.MULTI) { + //} else if (!migrateDialog && (!useDialog || mode === PickerModes.MULTI)) { + } else if (!migrateDialog && (!useDialog || mode === PickerModes.MULTI)) { return ; } }; diff --git a/src/components/picker/helpers/usePickerDialogProps.tsx b/src/components/picker/helpers/usePickerDialogProps.tsx new file mode 100644 index 0000000000..a8158f8d91 --- /dev/null +++ b/src/components/picker/helpers/usePickerDialogProps.tsx @@ -0,0 +1,67 @@ +import React from 'react'; +import {StyleSheet} from 'react-native'; +import {PickerProps, PickerModes} from '../types'; +import Button from '../../button'; +import {Colors} from '../../../style'; + +const DIALOG_PROPS = { + bottom: true, + width: '100%', + height: 250 +}; + +const NEW_DIALOG_PROPS = { + bottom: true, + useSafeArea: true, + height: '60%', + width: '95%' +}; + +type HookProps = PickerProps & { + shouldDisableDoneButton?: boolean; +}; + +const usePickerDialogProps = (props: HookProps, onDone: any) => { + const {customPickerProps, mode, testID, selectionOptions, shouldDisableDoneButton} = props; + const migrateDialog = customPickerProps?.migrateDialog; + const defaultProps = migrateDialog ? NEW_DIALOG_PROPS : DIALOG_PROPS; + const {validationMessage, validationMessageStyle} = selectionOptions || {}; + + console.log(`shouldDisableDoneButton?`, shouldDisableDoneButton); + + const modifiedHeaderProps = migrateDialog && { + headerProps: { + trailingAccessory: ( +