From ee21567ba25a1c01ec75128962697678999715ad Mon Sep 17 00:00:00 2001 From: Adi Mordo Date: Sun, 19 Jan 2025 16:54:49 +0200 Subject: [PATCH 1/6] Feat/picker custom top element (#3465) * Picker types - customTopElement, onItemSelection * add customTopElement support in Picker component * PickerScreen example * refactor: rename customTopElement, types fix * remove onItemSelection prop * remove unused setValue from Picker context * use optional chaining for renderCustomTopElement * renderCustomTopElement added to api.json --- .../screens/componentScreens/PickerScreen.tsx | 46 ++++++++++++++++++- src/components/picker/PickerItemsList.tsx | 4 +- src/components/picker/api/picker.api.json | 5 ++ src/components/picker/index.tsx | 2 + src/components/picker/types.ts | 5 ++ 5 files changed, 60 insertions(+), 2 deletions(-) diff --git a/demo/src/screens/componentScreens/PickerScreen.tsx b/demo/src/screens/componentScreens/PickerScreen.tsx index 4a2c20fa0d..fa7459bffa 100644 --- a/demo/src/screens/componentScreens/PickerScreen.tsx +++ b/demo/src/screens/componentScreens/PickerScreen.tsx @@ -83,6 +83,15 @@ const dialogOptions = [ {label: 'Option 8', value: 6} ]; +const statusOptions = [ + {label: 'Overview', value: 'overview'}, + {label: 'In Progress', value: 'inProgress'}, + {label: 'Completed', value: 'completed'}, + {label: 'Pending Review', value: 'pendingReview'}, + {label: 'Approved', value: 'approved'}, + {label: 'Rejected', value: 'rejected'} +]; + export default class PickerScreen extends Component { picker = React.createRef(); state = { @@ -96,6 +105,7 @@ export default class PickerScreen extends Component { dialogPickerValue: 'java', customModalValues: [], filter: undefined, + statOption: [], scheme: undefined, contact: 0 }; @@ -122,6 +132,15 @@ export default class PickerScreen extends Component { ); }; + onTopElementPress = (allOptionsSelected: boolean) => { + if (allOptionsSelected) { + this.setState({statOption: []}); + } else { + const allValues = statusOptions.map(option => option.value); + this.setState({statOption: allValues}); + } + }; + render() { return ( @@ -195,7 +214,32 @@ export default class PickerScreen extends Component { searchPlaceholder={'Search a language'} items={dialogOptions} /> - + + + Custom Top Element: + + this.setState({statOption: items})} + topBarProps={{title: 'Status'}} + mode={Picker.modes.MULTI} + items={statusOptions} + renderCustomTopElement={value => { + const allOptionsSelected = Array.isArray(value) && value.length === statusOptions.length; + return ( + +