import { useDevice } from '../../../providers' ; import { ActionListProps } from '../../action-list' ; import { BoxProps } from '../../layout' ; const getMaxNodes = ( device ) => { if ( device === 'phone' ) { return 2 ; } return Infinity ; } ; export interface UseLegacyToolbarProps extends BoxProps { actions ? : ActionListProps [ 'actions' ] ; } export function useLegacyToolbar ( props ) { const { actions : actionsProp = [ ] , ... htmlProps } = props ; const device = useDevice ( ) ; const max = getMaxNodes ( device . name ) ; let left = actionsProp ; let more = [ ] ; if ( actionsProp . length > max ) { left = actionsProp . slice ( 0 , max ) ; more = actionsProp . slice ( max , actionsProp . length ) ; } if ( more . length ) { left . push ( { key : 'more' , label : '更多' , children : more , } ) ; } return { actions : left , htmlProps , } ; }