mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Updating Avatar components to forward refs (#18678)
Co-authored-by: Brad Decker <bhdecker84@gmail.com>
This commit is contained in:
parent
7617a44a57
commit
d2779c9ef1
@ -13,14 +13,19 @@ import {
|
|||||||
AvatarAccountSize,
|
AvatarAccountSize,
|
||||||
} from './avatar-account.types';
|
} from './avatar-account.types';
|
||||||
|
|
||||||
export const AvatarAccount = ({
|
export const AvatarAccount = React.forwardRef(
|
||||||
|
(
|
||||||
|
{
|
||||||
size = AvatarAccountSize.Md,
|
size = AvatarAccountSize.Md,
|
||||||
address,
|
address,
|
||||||
className,
|
className,
|
||||||
variant = AvatarAccountVariant.Jazzicon,
|
variant = AvatarAccountVariant.Jazzicon,
|
||||||
...props
|
...props
|
||||||
}) => (
|
},
|
||||||
|
ref,
|
||||||
|
) => (
|
||||||
<AvatarBase
|
<AvatarBase
|
||||||
|
ref={ref}
|
||||||
size={size}
|
size={size}
|
||||||
className={classnames('mm-avatar-account', className)}
|
className={classnames('mm-avatar-account', className)}
|
||||||
{...props}
|
{...props}
|
||||||
@ -39,6 +44,7 @@ export const AvatarAccount = ({
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</AvatarBase>
|
</AvatarBase>
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
AvatarAccount.propTypes = {
|
AvatarAccount.propTypes = {
|
||||||
@ -66,3 +72,5 @@ AvatarAccount.propTypes = {
|
|||||||
*/
|
*/
|
||||||
...Box.propTypes,
|
...Box.propTypes,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
AvatarAccount.displayName = 'AvatarAccount';
|
||||||
|
@ -112,4 +112,15 @@ describe('AvatarAccount', () => {
|
|||||||
'mm-avatar-base--size-xl',
|
'mm-avatar-base--size-xl',
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
it('should forward a ref to the root html element', () => {
|
||||||
|
const ref = React.createRef();
|
||||||
|
render(
|
||||||
|
<AvatarAccount
|
||||||
|
address="0x5CfE73b6021E818B776b421B1c4Db2474086a7e1"
|
||||||
|
ref={ref}
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
expect(ref.current).not.toBeNull();
|
||||||
|
expect(ref.current.nodeName).toBe('DIV');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -121,4 +121,10 @@ describe('AvatarBase', () => {
|
|||||||
`box--border-color-${Color.errorDefault}`,
|
`box--border-color-${Color.errorDefault}`,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
it('should forward a ref to the root html element', () => {
|
||||||
|
const ref = React.createRef();
|
||||||
|
render(<AvatarBase ref={ref}>A</AvatarBase>);
|
||||||
|
expect(ref.current).not.toBeNull();
|
||||||
|
expect(ref.current.nodeName).toBe('DIV');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -15,7 +15,9 @@ import {
|
|||||||
import { useI18nContext } from '../../../hooks/useI18nContext';
|
import { useI18nContext } from '../../../hooks/useI18nContext';
|
||||||
import { AVATAR_FAVICON_SIZES } from './avatar-favicon.constants';
|
import { AVATAR_FAVICON_SIZES } from './avatar-favicon.constants';
|
||||||
|
|
||||||
export const AvatarFavicon = ({
|
export const AvatarFavicon = React.forwardRef(
|
||||||
|
(
|
||||||
|
{
|
||||||
size = Size.MD,
|
size = Size.MD,
|
||||||
src,
|
src,
|
||||||
name = 'avatar-favicon',
|
name = 'avatar-favicon',
|
||||||
@ -23,11 +25,13 @@ export const AvatarFavicon = ({
|
|||||||
fallbackIconProps,
|
fallbackIconProps,
|
||||||
borderColor = BorderColor.transparent,
|
borderColor = BorderColor.transparent,
|
||||||
...props
|
...props
|
||||||
}) => {
|
},
|
||||||
|
ref,
|
||||||
|
) => {
|
||||||
const t = useI18nContext();
|
const t = useI18nContext();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AvatarBase
|
<AvatarBase
|
||||||
|
ref={ref}
|
||||||
size={size}
|
size={size}
|
||||||
display={DISPLAY.FLEX}
|
display={DISPLAY.FLEX}
|
||||||
alignItems={AlignItems.center}
|
alignItems={AlignItems.center}
|
||||||
@ -51,7 +55,8 @@ export const AvatarFavicon = ({
|
|||||||
)}
|
)}
|
||||||
</AvatarBase>
|
</AvatarBase>
|
||||||
);
|
);
|
||||||
};
|
},
|
||||||
|
);
|
||||||
|
|
||||||
AvatarFavicon.propTypes = {
|
AvatarFavicon.propTypes = {
|
||||||
/**
|
/**
|
||||||
@ -87,3 +92,5 @@ AvatarFavicon.propTypes = {
|
|||||||
*/
|
*/
|
||||||
...Box.propTypes,
|
...Box.propTypes,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
AvatarFavicon.displayName = 'AvatarFavicon';
|
||||||
|
@ -105,4 +105,10 @@ describe('AvatarFavicon', () => {
|
|||||||
);
|
);
|
||||||
expect(getByTestId('classname')).toHaveClass('mm-avatar-favicon--test');
|
expect(getByTestId('classname')).toHaveClass('mm-avatar-favicon--test');
|
||||||
});
|
});
|
||||||
|
it('should forward a ref to the root html element', () => {
|
||||||
|
const ref = React.createRef();
|
||||||
|
render(<AvatarFavicon name="test" ref={ref} />);
|
||||||
|
expect(ref.current).not.toBeNull();
|
||||||
|
expect(ref.current.nodeName).toBe('DIV');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -19,7 +19,9 @@ import { AvatarBase } from '../avatar-base';
|
|||||||
|
|
||||||
import { AVATAR_ICON_SIZES } from './avatar-icon.constants';
|
import { AVATAR_ICON_SIZES } from './avatar-icon.constants';
|
||||||
|
|
||||||
export const AvatarIcon = ({
|
export const AvatarIcon = React.forwardRef(
|
||||||
|
(
|
||||||
|
{
|
||||||
size = Size.MD,
|
size = Size.MD,
|
||||||
color = TextColor.primaryDefault,
|
color = TextColor.primaryDefault,
|
||||||
backgroundColor = BackgroundColor.primaryMuted,
|
backgroundColor = BackgroundColor.primaryMuted,
|
||||||
@ -27,8 +29,11 @@ export const AvatarIcon = ({
|
|||||||
iconProps,
|
iconProps,
|
||||||
iconName,
|
iconName,
|
||||||
...props
|
...props
|
||||||
}) => (
|
},
|
||||||
|
ref,
|
||||||
|
) => (
|
||||||
<AvatarBase
|
<AvatarBase
|
||||||
|
ref={ref}
|
||||||
size={size}
|
size={size}
|
||||||
display={DISPLAY.FLEX}
|
display={DISPLAY.FLEX}
|
||||||
alignItems={AlignItems.center}
|
alignItems={AlignItems.center}
|
||||||
@ -46,6 +51,7 @@ export const AvatarIcon = ({
|
|||||||
{...iconProps}
|
{...iconProps}
|
||||||
/>
|
/>
|
||||||
</AvatarBase>
|
</AvatarBase>
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
AvatarIcon.propTypes = {
|
AvatarIcon.propTypes = {
|
||||||
@ -87,3 +93,5 @@ AvatarIcon.propTypes = {
|
|||||||
*/
|
*/
|
||||||
...Box.propTypes,
|
...Box.propTypes,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
AvatarIcon.displayName = 'AvatarIcon';
|
||||||
|
@ -105,4 +105,10 @@ describe('AvatarIcon', () => {
|
|||||||
'box--background-color-success-muted',
|
'box--background-color-success-muted',
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
it('should forward a ref to the root html element', () => {
|
||||||
|
const ref = React.createRef();
|
||||||
|
render(<AvatarIcon iconName={IconName.SwapHorizontal} ref={ref} />);
|
||||||
|
expect(ref.current).not.toBeNull();
|
||||||
|
expect(ref.current.nodeName).toBe('DIV');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -123,4 +123,10 @@ describe('AvatarNetwork', () => {
|
|||||||
`box--border-color-${BorderColor.errorDefault}`,
|
`box--border-color-${BorderColor.errorDefault}`,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
it('should forward a ref to the root html element', () => {
|
||||||
|
const ref = React.createRef();
|
||||||
|
render(<AvatarNetwork ref={ref} />);
|
||||||
|
expect(ref.current).not.toBeNull();
|
||||||
|
expect(ref.current.nodeName).toBe('DIV');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -14,7 +14,9 @@ import {
|
|||||||
} from '../../../helpers/constants/design-system';
|
} from '../../../helpers/constants/design-system';
|
||||||
import { AVATAR_TOKEN_SIZES } from './avatar-token.constants';
|
import { AVATAR_TOKEN_SIZES } from './avatar-token.constants';
|
||||||
|
|
||||||
export const AvatarToken = ({
|
export const AvatarToken = React.forwardRef(
|
||||||
|
(
|
||||||
|
{
|
||||||
size = Size.MD,
|
size = Size.MD,
|
||||||
name,
|
name,
|
||||||
src,
|
src,
|
||||||
@ -24,7 +26,9 @@ export const AvatarToken = ({
|
|||||||
borderColor = BorderColor.transparent,
|
borderColor = BorderColor.transparent,
|
||||||
className,
|
className,
|
||||||
...props
|
...props
|
||||||
}) => {
|
},
|
||||||
|
ref,
|
||||||
|
) => {
|
||||||
const [showFallback, setShowFallback] = useState(false);
|
const [showFallback, setShowFallback] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -39,6 +43,7 @@ export const AvatarToken = ({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<AvatarBase
|
<AvatarBase
|
||||||
|
ref={ref}
|
||||||
size={size}
|
size={size}
|
||||||
display={DISPLAY.FLEX}
|
display={DISPLAY.FLEX}
|
||||||
alignItems={AlignItems.center}
|
alignItems={AlignItems.center}
|
||||||
@ -77,7 +82,8 @@ export const AvatarToken = ({
|
|||||||
)}
|
)}
|
||||||
</AvatarBase>
|
</AvatarBase>
|
||||||
);
|
);
|
||||||
};
|
},
|
||||||
|
);
|
||||||
|
|
||||||
AvatarToken.propTypes = {
|
AvatarToken.propTypes = {
|
||||||
/**
|
/**
|
||||||
@ -123,3 +129,5 @@ AvatarToken.propTypes = {
|
|||||||
*/
|
*/
|
||||||
...Box.propTypes,
|
...Box.propTypes,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
AvatarToken.displayName = 'AvatarToken';
|
||||||
|
@ -121,4 +121,10 @@ describe('AvatarToken', () => {
|
|||||||
`box--border-color-${BorderColor.errorDefault}`,
|
`box--border-color-${BorderColor.errorDefault}`,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
it('should forward a ref to the root html element', () => {
|
||||||
|
const ref = React.createRef();
|
||||||
|
render(<AvatarToken ref={ref} />);
|
||||||
|
expect(ref.current).not.toBeNull();
|
||||||
|
expect(ref.current.nodeName).toBe('DIV');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user