Skip to content

Commit fd54978

Browse files
committed
Allow to set default props for DeleteButton.
1 parent f9586d4 commit fd54978

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

packages/ra-ui-materialui/src/button/DeleteButton.tsx

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
useResourceContext,
1212
useCanAccess,
1313
} from 'ra-core';
14+
import { useThemeProps } from '@mui/material/styles';
1415

1516
import { ButtonProps } from './Button';
1617
import { DeleteWithUndoButton } from './DeleteWithUndoButton';
@@ -28,7 +29,7 @@ import { DeleteWithConfirmButton } from './DeleteWithConfirmButton';
2829
* @prop {string} variant Material UI variant for the button. Defaults to 'contained'.
2930
* @prop {ReactElement} icon Override the icon. Defaults to the Delete icon from Material UI.
3031
*
31-
* @param {Props} props
32+
* @param {Props} inProps
3233
*
3334
* @example Usage in the <TopToolbar> of an <Edit> form
3435
*
@@ -51,8 +52,13 @@ import { DeleteWithConfirmButton } from './DeleteWithConfirmButton';
5152
* };
5253
*/
5354
export const DeleteButton = <RecordType extends RaRecord = any>(
54-
props: DeleteButtonProps<RecordType>
55+
inProps: DeleteButtonProps<RecordType>
5556
) => {
57+
const props = useThemeProps({
58+
name: PREFIX,
59+
props: inProps,
60+
});
61+
5662
const { mutationMode, ...rest } = props;
5763
const record = useRecordContext(props);
5864
const resource = useResourceContext(props);
@@ -109,3 +115,17 @@ export interface DeleteButtonProps<
109115
resource?: string;
110116
successMessage?: string;
111117
}
118+
119+
const PREFIX = 'RaDeleteButton';
120+
121+
declare module '@mui/material/styles' {
122+
interface ComponentsPropsList {
123+
[PREFIX]: Partial<DeleteButtonProps>;
124+
}
125+
126+
interface Components {
127+
[PREFIX]?: {
128+
defaultProps?: ComponentsPropsList[typeof PREFIX];
129+
};
130+
}
131+
}

0 commit comments

Comments
 (0)