Skip to content

Commit 8a27e8d

Browse files
committed
Allow to theme RefreshButton and set its default props.
1 parent 12f9a4f commit 8a27e8d

File tree

1 file changed

+39
-3
lines changed

1 file changed

+39
-3
lines changed

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

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,20 @@ import * as React from 'react';
22
import { MouseEvent, useCallback } from 'react';
33
import NavigationRefresh from '@mui/icons-material/Refresh';
44
import { useRefresh } from 'ra-core';
5+
import {
6+
ComponentsOverrides,
7+
styled,
8+
useThemeProps,
9+
} from '@mui/material/styles';
510

611
import { Button, ButtonProps } from './Button';
712

8-
export const RefreshButton = (props: RefreshButtonProps) => {
13+
export const RefreshButton = (inProps: RefreshButtonProps) => {
14+
const props = useThemeProps({
15+
props: inProps,
16+
name: PREFIX,
17+
});
18+
919
const {
1020
label = 'ra.action.refresh',
1121
icon = defaultIcon,
@@ -25,9 +35,9 @@ export const RefreshButton = (props: RefreshButtonProps) => {
2535
);
2636

2737
return (
28-
<Button label={label} onClick={handleClick} {...rest}>
38+
<StyledButton label={label} onClick={handleClick} {...rest}>
2939
{icon}
30-
</Button>
40+
</StyledButton>
3141
);
3242
};
3343

@@ -40,3 +50,29 @@ interface Props {
4050
}
4151

4252
export type RefreshButtonProps = Props & ButtonProps;
53+
54+
const PREFIX = 'RaRefreshButton';
55+
56+
const StyledButton = styled(Button, {
57+
name: PREFIX,
58+
overridesResolver: (props, styles) => styles.root,
59+
})({});
60+
61+
declare module '@mui/material/styles' {
62+
interface ComponentNameToClassKey {
63+
[PREFIX]: 'root';
64+
}
65+
66+
interface ComponentsPropsList {
67+
[PREFIX]: Partial<RefreshButtonProps>;
68+
}
69+
70+
interface Components {
71+
[PREFIX]?: {
72+
defaultProps?: ComponentsPropsList[typeof PREFIX];
73+
styleOverrides?: ComponentsOverrides<
74+
Omit<Theme, 'components'>
75+
>[typeof PREFIX];
76+
};
77+
}
78+
}

0 commit comments

Comments
 (0)