Skip to content

Commit f7198fe

Browse files
💄 style: Add roundToEven
1 parent fc13845 commit f7198fe

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/IconAvatar/index.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { Center, type FlexboxProps } from 'react-layout-kit';
33

44
import { IconType } from '@/types';
55

6+
import { roundToEven } from './util';
7+
68
export interface IconAvatarProps extends Omit<FlexboxProps, 'children'> {
79
Icon?: IconType;
810
background?: string;
@@ -42,7 +44,13 @@ const IconAvatar = forwardRef<HTMLDivElement, IconAvatarProps>(
4244
...style,
4345
}}
4446
>
45-
{Icon && <Icon className={iconClassName} size={size * iconMultiple} style={iconStyle} />}
47+
{Icon && (
48+
<Icon
49+
className={iconClassName}
50+
size={roundToEven(size * iconMultiple)}
51+
style={iconStyle}
52+
/>
53+
)}
4654
</Center>
4755
);
4856
},

src/IconAvatar/util.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export const roundToEven = (number: number) => {
2+
const rounded = Math.round(number);
3+
const diff = Math.abs(number - rounded);
4+
5+
if (diff === 0.5) {
6+
return rounded % 2 === 0 ? rounded : rounded - 1;
7+
}
8+
return rounded;
9+
};

0 commit comments

Comments
 (0)