Skip to content

Commit 31fb3f3

Browse files
committed
Remove badge element – now handled via data attribute
1 parent cd1e82f commit 31fb3f3

File tree

4 files changed

+8
-45
lines changed

4 files changed

+8
-45
lines changed

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)