Skip to content

Commit

Permalink
Merge pull request #34333 from software-mansion-labs/ts/AutoEmailLink
Browse files Browse the repository at this point in the history
[TS migration] Migrate 'AutoEmailLink.js' component to TypeScript
  • Loading branch information
deetergp authored Jan 17, 2024
2 parents fe9e9e3 + ad8a5bb commit 0c599f0
Showing 1 changed file with 11 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import {CONST} from 'expensify-common/lib/CONST';
import PropTypes from 'prop-types';
import React from 'react';
import _ from 'underscore';
import type {StyleProp, TextStyle} from 'react-native';
import useThemeStyles from '@hooks/useThemeStyles';
import Text from './Text';
import TextLink from './TextLink';

const propTypes = {
text: PropTypes.string.isRequired,
style: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.object), PropTypes.object]),
};

const defaultProps = {
style: [],
type AutoEmailLinkProps = {
text: string;
style?: StyleProp<TextStyle>;
};

/*
Expand All @@ -21,14 +16,15 @@ const defaultProps = {
* - Else just render it inside `Text` component
*/

function AutoEmailLink(props) {
function AutoEmailLink({text, style}: AutoEmailLinkProps) {
const styles = useThemeStyles();
return (
<Text style={props.style}>
{_.map(props.text.split(CONST.REG_EXP.EXTRACT_EMAIL), (str, index) => {
<Text style={style}>
{text.split(CONST.REG_EXP.EXTRACT_EMAIL).map((str, index) => {
if (CONST.REG_EXP.EMAIL.test(str)) {
return (
<TextLink
// eslint-disable-next-line react/no-array-index-key
key={`${index}-${str}`}
href={`mailto:${str}`}
style={styles.link}
Expand All @@ -40,7 +36,8 @@ function AutoEmailLink(props) {

return (
<Text
style={props.style}
style={style}
// eslint-disable-next-line react/no-array-index-key
key={`${index}-${str}`}
>
{str}
Expand All @@ -52,6 +49,5 @@ function AutoEmailLink(props) {
}

AutoEmailLink.displayName = 'AutoEmailLink';
AutoEmailLink.propTypes = propTypes;
AutoEmailLink.defaultProps = defaultProps;

export default AutoEmailLink;

0 comments on commit 0c599f0

Please sign in to comment.