Skip to content
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

[feature]: Replace ProductQuantity on Product Page with QuantityFields stepper #2690

Merged
merged 9 commits into from Oct 1, 2020
Expand Up @@ -119,5 +119,6 @@ exports[`renders quantity correctly 1`] = `
</span>
</button>
</div>

</form>
`;
Expand Up @@ -12,7 +12,8 @@ const defaultProps = {
itemId: 'item1',
label: 'Test Quantity',
min: 0,
onChange: mockOnChange
onChange: mockOnChange,
message: ''
};

test('renders quantity correctly', () => {
Expand Down
@@ -1,4 +1,4 @@
import React from 'react';
import React, { Fragment } from 'react';
import { Form } from 'informed';
import { func, number, string } from 'prop-types';
import { Minus as MinusIcon, Plus as PlusIcon } from 'react-feather';
Expand All @@ -7,10 +7,11 @@ import { useQuantity } from '@magento/peregrine/lib/talons/CartPage/ProductListi
import { mergeClasses } from '../../../classify';
import Icon from '../../Icon';
import TextInput from '../../TextInput';
import { Message } from '../../Field';
import defaultClasses from './quantity.css';

export const QuantityFields = props => {
const { initialValue, itemId, label, min, onChange } = props;
const { initialValue, itemId, label, min, onChange, message } = props;
const classes = mergeClasses(defaultClasses, props.classes);
const iconClasses = { root: classes.icon };

Expand All @@ -30,40 +31,43 @@ export const QuantityFields = props => {
} = talonProps;

return (
<div className={classes.root}>
<label className={classes.label} htmlFor={itemId}>
{label}
</label>
<button
aria-label={'Decrease Quantity'}
className={classes.button_decrement}
disabled={isDecrementDisabled}
onClick={handleDecrement}
type="button"
>
<Icon classes={iconClasses} src={MinusIcon} size={22} />
</button>
<TextInput
aria-label="Item Quantity"
classes={{ input: classes.input }}
field="quantity"
id={itemId}
inputMode="numeric"
mask={maskInput}
min={min}
onBlur={handleBlur}
pattern="[0-9]*"
/>
<button
aria-label={'Increase Quantity'}
className={classes.button_increment}
disabled={isIncrementDisabled}
onClick={handleIncrement}
type="button"
>
<Icon classes={iconClasses} src={PlusIcon} size={20} />
</button>
</div>
<Fragment>
<div className={classes.root}>
<label className={classes.label} htmlFor={itemId}>
{label}
</label>
<button
aria-label={'Decrease Quantity'}
className={classes.button_decrement}
disabled={isDecrementDisabled}
onClick={handleDecrement}
type="button"
>
<Icon classes={iconClasses} src={MinusIcon} size={22} />
</button>
<TextInput
aria-label="Item Quantity"
classes={{ input: classes.input }}
field="quantity"
id={itemId}
inputMode="numeric"
mask={maskInput}
min={min}
onBlur={handleBlur}
pattern="[0-9]*"
/>
<button
aria-label={'Increase Quantity'}
className={classes.button_increment}
disabled={isIncrementDisabled}
onClick={handleIncrement}
type="button"
>
<Icon classes={iconClasses} src={PlusIcon} size={20} />
</button>
</div>
{message && <Message>{message}</Message>}
tjwiebell marked this conversation as resolved.
Show resolved Hide resolved
</Fragment>
);
};

Expand All @@ -84,7 +88,8 @@ Quantity.propTypes = {
itemId: string,
label: string,
min: number,
onChange: func
onChange: func,
message: string
};

Quantity.defaultProps = {
Expand Down
Expand Up @@ -149,6 +149,8 @@ const ProductFullDetail = props => {
classes={{ root: classes.quantityRoot }}
initialValue={quantity}
onChange={handleSetQuantity}
min={1}
message={errors.get('quantity')}
/>
</section>
<section className={classes.cartActions}>
Expand Down