Skip to content

Commit

Permalink
fix the default props usage and use hooks instead of HOC
Browse files Browse the repository at this point in the history
  • Loading branch information
rayane-djouah committed Dec 15, 2023
1 parent 8964dc9 commit 416229d
Showing 1 changed file with 20 additions and 21 deletions.
41 changes: 20 additions & 21 deletions src/components/Icon/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';
import {StyleProp, View, ViewStyle} from 'react-native';
import withStyleUtils, {WithStyleUtilsProps} from '@components/withStyleUtils';
import withTheme, {WithThemeProps} from '@components/withTheme';
import withThemeStyles, {type WithThemeStylesProps} from '@components/withThemeStyles';
import useTheme from '@styles/themes/useTheme';

Check failure on line 3 in src/components/Icon/index.tsx

View workflow job for this annotation

GitHub Actions / typecheck

Cannot find module '@styles/themes/useTheme' or its corresponding type declarations.
import useStyleUtils from '@styles/useStyleUtils';

Check failure on line 4 in src/components/Icon/index.tsx

View workflow job for this annotation

GitHub Actions / typecheck

Cannot find module '@styles/useStyleUtils' or its corresponding type declarations.
import useThemeStyles from '@styles/useThemeStyles';

Check failure on line 5 in src/components/Icon/index.tsx

View workflow job for this annotation

GitHub Actions / typecheck

Cannot find module '@styles/useThemeStyles' or its corresponding type declarations.
import variables from '@styles/variables';
import IconWrapperStyles from './IconWrapperStyles';

Expand Down Expand Up @@ -41,33 +41,33 @@ type IconProps = {

/** Additional styles to add to the Icon */
additionalStyles?: StyleProp<ViewStyle>;
} & WithThemeStylesProps &
WithThemeProps &
WithStyleUtilsProps;

const defaultProps = {
width: variables.iconSizeNormal,
height: variables.iconSizeNormal,
fill: undefined,
small: false,
inline: false,
additionalStyles: [],
hovered: false,
pressed: false,
};

function Icon({src, width, height, fill, small, inline, hovered, pressed, theme, themeStyles, StyleUtils, additionalStyles}: IconProps) {
function Icon({
src,
width = variables.iconSizeNormal,
height = variables.iconSizeNormal,
fill = undefined,
small = false,
inline = false,
hovered = false,
pressed = false,
additionalStyles = [],
}: IconProps) {
const theme = useTheme();
const StyleUtils = useStyleUtils();
const styles = useThemeStyles();
const iconWidth = small ? variables.iconSizeSmall : width;
const iconHeight = small ? variables.iconSizeSmall : height;
const iconStyles = [StyleUtils.getWidthAndHeightStyle(width ?? 0, height), IconWrapperStyles, themeStyles.pAbsolute, additionalStyles];
const iconStyles = [StyleUtils.getWidthAndHeightStyle(width ?? 0, height), IconWrapperStyles, styles.pAbsolute, additionalStyles];
const iconFill = fill ?? theme.icon;
const IconComponent = src;

if (inline) {
return (
<View
testID={`${src.name} Icon`}
style={[StyleUtils.getWidthAndHeightStyle(width ?? 0, height), themeStyles.bgTransparent, themeStyles.overflowVisible]}
style={[StyleUtils.getWidthAndHeightStyle(width ?? 0, height), styles.bgTransparent, styles.overflowVisible]}
>
<View style={iconStyles}>
<IconComponent
Expand Down Expand Up @@ -98,7 +98,6 @@ function Icon({src, width, height, fill, small, inline, hovered, pressed, theme,
);
}

Icon.defaultProps = defaultProps;
Icon.displayName = 'Icon';

export default withTheme(withThemeStyles(withStyleUtils(Icon)));
export default Icon;

0 comments on commit 416229d

Please sign in to comment.