Skip to content

Commit 1a0078e

Browse files
committed
Merge branch 'next' into confirm-record-representation
2 parents 674674e + 983d257 commit 1a0078e

File tree

117 files changed

+3867
-768
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+3867
-768
lines changed

docs/AppTheme.md

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,24 @@ const theme = deepmerge(defaultTheme, {
356356
});
357357
```
358358

359+
This also works with many React Admin components. For instance, here's how to change the icon for all `<SaveButton>`:
360+
361+
```tsx
362+
import { defaultTheme } from 'react-admin';
363+
import { deepmerge } from '@mui/utils';
364+
import CheckIcon from '@mui/icons-material/Check';
365+
366+
const theme = deepmerge(defaultTheme, {
367+
components: {
368+
RaSaveButton: {
369+
defaultProps: {
370+
icon: <CheckIcon />,
371+
},
372+
},
373+
}
374+
});
375+
```
376+
359377
## Customizing The Sidebar Width
360378

361379
You can specify the `Sidebar` width by setting the `width` and `closedWidth` properties on your custom Material UI theme:
@@ -423,10 +441,11 @@ A `theme` object can contain the following keys:
423441

424442
**Tip**: Check [Material UI default theme documentation](https://mui.com/material-ui/customization/default-theme/) to see the default values and meaning for these keys.
425443

426-
```jsx
444+
```tsx
427445
import { lime, purple } from '@mui/material/colors';
446+
import type { ThemeOptions } from '@mui/material';
428447

429-
const theme = {
448+
const theme: ThemeOptions = {
430449
palette: {
431450
primary: {
432451
main: '#FF5733',
@@ -514,10 +533,10 @@ const myTheme = deepmerge(defaultTheme, {
514533
Here is the default theme:
515534

516535
```tsx
517-
import { RaThemeOptions } from './types';
536+
import type { ThemeOptions } from '@mui/material';
518537
import { deepmerge } from '@mui/utils';
519538

520-
const defaultThemeInvariants = {
539+
const defaultThemeInvariants: ThemeOptions = {
521540
typography: {
522541
h6: {
523542
fontWeight: 400,
@@ -578,7 +597,7 @@ const defaultThemeInvariants = {
578597
},
579598
};
580599

581-
export const defaultLightTheme: RaThemeOptions = deepmerge(
600+
export const defaultLightTheme: ThemeOptions = deepmerge(
582601
defaultThemeInvariants,
583602
{
584603
palette: {
@@ -607,7 +626,7 @@ export const defaultLightTheme: RaThemeOptions = deepmerge(
607626
}
608627
);
609628

610-
export const defaultDarkTheme: RaThemeOptions = deepmerge(
629+
export const defaultDarkTheme: ThemeOptions = deepmerge(
611630
defaultThemeInvariants,
612631
{
613632
palette: {
@@ -623,5 +642,4 @@ export const defaultDarkTheme: RaThemeOptions = deepmerge(
623642
);
624643

625644
export const defaultTheme = defaultLightTheme;
626-
627645
```
Lines changed: 85 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import * as React from 'react';
2-
import { ElementType, ReactElement } from 'react';
2+
import type { ElementType, ReactElement } from 'react';
33
import {
44
Stack,
5-
StackProps,
6-
Theme,
5+
type StackProps,
6+
type Theme,
77
Typography,
8-
TypographyProps,
8+
type TypographyProps,
99
} from '@mui/material';
10-
import { styled } from '@mui/material/styles';
11-
import { Property } from 'csstype';
10+
import { type ComponentsOverrides, styled } from '@mui/material/styles';
11+
import { type Property } from 'csstype';
1212
import clsx from 'clsx';
1313

1414
import { FieldTitle } from 'ra-core';
15-
import { ResponsiveStyleValue } from '@mui/system';
15+
import { useThemeProps, type ResponsiveStyleValue } from '@mui/system';
1616

1717
/**
1818
* Wrap a field or an input with a label if necessary.
@@ -26,57 +26,65 @@ import { ResponsiveStyleValue } from '@mui/system';
2626
* <FooComponent source="title" />
2727
* </Labeled>
2828
*/
29-
export const Labeled = ({
30-
children,
31-
className = '',
32-
color,
33-
component = 'span',
34-
fullWidth,
35-
isRequired,
36-
label,
37-
resource,
38-
source,
39-
TypographyProps,
40-
...rest
41-
}: LabeledProps) => (
42-
<Root
43-
// @ts-ignore https://github.com/mui/material-ui/issues/29875
44-
component={component}
45-
className={clsx(className, {
46-
[LabeledClasses.fullWidth]: fullWidth,
47-
})}
48-
{...rest}
49-
>
50-
{label !== false &&
51-
children.props.label !== false &&
52-
typeof children.type !== 'string' &&
53-
// @ts-ignore
54-
children.type?.displayName !== 'Labeled' &&
55-
// @ts-ignore
56-
children.type?.displayName !== 'Labeled' ? (
57-
<Typography
58-
sx={
59-
color
60-
? undefined
61-
: {
62-
color: theme => theme.palette.text.secondary,
63-
}
64-
}
65-
color={color}
66-
className={LabeledClasses.label}
67-
{...TypographyProps}
68-
>
69-
<FieldTitle
70-
label={label || children.props.label}
71-
source={source || children.props.source}
72-
resource={resource}
73-
isRequired={isRequired}
74-
/>
75-
</Typography>
76-
) : null}
77-
{children}
78-
</Root>
79-
);
29+
export const Labeled = (inProps: LabeledProps) => {
30+
const props = useThemeProps({
31+
props: inProps,
32+
name: PREFIX,
33+
});
34+
const {
35+
children,
36+
className = '',
37+
color,
38+
component = 'span',
39+
fullWidth,
40+
isRequired,
41+
label,
42+
resource,
43+
source,
44+
TypographyProps,
45+
...rest
46+
} = props;
47+
48+
return (
49+
<Root
50+
// @ts-ignore https://github.com/mui/material-ui/issues/29875
51+
component={component}
52+
className={clsx(className, {
53+
[LabeledClasses.fullWidth]: fullWidth,
54+
})}
55+
{...rest}
56+
>
57+
{label !== false &&
58+
children.props.label !== false &&
59+
typeof children.type !== 'string' &&
60+
// @ts-ignore
61+
children.type?.displayName !== 'Labeled' &&
62+
// @ts-ignore
63+
children.type?.displayName !== 'Labeled' ? (
64+
<Typography
65+
sx={
66+
color
67+
? undefined
68+
: {
69+
color: theme => theme.palette.text.secondary,
70+
}
71+
}
72+
color={color}
73+
className={LabeledClasses.label}
74+
{...TypographyProps}
75+
>
76+
<FieldTitle
77+
label={label || children.props.label}
78+
source={source || children.props.source}
79+
resource={resource}
80+
isRequired={isRequired}
81+
/>
82+
</Typography>
83+
) : null}
84+
{children}
85+
</Root>
86+
);
87+
};
8088

8189
Labeled.displayName = 'Labeled';
8290

@@ -121,3 +129,22 @@ const Root = styled(Stack, {
121129
marginBottom: '0.2em',
122130
},
123131
});
132+
133+
declare module '@mui/material/styles' {
134+
interface ComponentNameToClassKey {
135+
RaLabeled: 'root' | 'label' | 'fullWidth';
136+
}
137+
138+
interface ComponentsPropsList {
139+
RaLabeled: Partial<LabeledProps>;
140+
}
141+
142+
interface Components {
143+
RaLabeled?: {
144+
defaultProps?: ComponentsPropsList['RaLabeled'];
145+
styleOverrides?: ComponentsOverrides<
146+
Omit<Theme, 'components'>
147+
>['RaLabeled'];
148+
};
149+
}
150+
}

packages/ra-ui-materialui/src/Link.tsx

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
import * as React from 'react';
22
import clsx from 'clsx';
3-
import { Link as RRLink, LinkProps as RRLinkProps } from 'react-router-dom';
3+
import {
4+
Link as RRLink,
5+
type LinkProps as RRLinkProps,
6+
} from 'react-router-dom';
47
import {
58
styled,
69
Link as MuiLink,
7-
LinkProps as MuiLinkProps,
10+
type LinkProps as MuiLinkProps,
11+
type ComponentsOverrides,
12+
useThemeProps,
813
} from '@mui/material';
914

10-
export const Link = (props: LinkProps) => {
15+
export const Link = (inProps: LinkProps) => {
16+
const props = useThemeProps({
17+
props: inProps,
18+
name: PREFIX,
19+
});
1120
const { to, children, className, ...rest } = props;
1221

1322
return (
@@ -28,10 +37,32 @@ export const LinkClasses = {
2837
link: `${PREFIX}-link`,
2938
};
3039

31-
const StyledMuiLink = styled(MuiLink)({}) as typeof MuiLink; // @see https://mui.com/material-ui/guides/typescript/#complications-with-the-component-prop
40+
const StyledMuiLink = styled(MuiLink)({
41+
name: PREFIX,
42+
overridesResolver: (props, styles) => styles.root,
43+
}) as typeof MuiLink; // @see https://mui.com/material-ui/guides/typescript/#complications-with-the-component-prop
3244

3345
// @see https://mui.com/material-ui/guides/composition/#with-typescript
3446
export interface LinkProps
3547
extends MuiLinkProps<React.ElementType<any>, RRLinkProps> {
3648
className?: string;
3749
}
50+
51+
declare module '@mui/material/styles' {
52+
interface ComponentNameToClassKey {
53+
RaLink: 'root' | 'link';
54+
}
55+
56+
interface ComponentsPropsList {
57+
RaLink: Partial<LinkProps>;
58+
}
59+
60+
interface Components {
61+
RaLink?: {
62+
defaultProps?: ComponentsPropsList['RaLink'];
63+
styleOverrides?: ComponentsOverrides<
64+
Omit<Theme, 'components'>
65+
>['RaLink'];
66+
};
67+
}
68+
}

packages/ra-ui-materialui/src/auth/AuthError.tsx

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
import * as React from 'react';
2-
import { styled, SxProps } from '@mui/material';
2+
import {
3+
type ComponentsOverrides,
4+
styled,
5+
type SxProps,
6+
type Theme,
7+
useThemeProps,
8+
} from '@mui/material';
39
import LockIcon from '@mui/icons-material/Lock';
410
import { useTranslate } from 'ra-core';
511
import { Button } from '../button';
612
import { Link } from 'react-router-dom';
713

8-
export const AuthError = (props: AuthErrorProps) => {
14+
export const AuthError = (inProps: AuthErrorProps) => {
15+
const props = useThemeProps({
16+
props: inProps,
17+
name: PREFIX,
18+
});
919
const {
1020
className,
1121
title = 'ra.page.error',
@@ -31,7 +41,7 @@ export interface AuthErrorProps {
3141
className?: string;
3242
title?: string;
3343
message?: string;
34-
sx?: SxProps;
44+
sx?: SxProps<Theme>;
3545
}
3646

3747
const PREFIX = 'RaAuthError';
@@ -63,3 +73,22 @@ const Root = styled('div', {
6373
margin: '0 1em',
6474
},
6575
}));
76+
77+
declare module '@mui/material/styles' {
78+
interface ComponentNameToClassKey {
79+
RaAuthError: 'root' | 'message';
80+
}
81+
82+
interface ComponentsPropsList {
83+
RaAuthError: Partial<AuthErrorProps>;
84+
}
85+
86+
interface Components {
87+
RaAuthError?: {
88+
defaultProps?: ComponentsPropsList['RaAuthError'];
89+
styleOverrides?: ComponentsOverrides<
90+
Omit<Theme, 'components'>
91+
>['RaAuthError'];
92+
};
93+
}
94+
}

0 commit comments

Comments
 (0)