Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TS migration] Migrate 'ExpensifyWordmark.js' component to TypeScript #31478

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
};
Julesssss marked this conversation as resolved.
Show resolved Hide resolved

function ExpensifyWordmark(props) {
function ExpensifyWordmark({isSmallScreenWidth, style = {}}: ExpensifyWordmarkProps) {
const theme = useTheme();
VickyStash marked this conversation as resolved.
Show resolved Hide resolved
const styles = useThemeStyles();
const {environment} = useEnvironment();
// PascalCase is required for React components, so capitalize the const here
const LogoComponent = (environment && logoComponents[environment]) ?? AdHocLogo;

VickyStash marked this conversation as resolved.
Show resolved Hide resolved
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(environment ?? '', isSmallScreenWidth),
StyleUtils.getHeight(isSmallScreenWidth ? variables.signInLogoHeightSmallScreen : variables.signInLogoHeight),
VickyStash marked this conversation as resolved.
Show resolved Hide resolved
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);
Loading