Skip to content

Commit

Permalink
Merge pull request #31478 from VickyStash/ts-migration/expensifyWordm…
Browse files Browse the repository at this point in the history
…ark-component

[TS migration] Migrate 'ExpensifyWordmark.js' component to TypeScript
  • Loading branch information
Julesssss authored Nov 20, 2023
2 parents 77be80b + 594056b commit e79d5c7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import PropTypes from 'prop-types';
import React from 'react';
import {View} from 'react-native';
import _ from 'underscore';
import {StyleProp, View, ViewStyle} from 'react-native';
import AdHocLogo from '@assets/images/expensify-logo--adhoc.svg';
import DevLogo from '@assets/images/expensify-logo--dev.svg';
import StagingLogo from '@assets/images/expensify-logo--staging.svg';
Expand All @@ -12,40 +10,36 @@ import useTheme from '@styles/themes/useTheme';
import useThemeStyles from '@styles/useThemeStyles';
import variables from '@styles/variables';
import CONST from '@src/CONST';
import withWindowDimensions, {windowDimensionsPropTypes} from './withWindowDimensions';
import withWindowDimensions from './withWindowDimensions';
import type {WindowDimensionsProps} from './withWindowDimensions/types';

const propTypes = {
type ExpensifyWordmarkProps = WindowDimensionsProps & {
/** Additional styles to add to the component */
style: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.object), PropTypes.object]),

...windowDimensionsPropTypes,
};

const defaultProps = {
style: {},
style?: StyleProp<ViewStyle>;
};

const logoComponents = {
[CONST.ENVIRONMENT.DEV]: DevLogo,
[CONST.ENVIRONMENT.STAGING]: StagingLogo,
[CONST.ENVIRONMENT.PRODUCTION]: ProductionLogo,
[CONST.ENVIRONMENT.ADHOC]: AdHocLogo,
};

function ExpensifyWordmark(props) {
function ExpensifyWordmark({isSmallScreenWidth, style}: ExpensifyWordmarkProps) {
const theme = useTheme();
const styles = useThemeStyles();
const {environment} = useEnvironment();
// PascalCase is required for React components, so capitalize the const here
const LogoComponent = environment ? logoComponents[environment] : AdHocLogo;

const LogoComponent = logoComponents[environment] || AdHocLogo;
return (
<>
<View
style={[
StyleUtils.getSignInWordmarkWidthStyle(environment, props.isSmallScreenWidth),
StyleUtils.getHeight(props.isSmallScreenWidth ? variables.signInLogoHeightSmallScreen : variables.signInLogoHeight),
props.isSmallScreenWidth && (environment === CONST.ENVIRONMENT.DEV || environment === CONST.ENVIRONMENT.STAGING) ? styles.ml3 : {},
...(_.isArray(props.style) ? props.style : [props.style]),
StyleUtils.getSignInWordmarkWidthStyle(isSmallScreenWidth, environment),
StyleUtils.getHeight(isSmallScreenWidth ? variables.signInLogoHeightSmallScreen : variables.signInLogoHeight),
isSmallScreenWidth && (environment === CONST.ENVIRONMENT.DEV || environment === CONST.ENVIRONMENT.STAGING) ? styles.ml3 : {},
style,
]}
>
<LogoComponent fill={theme.success} />
Expand All @@ -55,6 +49,5 @@ function ExpensifyWordmark(props) {
}

ExpensifyWordmark.displayName = 'ExpensifyWordmark';
ExpensifyWordmark.defaultProps = defaultProps;
ExpensifyWordmark.propTypes = propTypes;

export default withWindowDimensions(ExpensifyWordmark);
2 changes: 1 addition & 1 deletion src/styles/StyleUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ function getBorderColorStyle(borderColor: string): ViewStyle {
/**
* Returns the width style for the wordmark logo on the sign in page
*/
function getSignInWordmarkWidthStyle(environment: string, isSmallScreenWidth: boolean): ViewStyle {
function getSignInWordmarkWidthStyle(isSmallScreenWidth: boolean, environment?: ValueOf<typeof CONST.ENVIRONMENT>): ViewStyle {
if (environment === CONST.ENVIRONMENT.DEV) {
return isSmallScreenWidth ? {width: variables.signInLogoWidthPill} : {width: variables.signInLogoWidthLargeScreenPill};
}
Expand Down

0 comments on commit e79d5c7

Please sign in to comment.