Skip to content

Commit 403bf68

Browse files
committed
chore: code review getStatusColor
1 parent 9c2c239 commit 403bf68

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

packages/avatars/src/styled/utility.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,25 @@ export interface IStyledStatusIndicatorProps extends ThemeProps<DefaultTheme> {
2020
readonly $type?: IAvatarProps['status'] | 'active';
2121
}
2222

23+
const StatusColorParams = {
24+
active: { hue: 'crimson', light: { shade: 700 }, dark: { shade: 600 } },
25+
available: { hue: 'mint', light: { shade: 500 }, dark: { shade: 400 } },
26+
away: { hue: 'orange', light: { shade: 500 }, dark: { shade: 400 } },
27+
transfers: { hue: 'azure', light: { shade: 500 }, dark: { shade: 400 } },
28+
offline: { hue: 'grey', light: { shade: 500 }, dark: { shade: 400 } }
29+
};
30+
2331
export function getStatusColor(
2432
theme: IStyledStatusIndicatorProps['theme'],
2533
type?: IStyledStatusIndicatorProps['$type']
2634
): string {
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-
);
35+
if (type === undefined) {
36+
return 'transparent';
37+
}
38+
39+
const colorArgs = StatusColorParams[type];
40+
41+
return getColor({ ...colorArgs, theme });
3642
}
3743

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

0 commit comments

Comments
 (0)