diff --git a/ui/components/component-library/avatar-base/README.mdx b/ui/components/component-library/avatar-base/README.mdx index d232dfc10ac8..da27d6677790 100644 --- a/ui/components/component-library/avatar-base/README.mdx +++ b/ui/components/component-library/avatar-base/README.mdx @@ -39,13 +39,13 @@ The text styles of the `AvatarBase` is based on the `size` prop. To override thi ```jsx -import { AVATAR_BASE_SIZES } from '../ui/component-library/avatar-base'; -import { AvatarBase } from '../../component-library'; - - - - - +import { AvatarBaseSize } from '../ui/component-library/avatar-base/avatar-base.types'; +import { AvatarBase } from '../../component-library/avatar-base'; + + + + + ``` ### Children diff --git a/ui/components/component-library/avatar-base/__snapshots__/avatar-base.test.js.snap b/ui/components/component-library/avatar-base/__snapshots__/avatar-base.test.tsx.snap similarity index 100% rename from ui/components/component-library/avatar-base/__snapshots__/avatar-base.test.js.snap rename to ui/components/component-library/avatar-base/__snapshots__/avatar-base.test.tsx.snap diff --git a/ui/components/component-library/avatar-base/avatar-base.constants.js b/ui/components/component-library/avatar-base/avatar-base.constants.js deleted file mode 100644 index 6adba7a62994..000000000000 --- a/ui/components/component-library/avatar-base/avatar-base.constants.js +++ /dev/null @@ -1,9 +0,0 @@ -import { Size } from '../../../helpers/constants/design-system'; - -export const AVATAR_BASE_SIZES = { - XS: Size.XS, - SM: Size.SM, - MD: Size.MD, - LG: Size.LG, - XL: Size.XL, -}; diff --git a/ui/components/component-library/avatar-base/avatar-base.js b/ui/components/component-library/avatar-base/avatar-base.js deleted file mode 100644 index 7134ee9cc574..000000000000 --- a/ui/components/component-library/avatar-base/avatar-base.js +++ /dev/null @@ -1,106 +0,0 @@ -import React from 'react'; -import PropTypes from 'prop-types'; -import classnames from 'classnames'; - -import { - BackgroundColor, - BorderColor, - TextColor, - IconColor, - DISPLAY, - JustifyContent, - AlignItems, - BorderRadius, - TextVariant, - TEXT_TRANSFORM, -} from '../../../helpers/constants/design-system'; - -import { Text } from '../text'; - -import { AVATAR_BASE_SIZES } from './avatar-base.constants'; - -export const AvatarBase = React.forwardRef( - ( - { - size = AVATAR_BASE_SIZES.MD, - children, - backgroundColor = BackgroundColor.backgroundAlternative, - borderColor = BorderColor.borderDefault, - color = TextColor.textDefault, - className, - ...props - }, - ref, - ) => { - let fallbackTextVariant; - - if (size === AVATAR_BASE_SIZES.LG || size === AVATAR_BASE_SIZES.XL) { - fallbackTextVariant = TextVariant.bodyLgMedium; - } else if (size === AVATAR_BASE_SIZES.SM || size === AVATAR_BASE_SIZES.MD) { - fallbackTextVariant = TextVariant.bodySm; - } else { - fallbackTextVariant = TextVariant.bodyXs; - } - return ( - - {children} - - ); - }, -); - -AvatarBase.propTypes = { - /** - * The size of the AvatarBase. - * Possible values could be 'AVATAR_BASE_SIZES.XS'(16px), 'AVATAR_BASE_SIZES.SM'(24px), 'AVATAR_BASE_SIZES.MD'(32px), 'AVATAR_BASE_SIZES.LG'(40px), 'AVATAR_BASE_SIZES.XL'(48px) - * Defaults to AVATAR_BASE_SIZES.MD - */ - size: PropTypes.oneOf(Object.values(AVATAR_BASE_SIZES)), - /** - * The children to be rendered inside the AvatarBase - */ - children: PropTypes.node, - /** - * The background color of the AvatarBase - * Defaults to Color.backgroundAlternative - */ - backgroundColor: PropTypes.oneOf(Object.values(BackgroundColor)), - /** - * The background color of the AvatarBase - * Defaults to Color.borderDefault - */ - borderColor: PropTypes.oneOf(Object.values(BorderColor)), - /** - * The color of the text inside the AvatarBase - * Defaults to TextColor.textDefault - */ - color: PropTypes.oneOf([ - ...Object.values(TextColor), - ...Object.values(IconColor), - ]), - /** - * Additional classNames to be added to the AvatarToken - */ - className: PropTypes.string, - /** - * AvatarBase also accepts all Text props including variant and all Box props - */ - ...Text.propTypes, -}; - -AvatarBase.displayName = 'AvatarBase'; diff --git a/ui/components/component-library/avatar-base/avatar-base.stories.js b/ui/components/component-library/avatar-base/avatar-base.stories.tsx similarity index 77% rename from ui/components/component-library/avatar-base/avatar-base.stories.js rename to ui/components/component-library/avatar-base/avatar-base.stories.tsx index cd86e81d1b5b..85852edde464 100644 --- a/ui/components/component-library/avatar-base/avatar-base.stories.js +++ b/ui/components/component-library/avatar-base/avatar-base.stories.tsx @@ -1,3 +1,4 @@ +import { ComponentMeta } from '@storybook/react'; import React from 'react'; import { AlignItems, @@ -5,7 +6,7 @@ import { TextColor, BackgroundColor, BorderColor, - Color, + IconColor, } from '../../../helpers/constants/design-system'; import Box from '../../ui/box/box'; @@ -13,7 +14,7 @@ import Box from '../../ui/box/box'; import { Icon, IconName } from '..'; import README from './README.mdx'; import { AvatarBase } from './avatar-base'; -import { AVATAR_BASE_SIZES } from './avatar-base.constants'; +import { AvatarBaseProps, AvatarBaseSize } from './avatar-base.types'; const marginSizeKnobOptions = [ 0, @@ -44,7 +45,7 @@ export default { argTypes: { size: { control: 'select', - options: Object.values(AVATAR_BASE_SIZES), + options: Object.values(AvatarBaseSize), }, color: { options: Object.values(TextColor), @@ -85,29 +86,29 @@ export default { }, }, args: { - size: AVATAR_BASE_SIZES.MD, + size: AvatarBaseSize.Md, color: TextColor.textDefault, backgroundColor: BackgroundColor.backgroundAlternative, borderColor: BorderColor.borderDefault, children: 'B', }, -}; +} as ComponentMeta; -export const DefaultStory = (args) => ; +export const DefaultStory = (args: AvatarBaseProps) => ; DefaultStory.storyName = 'Default'; -export const Size = (args) => ( +export const Size = (args: AvatarBaseProps) => ( - - - - - + + + + + ); -export const Children = (args) => ( +export const Children = (args: AvatarBaseProps) => ( @@ -124,12 +125,12 @@ export const Children = (args) => ( backgroundColor={BackgroundColor.infoMuted} borderColor={BorderColor.infoMuted} > - + ); -export const ColorBackgroundColorAndBorderColor = (args) => ( +export const ColorBackgroundColorAndBorderColor = (args: AvatarBaseProps) => ( B { it('should render correctly', () => { @@ -17,11 +23,11 @@ describe('AvatarBase', () => { it('should render with different size classes', () => { const { getByTestId } = render( <> - - - - - + + + + + , ); expect(getByTestId('avatar-base-xs')).toHaveClass( @@ -84,11 +90,11 @@ describe('AvatarBase', () => { const { getByTestId } = render( <> , @@ -105,11 +111,11 @@ describe('AvatarBase', () => { const { getByTestId } = render( <> , diff --git a/ui/components/component-library/avatar-base/avatar-base.tsx b/ui/components/component-library/avatar-base/avatar-base.tsx new file mode 100644 index 000000000000..e2dde68709ad --- /dev/null +++ b/ui/components/component-library/avatar-base/avatar-base.tsx @@ -0,0 +1,63 @@ +import React, { forwardRef, Ref } from 'react'; +import classnames from 'classnames'; + +import { + BackgroundColor, + BorderColor, + TextColor, + DISPLAY, + JustifyContent, + AlignItems, + BorderRadius, + TextVariant, + TextTransform, +} from '../../../helpers/constants/design-system'; + +import { Text, ValidTag } from '../text'; + +import { AvatarBaseProps, AvatarBaseSize } from './avatar-base.types'; + +export const AvatarBase = forwardRef( + ( + { + size = AvatarBaseSize.Md, + children, + backgroundColor = BackgroundColor.backgroundAlternative, + borderColor = BorderColor.borderDefault, + color = TextColor.textDefault, + className = '', + ...props + }: AvatarBaseProps, + ref: Ref, + ) => { + 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 ( + + {children} + + ); + }, +); diff --git a/ui/components/component-library/avatar-base/avatar-base.types.ts b/ui/components/component-library/avatar-base/avatar-base.types.ts new file mode 100644 index 000000000000..11bc51ac7453 --- /dev/null +++ b/ui/components/component-library/avatar-base/avatar-base.types.ts @@ -0,0 +1,47 @@ +import { + BackgroundColor, + BorderColor, + TextColor, +} from '../../../helpers/constants/design-system'; +import { TextProps } from '../text'; + +export enum AvatarBaseSize { + Xs = 'xs', + Sm = 'sm', + Md = 'md', + Lg = 'lg', + Xl = 'xl', +} + +export interface AvatarBaseProps extends TextProps { + /** + * The size of the AvatarBase. + * Possible values could be 'AvatarBaseSize.Xs'(16px), 'AvatarBaseSize.Sm'(24px), + * 'AvatarBaseSize.Md'(32px), 'AvatarBaseSize.Lg'(40px), 'AvatarBaseSize.Xl'(48px) + * Defaults to AvatarBaseSize.Md + */ + size?: AvatarBaseSize; + /** + * The children to be rendered inside the AvatarBase + */ + children: React.ReactNode; + /** + * The background color of the AvatarBase + * Defaults to Color.backgroundAlternative + */ + backgroundColor?: BackgroundColor; + /** + * The background color of the AvatarBase + * Defaults to Color.borderDefault + */ + borderColor?: BorderColor; + /** + * The color of the text inside the AvatarBase + * Defaults to TextColor.textDefault + */ + color?: TextColor; + /** + * Additional classNames to be added to the AvatarBase + */ + className?: string; +} diff --git a/ui/components/component-library/avatar-base/index.js b/ui/components/component-library/avatar-base/index.js deleted file mode 100644 index 5cd6109d9e85..000000000000 --- a/ui/components/component-library/avatar-base/index.js +++ /dev/null @@ -1,2 +0,0 @@ -export { AvatarBase } from './avatar-base'; -export { AVATAR_BASE_SIZES } from './avatar-base.constants'; diff --git a/ui/components/component-library/avatar-base/index.ts b/ui/components/component-library/avatar-base/index.ts new file mode 100644 index 000000000000..e1295f32a341 --- /dev/null +++ b/ui/components/component-library/avatar-base/index.ts @@ -0,0 +1,3 @@ +export { AvatarBase } from './avatar-base'; +export { AvatarBaseSize } from './avatar-base.types'; +export type { AvatarBaseProps } from './avatar-base.types';