Skip to content

Commit

Permalink
using isButtonIcon new prop to determine width and height for the Ico…
Browse files Browse the repository at this point in the history
…n component
  • Loading branch information
jayeshmangwani committed Nov 5, 2024
1 parent 2b2d503 commit 708a503
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
3 changes: 3 additions & 0 deletions src/components/Button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ function Button(
small={small}
medium={medium}
large={large}
isButtonIcon
/>
</View>
)}
Expand All @@ -311,6 +312,7 @@ function Button(
small={small}
medium={medium}
large={large}
isButtonIcon
/>
) : (
<Icon
Expand All @@ -319,6 +321,7 @@ function Button(
small={small}
medium={medium}
large={large}
isButtonIcon
/>
)}
</View>
Expand Down
4 changes: 1 addition & 3 deletions src/components/ContextMenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import useThemeStyles from '@hooks/useThemeStyles';
import useThrottledButtonState from '@hooks/useThrottledButtonState';
import useWindowDimensions from '@hooks/useWindowDimensions';
import getButtonState from '@libs/getButtonState';
import variables from '@styles/variables';
import type IconAsset from '@src/types/utils/IconAsset';
import BaseMiniContextMenuItem from './BaseMiniContextMenuItem';
import FocusableMenuItem from './FocusableMenuItem';
Expand Down Expand Up @@ -123,8 +122,7 @@ function ContextMenuItem(
>
{({hovered, pressed}) => (
<Icon
height={variables.iconSizeSmall}
width={variables.iconSizeSmall}
small
src={itemIcon}
fill={StyleUtils.getIconFillColor(getButtonState(hovered, pressed, !isThrottledButtonActive))}
/>
Expand Down
6 changes: 5 additions & 1 deletion src/components/Icon/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ type IconProps = {

/** Determines how the image should be resized to fit its container */
contentFit?: ImageContentFit;

/** Determines whether the icon is being used within a button. The icon size will remain the same for both icon-only buttons and buttons with text. */
isButtonIcon?: boolean;
};

function Icon({
Expand All @@ -64,10 +67,11 @@ function Icon({
pressed = false,
testID = '',
contentFit = 'cover',
isButtonIcon = false,
}: IconProps) {
const StyleUtils = useStyleUtils();
const styles = useThemeStyles();
const {width: iconWidth, height: iconHeight} = StyleUtils.getIconWidthAndHeightStyle(small, medium, large, width, height);
const {width: iconWidth, height: iconHeight} = StyleUtils.getIconWidthAndHeightStyle(small, medium, large, width, height, isButtonIcon);
const iconStyles = [StyleUtils.getWidthAndHeightStyle(width ?? 0, height), IconWrapperStyles, styles.pAbsolute, additionalStyles];

if (inline) {
Expand Down
8 changes: 4 additions & 4 deletions src/styles/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,14 +490,14 @@ function getWidthAndHeightStyle(width: number, height?: number): Pick<ViewStyle,
};
}

function getIconWidthAndHeightStyle(small: boolean, medium: boolean, large: boolean, width: number, height: number): Pick<ImageSVGProps, 'width' | 'height'> {
function getIconWidthAndHeightStyle(small: boolean, medium: boolean, large: boolean, width: number, height: number, isButtonIcon: boolean): Pick<ImageSVGProps, 'width' | 'height'> {
switch (true) {
case small:
return {width: variables.iconSizeExtraSmall, height: variables.iconSizeExtraSmall};
return {width: isButtonIcon ? variables.iconSizeExtraSmall : variables.iconSizeSmall, height: isButtonIcon ? variables.iconSizeExtraSmall : variables?.iconSizeSmall};
case medium:
return {width: variables.iconSizeSmall, height: variables.iconSizeSmall};
return {width: isButtonIcon ? variables.iconSizeSmall : variables.iconSizeNormal, height: isButtonIcon ? variables.iconSizeSmall : variables.iconSizeNormal};
case large:
return {width: variables.iconSizeNormal, height: variables.iconSizeNormal};
return {width: isButtonIcon ? variables.iconSizeNormal : variables.iconSizeLarge, height: isButtonIcon ? variables.iconSizeNormal : variables.iconSizeLarge};
default: {
return {width, height};
}
Expand Down

0 comments on commit 708a503

Please sign in to comment.