-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30487 from pasyukevich/feature/migrate-FormHelpMe…
…ssage [TS Migration] Migrate 'FormHelpMessage.js' component to TypeScript
- Loading branch information
Showing
3 changed files
with
51 additions
and
63 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters