Skip to content

Commit 1710e82

Browse files
committed
Allow to set default props for UpdateButton, BulkDeleteButton and BulkUpdateButton.
1 parent 44c5259 commit 1710e82

File tree

3 files changed

+67
-8
lines changed

3 files changed

+67
-8
lines changed

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

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import * as React from 'react';
2+
import { MutationMode, useCanAccess, useResourceContext } from 'ra-core';
3+
import { useThemeProps } from '@mui/material/styles';
4+
25
import {
36
BulkDeleteWithConfirmButton,
47
BulkDeleteWithConfirmButtonProps,
@@ -7,7 +10,6 @@ import {
710
BulkDeleteWithUndoButton,
811
BulkDeleteWithUndoButtonProps,
912
} from './BulkDeleteWithUndoButton';
10-
import { MutationMode, useCanAccess, useResourceContext } from 'ra-core';
1113

1214
/**
1315
* Deletes the selected rows.
@@ -32,10 +34,12 @@ import { MutationMode, useCanAccess, useResourceContext } from 'ra-core';
3234
* </List>
3335
* );
3436
*/
35-
export const BulkDeleteButton = ({
36-
mutationMode = 'undoable',
37-
...props
38-
}: BulkDeleteButtonProps) => {
37+
export const BulkDeleteButton = (inProps: BulkDeleteButtonProps) => {
38+
const { mutationMode = 'undoable', ...props } = useThemeProps({
39+
name: PREFIX,
40+
props: inProps,
41+
});
42+
3943
const resource = useResourceContext(props);
4044
if (!resource) {
4145
throw new Error(
@@ -62,3 +66,17 @@ interface Props {
6266

6367
export type BulkDeleteButtonProps = Props &
6468
(BulkDeleteWithUndoButtonProps | BulkDeleteWithConfirmButtonProps);
69+
70+
const PREFIX = 'RaBulkDeleteButton';
71+
72+
declare module '@mui/material/styles' {
73+
interface ComponentsPropsList {
74+
[PREFIX]: Partial<BulkDeleteButtonProps>;
75+
}
76+
77+
interface Components {
78+
[PREFIX]?: {
79+
defaultProps?: ComponentsPropsList[typeof PREFIX];
80+
};
81+
}
82+
}

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

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import * as React from 'react';
2+
import { MutationMode } from 'ra-core';
3+
import { useThemeProps } from '@mui/material/styles';
4+
25
import {
36
BulkUpdateWithConfirmButton,
47
BulkUpdateWithConfirmButtonProps,
@@ -7,7 +10,6 @@ import {
710
BulkUpdateWithUndoButton,
811
BulkUpdateWithUndoButtonProps,
912
} from './BulkUpdateWithUndoButton';
10-
import { MutationMode } from 'ra-core';
1113

1214
/**
1315
* Updates the selected rows.
@@ -33,7 +35,14 @@ import { MutationMode } from 'ra-core';
3335
* );
3436
*/
3537
export const BulkUpdateButton = (props: BulkUpdateButtonProps) => {
36-
const { mutationMode = 'undoable', data = defaultData, ...rest } = props;
38+
const {
39+
mutationMode = 'undoable',
40+
data = defaultData,
41+
...rest
42+
} = useThemeProps({
43+
name: PREFIX,
44+
props: props,
45+
});
3746

3847
return mutationMode === 'undoable' ? (
3948
<BulkUpdateWithUndoButton data={data} {...rest} />
@@ -54,3 +63,17 @@ export type BulkUpdateButtonProps = Props &
5463
(BulkUpdateWithUndoButtonProps | BulkUpdateWithConfirmButtonProps);
5564

5665
const defaultData = [];
66+
67+
const PREFIX = 'RaBulkUpdateButton';
68+
69+
declare module '@mui/material/styles' {
70+
interface ComponentsPropsList {
71+
[PREFIX]: Partial<BulkUpdateButtonProps>;
72+
}
73+
74+
interface Components {
75+
[PREFIX]?: {
76+
defaultProps?: ComponentsPropsList[typeof PREFIX];
77+
};
78+
}
79+
}

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
UpdateWithUndoButton,
88
UpdateWithUndoButtonProps,
99
} from './UpdateWithUndoButton';
10+
import { useThemeProps } from '@mui/material/styles';
1011

1112
/**
1213
* Updates the current record.
@@ -30,7 +31,10 @@ import {
3031
* );
3132
*/
3233
export const UpdateButton = (props: UpdateButtonProps) => {
33-
const { mutationMode = 'undoable', ...rest } = props;
34+
const { mutationMode = 'undoable', ...rest } = useThemeProps({
35+
name: PREFIX,
36+
props: props,
37+
});
3438

3539
return mutationMode === 'undoable' ? (
3640
<UpdateWithUndoButton {...rest} />
@@ -46,3 +50,17 @@ export type UpdateButtonProps =
4650
| ({
4751
mutationMode?: 'pessimistic' | 'optimistic';
4852
} & UpdateWithConfirmButtonProps);
53+
54+
const PREFIX = 'RaUpdateButton';
55+
56+
declare module '@mui/material/styles' {
57+
interface ComponentsPropsList {
58+
[PREFIX]: Partial<UpdateButtonProps>;
59+
}
60+
61+
interface Components {
62+
[PREFIX]?: {
63+
defaultProps?: ComponentsPropsList[typeof PREFIX];
64+
};
65+
}
66+
}

0 commit comments

Comments
 (0)