Skip to content

Commit fd8cbb8

Browse files
authored
fix(avatar): make size optional and have default size (#1345)
* fix(avatar): make size optional and have default size * chore: changeset
1 parent a440767 commit fd8cbb8

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

.changeset/twenty-parrots-care.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@twilio-paste/avatar': patch
3+
'@twilio-paste/core': patch
4+
---
5+
6+
Avatar: fixed size prop to make it optional and have a default of icon-size-70.

packages/paste-core/components/avatar/src/index.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import {isIconSizeTokenProp} from '@twilio-paste/style-props';
66
import {getComputedTokenNames, getInitialsFromName} from './utils';
77
import type {AvatarProps} from './types';
88

9-
const AvatarContents: React.FC<AvatarProps> = ({name, size, src, icon: Icon}) => {
9+
const DEFAULT_SIZE = 'sizeIcon70';
10+
11+
const AvatarContents: React.FC<AvatarProps> = ({name, size = DEFAULT_SIZE, src, icon: Icon}) => {
1012
const computedTokenNames = getComputedTokenNames(size);
1113
if (Icon != null) {
1214
if (typeof Icon !== 'function' || typeof Icon.displayName !== 'string' || !Icon.displayName.includes('Icon')) {
@@ -38,7 +40,7 @@ const AvatarContents: React.FC<AvatarProps> = ({name, size, src, icon: Icon}) =>
3840
};
3941

4042
const Avatar = React.forwardRef<HTMLDivElement, AvatarProps>(
41-
({name, children, size = 'sizeIcon70', src, icon, ...props}, ref) => {
43+
({name, children, size = DEFAULT_SIZE, src, icon, ...props}, ref) => {
4244
if (name === undefined) {
4345
console.error('[Paste Avatar]: name prop is required');
4446
}

packages/paste-core/components/avatar/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type {GenericIconProps} from '@twilio-paste/icons/esm/types';
33

44
export interface AvatarProps extends React.HTMLAttributes<'div'> {
55
name: string;
6-
size: IconSize;
6+
size?: IconSize;
77
src?: string;
88
icon?: React.FC<GenericIconProps>;
99
}

0 commit comments

Comments
 (0)