Skip to content

Commit 9cce9ad

Browse files
committed
chore: code review changes
1 parent 462d84d commit 9cce9ad

File tree

5 files changed

+20
-34
lines changed

5 files changed

+20
-34
lines changed

packages/avatars/src/elements/Avatar.spec.tsx

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

88
import React from 'react';
99
import { render, cleanup } from 'garden-test-utils';
10-
import { DEFAULT_THEME, getColor } from '@zendeskgarden/react-theming';
10+
import { DEFAULT_THEME, PALETTE } from '@zendeskgarden/react-theming';
1111
import { Avatar } from './Avatar';
1212

13-
const activeBoxShadow = DEFAULT_THEME.shadows.sm(
14-
getColor({ hue: 'crimson', shade: 700, theme: DEFAULT_THEME })!
15-
);
13+
const activeBoxShadow = DEFAULT_THEME.shadows.sm(PALETTE.crimson[700]);
1614

1715
describe('Avatar', () => {
1816
afterEach(cleanup);

packages/avatars/src/styled/StyledAvatar.spec.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { DEFAULT_THEME } from '@zendeskgarden/react-theming';
1111

1212
import { StyledAvatar } from './StyledAvatar';
1313
import { StyledStatusIndicator } from './StyledStatusIndicator';
14-
import { css } from 'styled-components';
1514

1615
describe('StyledAvatar', () => {
1716
it('renders the expected element', () => {
@@ -37,7 +36,7 @@ describe('StyledAvatar', () => {
3736
const { container } = render(<StyledAvatar $status="away" $surfaceColor="red" />);
3837

3938
expect(container.firstChild).toHaveStyleRule('color', 'red', {
40-
modifier: css`&&`
39+
modifier: '&&'
4140
});
4241
});
4342

packages/avatars/src/styled/StyledStandaloneStatusIndicator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ export const StyledStandaloneStatusIndicator = styled(StyledStatusIndicatorBase)
2626
`;
2727

2828
StyledStandaloneStatusIndicator.defaultProps = {
29-
type: 'offline',
29+
$type: 'offline',
3030
theme: DEFAULT_THEME
3131
};

packages/avatars/src/styled/StyledStatusIndicator.spec.tsx

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

88
import React from 'react';
99
import { render } from 'garden-test-utils';
10-
import { getColor, DEFAULT_THEME } from '@zendeskgarden/react-theming';
10+
import { DEFAULT_THEME, PALETTE } from '@zendeskgarden/react-theming';
1111

1212
import { StyledStatusIndicator } from './StyledStatusIndicator';
1313

@@ -94,54 +94,48 @@ describe('StyledStatusIndicator', () => {
9494
describe('away', () => {
9595
it('renders away style', () => {
9696
const { container } = render(<StyledStatusIndicator $type="away" />);
97-
const color = getColor({ hue: 'orange', shade: 500, theme: DEFAULT_THEME });
9897

99-
expect(container.firstChild).toHaveStyleRule('background-color', color);
98+
expect(container.firstChild).toHaveStyleRule('background-color', PALETTE.orange[500]);
10099
});
101100
});
102101

103102
describe('transfers', () => {
104103
it('renders transfers style', () => {
105104
const { container } = render(<StyledStatusIndicator $type="transfers" />);
106-
const color = getColor({ hue: 'azure', shade: 500, theme: DEFAULT_THEME });
107105

108-
expect(container.firstChild).toHaveStyleRule('background-color', color);
106+
expect(container.firstChild).toHaveStyleRule('background-color', PALETTE.azure[500]);
109107
});
110108
});
111109

112110
describe('active', () => {
113111
it('renders active style', () => {
114112
const { container } = render(<StyledStatusIndicator $type="active" />);
115-
const color = getColor({ hue: 'crimson', shade: 700, theme: DEFAULT_THEME });
116113

117114
expect(container.firstChild).toHaveStyleRule('height', '16px');
118-
expect(container.firstChild).toHaveStyleRule('background-color', color);
115+
expect(container.firstChild).toHaveStyleRule('background-color', PALETTE.crimson[700]);
119116
});
120117

121118
it('renders active style with small size', () => {
122119
const { container } = render(<StyledStatusIndicator $type="active" $size="small" />);
123-
const color = getColor({ hue: 'crimson', shade: 700, theme: DEFAULT_THEME });
124120

125121
expect(container.firstChild).toHaveStyleRule('height', '12px');
126-
expect(container.firstChild).toHaveStyleRule('background-color', color);
122+
expect(container.firstChild).toHaveStyleRule('background-color', PALETTE.crimson[700]);
127123
});
128124
});
129125

130126
describe('available', () => {
131127
it('renders available style', () => {
132128
const { container } = render(<StyledStatusIndicator $type="available" />);
133-
const color = getColor({ hue: 'mint', shade: 500, theme: DEFAULT_THEME });
134129

135-
expect(container.firstChild).toHaveStyleRule('background-color', color);
130+
expect(container.firstChild).toHaveStyleRule('background-color', PALETTE.mint[500]);
136131
});
137132
});
138133

139134
describe('offline', () => {
140135
it('renders offline style', () => {
141136
const { container } = render(<StyledStatusIndicator $type="offline" />);
142-
const color = getColor({ hue: 'grey', shade: 500, theme: DEFAULT_THEME });
143137

144-
expect(container.firstChild).toHaveStyleRule('border-color', `${color}`);
138+
expect(container.firstChild).toHaveStyleRule('border-color', PALETTE.grey[500]);
145139
});
146140
});
147141
});

packages/avatars/src/styled/utility.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,15 @@ export function getStatusColor(
2424
theme: IStyledStatusIndicatorProps['theme'],
2525
type?: IStyledStatusIndicatorProps['$type']
2626
): string {
27-
switch (type) {
28-
case 'active':
29-
return getColor({ hue: 'crimson', light: { shade: 700 }, dark: { shade: 600 }, theme });
30-
case 'available':
31-
return getColor({ hue: 'mint', light: { shade: 500 }, dark: { shade: 400 }, theme });
32-
case 'away':
33-
return getColor({ hue: 'orange', light: { shade: 500 }, dark: { shade: 400 }, theme });
34-
case 'transfers':
35-
return getColor({ hue: 'azure', light: { shade: 500 }, dark: { shade: 400 }, theme });
36-
case 'offline':
37-
return getColor({ hue: 'grey', light: { shade: 500 }, dark: { shade: 400 }, theme });
38-
default:
39-
return 'transparent';
40-
}
27+
return (
28+
{
29+
active: getColor({ hue: 'crimson', light: { shade: 700 }, dark: { shade: 600 }, theme }),
30+
available: getColor({ hue: 'mint', light: { shade: 500 }, dark: { shade: 400 }, theme }),
31+
away: getColor({ hue: 'orange', light: { shade: 500 }, dark: { shade: 400 }, theme }),
32+
transfers: getColor({ hue: 'azure', light: { shade: 500 }, dark: { shade: 400 }, theme }),
33+
offline: getColor({ hue: 'grey', light: { shade: 500 }, dark: { shade: 400 }, theme })
34+
}[type as string] || 'transparent'
35+
);
4136
}
4237

4338
export function getStatusBorderOffset(props: IStyledStatusIndicatorProps): string {

0 commit comments

Comments
 (0)