-
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 2 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,13 @@ 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 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 +49,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 message; | ||
if (_.isEmpty(props.message)) { | ||
message = ( | ||
<> | ||
{`${props.translate('common.please')} `} | ||
<TextLink | ||
style={styles.label} | ||
onPress={props.onFixTheErrorsLinkPressed} | ||
> | ||
{props.translate('common.fixTheErrors')} | ||
</TextLink> | ||
{` ${props.translate('common.inTheFormBeforeContinuing')}.`} | ||
</> | ||
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. We don't use such patterns where UI blocks are passed as props. What you can do is?
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 I did this because it shouldn't be rendered inside 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.
Instead, the 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 updated from your feedback and pushed |
||
); | ||
} else if (!props.isMessageHtml) { | ||
message = props.message; | ||
} | ||
return ( | ||
<View style={props.containerStyles}> | ||
{props.isAlertVisible && ( | ||
<FormHelpMessage message={message} style={[styles.mb3]}> | ||
{_.isEmpty(message) && <RenderHTML html={`<muted-text>${props.message}</muted-text>`} />} | ||
</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,50 @@ | ||
import React from 'react'; | ||
import _ from 'underscore'; | ||
import PropTypes from 'prop-types'; | ||
import {View} from 'react-native'; | ||
import styles from '../styles/styles'; | ||
import Icon from './Icon'; | ||
import * as Expensicons from './Icon/Expensicons'; | ||
import colors from '../styles/colors'; | ||
import Text from './Text'; | ||
|
||
const propTypes = { | ||
message: PropTypes.node, | ||
|
||
children: PropTypes.node, | ||
|
||
isError: PropTypes.bool, | ||
|
||
// eslint-disable-next-line react/forbid-prop-types | ||
style: PropTypes.arrayOf(PropTypes.object), | ||
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. Missing comments. Check styleGuide. 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. Please use stylePropTypes via import. |
||
}; | ||
|
||
const defaultProps = { | ||
message: null, | ||
children: null, | ||
isError: true, | ||
style: [], | ||
}; | ||
|
||
const FormHelpMessage = (props) => { | ||
if (_.isEmpty(props.message) && _.isEmpty(props.children)) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<View style={[styles.formHelpMessage, styles.mt1, styles.mb1, ...props.style]}> | ||
{props.isError && <Icon src={Expensicons.DotIndicator} fill={colors.red} />} | ||
{!_.isEmpty(props.message) ? ( | ||
<Text style={[props.isError ? styles.formError : styles.formHelp, styles.flex1, styles.mb0, styles.ml2]}> | ||
{props.message} | ||
</Text> | ||
) : <View style={[styles.flex1, styles.ml2]}>{props.children}</View>} | ||
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. Now reverse this condition. Children take priority. When |
||
</View> | ||
); | ||
}; | ||
|
||
FormHelpMessage.propTypes = propTypes; | ||
FormHelpMessage.defaultProps = defaultProps; | ||
FormHelpMessage.displayName = 'FormHelpMessage'; | ||
|
||
export default FormHelpMessage; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -869,6 +869,12 @@ const styles = { | |
marginBottom: 8, | ||
}, | ||
|
||
formHelpMessage: { | ||
display: 'flex', | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
}, | ||
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. Please use style util objects. e.g. |
||
|
||
formHelp: { | ||
color: themeColors.textSupporting, | ||
fontSize: variables.fontSizeLabel, | ||
|
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