import * as React from 'react' ; import { cloneElement , useMemo , useContext , ReactElement } from 'react' ; import PropTypes from 'prop-types' ; import { sanitizeListRestProps , Identifier , SortPayload , Exporter , useListContext , useResourceContext , useResourceDefinition , } from 'ra-core' ; import { ToolbarProps } from '@material-ui/core' ; import TopToolbar from '../layout/TopToolbar' ; import { CreateButton , ExportButton } from '../button' ; import { FilterContext } from './FilterContext' ; import FilterButton from './filter/FilterButton' ; example const ListActions = ( props ) => { const { className , exporter , filters : filtersProp , ... rest } = props ; const { currentSort , displayedFilters , filterValues , basePath , showFilter , total , } = useListContext ( props ) ; const resource = useResourceContext ( rest ) ; const { hasCreate } = useResourceDefinition ( rest ) ; const filters = useContext ( FilterContext ) || filtersProp ; return useMemo ( ( ) => ( < TopToolbar className = { className } { ... sanitizeListRestProps ( rest ) } > { filtersProp ? cloneElement ( filtersProp , { resource , showFilter , displayedFilters , filterValues , context : 'button' , } ) : filters && < FilterButton />} { hasCreate && < CreateButton basePath = { basePath } / > } { exporter !== false && ( < ExportButton disabled = { total === 0 } resource = { resource } sort = { currentSort } filterValues = { filterValues } / > ) } < /TopToolbar>),  [ resource , displayedFilters , filterValues , showFilter , filters , total , basePath , className , currentSort , exporter , hasCreate , ] ) ; } ; ListActions . propTypes = { basePath : PropTypes . string , className : PropTypes . string , currentSort : PropTypes . any , displayedFilters : PropTypes . object , exporter : PropTypes . oneOfType ( [ PropTypes . func , PropTypes . bool ] ) , filters : PropTypes . element , filterValues : PropTypes . object , hasCreate : PropTypes . bool , resource : PropTypes . string , onUnselectItems : PropTypes . func . isRequired , selectedIds : PropTypes . arrayOf ( PropTypes . any ) , showFilter : PropTypes . func , total : PropTypes . number , } ; ListActions . defaultProps = { selectedIds : [ ] , onUnselectItems : ( ) => null , } ; export interface ListActionsProps extends ToolbarProps { currentSort ? : SortPayload ; className ? : string ; resource ? : string ; filters ? : ReactElement < any > ; displayedFilters ? : any ; exporter ? : Exporter | boolean ; filterValues ? : any ; permanentFilter ? : any ; hasCreate ? : boolean ; basePath ? : string ; selectedIds ? : Identifier [ ] ; onUnselectItems ? : ( ) => void ; showFilter ? : ( filterName : string , defaultValue : any ) => void ; total ? : number ; } export default ListActions ;