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 'FormHelpMessage.js' component to TypeScript #30487

Merged
merged 11 commits into from
Dec 11, 2023
62 changes: 0 additions & 62 deletions src/components/FormHelpMessage.js

This file was deleted.

49 changes: 49 additions & 0 deletions src/components/FormHelpMessage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import isEmpty from 'lodash/isEmpty';
import React from 'react';
import {StyleProp, View, ViewStyle} from 'react-native';
import * as Localize from '@libs/Localize';
import useTheme from '@styles/themes/useTheme';
import useThemeStyles from '@styles/useThemeStyles';
import Icon from './Icon';
import * as Expensicons from './Icon/Expensicons';
import Text from './Text';

type FormHelpMessageProps = {
/** Error or hint text. Ignored when children is not empty */
message?: Localize.MaybePhraseKey;

/** Children to render next to dot indicator */
children?: React.ReactNode;

/** Indicates whether to show error or hint */
isError?: boolean;

/** Container style props */
style?: StyleProp<ViewStyle>;
};

function FormHelpMessage({message = '', children, isError = true, style}: FormHelpMessageProps) {
const theme = useTheme();
const styles = useThemeStyles();
if (isEmpty(message) && isEmpty(children)) {
pasyukevich marked this conversation as resolved.
Show resolved Hide resolved
return null;
}

const translatedMessage = Localize.translateIfPhraseKey(message);
pasyukevich marked this conversation as resolved.
Show resolved Hide resolved

return (
<View style={[styles.flexRow, styles.alignItemsCenter, styles.mt2, styles.mb1, style]}>
{isError && (
<Icon
src={Expensicons.DotIndicator}
fill={theme.danger}
/>
)}
<View style={[styles.flex1, isError && styles.ml2]}>{children ?? <Text style={[isError ? styles.formError : styles.formHelp, styles.mb0]}>{translatedMessage}</Text>}</View>
</View>
);
}

FormHelpMessage.displayName = 'FormHelpMessage';

export default FormHelpMessage;
3 changes: 2 additions & 1 deletion src/components/SingleChoiceQuestion.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import React, {ForwardedRef, forwardRef} from 'react';
import {Text as RNText} from 'react-native';
import type {MaybePhraseKey} from '@libs/Localize';
import useThemeStyles from '@styles/useThemeStyles';
import FormHelpMessage from './FormHelpMessage';
import RadioButtons, {Choice} from './RadioButtons';
import Text from './Text';

type SingleChoiceQuestionProps = {
prompt: string;
errorText?: string | string[];
errorText?: MaybePhraseKey;
possibleAnswers: Choice[];
currentQuestionIndex: number;
onInputChange: (value: string) => void;
Expand Down
Loading