Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/ui/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

### Enhancements

- `Avatar`: Add an optional `color` prop for a ring with a gap, preserving the avatar's layout size and neutral fallbacks ([#84822](https://github.com/WordPress/gutenberg/pull/84822)).
- `Link`: Use a small border radius for consistent focus rings in the default variant ([#84697](https://github.com/WordPress/gutenberg/pull/84697)).
- `Tabs`: Add interaction backgrounds to unselected tabs, preserve keyboard focus rings, and replace vertical chevrons with content-height selection lines without widening minimal tab lists ([#84572](https://github.com/WordPress/gutenberg/pull/84572)).
- `Dialog`: Use the WordPress compatibility overlay slot as the default portal container when available, preserving explicit container overrides, including null to delay rendering ([#84379](https://github.com/WordPress/gutenberg/pull/84379)).
Expand Down
9 changes: 8 additions & 1 deletion packages/ui/src/avatar/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,25 @@ import styles from './style.module.css';
*/
export const Root = forwardRef< HTMLSpanElement, RootProps >(
function AvatarRoot(
{ size = 'md', shape = 'circle', className, ...props },
{ size = 'md', shape = 'circle', color, className, style, ...props },
ref
) {
const customProperties =
color === undefined
? style
: { ...style, '--_wp-ui-avatar-color': color };

return (
<_Avatar.Root
ref={ ref }
style={ customProperties }
className={ clsx(
resetStyles[ 'box-sizing' ],
defenseStyles.span,
styles.root,
styles[ `is-${ size }` ],
shape === 'square' && styles[ 'is-square' ],
color !== undefined && styles[ 'has-color' ],
className
) }
{ ...props }
Expand Down
22 changes: 22 additions & 0 deletions packages/ui/src/avatar/stories/index.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ const meta: Meta< typeof Avatar.Root > = {
role: 'img',
'aria-label': 'Alex Morgan',
},
argTypes: {
color: { control: 'color' },
},
render: ( args ) => (
<Avatar.Root { ...args }>
<Avatar.Fallback delay={ 300 }>AM</Avatar.Fallback>
Expand All @@ -43,6 +46,25 @@ type Story = StoryObj< typeof Avatar.Root >;

export const Default: Story = {};

/** The optional color ring leaves images, initials, and the person fallback unchanged. */
export const WithColor: Story = {
args: { color: '#008a20' },
render: ( args ) => (
<Stack gap="lg" align="center">
<Avatar.Root { ...args }>
<Avatar.Fallback />
<Avatar.Image src={ IMAGE_SRC } alt="" />
</Avatar.Root>
<Avatar.Root { ...args }>
<Avatar.Initials name="Alex Morgan" />
</Avatar.Root>
<Avatar.Root { ...args }>
<Avatar.Fallback />
</Avatar.Root>
</Stack>
),
};

/** Square avatars use the theme's corner radius for buttons and controls. */
export const Square: Story = {
args: { shape: 'square' },
Expand Down
11 changes: 11 additions & 0 deletions packages/ui/src/avatar/style.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@
vertical-align: middle;
}

.has-color::after {
content: "";
position: absolute;
/* Match the outer border edge of the root's padding-box containing block. */
inset: calc(-1 * var(--wpds-border-width-xs));
border-radius: inherit;
outline: var(--wpds-border-width-focus) solid var(--_wp-ui-avatar-color);
outline-offset: var(--wpds-border-width-focus);
pointer-events: none;
}

.is-square {
border-radius: var(--wpds-border-radius-sm);
}
Expand Down
11 changes: 10 additions & 1 deletion packages/ui/src/avatar/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import type { Avatar as _Avatar } from '@base-ui/react/avatar';
import type { ComponentProps } from '../utils/types';

export type RootProps = ComponentProps< typeof _Avatar.Root > & {
export type RootProps = Omit<
ComponentProps< typeof _Avatar.Root >,
'color'
> & {
/**
* The color of an optional ring around the avatar. Accepts any CSS color,
* including CSS variables. The image and fallback keep their own colors.
* The ring and its gap extend outside the avatar's layout size.
*/
color?: React.CSSProperties[ 'color' ];
/**
* The size of the avatar: `xs` (16px), `sm` (24px), `md` (32px),
* `lg` (40px), or `xl` (64px) with the default design tokens.
Expand Down
Loading