diff --git a/packages/ui/report.api.md b/packages/ui/report.api.md index 1a015747a8..4a94c2fd9f 100644 --- a/packages/ui/report.api.md +++ b/packages/ui/report.api.md @@ -256,13 +256,27 @@ export const Avatar: ForwardRefExoticComponent< // @public export const AvatarDefinition: { + readonly styles: { + readonly [key: string]: string; + }; readonly classNames: { readonly root: 'bui-AvatarRoot'; readonly image: 'bui-AvatarImage'; readonly fallback: 'bui-AvatarFallback'; }; - readonly dataAttributes: { - readonly size: readonly ['small', 'medium', 'large']; + readonly propDefs: { + readonly size: { + readonly dataAttribute: true; + readonly default: 'medium'; + }; + readonly purpose: { + readonly default: 'informative'; + }; + readonly src: {}; + readonly name: {}; + readonly children: {}; + readonly className: {}; + readonly style: {}; }; }; diff --git a/packages/ui/src/components/Avatar/Avatar.tsx b/packages/ui/src/components/Avatar/Avatar.tsx index 920a9b127f..c36c5f02a0 100644 --- a/packages/ui/src/components/Avatar/Avatar.tsx +++ b/packages/ui/src/components/Avatar/Avatar.tsx @@ -15,24 +15,18 @@ */ import { forwardRef, useState, useEffect } from 'react'; -import clsx from 'clsx'; import { AvatarProps } from './types'; -import { useStyles } from '../../hooks/useStyles'; +import { useDefinition } from '../../hooks/useDefinition'; import { AvatarDefinition } from './definition'; -import styles from './Avatar.module.css'; /** @public */ export const Avatar = forwardRef((props, ref) => { - const { classNames, dataAttributes, cleanedProps } = useStyles( + const { ownProps, restProps, dataAttributes } = useDefinition( AvatarDefinition, - { - size: 'medium', - purpose: 'informative', - ...props, - }, + props, ); - const { className, src, name, purpose, ...rest } = cleanedProps; + const { classes, size, src, name, purpose, style } = ownProps; const [imageStatus, setImageStatus] = useState< 'loading' | 'loaded' | 'error' @@ -51,9 +45,7 @@ export const Avatar = forwardRef((props, ref) => { }; }, [src]); - const initialsCount = ['x-small', 'small'].includes(cleanedProps.size) - ? 1 - : 2; + const initialsCount = ['x-small', 'small'].includes(size) ? 1 : 2; const initials = name .split(' ') @@ -68,21 +60,15 @@ export const Avatar = forwardRef((props, ref) => { role="img" aria-label={purpose === 'informative' ? name : undefined} aria-hidden={purpose === 'decoration' ? true : undefined} - className={clsx(classNames.root, styles[classNames.root], className)} + className={classes.root} + style={style} {...dataAttributes} - {...rest} + {...restProps} > {imageStatus === 'loaded' ? ( - + ) : ( -