@@ -8,6 +8,11 @@ import {
88 RaRecord ,
99} from 'ra-core' ;
1010import { Typography , TypographyProps , CircularProgress } from '@mui/material' ;
11+ import {
12+ ComponentsOverrides ,
13+ styled ,
14+ useThemeProps ,
15+ } from '@mui/material/styles' ;
1116import ErrorIcon from '@mui/icons-material/Error' ;
1217
1318import { FieldProps } from './types' ;
@@ -29,8 +34,13 @@ import { Link } from '../Link';
2934 * <ReferenceManyCount reference="comments" target="post_id" variant="h1" />
3035 */
3136export const ReferenceManyCount = < RecordType extends RaRecord = RaRecord > (
32- props : ReferenceManyCountProps < RecordType >
37+ inProps : ReferenceManyCountProps < RecordType >
3338) => {
39+ const props = useThemeProps ( {
40+ props : inProps ,
41+ name : PREFIX ,
42+ } ) ;
43+
3444 const {
3545 reference,
3646 target,
@@ -72,29 +82,32 @@ export const ReferenceManyCount = <RecordType extends RaRecord = RaRecord>(
7282 total
7383 ) ;
7484
75- return link && record ? (
76- < Link
77- to = { {
78- pathname : createPath ( { resource : reference , type : 'list' } ) ,
79- search : `filter=${ JSON . stringify ( {
80- ...( filter || { } ) ,
81- [ target ] : record [ source ] ,
82- } ) } `,
83- } }
84- variant = "body2"
85- onClick = { e => e . stopPropagation ( ) }
86- { ...sanitizeFieldRestProps ( rest ) }
87- >
88- { body }
89- </ Link >
90- ) : (
91- < Typography
85+ return (
86+ < StyledTypography
9287 component = "span"
9388 variant = "body2"
9489 { ...sanitizeFieldRestProps ( rest ) }
9590 >
96- { body }
97- </ Typography >
91+ { link && record ? (
92+ < Link
93+ to = { {
94+ pathname : createPath ( {
95+ resource : reference ,
96+ type : 'list' ,
97+ } ) ,
98+ search : `filter=${ JSON . stringify ( {
99+ ...( filter || { } ) ,
100+ [ target ] : record [ source ] ,
101+ } ) } `,
102+ } }
103+ onClick = { e => e . stopPropagation ( ) }
104+ >
105+ { body }
106+ </ Link >
107+ ) : (
108+ body
109+ ) }
110+ </ StyledTypography >
98111 ) ;
99112} ;
100113
@@ -112,3 +125,29 @@ export interface ReferenceManyCountProps<RecordType extends RaRecord = RaRecord>
112125 link ?: boolean ;
113126 timeout ?: number ;
114127}
128+
129+ const PREFIX = 'RaReferenceManyCount' ;
130+
131+ const StyledTypography = styled ( Typography , {
132+ name : PREFIX ,
133+ overridesResolver : ( props , styles ) => styles . root ,
134+ } ) ( { } ) ;
135+
136+ declare module '@mui/material/styles' {
137+ interface ComponentNameToClassKey {
138+ [ PREFIX ] : 'root' ;
139+ }
140+
141+ interface ComponentsPropsList {
142+ [ PREFIX ] : Partial < ReferenceManyCountProps > ;
143+ }
144+
145+ interface Components {
146+ [ PREFIX ] ?: {
147+ defaultProps ?: ComponentsPropsList [ typeof PREFIX ] ;
148+ styleOverrides ?: ComponentsOverrides <
149+ Omit < Theme , 'components' >
150+ > [ typeof PREFIX ] ;
151+ } ;
152+ }
153+ }
0 commit comments