@@ -2,15 +2,26 @@ import * as React from 'react';
22import { AnchorHTMLAttributes } from 'react' ;
33import { sanitizeFieldRestProps } from './sanitizeFieldRestProps' ;
44import { Typography , Link } from '@mui/material' ;
5+ import {
6+ ComponentsOverrides ,
7+ styled ,
8+ useThemeProps ,
9+ } from '@mui/material/styles' ;
510import { useFieldValue , useTranslate } from 'ra-core' ;
11+
612import { FieldProps } from './types' ;
713import { genericMemo } from './genericMemo' ;
814
915const UrlFieldImpl = <
1016 RecordType extends Record < string , any > = Record < string , any > ,
1117> (
12- props : UrlFieldProps < RecordType >
18+ inProps : UrlFieldProps < RecordType >
1319) => {
20+ const props = useThemeProps ( {
21+ props : inProps ,
22+ name : PREFIX ,
23+ } ) ;
24+
1425 const { className, emptyText, content, ...rest } = props ;
1526 const value = useFieldValue ( props ) ;
1627 const translate = useTranslate ( ) ;
@@ -29,15 +40,15 @@ const UrlFieldImpl = <
2940 }
3041
3142 return (
32- < Link
43+ < StyledLink
3344 className = { className }
3445 href = { value }
3546 onClick = { stopPropagation }
3647 variant = "body2"
3748 { ...sanitizeFieldRestProps ( rest ) }
3849 >
3950 { content ?? value }
40- </ Link >
51+ </ StyledLink >
4152 ) ;
4253} ;
4354UrlFieldImpl . displayName = 'UrlFieldImpl' ;
@@ -53,3 +64,29 @@ export interface UrlFieldProps<
5364
5465// useful to prevent click bubbling in a Datagrid with rowClick
5566const stopPropagation = e => e . stopPropagation ( ) ;
67+
68+ const PREFIX = 'RaUrlField' ;
69+
70+ const StyledLink = styled ( Link , {
71+ name : PREFIX ,
72+ overridesResolver : ( props , styles ) => styles . root ,
73+ } ) ( { } ) ;
74+
75+ declare module '@mui/material/styles' {
76+ interface ComponentNameToClassKey {
77+ [ PREFIX ] : 'root' ;
78+ }
79+
80+ interface ComponentsPropsList {
81+ [ PREFIX ] : Partial < UrlFieldProps > ;
82+ }
83+
84+ interface Components {
85+ [ PREFIX ] ?: {
86+ defaultProps ?: ComponentsPropsList [ typeof PREFIX ] ;
87+ styleOverrides ?: ComponentsOverrides <
88+ Omit < Theme , 'components' >
89+ > [ typeof PREFIX ] ;
90+ } ;
91+ }
92+ }
0 commit comments