|
1 | 1 | import * as React from 'react'; |
2 | 2 | import { Typography, TypographyProps } from '@mui/material'; |
| 3 | +import { |
| 4 | + ComponentsOverrides, |
| 5 | + styled, |
| 6 | + useThemeProps, |
| 7 | +} from '@mui/material/styles'; |
3 | 8 | import { useFieldValue, useTranslate } from 'ra-core'; |
4 | 9 |
|
5 | 10 | import { sanitizeFieldRestProps } from './sanitizeFieldRestProps'; |
@@ -33,8 +38,13 @@ import { genericMemo } from './genericMemo'; |
33 | 38 | const DateFieldImpl = < |
34 | 39 | RecordType extends Record<string, any> = Record<string, any>, |
35 | 40 | >( |
36 | | - props: DateFieldProps<RecordType> |
| 41 | + inProps: DateFieldProps<RecordType> |
37 | 42 | ) => { |
| 43 | + const props = useThemeProps({ |
| 44 | + props: inProps, |
| 45 | + name: PREFIX, |
| 46 | + }); |
| 47 | + |
38 | 48 | const { |
39 | 49 | className, |
40 | 50 | emptyText, |
@@ -95,14 +105,14 @@ const DateFieldImpl = < |
95 | 105 | } |
96 | 106 |
|
97 | 107 | return ( |
98 | | - <Typography |
| 108 | + <StyledTypography |
99 | 109 | component="span" |
100 | 110 | variant="body2" |
101 | 111 | className={className} |
102 | 112 | {...sanitizeFieldRestProps(rest)} |
103 | 113 | > |
104 | 114 | {dateString} |
105 | | - </Typography> |
| 115 | + </StyledTypography> |
106 | 116 | ); |
107 | 117 | }; |
108 | 118 | DateFieldImpl.displayName = 'DateFieldImpl'; |
@@ -136,3 +146,29 @@ const toLocaleStringSupportsLocales = (() => { |
136 | 146 | } |
137 | 147 | return false; |
138 | 148 | })(); |
| 149 | + |
| 150 | +const PREFIX = 'RaDateField'; |
| 151 | + |
| 152 | +const StyledTypography = styled(Typography, { |
| 153 | + name: PREFIX, |
| 154 | + overridesResolver: (props, styles) => styles.root, |
| 155 | +})({}); |
| 156 | + |
| 157 | +declare module '@mui/material/styles' { |
| 158 | + interface ComponentNameToClassKey { |
| 159 | + [PREFIX]: 'root'; |
| 160 | + } |
| 161 | + |
| 162 | + interface ComponentsPropsList { |
| 163 | + [PREFIX]: Partial<DateFieldProps>; |
| 164 | + } |
| 165 | + |
| 166 | + interface Components { |
| 167 | + [PREFIX]?: { |
| 168 | + defaultProps?: ComponentsPropsList[typeof PREFIX]; |
| 169 | + styleOverrides?: ComponentsOverrides< |
| 170 | + Omit<Theme, 'components'> |
| 171 | + >[typeof PREFIX]; |
| 172 | + }; |
| 173 | + } |
| 174 | +} |
0 commit comments