Skip to content

Commit 92110f1

Browse files
authored
fix(avatars): update avatar CSS for badge animation (#363)
...also fix demo page to use `isSystem` (not `system`) for system avatars.
1 parent 104615f commit 92110f1

File tree

6 files changed

+14
-51
lines changed

6 files changed

+14
-51
lines changed

packages/avatars/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"styled-components": "^4.2.0"
3030
},
3131
"devDependencies": {
32-
"@zendeskgarden/css-avatars": "5.0.0",
32+
"@zendeskgarden/css-avatars": "6.0.0",
3333
"@zendeskgarden/react-theming": "^6.0.1"
3434
},
3535
"keywords": [

packages/avatars/src/Avatar.example.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const StyledSvgAvatar = styled(Avatar)`
2727
</Col>
2828
<Col md>
2929
<h3>System</h3>
30-
<Avatar system>
30+
<Avatar isSystem>
3131
<img src="images/system.png" alt="System avatar" />
3232
</Avatar>
3333
</Col>
@@ -75,22 +75,22 @@ const StyledSvgAvatar = styled(Avatar)`
7575
</Row>
7676
<Row alignItems="center" justifyContent="center">
7777
<Col md>
78-
<Avatar size="extrasmall" system>
78+
<Avatar size="extrasmall" isSystem>
7979
<img src="images/system.png" alt="System Avatar" />
8080
</Avatar>
8181
</Col>
8282
<Col md>
83-
<Avatar size="small" system>
83+
<Avatar size="small" isSystem>
8484
<img src="images/system.png" alt="System Avatar" />
8585
</Avatar>
8686
</Col>
8787
<Col md>
88-
<Avatar system>
88+
<Avatar isSystem>
8989
<img src="images/system.png" alt="System Avatar" />
9090
</Avatar>
9191
</Col>
9292
<Col md>
93-
<Avatar size="large" system>
93+
<Avatar size="large" isSystem>
9494
<img src="images/system.png" alt="System Avatar" />
9595
</Avatar>
9696
</Col>

packages/avatars/src/Avatar.js

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import React from 'react';
99
import PropTypes from 'prop-types';
10-
import { StyledAvatar, StyledBadge } from './styled';
10+
import { StyledAvatar } from './styled';
1111

1212
const SIZE = {
1313
EXTRASMALL: 'extrasmall',
@@ -27,40 +27,28 @@ const STATUS = {
2727
const Avatar = ({ isSystem, size, status, children, badge, ...other }) => {
2828
let computedStatus = status;
2929

30-
if (status === STATUS.AVAILABLE && badge !== undefined) {
30+
if (status === STATUS.AVAILABLE && badge) {
3131
computedStatus = STATUS.ACTIVE;
3232
}
3333

34-
const FormattedBadge = () => {
35-
if (status === undefined || status === STATUS.AWAY) {
36-
return null;
37-
}
38-
39-
if (computedStatus === STATUS.AVAILABLE) {
40-
return <StyledBadge />;
41-
}
42-
43-
return <StyledBadge>{badge}</StyledBadge>;
44-
};
45-
4634
return (
4735
<StyledAvatar
4836
isSystem={isSystem}
4937
size={size}
5038
status={computedStatus}
39+
data-badge={badge}
5140
aria-live="polite"
5241
{...other}
5342
>
5443
{children}
55-
<FormattedBadge />
5644
</StyledAvatar>
5745
);
5846
};
5947

6048
Avatar.propTypes = {
6149
/** Applies system styling */
6250
isSystem: PropTypes.bool,
63-
badge: PropTypes.node,
51+
badge: PropTypes.oneOf([PropTypes.string, PropTypes.number]),
6452
size: PropTypes.oneOf([SIZE.EXTRASMALL, SIZE.SMALL, SIZE.LARGE]),
6553
status: PropTypes.oneOf([STATUS.AVAILABLE, STATUS.AWAY]),
6654
children: PropTypes.node

packages/avatars/src/Avatar.spec.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,15 @@ describe('Avatar', () => {
3535
});
3636

3737
it('applies active styling if provided with badge', () => {
38-
const { container } = render(
39-
<Avatar status="available" badge={<span data-test-id="badge">2</span>} />
40-
);
38+
const { container } = render(<Avatar status="available" badge="2" />);
4139

4240
expect(container.firstChild).toHaveClass('is-active');
4341
});
4442

4543
it('renders badge if provided with status', () => {
46-
const { getByTestId } = render(
47-
<Avatar status="available" badge={<span data-test-id="badge">2</span>} />
48-
);
44+
const { container } = render(<Avatar status="available" badge="2" />);
4945

50-
expect(getByTestId('badge')).not.toBeUndefined();
46+
expect(container.firstChild).toHaveAttribute('data-badge');
5147
});
5248

5349
it('does not render badge if away status is provided', () => {

packages/avatars/src/styled.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,6 @@ StyledAvatar.propTypes = {
5858
status: PropTypes.oneOf([STATUS.AVAILABLE, STATUS.ACTIVE, STATUS.AWAY])
5959
};
6060

61-
const BADGE_COMPONENT_ID = 'avatars.badge';
62-
63-
/**
64-
* Accepts all `<figcaption>` attributes
65-
*/
66-
export const StyledBadge = styled.figcaption.attrs({
67-
'data-garden-id': BADGE_COMPONENT_ID,
68-
'data-garden-version': PACKAGE_VERSION,
69-
className: AvatarStyles['c-avatar__badge']
70-
})`
71-
${props => retrieveTheme(BADGE_COMPONENT_ID, props)};
72-
`;
73-
7461
const TEXT_COMPONENT_ID = 'avatars.text';
7562

7663
/**

packages/avatars/src/styled.spec.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import React from 'react';
99
import { render, renderRtl } from 'garden-test-utils';
10-
import { StyledAvatar, StyledBadge, StyledText } from './styled';
10+
import { StyledAvatar, StyledText } from './styled';
1111

1212
describe('Styled Elements', () => {
1313
describe('StyledAvatar', () => {
@@ -52,14 +52,6 @@ describe('Styled Elements', () => {
5252
});
5353
});
5454

55-
describe('StyledBadge', () => {
56-
it('renders badge styling by default', () => {
57-
const { container } = render(<StyledBadge />);
58-
59-
expect(container.firstChild).toHaveClass(`c-avatar__badge`);
60-
});
61-
});
62-
6355
describe('StyledText', () => {
6456
it('renders text styling by default', () => {
6557
const { container } = render(<StyledText />);

0 commit comments

Comments
 (0)