diff --git a/ui/components/app/nft-details/__snapshots__/nft-details.test.js.snap b/ui/components/app/nft-details/__snapshots__/nft-details.test.js.snap index ec9fd7afe..f2a08036e 100644 --- a/ui/components/app/nft-details/__snapshots__/nft-details.test.js.snap +++ b/ui/components/app/nft-details/__snapshots__/nft-details.test.js.snap @@ -50,7 +50,7 @@ exports[`NFT Details should match minimal props and state snapshot 1`] = ` data-testid="nft-item" >
MUNK #1 1
content
{ badge
} badgeContainerProps={{ 'data-testid': 'badge-custom' }} - position={{ - top: -10, - right: -10, + positionObj={{ + top: '-10px', + right: '-10px', }} > content custom @@ -108,8 +108,8 @@ describe('BadgeWrapper', () => { 'mm-badge-wrapper__badge-container--circular-top-right', ); expect(getByTestId('badge-custom')).toHaveStyle({ - top: -10, - right: -10, + top: '-10px', + right: '-10px', }); }); diff --git a/ui/components/component-library/badge-wrapper/badge-wrapper.tsx b/ui/components/component-library/badge-wrapper/badge-wrapper.tsx index b8ae0df7a..a566c2126 100644 --- a/ui/components/component-library/badge-wrapper/badge-wrapper.tsx +++ b/ui/components/component-library/badge-wrapper/badge-wrapper.tsx @@ -1,44 +1,50 @@ import React from 'react'; import classnames from 'classnames'; -import { DISPLAY } from '../../../helpers/constants/design-system'; - -import Box from '../../ui/box'; +import { Display } from '../../../helpers/constants/design-system'; +import { Box } from '..'; +import type { PolymorphicRef } from '../box'; import { BadgeWrapperPosition, BadgeWrapperAnchorElementShape, BadgeWrapperProps, + BadgeWrapperComponent, } from './badge-wrapper.types'; -export const BadgeWrapper = ({ - children, - badge, - badgeContainerProps, - position = BadgeWrapperPosition.topRight, - positionObj, - anchorElementShape = BadgeWrapperAnchorElementShape.circular, - className = '', - color, - ...props -}: BadgeWrapperProps) => ( - - {/* Generally the AvatarAccount or AvatarToken */} - {children} +export const BadgeWrapper: BadgeWrapperComponent = React.forwardRef( + ( + { + children, + badge, + badgeContainerProps, + position = BadgeWrapperPosition.topRight, + positionObj, + anchorElementShape = BadgeWrapperAnchorElementShape.circular, + className = '', + ...props + }: BadgeWrapperProps, + ref?: PolymorphicRef, + ) => ( - {/* Generally the AvatarNetwork at SIZES.XS */} - {badge} + {/* Generally the AvatarAccount or AvatarToken */} + {children} + + {/* Generally the AvatarNetwork at SIZES.XS */} + {badge} + - + ), ); diff --git a/ui/components/component-library/badge-wrapper/badge-wrapper.types.ts b/ui/components/component-library/badge-wrapper/badge-wrapper.types.ts index 3ff416c02..2bd65452f 100644 --- a/ui/components/component-library/badge-wrapper/badge-wrapper.types.ts +++ b/ui/components/component-library/badge-wrapper/badge-wrapper.types.ts @@ -1,4 +1,9 @@ -import type { BoxProps } from '../../ui/box/box.d'; +import React from 'react'; + +import type { + StyleUtilityProps, + PolymorphicComponentPropWithRef, +} from '../box'; export enum BadgeWrapperPosition { topRight = 'top-right', @@ -12,7 +17,7 @@ export enum BadgeWrapperAnchorElementShape { circular = 'circular', } -export interface BadgeWrapperProps extends BoxProps { +export interface BadgeWrapperStyleUtilityProps extends StyleUtilityProps { /** * The element to be wrapped by the BadgeWrapper and for the badge to be positioned on top of */ @@ -24,7 +29,7 @@ export interface BadgeWrapperProps extends BoxProps { /** * The BadgeWrapper props of the component. All Box props can be used */ - badgeContainerProps?: BoxProps; + badgeContainerProps?: any; // TODO: Replace with Box types when the syntax and typing is properly figured out. Needs to accept everything Box accepts /** * The position of the Badge. Possible values could be 'BadgeWrapperPosition.topRight', 'BadgeWrapperPosition.bottomRight','BadgeWrapperPosition.topLeft', 'BadgeWrapperPosition.bottomLeft' * Defaults to 'BadgeWrapperPosition.topRight' @@ -34,10 +39,10 @@ export interface BadgeWrapperProps extends BoxProps { * The positionObj can be used to override the default positioning of the badge it accepts an object with the following keys { top, right, bottom, left } */ positionObj?: { - top?: number; - right?: number; - bottom?: number; - left?: number; + top?: number | string; + right?: number | string; + bottom?: number | string; + left?: number | string; }; /** * The shape of the anchor element. Possible values could be 'BadgeWrapperAnchorElementShape.circular', 'BadgeWrapperAnchorElementShape.square' @@ -49,3 +54,10 @@ export interface BadgeWrapperProps extends BoxProps { */ className?: string; } + +export type BadgeWrapperProps = + PolymorphicComponentPropWithRef; + +export type BadgeWrapperComponent = ( + props: BadgeWrapperProps, +) => React.ReactElement | null; diff --git a/ui/components/multichain/connected-site-menu/__snapshots__/connected-site-menu.test.js.snap b/ui/components/multichain/connected-site-menu/__snapshots__/connected-site-menu.test.js.snap index b85220409..372d90b6f 100644 --- a/ui/components/multichain/connected-site-menu/__snapshots__/connected-site-menu.test.js.snap +++ b/ui/components/multichain/connected-site-menu/__snapshots__/connected-site-menu.test.js.snap @@ -16,14 +16,14 @@ exports[`Connected Site Menu should render the site menu in connected state 1`] tabindex="0" >