Skip to content

Commit

Permalink
Merge pull request #30487 from pasyukevich/feature/migrate-FormHelpMe…
Browse files Browse the repository at this point in the history
…ssage

[TS Migration] Migrate 'FormHelpMessage.js' component to TypeScript
  • Loading branch information
MariaHCD authored Dec 11, 2023
2 parents 68e8ba2 + 2bfa28d commit ab4449c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 63 deletions.
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)) {
return null;
}

const translatedMessage = Localize.translateIfPhraseKey(message);

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

0 comments on commit ab4449c

Please sign in to comment.