-
Notifications
You must be signed in to change notification settings - Fork 734
Picker selection control bar and toggle all items functionality #3557
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 11 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
3fe8e8d
Picker selection control bar and toggle all items functionality
adids1221 c0c0abd
Merge branch 'master' into feat/Picker_selection_control_bar
M-i-k-e-l 81ee794
Refactor PickerScreen layout
adids1221 fb6f149
Rename PickerSelectionControlBar to PickerSelectionStatusToolbar and …
adids1221 557cc54
Enhance selection status label functionality in PickerSelectionStatus…
adids1221 fa26403
Refactor PickerSelectionStatusToolbar and types for improved selectio…
adids1221 ed00693
Remove 'none' option from select all types in Picker and update relat…
adids1221 f589ba1
Fix types issue in PickerItemsList
adids1221 c612817
Refactor toggleAllItemsSelection and availableItems usage
adids1221 24e1569
Remove customLabel prop from PickerSelectionStatusProps
adids1221 a07a980
Add renderTopCustomElement and renderBottomCustomElement props to Pic…
adids1221 2b71bbb
Rename getLabel prop to getSelectionStatusLabe and update related usages
adids1221 a87e350
Refactor selectionStatus handling in PickerItemsList
adids1221 3c4dc79
Remove unnecessary null return in renderLabel
adids1221 23f0fec
Remove renderTopCustomElement prop
adids1221 59af447
Rename _onSegmentChange to onSegmentChange
adids1221 171e20b
Fix TypeScript ignore directive for selectAllType in Picker
adids1221 2d4d7d4
Update buttonProps onPress parameter to use selectionValue and set de…
adids1221 cdb80a2
Refactor Picker selection logic to use areAllItemsSelected and simpli…
adids1221 91aa052
Rename getSelectionStatusLabel to getLabel and update type definition…
adids1221 f76d7f8
Remove renderBottomCustomElement prop and add divider in PickerSelect…
adids1221 a93f066
Refactor Picker component to remove PickerSelectAllType enum
adids1221 9d75b2b
Refactor PickerSelectionStatusToolbar to simplify props and selection…
adids1221 f0ef350
Rename PickerSelectionStatusToolbar to PickerSelectionStatusBar and u…
adids1221 7d2086d
Update buttonProps onPress to use customValue instead of selectionVal…
adids1221 de9f42f
Add selectAllType prop to PickerSelectionStatusBar for flexible selec…
adids1221 45bca54
Refactor PickerSelectionStatusBar to remove selectAllType prop and si…
adids1221 0b584ff
Fix type assertion for value in PickerSelectionStatusBar to ensure co…
adids1221 dafe4f0
Refactor renderSelectionStatus, fix when showLabel is false
adids1221 34d7710
Add PickerSelectionStatusProps import to PickerScreen and index files
adids1221 5735e78
Remove unused setMultiFinalValue from usePickerSelection hook
adids1221 4abcfd7
Remove value from PickerSelectionStatusLabelData
adids1221 373e9d4
selectedCount moved to usePickerSelection
adids1221 40790cd
PickerSelectionStatusBar simplify selectedCount
adids1221 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import React, {useCallback} from 'react'; | ||
import Button from '../button'; | ||
import Checkbox from '../checkbox'; | ||
import View from '../view'; | ||
import Text from '../text'; | ||
import { | ||
PickerProps, | ||
PickerContextProps, | ||
PickerMultiValue, | ||
PickerSelectAllType, | ||
ButtonSelectionStatus, | ||
CheckboxSelectionStatus | ||
} from './types'; | ||
|
||
export type PickerSelectionStatusToolbarBaseProps = PickerProps['selectionStatus'] & { | ||
value?: PickerMultiValue; | ||
availableItems?: PickerMultiValue; | ||
}; | ||
|
||
export type PickerSelectionStatusToolbarProps = | ||
| (Partial<PickerContextProps> & (ButtonSelectionStatus & PickerSelectionStatusToolbarBaseProps)) | ||
| (Partial<PickerContextProps> & (CheckboxSelectionStatus & PickerSelectionStatusToolbarBaseProps)); | ||
|
||
export default function PickerSelectionStatusToolbar(props: PickerSelectionStatusToolbarProps) { | ||
const { | ||
containerStyle, | ||
getLabel, | ||
availableItems = [], | ||
selectAllType = 'none', | ||
M-i-k-e-l marked this conversation as resolved.
Show resolved
Hide resolved
|
||
showLabel = true, | ||
toggleAllItemsSelection, | ||
value = [], | ||
renderTopCustomElement, | ||
renderBottomCustomElement | ||
} = props; | ||
|
||
const isAllSelected = value.length === availableItems.length; | ||
const checkboxIndeterminate = value.length > 0 && value.length < availableItems.length; | ||
const label = | ||
getLabel?.({selectedCount: value.length, value, isAllSelected}) ?? | ||
`${value.length} Selected ${isAllSelected ? '(All)' : ''}`; | ||
|
||
let buttonProps: ButtonSelectionStatus['buttonProps'] | undefined; | ||
let checkboxProps: CheckboxSelectionStatus['checkboxProps'] | undefined; | ||
|
||
switch (props.selectAllType) { | ||
case PickerSelectAllType.button: | ||
buttonProps = props.buttonProps; | ||
break; | ||
case PickerSelectAllType.checkbox: | ||
checkboxProps = props.checkboxProps; | ||
break; | ||
} | ||
M-i-k-e-l marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const handlePress = useCallback(() => { | ||
const newSelectionState = !isAllSelected; | ||
toggleAllItemsSelection?.(newSelectionState); | ||
buttonProps?.onPress?.(availableItems); | ||
M-i-k-e-l marked this conversation as resolved.
Show resolved
Hide resolved
|
||
checkboxProps?.onValueChange?.(newSelectionState); | ||
}, [isAllSelected, toggleAllItemsSelection, availableItems, buttonProps, checkboxProps]); | ||
|
||
const renderSelectionStatus = () => { | ||
if (selectAllType === 'button') { | ||
return ( | ||
<Button label={isAllSelected ? 'Deselect All' : 'Select All'} link {...buttonProps} onPress={handlePress}/> | ||
); | ||
} else if (selectAllType === 'checkbox') { | ||
return ( | ||
<Checkbox | ||
{...checkboxProps} | ||
value={value.length > 0} | ||
indeterminate={checkboxIndeterminate} | ||
onValueChange={handlePress} | ||
/> | ||
); | ||
} | ||
}; | ||
|
||
const renderLabel = () => { | ||
if (showLabel) { | ||
return <Text>{label}</Text>; | ||
} | ||
return null; | ||
M-i-k-e-l marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
|
||
return ( | ||
<View> | ||
{renderTopCustomElement?.()} | ||
<View row spread centerV paddingH-page style={containerStyle}> | ||
{renderLabel()} | ||
{renderSelectionStatus()} | ||
</View> | ||
{renderBottomCustomElement?.()} | ||
</View> | ||
); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.