Skip to content
This repository was archived by the owner on Feb 23, 2024. It is now read-only.

Commit ea74395

Browse files
committed
Revert "Move TextInput to checkout package and allow it to be used for input type=number (#4238)"
This reverts commit 15c1779.
1 parent 6c063d5 commit ea74395

File tree

11 files changed

+27
-138
lines changed

11 files changed

+27
-138
lines changed

assets/js/base/components/cart-checkout/address-form/address-form.js

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* External dependencies
33
*/
44
import PropTypes from 'prop-types';
5-
import { ValidatedTextInput } from '@woocommerce/blocks-checkout';
5+
import { ValidatedTextInput } from '@woocommerce/base-components/text-input';
66
import {
77
BillingCountryInput,
88
ShippingCountryInput,
@@ -11,10 +11,7 @@ import {
1111
BillingStateInput,
1212
ShippingStateInput,
1313
} from '@woocommerce/base-components/state-input';
14-
import {
15-
useValidationContext,
16-
ValidationInputError,
17-
} from '@woocommerce/base-context';
14+
import { useValidationContext } from '@woocommerce/base-context';
1815
import { useEffect, useMemo } from '@wordpress/element';
1916
import { __ } from '@wordpress/i18n';
2017
import { withInstanceId } from '@woocommerce/base-hocs/with-instance-id';
@@ -77,20 +74,10 @@ const AddressForm = ( {
7774
} ) => {
7875
const {
7976
getValidationError,
80-
getValidationErrorId,
8177
setValidationErrors,
8278
clearValidationError,
83-
hideValidationError,
8479
} = useValidationContext();
8580

86-
const textInputValidationFunctions = {
87-
getValidationError,
88-
getValidationErrorId,
89-
setValidationErrors,
90-
clearValidationError,
91-
hideValidationError,
92-
};
93-
9481
const currentFields = useShallowEqual( fields );
9582

9683
const countryValidationError =
@@ -214,9 +201,8 @@ const AddressForm = ( {
214201
[ field.key ]: newValue,
215202
} )
216203
}
204+
errorMessage={ field.errorMessage }
217205
required={ field.required }
218-
inputErrorComponent={ ValidationInputError }
219-
{ ...textInputValidationFunctions }
220206
/>
221207
);
222208
} ) }

assets/js/base/components/cart-checkout/totals/coupon/index.js

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,8 @@
33
*/
44
import { __ } from '@wordpress/i18n';
55
import { useState, useEffect, useRef } from '@wordpress/element';
6-
import {
7-
Button,
8-
Panel,
9-
Label,
10-
ValidatedTextInput,
11-
} from '@woocommerce/blocks-checkout';
6+
import { Button, Panel, Label } from '@woocommerce/blocks-checkout';
7+
import { ValidatedTextInput } from '@woocommerce/base-components/text-input';
128
import LoadingMask from '@woocommerce/base-components/loading-mask';
139
import PropTypes from 'prop-types';
1410
import { withInstanceId } from '@woocommerce/base-hocs/with-instance-id';
@@ -30,21 +26,7 @@ const TotalsCoupon = ( {
3026
} ) => {
3127
const [ couponValue, setCouponValue ] = useState( '' );
3228
const currentIsLoading = useRef( false );
33-
const {
34-
getValidationError,
35-
getValidationErrorId,
36-
setValidationErrors,
37-
clearValidationError,
38-
hideValidationError,
39-
} = useValidationContext();
40-
41-
const textInputValidationFunctions = {
42-
getValidationError,
43-
getValidationErrorId,
44-
setValidationErrors,
45-
clearValidationError,
46-
hideValidationError,
47-
};
29+
const { getValidationError, getValidationErrorId } = useValidationContext();
4830

4931
const validationError = getValidationError( 'coupon' );
5032

@@ -106,8 +88,6 @@ const TotalsCoupon = ( {
10688
validateOnMount={ false }
10789
focusOnMount={ true }
10890
showError={ false }
109-
inputErrorComponent={ ValidationInputError }
110-
{ ...textInputValidationFunctions }
11191
/>
11292
<Button
11393
className="wc-block-components-totals-coupon__button"

assets/js/base/components/state-input/state-input.js

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,14 @@
33
*/
44
import { __ } from '@wordpress/i18n';
55
import PropTypes from 'prop-types';
6-
import { ValidatedTextInput } from '@woocommerce/blocks-checkout';
76
import { decodeEntities } from '@wordpress/html-entities';
87
import { useCallback, useMemo } from '@wordpress/element';
98
import classnames from 'classnames';
10-
import {
11-
useValidationContext,
12-
ValidationInputError,
13-
} from '@woocommerce/base-context';
149

1510
/**
1611
* Internal dependencies
1712
*/
13+
import { ValidatedTextInput } from '../text-input';
1814
import { ValidatedSelect } from '../select';
1915
import './style.scss';
2016

@@ -29,22 +25,6 @@ const StateInput = ( {
2925
value = '',
3026
required = false,
3127
} ) => {
32-
const {
33-
getValidationError,
34-
getValidationErrorId,
35-
setValidationErrors,
36-
clearValidationError,
37-
hideValidationError,
38-
} = useValidationContext();
39-
40-
const textInputValidationFunctions = {
41-
getValidationError,
42-
getValidationErrorId,
43-
setValidationErrors,
44-
clearValidationError,
45-
hideValidationError,
46-
};
47-
4828
const countryStates = states[ country ];
4929
const options = useMemo(
5030
() =>
@@ -128,8 +108,6 @@ const StateInput = ( {
128108
autoComplete={ autoComplete }
129109
value={ value }
130110
required={ required }
131-
inputErrorComponent={ ValidationInputError }
132-
{ ...textInputValidationFunctions }
133111
/>
134112
);
135113
};
File renamed without changes.

packages/checkout/text-input/style.scss renamed to assets/js/base/components/text-input/style.scss

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939

4040
input[type="tel"],
4141
input[type="url"],
42-
input[type="number"],
4342
input[type="text"],
4443
input[type="email"] {
4544
@include font-size(regular);
@@ -75,7 +74,6 @@
7574

7675
&.is-active input[type="tel"],
7776
&.is-active input[type="url"],
78-
&.is-active input[type="number"],
7977
&.is-active input[type="text"],
8078
&.is-active input[type="email"] {
8179
padding: em($gap-large) 0 em($gap-smallest) $gap;

packages/checkout/text-input/text-input.tsx renamed to assets/js/base/components/text-input/text-input.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
import { forwardRef, InputHTMLAttributes } from 'react';
55
import classnames from 'classnames';
66
import { useState } from '@wordpress/element';
7+
import { Label } from '@woocommerce/blocks-checkout';
78

89
/**
910
* Internal dependencies
1011
*/
1112
import './style.scss';
12-
import Label from '../label';
1313

1414
interface TextInputProps
1515
extends Omit<
@@ -49,21 +49,18 @@ const TextInput = forwardRef< HTMLInputElement, TextInputProps >(
4949
/* Do nothing */
5050
},
5151
feedback,
52-
...rest
5352
},
5453
ref
5554
) => {
5655
const [ isActive, setIsActive ] = useState( false );
56+
5757
return (
5858
<div
5959
className={ classnames(
6060
'wc-block-components-text-input',
6161
className,
6262
{
63-
'is-active':
64-
isActive ||
65-
value ||
66-
( value === 0 && type === 'number' ),
63+
'is-active': isActive || value,
6764
}
6865
) }
6966
>
@@ -90,7 +87,6 @@ const TextInput = forwardRef< HTMLInputElement, TextInputProps >(
9087
: ariaDescribedBy
9188
}
9289
required={ required }
93-
{ ...rest }
9490
/>
9591
<Label
9692
label={ label }

packages/checkout/text-input/validated-text-input.tsx renamed to assets/js/base/components/text-input/validated-text-input.tsx

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22
* External dependencies
33
*/
44
import { __ } from '@wordpress/i18n';
5-
import { useCallback, useRef, useEffect, useState, Component } from 'react';
5+
import { useCallback, useRef, useEffect, useState } from 'react';
66
import classnames from 'classnames';
7+
import {
8+
ValidationInputError,
9+
useValidationContext,
10+
} from '@woocommerce/base-context';
711
import { withInstanceId } from '@woocommerce/base-hocs/with-instance-id';
812

913
/**
@@ -33,18 +37,6 @@ type ValidatedTextInputProps = (
3337
focusOnMount?: boolean;
3438
showError?: boolean;
3539
onChange: ( newValue: string ) => void;
36-
// @todo Type this properly when validation context is typed
37-
getValidationError: (
38-
errorId: string
39-
) => {
40-
message?: string;
41-
hidden?: boolean;
42-
};
43-
hideValidationError: ( errorId: string ) => void;
44-
setValidationErrors: ( errors: Record< string, unknown > ) => void;
45-
clearValidationError: ( errorId: string ) => void;
46-
getValidationErrorId: ( errorId: string ) => string;
47-
inputErrorComponent: typeof Component;
4840
};
4941

5042
const ValidatedTextInput = ( {
@@ -57,16 +49,18 @@ const ValidatedTextInput = ( {
5749
focusOnMount = false,
5850
onChange,
5951
showError = true,
60-
getValidationError,
61-
hideValidationError,
62-
setValidationErrors,
63-
clearValidationError,
64-
getValidationErrorId,
65-
inputErrorComponent: ValidationInputError,
6652
...rest
6753
}: ValidatedTextInputProps ) => {
6854
const [ isPristine, setIsPristine ] = useState( true );
6955
const inputRef = useRef< HTMLInputElement >( null );
56+
const {
57+
getValidationError,
58+
hideValidationError,
59+
setValidationErrors,
60+
clearValidationError,
61+
getValidationErrorId,
62+
} = useValidationContext();
63+
7064
const textInputId =
7165
typeof id !== 'undefined' ? id : 'textinput-' + instanceId;
7266
const errorIdString = errorId !== undefined ? errorId : textInputId;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"extends": "../../../../tsconfig.base.json",
33
"compilerOptions": {},
4-
"include": [ ".", "../../../../packages/prices", "../../../../packages/checkout", "../context/hooks", "../../type-defs" ],
4+
"include": [ ".", "../../../../packages/prices", "../context/hooks", "../../type-defs" ],
55
"exclude": [ "**/test/**" ]
66
}

assets/js/blocks/cart-checkout/checkout/form/contact-fields-step.js

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,8 @@
33
*/
44
import { __ } from '@wordpress/i18n';
55
import { FormStep } from '@woocommerce/base-components/cart-checkout';
6-
import { ValidatedTextInput } from '@woocommerce/blocks-checkout';
7-
import {
8-
useCheckoutContext,
9-
useValidationContext,
10-
ValidationInputError,
11-
} from '@woocommerce/base-context';
6+
import { ValidatedTextInput } from '@woocommerce/base-components/text-input';
7+
import { useCheckoutContext } from '@woocommerce/base-context';
128
import { getSetting } from '@woocommerce/settings';
139
import CheckboxControl from '@woocommerce/base-components/checkbox-control';
1410

@@ -27,21 +23,6 @@ const ContactFieldsStep = ( {
2723
shouldCreateAccount,
2824
setShouldCreateAccount,
2925
} = useCheckoutContext();
30-
const {
31-
getValidationError,
32-
getValidationErrorId,
33-
setValidationErrors,
34-
clearValidationError,
35-
hideValidationError,
36-
} = useValidationContext();
37-
38-
const textInputValidationFunctions = {
39-
getValidationError,
40-
getValidationErrorId,
41-
setValidationErrors,
42-
clearValidationError,
43-
hideValidationError,
44-
};
4526

4627
const createAccountUI = ! customerId &&
4728
allowCreateAccount &&
@@ -80,8 +61,6 @@ const ContactFieldsStep = ( {
8061
autoComplete="email"
8162
onChange={ onChangeEmail }
8263
required={ true }
83-
inputErrorComponent={ ValidationInputError }
84-
{ ...textInputValidationFunctions }
8564
/>
8665
{ createAccountUI }
8766
</FormStep>

assets/js/blocks/cart-checkout/checkout/form/phone-number/index.js

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22
* External dependencies
33
*/
44
import { __ } from '@wordpress/i18n';
5-
import { ValidatedTextInput } from '@woocommerce/blocks-checkout';
6-
import {
7-
useValidationContext,
8-
ValidationInputError,
9-
} from '@woocommerce/base-context';
5+
import { ValidatedTextInput } from '@woocommerce/base-components/text-input';
106

117
/**
128
* Renders a phone number input.
@@ -18,21 +14,6 @@ import {
1814
* @return {*} The component.
1915
*/
2016
const PhoneNumber = ( { isRequired = false, value = '', onChange } ) => {
21-
const {
22-
getValidationError,
23-
getValidationErrorId,
24-
setValidationErrors,
25-
clearValidationError,
26-
hideValidationError,
27-
} = useValidationContext();
28-
29-
const textInputValidationFunctions = {
30-
getValidationError,
31-
getValidationErrorId,
32-
setValidationErrors,
33-
clearValidationError,
34-
hideValidationError,
35-
};
3617
return (
3718
<ValidatedTextInput
3819
id="phone"
@@ -46,8 +27,6 @@ const PhoneNumber = ( { isRequired = false, value = '', onChange } ) => {
4627
}
4728
value={ value }
4829
onChange={ onChange }
49-
inputErrorComponent={ ValidationInputError }
50-
{ ...textInputValidationFunctions }
5130
/>
5231
);
5332
};

0 commit comments

Comments
 (0)