Skip to content

Commit

Permalink
fix(BaseIcon): useMemo for styles
Browse files Browse the repository at this point in the history
  • Loading branch information
awinogradov committed Feb 8, 2024
1 parent fa7acc3 commit 6c3e702
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions src/components/BaseIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useMemo } from 'react';

export const iconSizesMap = {
xxs: 12,
Expand All @@ -13,26 +13,33 @@ export interface BaseIconProps extends React.HTMLAttributes<HTMLSpanElement> {
value: React.FunctionComponent<React.SVGAttributes<SVGElement>>;
color?: string;
stroke?: number;
className?: string;

onClick?: (e: React.MouseEvent) => void;
}

export const BaseIcon = React.forwardRef<HTMLSpanElement, BaseIconProps>(
({ size, value: Component, color, stroke = 1, onClick, className = '', ...props }, ref) => {
({ size, value: Component, color, stroke = 1, onClick, className, ...props }, ref) => {
const sizePx = `${typeof size === 'string' ? iconSizesMap[size] : size}px`;
const classes = `TaskanyIconsWrapper${onClick ? ' TaskanyIconsWrapper_hover' : ''} ${className}`.trim();
let classes = 'TaskanyIconsWrapper';

if (onClick) {
classes += ' TaskanyIconsWrapper_hover';
}

if (className) {
classes += ` ${className}`;
}

const style = useMemo<React.CSSProperties>(() => ({
fontSize: sizePx,
width: sizePx,
height: sizePx,
color,
}), [color, sizePx]);

return (
<span
ref={ref}
className={classes}
style={{
fontSize: sizePx,
width: sizePx,
height: sizePx,
color,
}}
style={style}
onClick={onClick}
{...props}
>
Expand Down

0 comments on commit 6c3e702

Please sign in to comment.