@@ -22,6 +22,10 @@ export const BulkSelectValue = {
2222
2323export type BulkSelectValue = ( typeof BulkSelectValue ) [ keyof typeof BulkSelectValue ] ;
2424
25+ const defaultSelectPageLabel = ( pageCount ?: number ) => `Select page${ pageCount ? ` (${ pageCount } )` : '' } ` ;
26+ const defaultSelectAllLabel = ( totalCount ?: number ) => `Select all${ totalCount ? ` (${ totalCount } )` : '' } ` ;
27+ const defaultSelectedLabel = ( selectedCount : number ) => `${ selectedCount } selected` ;
28+
2529/** extends DropdownProps */
2630export interface BulkSelectProps extends Omit < DropdownProps , 'toggle' | 'onSelect' > {
2731 /** BulkSelect className */
@@ -50,6 +54,14 @@ export interface BulkSelectProps extends Omit<DropdownProps, 'toggle' | 'onSelec
5054 dropdownListProps ?: Omit < DropdownListProps , 'children' > ;
5155 /** Additional props for MenuToggleProps */
5256 menuToggleProps ?: Omit < MenuToggleProps , 'children' | 'splitButtonItems' | 'ref' | 'isExpanded' | 'onClick' > ;
57+ /** Custom label for "Select none" option. Defaults to "Select none (0)" */
58+ selectNoneLabel ?: string ;
59+ /** Custom label for "Select page" option. Receives pageCount as parameter. Defaults to "Select page (N)" */
60+ selectPageLabel ?: ( pageCount ?: number ) => string ;
61+ /** Custom label for "Select all" option. Receives totalCount as parameter. Defaults to "Select all (N)" */
62+ selectAllLabel ?: ( totalCount ?: number ) => string ;
63+ /** Custom label formatter for selected count. Receives selectedCount as parameter. Defaults to "N selected" */
64+ selectedLabel ?: ( selectedCount : number ) => string ;
5365}
5466
5567export const BulkSelect : FC < BulkSelectProps > = ( {
@@ -65,29 +77,38 @@ export const BulkSelect: FC<BulkSelectProps> = ({
6577 menuToggleCheckboxProps,
6678 dropdownListProps,
6779 menuToggleProps,
80+ selectNoneLabel = 'Select none (0)' ,
81+ selectPageLabel = defaultSelectPageLabel ,
82+ selectAllLabel = defaultSelectAllLabel ,
83+ selectedLabel = defaultSelectedLabel ,
6884 ...props
6985} : BulkSelectProps ) => {
7086 const [ isOpen , setOpen ] = useState ( false ) ;
7187
88+ // Compute label text to use as memo dependencies for i18n support
89+ const selectPageLabelText = selectPageLabel ( pageCount ) ;
90+ const selectAllLabelText = selectAllLabel ( totalCount ) ;
91+ const selectedLabelText = selectedLabel ( selectedCount ) ;
92+
7293 const splitButtonDropdownItems = useMemo (
7394 ( ) => (
7495 < >
7596 < DropdownItem ouiaId = { `${ ouiaId } -select-none` } value = { BulkSelectValue . none } key = { BulkSelectValue . none } >
76- Select none (0)
97+ { selectNoneLabel }
7798 </ DropdownItem >
7899 { isDataPaginated && (
79100 < DropdownItem ouiaId = { `${ ouiaId } -select-page` } value = { BulkSelectValue . page } key = { BulkSelectValue . page } >
80- { `Select page ${ pageCount ? ` ( ${ pageCount } )` : '' } ` }
101+ { selectPageLabelText }
81102 </ DropdownItem >
82103 ) }
83104 { canSelectAll && (
84105 < DropdownItem ouiaId = { `${ ouiaId } -select-all` } value = { BulkSelectValue . all } key = { BulkSelectValue . all } >
85- { `Select all ${ totalCount ? ` ( ${ totalCount } )` : '' } ` }
106+ { selectAllLabelText }
86107 </ DropdownItem >
87108 ) }
88109 </ >
89110 ) ,
90- [ isDataPaginated , canSelectAll , ouiaId , pageCount , totalCount ]
111+ [ isDataPaginated , canSelectAll , ouiaId , selectNoneLabel , selectPageLabelText , selectAllLabelText ]
91112 ) ;
92113
93114 const allOption = isDataPaginated ? BulkSelectValue . page : BulkSelectValue . all ;
@@ -129,7 +150,7 @@ export const BulkSelect: FC<BulkSelectProps> = ({
129150 >
130151 { selectedCount > 0 ? (
131152 < span data-ouia-component-id = { `${ ouiaId } -text` } >
132- { ` ${ selectedCount } selected` }
153+ { selectedLabelText }
133154 </ span >
134155 ) : null }
135156 </ MenuToggleCheckbox >
0 commit comments