2023-03-08 22:18:55 +01:00
|
|
|
import React from 'react';
|
|
|
|
import classnames from 'classnames';
|
|
|
|
|
2023-07-14 22:05:00 +02:00
|
|
|
import { Display } from '../../../helpers/constants/design-system';
|
|
|
|
import { Box } from '..';
|
|
|
|
import type { PolymorphicRef } from '../box';
|
2023-03-08 22:18:55 +01:00
|
|
|
|
|
|
|
import {
|
|
|
|
BadgeWrapperPosition,
|
|
|
|
BadgeWrapperAnchorElementShape,
|
|
|
|
BadgeWrapperProps,
|
2023-07-14 22:05:00 +02:00
|
|
|
BadgeWrapperComponent,
|
2023-03-08 22:18:55 +01:00
|
|
|
} from './badge-wrapper.types';
|
|
|
|
|
2023-07-14 22:05:00 +02:00
|
|
|
export const BadgeWrapper: BadgeWrapperComponent = React.forwardRef(
|
|
|
|
<C extends React.ElementType = 'div'>(
|
|
|
|
{
|
|
|
|
children,
|
|
|
|
badge,
|
|
|
|
badgeContainerProps,
|
|
|
|
position = BadgeWrapperPosition.topRight,
|
|
|
|
positionObj,
|
|
|
|
anchorElementShape = BadgeWrapperAnchorElementShape.circular,
|
|
|
|
className = '',
|
|
|
|
...props
|
|
|
|
}: BadgeWrapperProps<C>,
|
|
|
|
ref?: PolymorphicRef<C>,
|
|
|
|
) => (
|
2023-03-08 22:18:55 +01:00
|
|
|
<Box
|
2023-07-14 22:05:00 +02:00
|
|
|
className={classnames('mm-badge-wrapper', className)}
|
|
|
|
ref={ref}
|
|
|
|
display={Display.InlineBlock}
|
|
|
|
{...props} // TODO: There is a typing issue with spreading props to the Box component. It still works but TypeScript complains.
|
2023-03-08 22:18:55 +01:00
|
|
|
>
|
2023-07-14 22:05:00 +02:00
|
|
|
{/* Generally the AvatarAccount or AvatarToken */}
|
|
|
|
{children}
|
|
|
|
<Box
|
|
|
|
className={classnames('mm-badge-wrapper__badge-container', {
|
|
|
|
[`mm-badge-wrapper__badge-container--${anchorElementShape}-${position}`]:
|
|
|
|
!positionObj,
|
|
|
|
})}
|
|
|
|
style={{ ...positionObj }}
|
|
|
|
{...badgeContainerProps}
|
|
|
|
>
|
|
|
|
{/* Generally the AvatarNetwork at SIZES.XS */}
|
|
|
|
{badge}
|
|
|
|
</Box>
|
2023-03-08 22:18:55 +01:00
|
|
|
</Box>
|
2023-07-14 22:05:00 +02:00
|
|
|
),
|
2023-03-08 22:18:55 +01:00
|
|
|
);
|