@ -18,8 +18,9 @@ const getStyles = (theme: GrafanaTheme2) => {
text - overflow : ellipsis ;
box - sizing : border - box ;
max - width : 100 % ;
grid - area : 1 / 1 / 2 / 3 ;
` ;
const contain er = css `
const spinnerWrapp er = css `
width : 16px ;
height : 16px ;
display : inline - block ;
@ -29,7 +30,7 @@ const getStyles = (theme: GrafanaTheme2) => {
overflow : hidden ;
` ;
const item = css `
const spinnerIcon = css `
width : 100 % ;
height : 100 % ;
position : absolute ;
@ -39,7 +40,7 @@ const getStyles = (theme: GrafanaTheme2) => {
color : $ { tinycolor ( theme . colors . text . disabled ) . setAlpha ( 0.64 ) . toString ( ) } ;
` ;
return { singleValue , container , item , disabled } ;
return { singleValue , spinnerWrapper , spinnerIcon , disabled } ;
} ;
type StylesType = ReturnType < typeof getStyles > ;
@ -52,36 +53,34 @@ export const SingleValue = <T extends unknown>(props: Props<T>) => {
const loading = useDelayedSwitch ( data . loading || false , { delay : 250 , duration : 750 } ) ;
return (
< components.SingleValue { ...props } >
< div className = { cx ( styles . singleValue , isDisabled && styles . disabled ) } >
{ data . imgUrl ? (
< FadeWithImage
loading = { loading }
imgUrl = { data . imgUrl }
styles = { styles }
alt = { ( data . label || data . value ) as string }
/ >
) : (
< SlideOutTransition horizontal size = { 16 } visible = { loading } duration = { 150 } >
< div className = { styles . container } >
< Spinner className = { styles . item } inline / >
< / div >
< / SlideOutTransition >
) }
{ ! data . hideText && children }
< / div >
< components.SingleValue { ...props } className = { cx ( styles . singleValue , isDisabled && styles . disabled ) } >
{ data . imgUrl ? (
< FadeWithImage
loading = { loading }
imgUrl = { data . imgUrl }
styles = { styles }
alt = { ( data . label ? ? data . value ) as string }
/ >
) : (
< SlideOutTransition horizontal size = { 16 } visible = { loading } duration = { 150 } >
< div className = { styles . spinnerWrapper } >
< Spinner className = { styles . spinnerIcon } inline / >
< / div >
< / SlideOutTransition >
) }
{ ! data . hideText && children }
< / components.SingleValue >
) ;
} ;
const FadeWithImage = ( props : { loading : boolean ; imgUrl : string ; styles : StylesType ; alt? : string } ) = > {
return (
< div className = { props . styles . contain er} >
< div className = { props . styles . spinnerWrapp er} >
< FadeTransition duration = { 150 } visible = { props . loading } >
< Spinner className = { props . styles . item } inline / >
< Spinner className = { props . styles . spinnerIcon } inline / >
< / FadeTransition >
< FadeTransition duration = { 150 } visible = { ! props . loading } >
< img className = { props . styles . item } src = { props . imgUrl } alt = { props . alt } / >
< img className = { props . styles . spinnerIcon } src = { props . imgUrl } alt = { props . alt } / >
< / FadeTransition >
< / div >
) ;