-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Standardize form error styles #12098
Changes from all commits
817f637
ae1a24e
3b4f59f
dcd79a6
236d9c2
26e5948
0477a6e
8700155
8f004ab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -3,16 +3,14 @@ import {View} from 'react-native'; | |||
import PropTypes from 'prop-types'; | ||||
import React from 'react'; | ||||
import {withNetwork} from './OnyxProvider'; | ||||
import Icon from './Icon'; | ||||
import * as Expensicons from './Icon/Expensicons'; | ||||
import RenderHTML from './RenderHTML'; | ||||
import TextLink from './TextLink'; | ||||
import Text from './Text'; | ||||
import colors from '../styles/colors'; | ||||
import TextLink from './TextLink'; | ||||
import compose from '../libs/compose'; | ||||
import networkPropTypes from './networkPropTypes'; | ||||
import styles from '../styles/styles'; | ||||
import withLocalize, {withLocalizePropTypes} from './withLocalize'; | ||||
import FormHelpMessage from './FormHelpMessage'; | ||||
|
||||
const propTypes = { | ||||
/** Wrapped child components */ | ||||
|
@@ -52,38 +50,35 @@ const defaultProps = { | |||
// | ||||
// This component takes other components as a child prop. It will then render any wrapped components as a function using "render props", | ||||
// and passes it a (bool) isOffline parameter. Child components can then use the isOffline variable to determine offline behavior. | ||||
const FormAlertWrapper = props => ( | ||||
<View style={props.containerStyles}> | ||||
{props.isAlertVisible && ( | ||||
<View style={[styles.flexRow, styles.alignItemsCenter, styles.mb3]}> | ||||
<Icon src={Expensicons.Exclamation} fill={colors.red} /> | ||||
<View style={[styles.flexRow, styles.ml2, styles.flexWrap, styles.flex1]}> | ||||
{!_.isEmpty(props.message) && props.isMessageHtml && <RenderHTML html={`<muted-text>${props.message}</muted-text>`} />} | ||||
|
||||
{!_.isEmpty(props.message) && !props.isMessageHtml && <Text style={styles.mutedTextLabel}>{props.message}</Text>} | ||||
|
||||
{_.isEmpty(props.message) && ( | ||||
<> | ||||
<Text style={styles.mutedTextLabel}> | ||||
{`${props.translate('common.please')} `} | ||||
</Text> | ||||
<TextLink | ||||
style={styles.label} | ||||
onPress={props.onFixTheErrorsLinkPressed} | ||||
> | ||||
{props.translate('common.fixTheErrors')} | ||||
</TextLink> | ||||
<Text style={styles.mutedTextLabel}> | ||||
{` ${props.translate('common.inTheFormBeforeContinuing')}.`} | ||||
</Text> | ||||
</> | ||||
)} | ||||
</View> | ||||
</View> | ||||
)} | ||||
{props.children(props.network.isOffline)} | ||||
</View> | ||||
); | ||||
const FormAlertWrapper = (props) => { | ||||
let children; | ||||
if (_.isEmpty(props.message)) { | ||||
children = ( | ||||
<Text style={[styles.formError, styles.mb0]}> | ||||
{`${props.translate('common.please')} `} | ||||
<TextLink | ||||
style={styles.label} | ||||
onPress={props.onFixTheErrorsLinkPressed} | ||||
> | ||||
{props.translate('common.fixTheErrors')} | ||||
</TextLink> | ||||
{` ${props.translate('common.inTheFormBeforeContinuing')}.`} | ||||
</Text> | ||||
); | ||||
} else if (props.isMessageHtml) { | ||||
children = <RenderHTML html={`<muted-text>${props.message}</muted-text>`} />; | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You will have to modify the style for
Also, please add a new story that usage There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @parasharrajat this is done |
||||
} | ||||
return ( | ||||
<View style={props.containerStyles}> | ||||
{props.isAlertVisible && ( | ||||
<FormHelpMessage message={props.message} style={[styles.mb3]}> | ||||
{children} | ||||
</FormHelpMessage> | ||||
)} | ||||
{props.children(props.network.isOffline)} | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm lost. Why did we need this? Can't we just subscribe to the Onyx |
||||
</View> | ||||
); | ||||
}; | ||||
|
||||
FormAlertWrapper.propTypes = propTypes; | ||||
FormAlertWrapper.defaultProps = defaultProps; | ||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,56 @@ | ||||||
import React from 'react'; | ||||||
import _ from 'underscore'; | ||||||
import PropTypes from 'prop-types'; | ||||||
import {View} from 'react-native'; | ||||||
import Icon from './Icon'; | ||||||
import * as Expensicons from './Icon/Expensicons'; | ||||||
import Text from './Text'; | ||||||
import colors from '../styles/colors'; | ||||||
import styles from '../styles/styles'; | ||||||
import stylePropTypes from '../styles/stylePropTypes'; | ||||||
|
||||||
const propTypes = { | ||||||
/** Error or hint text. Ignored when children is not empty */ | ||||||
message: PropTypes.string, | ||||||
|
||||||
/** Children to render next to dot indicator */ | ||||||
children: PropTypes.node, | ||||||
|
||||||
/** Indicates whether to show error or hint */ | ||||||
isError: PropTypes.bool, | ||||||
|
||||||
/** Container style props */ | ||||||
style: stylePropTypes, | ||||||
}; | ||||||
|
||||||
const defaultProps = { | ||||||
message: '', | ||||||
children: null, | ||||||
isError: true, | ||||||
style: [], | ||||||
}; | ||||||
|
||||||
const FormHelpMessage = (props) => { | ||||||
if (_.isEmpty(props.message) && _.isEmpty(props.children)) { | ||||||
return null; | ||||||
} | ||||||
|
||||||
return ( | ||||||
<View style={[styles.flexRow, styles.alignItemsCenter, styles.mt2, styles.mb1, ...props.style]}> | ||||||
{props.isError && <Icon src={Expensicons.DotIndicator} fill={colors.red} />} | ||||||
<View style={[styles.flex1, styles.ml2]}> | ||||||
{props.children || ( | ||||||
<Text style={[props.isError ? styles.formError : styles.formHelp, styles.mb0]}> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Do we need mb0 here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes because both |
||||||
{props.message} | ||||||
</Text> | ||||||
)} | ||||||
</View> | ||||||
</View> | ||||||
); | ||||||
}; | ||||||
|
||||||
FormHelpMessage.propTypes = propTypes; | ||||||
FormHelpMessage.defaultProps = defaultProps; | ||||||
FormHelpMessage.displayName = 'FormHelpMessage'; | ||||||
|
||||||
export default FormHelpMessage; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marcaaron that was already existing code before this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok thanks, let's see maybe it was me who added it lol