import * as React from 'react' ; import { ReactElement , SyntheticEvent } from 'react' ; import PropTypes from 'prop-types' ; import { Record , RedirectionSideEffect , MutationMode , getMutationMode , OnSuccess , OnFailure , } from 'ra-core' ; import { ButtonProps } from './Button' ; import { DeleteWithUndoButton } from './DeleteWithUndoButton' ; import { DeleteWithConfirmButton } from './DeleteWithConfirmButton' ; typedef Props prop { boolean } undoable prop { Object } record prop { string } className prop { string } label prop { boolean } disabled prop { string } variant prop { ReactElement } icon param { Props } props example export const DeleteButton = ( props ) => { const { undoable , mutationMode , record , ... rest } = props ; const mode = getMutationMode ( mutationMode , undoable ) ; if ( ! record || record . id == null ) { return null ; } return mode === 'undoable' ? ( < DeleteWithUndoButton record = { record } { ... rest } />) : (<DeleteWithConfirmButton mutationMode={mode} record={record} undoable={undoable} {...rest}/ > ) ; } ; interface Props { basePath ? : string ; classes ? : object ; className ? : string ; confirmTitle ? : string ; confirmContent ? : string ; icon ? : ReactElement ; label ? : string ; mutationMode ? : MutationMode ; onClick ? : ( e : MouseEvent ) => void ; record ? : Record ; redirect ? : RedirectionSideEffect ; resource ? : string ; handleSubmit ? : ( event ? : SyntheticEvent < HTMLFormElement > ) => Promise < Object > ; handleSubmitWithRedirect ? : ( redirect ? : RedirectionSideEffect ) => void ; invalid ? : boolean ; pristine ? : boolean ; saving ? : boolean ; submitOnEnter ? : boolean ; deprecated undoable ? : boolean ; onSuccess ? : OnSuccess ; onFailure ? : OnFailure ; } export type DeleteButtonProps = Props & ButtonProps ; DeleteButton . propTypes = { basePath : PropTypes . string , label : PropTypes . string , mutationMode : PropTypes . oneOf ( [ 'pessimistic' , 'optimistic' , 'undoable' ] ) , record : PropTypes . any , redirect : PropTypes . oneOfType ( [ PropTypes . string , PropTypes . bool , PropTypes . func , ] ) , resource : PropTypes . string , undoable : PropTypes . bool , icon : PropTypes . element , } ;