1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 18:00:18 +01:00
metamask-extension/ui/components/component-library/avatar-base/avatar-base.tsx
Binij Shrestha ceadfacb21
Fix/18884 migrate avatar network (#19079)
* Migrate AvatarNetwokr

fixing error

fix textAlign

added AvatarNetworkSize

NetworkProps extends BaseProps instead of Boxprops

omitted children from base, made name required

replace deprecated and fix lint

* update AvatarNetwork TS

* add AvatarNetworkSize test

* remove unused size import

* Update ui/components/component-library/avatar-network/avatar-network.types.ts

Co-authored-by: George Marshall <georgewrmarshall@gmail.com>

* fix readme

* update to latest box component

---------

Co-authored-by: garrettbear <gwhisten@gmail.com>
Co-authored-by: George Marshall <georgewrmarshall@gmail.com>
2023-07-24 11:15:33 -07:00

70 lines
1.8 KiB
TypeScript

import React from 'react';
import classnames from 'classnames';
import {
BackgroundColor,
BorderColor,
TextColor,
Display,
JustifyContent,
AlignItems,
BorderRadius,
TextVariant,
TextTransform,
} from '../../../helpers/constants/design-system';
import type { PolymorphicRef } from '../box';
import { Text } from '../text';
import type { TextProps } from '../text';
import {
AvatarBaseComponent,
AvatarBaseProps,
AvatarBaseSize,
} from './avatar-base.types';
export const AvatarBase: AvatarBaseComponent = React.forwardRef(
<C extends React.ElementType = 'div'>(
{
size = AvatarBaseSize.Md,
children,
backgroundColor = BackgroundColor.backgroundAlternative,
borderColor = BorderColor.borderDefault,
color = TextColor.textDefault,
className = '',
...props
}: AvatarBaseProps<C>,
ref?: PolymorphicRef<C>,
) => {
let fallbackTextVariant;
if (size === AvatarBaseSize.Lg || size === AvatarBaseSize.Xl) {
fallbackTextVariant = TextVariant.bodyLgMedium;
} else if (size === AvatarBaseSize.Sm || size === AvatarBaseSize.Md) {
fallbackTextVariant = TextVariant.bodySm;
} else {
fallbackTextVariant = TextVariant.bodyXs;
}
return (
<Text
className={classnames(
'mm-avatar-base',
`mm-avatar-base--size-${size}`,
className,
)}
ref={ref}
as="div"
display={Display.Flex}
justifyContent={JustifyContent.center}
alignItems={AlignItems.center}
borderRadius={BorderRadius.full}
variant={fallbackTextVariant}
textTransform={TextTransform.Uppercase}
{...{ backgroundColor, borderColor, color }}
{...(props as TextProps<C>)}
>
{children}
</Text>
);
},
);