From 15c9acf474968d7ee014cecfda2059954a90b41b Mon Sep 17 00:00:00 2001 From: Jules Rosser Date: Fri, 2 Dec 2022 14:24:19 +0000 Subject: [PATCH 1/2] revert PR 13187 --- .../{Checkbox/BaseCheckbox.js => Checkbox.js} | 48 +++++++------------ src/components/Checkbox/index.js | 16 ------- src/components/Checkbox/index.native.js | 16 ------- src/components/CheckboxWithLabel.js | 2 +- src/components/TextInput/BaseTextInput.js | 9 ++-- 5 files changed, 21 insertions(+), 70 deletions(-) rename src/components/{Checkbox/BaseCheckbox.js => Checkbox.js} (77%) delete mode 100644 src/components/Checkbox/index.js delete mode 100644 src/components/Checkbox/index.native.js diff --git a/src/components/Checkbox/BaseCheckbox.js b/src/components/Checkbox.js similarity index 77% rename from src/components/Checkbox/BaseCheckbox.js rename to src/components/Checkbox.js index c2310f4e7c36..2582ddf31bd4 100644 --- a/src/components/Checkbox/BaseCheckbox.js +++ b/src/components/Checkbox.js @@ -1,23 +1,19 @@ import React from 'react'; import {View, Pressable} from 'react-native'; import PropTypes from 'prop-types'; -import styles from '../../styles/styles'; -import themeColors from '../../styles/themes/default'; -import stylePropTypes from '../../styles/stylePropTypes'; -import Icon from '../Icon'; -import * as Expensicons from '../Icon/Expensicons'; - -// eslint-disable-next-line rulesdir/prefer-early-return -const requiredPropsCheck = (props, componentName) => { - if (!props.onMouseDown && !props.onPress) { - return new Error(`One of "onMouseDown" or "onPress" must be provided in ${componentName}`); - } -}; +import styles from '../styles/styles'; +import themeColors from '../styles/themes/default'; +import stylePropTypes from '../styles/stylePropTypes'; +import Icon from './Icon'; +import * as Expensicons from './Icon/Expensicons'; const propTypes = { /** Whether checkbox is checked */ isChecked: PropTypes.bool, + /** A function that is called when the box/label is pressed */ + onPress: PropTypes.func.isRequired, + /** Should the input be styled for errors */ hasError: PropTypes.bool, @@ -30,17 +26,14 @@ const propTypes = { /** Additional styles to add to checkbox button */ style: stylePropTypes, + /** Callback that is called when mousedown is triggered. */ + onMouseDown: PropTypes.func, + /** A ref to forward to the Pressable */ forwardedRef: PropTypes.oneOfType([ PropTypes.func, PropTypes.shape({current: PropTypes.instanceOf(React.Component)}), ]), - - /** A function that is called when the box/label is pressed */ - onPress: requiredPropsCheck, - - /** Callback that is called when mousedown is triggered. */ - onMouseDown: requiredPropsCheck, }; const defaultProps = { @@ -51,10 +44,9 @@ const defaultProps = { forwardedRef: undefined, children: null, onMouseDown: undefined, - onPress: undefined, }; -class BaseCheckbox extends React.Component { +class Checkbox extends React.Component { constructor(props) { super(props); this.state = { @@ -80,11 +72,7 @@ class BaseCheckbox extends React.Component { return; } - if (this.props.onPress) { - this.props.onPress(event); - } else { - this.props.onMouseDown(event); - } + this.props.onPress(); } firePressHandlerOnClick(event) { @@ -94,9 +82,7 @@ class BaseCheckbox extends React.Component { return; } - if (this.props.onPress) { - this.props.onPress(event); - } + this.props.onPress(); } render() { @@ -135,7 +121,7 @@ class BaseCheckbox extends React.Component { } } -BaseCheckbox.propTypes = propTypes; -BaseCheckbox.defaultProps = defaultProps; +Checkbox.propTypes = propTypes; +Checkbox.defaultProps = defaultProps; -export default BaseCheckbox; +export default Checkbox; \ No newline at end of file diff --git a/src/components/Checkbox/index.js b/src/components/Checkbox/index.js deleted file mode 100644 index 0fb56725b142..000000000000 --- a/src/components/Checkbox/index.js +++ /dev/null @@ -1,16 +0,0 @@ -import React from 'react'; -import BaseCheckbox from './BaseCheckbox'; - -const Checkbox = props => ( - -); - -Checkbox.propTypes = BaseCheckbox.propTypes; -Checkbox.defaultProps = BaseCheckbox.defaultProps; -Checkbox.displayName = 'Checkbox'; - -export default Checkbox; diff --git a/src/components/Checkbox/index.native.js b/src/components/Checkbox/index.native.js deleted file mode 100644 index 0fd4ee2716e6..000000000000 --- a/src/components/Checkbox/index.native.js +++ /dev/null @@ -1,16 +0,0 @@ -import React from 'react'; -import BaseCheckbox from './BaseCheckbox'; - -const Checkbox = props => ( - -); - -Checkbox.propTypes = BaseCheckbox.propTypes; -Checkbox.defaultProps = BaseCheckbox.defaultProps; -Checkbox.displayName = 'Checkbox'; - -export default Checkbox; diff --git a/src/components/CheckboxWithLabel.js b/src/components/CheckboxWithLabel.js index 96f85fb25d91..c12bdbc7904c 100644 --- a/src/components/CheckboxWithLabel.js +++ b/src/components/CheckboxWithLabel.js @@ -130,4 +130,4 @@ CheckboxWithLabel.defaultProps = defaultProps; export default React.forwardRef((props, ref) => ( // eslint-disable-next-line react/jsx-props-no-spreading -)); +)); \ No newline at end of file diff --git a/src/components/TextInput/BaseTextInput.js b/src/components/TextInput/BaseTextInput.js index 46f7109aec9e..fe29ff79bf25 100644 --- a/src/components/TextInput/BaseTextInput.js +++ b/src/components/TextInput/BaseTextInput.js @@ -186,11 +186,7 @@ class BaseTextInput extends Component { ]).start(); } - togglePasswordVisibility(event) { - if (!event) { - return; - } - event.preventDefault(); + togglePasswordVisibility() { this.setState(prevState => ({passwordHidden: !prevState.passwordHidden})); } @@ -295,7 +291,8 @@ class BaseTextInput extends Component { {this.props.secureTextEntry && ( e.preventDefault()} > Date: Fri, 2 Dec 2022 15:58:47 +0000 Subject: [PATCH 2/2] add missing newline --- src/components/Checkbox.js | 2 +- src/components/CheckboxWithLabel.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/Checkbox.js b/src/components/Checkbox.js index 2582ddf31bd4..d4f6adbf2c6c 100644 --- a/src/components/Checkbox.js +++ b/src/components/Checkbox.js @@ -124,4 +124,4 @@ class Checkbox extends React.Component { Checkbox.propTypes = propTypes; Checkbox.defaultProps = defaultProps; -export default Checkbox; \ No newline at end of file +export default Checkbox; diff --git a/src/components/CheckboxWithLabel.js b/src/components/CheckboxWithLabel.js index c12bdbc7904c..96f85fb25d91 100644 --- a/src/components/CheckboxWithLabel.js +++ b/src/components/CheckboxWithLabel.js @@ -130,4 +130,4 @@ CheckboxWithLabel.defaultProps = defaultProps; export default React.forwardRef((props, ref) => ( // eslint-disable-next-line react/jsx-props-no-spreading -)); \ No newline at end of file +));