2019-11-01 13:56:14 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import {
|
|
|
|
useState,
|
|
|
|
useEffect,
|
|
|
|
useCallback,
|
|
|
|
useMemo,
|
|
|
|
useRef,
|
|
|
|
} from '@wordpress/element';
|
|
|
|
import classnames from 'classnames';
|
2019-12-18 11:29:20 +00:00
|
|
|
import FormattedMonetaryAmount from '@woocommerce/base-components/formatted-monetary-amount';
|
2021-12-15 16:54:49 +00:00
|
|
|
import { Currency, isObject } from '@woocommerce/types';
|
2019-11-01 13:56:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import './style.scss';
|
2020-01-02 13:07:59 +00:00
|
|
|
import { constrainRangeSliderValues } from './constrain-range-slider-values';
|
2019-12-12 19:16:39 +00:00
|
|
|
import FilterSubmitButton from '../filter-submit-button';
|
2022-01-06 14:30:34 +00:00
|
|
|
import { isValidMaxValue, isValidMinValue } from './utils';
|
2019-11-01 13:56:14 +00:00
|
|
|
|
2021-12-15 16:54:49 +00:00
|
|
|
export interface PriceSliderProps {
|
|
|
|
/**
|
|
|
|
* Currency configuration object.
|
|
|
|
*/
|
|
|
|
currency: Currency;
|
|
|
|
/**
|
|
|
|
* Whether values are loading or not.
|
|
|
|
*/
|
|
|
|
isLoading?: boolean;
|
|
|
|
/**
|
|
|
|
* Maximum constraint.
|
|
|
|
*/
|
2022-06-14 08:48:49 +00:00
|
|
|
maxConstraint: number | null | undefined;
|
2021-12-15 16:54:49 +00:00
|
|
|
/**
|
|
|
|
* Maximum price for slider.
|
|
|
|
*/
|
2022-06-14 08:48:49 +00:00
|
|
|
maxPrice: number | null;
|
2021-12-15 16:54:49 +00:00
|
|
|
/**
|
|
|
|
* Minimum constraint.
|
|
|
|
*/
|
2022-06-14 08:48:49 +00:00
|
|
|
minConstraint: number | null | undefined;
|
2021-12-15 16:54:49 +00:00
|
|
|
/**
|
|
|
|
* Minimum price for slider.
|
|
|
|
*/
|
2022-06-14 08:48:49 +00:00
|
|
|
minPrice: number | null;
|
2021-12-15 16:54:49 +00:00
|
|
|
/**
|
|
|
|
* Function to call on the change event.
|
|
|
|
*/
|
2022-07-01 17:50:44 +00:00
|
|
|
onChange: ( value: [ number, number ] ) => void;
|
2021-12-15 16:54:49 +00:00
|
|
|
/**
|
|
|
|
* Function to call when submit event fires.
|
|
|
|
*/
|
|
|
|
onSubmit?: () => void;
|
|
|
|
/**
|
|
|
|
* Whether to show the filter button for the slider.
|
|
|
|
*/
|
|
|
|
showFilterButton?: boolean;
|
|
|
|
/**
|
|
|
|
* Whether to show input fields for the values or not.
|
|
|
|
*/
|
|
|
|
showInputFields?: boolean;
|
|
|
|
/**
|
|
|
|
* What step values the slider uses.
|
|
|
|
*/
|
2022-06-14 08:48:49 +00:00
|
|
|
step?: number;
|
2021-12-15 16:54:49 +00:00
|
|
|
}
|
|
|
|
|
2019-11-01 13:56:14 +00:00
|
|
|
const PriceSlider = ( {
|
2019-11-15 14:41:23 +00:00
|
|
|
minPrice,
|
|
|
|
maxPrice,
|
2019-11-01 13:56:14 +00:00
|
|
|
minConstraint,
|
|
|
|
maxConstraint,
|
2022-07-01 17:50:44 +00:00
|
|
|
onChange,
|
2019-12-18 11:29:20 +00:00
|
|
|
step,
|
|
|
|
currency,
|
2019-11-15 14:41:23 +00:00
|
|
|
showInputFields = true,
|
|
|
|
showFilterButton = false,
|
|
|
|
isLoading = false,
|
2021-12-15 16:54:49 +00:00
|
|
|
onSubmit = () => void 0,
|
|
|
|
}: PriceSliderProps ): JSX.Element => {
|
|
|
|
const minRange = useRef< HTMLInputElement >( null );
|
|
|
|
const maxRange = useRef< HTMLInputElement >( null );
|
2019-11-15 14:41:23 +00:00
|
|
|
|
2022-05-31 10:44:50 +00:00
|
|
|
// We want step to default to 1 major unit, e.g. $1.
|
|
|
|
const stepValue = step ? step : 10 ** currency.minorUnit;
|
2019-12-18 11:29:20 +00:00
|
|
|
|
|
|
|
const [ minPriceInput, setMinPriceInput ] = useState( minPrice );
|
|
|
|
const [ maxPriceInput, setMaxPriceInput ] = useState( maxPrice );
|
2019-11-01 13:56:14 +00:00
|
|
|
|
|
|
|
useEffect( () => {
|
2019-12-18 11:29:20 +00:00
|
|
|
setMinPriceInput( minPrice );
|
|
|
|
}, [ minPrice ] );
|
2019-11-01 13:56:14 +00:00
|
|
|
|
|
|
|
useEffect( () => {
|
2019-12-18 11:29:20 +00:00
|
|
|
setMaxPriceInput( maxPrice );
|
|
|
|
}, [ maxPrice ] );
|
2019-11-01 13:56:14 +00:00
|
|
|
|
2019-11-15 14:41:23 +00:00
|
|
|
/**
|
|
|
|
* Checks if the min and max constraints are valid.
|
|
|
|
*/
|
2019-11-11 11:05:18 +00:00
|
|
|
const hasValidConstraints = useMemo( () => {
|
|
|
|
return isFinite( minConstraint ) && isFinite( maxConstraint );
|
|
|
|
}, [ minConstraint, maxConstraint ] );
|
|
|
|
|
2019-11-01 13:56:14 +00:00
|
|
|
/**
|
|
|
|
* Handles styles for the shaded area of the range slider.
|
|
|
|
*/
|
2019-11-11 11:05:18 +00:00
|
|
|
const progressStyles = useMemo( () => {
|
2019-11-06 18:25:37 +00:00
|
|
|
if (
|
|
|
|
! isFinite( minPrice ) ||
|
|
|
|
! isFinite( maxPrice ) ||
|
2019-11-11 11:05:18 +00:00
|
|
|
! hasValidConstraints
|
2019-11-06 18:25:37 +00:00
|
|
|
) {
|
|
|
|
return {
|
|
|
|
'--low': '0%',
|
|
|
|
'--high': '100%',
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-11-01 13:56:14 +00:00
|
|
|
const low =
|
|
|
|
Math.round(
|
|
|
|
100 *
|
2020-01-02 11:10:41 +00:00
|
|
|
( ( minPrice - minConstraint ) /
|
2019-11-01 13:56:14 +00:00
|
|
|
( maxConstraint - minConstraint ) )
|
|
|
|
) - 0.5;
|
|
|
|
const high =
|
|
|
|
Math.round(
|
|
|
|
100 *
|
2020-01-02 11:10:41 +00:00
|
|
|
( ( maxPrice - minConstraint ) /
|
2019-11-01 13:56:14 +00:00
|
|
|
( maxConstraint - minConstraint ) )
|
|
|
|
) + 0.5;
|
|
|
|
|
|
|
|
return {
|
|
|
|
'--low': low + '%',
|
|
|
|
'--high': high + '%',
|
|
|
|
};
|
2019-11-11 11:05:18 +00:00
|
|
|
}, [
|
|
|
|
minPrice,
|
|
|
|
maxPrice,
|
|
|
|
minConstraint,
|
|
|
|
maxConstraint,
|
|
|
|
hasValidConstraints,
|
|
|
|
] );
|
2019-11-01 13:56:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Works around an IE issue where only one range selector is visible by changing the display order
|
|
|
|
* based on the mouse position.
|
|
|
|
*
|
2019-12-10 17:17:46 +00:00
|
|
|
* @param {Object} event event data.
|
2019-11-01 13:56:14 +00:00
|
|
|
*/
|
|
|
|
const findClosestRange = useCallback(
|
2021-12-15 16:54:49 +00:00
|
|
|
( event: React.MouseEvent< HTMLDivElement > ) => {
|
|
|
|
if (
|
|
|
|
isLoading ||
|
|
|
|
! hasValidConstraints ||
|
|
|
|
! minRange.current ||
|
|
|
|
! maxRange.current
|
|
|
|
) {
|
2019-11-01 13:56:14 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-12-15 16:54:49 +00:00
|
|
|
const bounds = ( event.target as Element ).getBoundingClientRect();
|
2019-11-01 13:56:14 +00:00
|
|
|
const x = event.clientX - bounds.left;
|
|
|
|
const minWidth = minRange.current.offsetWidth;
|
2021-12-15 16:54:49 +00:00
|
|
|
const minValue = +minRange.current.value;
|
2019-11-01 13:56:14 +00:00
|
|
|
const maxWidth = maxRange.current.offsetWidth;
|
2021-12-15 16:54:49 +00:00
|
|
|
const maxValue = +maxRange.current.value;
|
2019-11-01 13:56:14 +00:00
|
|
|
|
|
|
|
const minX = minWidth * ( minValue / maxConstraint );
|
|
|
|
const maxX = maxWidth * ( maxValue / maxConstraint );
|
|
|
|
|
|
|
|
const minXDiff = Math.abs( x - minX );
|
|
|
|
const maxXDiff = Math.abs( x - maxX );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The default z-index in the stylesheet as 20. 20 vs 21 is just for determining which range
|
|
|
|
* slider should be at the front and has no meaning beyond
|
|
|
|
*/
|
|
|
|
if ( minXDiff > maxXDiff ) {
|
2021-12-15 16:54:49 +00:00
|
|
|
minRange.current.style.zIndex = '20';
|
|
|
|
maxRange.current.style.zIndex = '21';
|
2019-11-01 13:56:14 +00:00
|
|
|
} else {
|
2021-12-15 16:54:49 +00:00
|
|
|
minRange.current.style.zIndex = '21';
|
|
|
|
maxRange.current.style.zIndex = '20';
|
2019-11-01 13:56:14 +00:00
|
|
|
}
|
|
|
|
},
|
2019-11-11 11:05:18 +00:00
|
|
|
[ isLoading, maxConstraint, hasValidConstraints ]
|
2019-11-01 13:56:14 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when the slider is dragged.
|
|
|
|
*/
|
|
|
|
const rangeInputOnChange = useCallback(
|
2021-12-15 16:54:49 +00:00
|
|
|
( event: React.ChangeEvent< HTMLInputElement > ) => {
|
2019-11-01 13:56:14 +00:00
|
|
|
const isMin = event.target.classList.contains(
|
|
|
|
'wc-block-price-filter__range-input--min'
|
|
|
|
);
|
2021-12-15 16:54:49 +00:00
|
|
|
const targetValue = +event.target.value;
|
|
|
|
const currentValues: [ number, number ] = isMin
|
2020-01-02 11:10:41 +00:00
|
|
|
? [
|
|
|
|
Math.round( targetValue / stepValue ) * stepValue,
|
|
|
|
maxPrice,
|
|
|
|
]
|
|
|
|
: [
|
|
|
|
minPrice,
|
|
|
|
Math.round( targetValue / stepValue ) * stepValue,
|
|
|
|
];
|
2019-11-01 13:56:14 +00:00
|
|
|
const values = constrainRangeSliderValues(
|
|
|
|
currentValues,
|
|
|
|
minConstraint,
|
|
|
|
maxConstraint,
|
2019-12-18 11:29:20 +00:00
|
|
|
stepValue,
|
2019-11-01 13:56:14 +00:00
|
|
|
isMin
|
|
|
|
);
|
2021-12-15 16:54:49 +00:00
|
|
|
onChange( values );
|
2019-11-01 13:56:14 +00:00
|
|
|
},
|
2020-10-27 15:39:08 +00:00
|
|
|
[
|
|
|
|
onChange,
|
|
|
|
minPrice,
|
|
|
|
maxPrice,
|
|
|
|
minConstraint,
|
|
|
|
maxConstraint,
|
|
|
|
stepValue,
|
|
|
|
]
|
2019-11-01 13:56:14 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when a price input loses focus - commit changes to slider.
|
|
|
|
*/
|
|
|
|
const priceInputOnBlur = useCallback(
|
2021-12-15 16:54:49 +00:00
|
|
|
( event: React.FocusEvent< HTMLInputElement > ) => {
|
2019-12-18 11:29:20 +00:00
|
|
|
// Only refresh when finished editing the min and max fields.
|
|
|
|
if (
|
|
|
|
event.relatedTarget &&
|
2021-12-15 16:54:49 +00:00
|
|
|
( event.relatedTarget as Element ).classList &&
|
|
|
|
( event.relatedTarget as Element ).classList.contains(
|
2019-12-18 11:29:20 +00:00
|
|
|
'wc-block-price-filter__amount'
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
2022-01-06 14:30:34 +00:00
|
|
|
|
2019-11-01 13:56:14 +00:00
|
|
|
const isMin = event.target.classList.contains(
|
|
|
|
'wc-block-price-filter__amount--min'
|
|
|
|
);
|
2022-01-06 14:30:34 +00:00
|
|
|
|
|
|
|
// When the user inserts in the max price input a value less or equal than the current minimum price,
|
|
|
|
// we set to 0 the minimum price.
|
|
|
|
if ( minPriceInput >= maxPriceInput ) {
|
|
|
|
const values = constrainRangeSliderValues(
|
|
|
|
[ 0, maxPriceInput ],
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
stepValue,
|
|
|
|
isMin
|
|
|
|
);
|
|
|
|
return onChange( [
|
|
|
|
parseInt( values[ 0 ], 10 ),
|
|
|
|
parseInt( values[ 1 ], 10 ),
|
|
|
|
] );
|
|
|
|
}
|
|
|
|
|
2019-11-01 13:56:14 +00:00
|
|
|
const values = constrainRangeSliderValues(
|
2019-12-18 11:29:20 +00:00
|
|
|
[ minPriceInput, maxPriceInput ],
|
2020-01-02 13:07:59 +00:00
|
|
|
null,
|
|
|
|
null,
|
2019-12-18 11:29:20 +00:00
|
|
|
stepValue,
|
2019-11-01 13:56:14 +00:00
|
|
|
isMin
|
|
|
|
);
|
2021-12-15 16:54:49 +00:00
|
|
|
onChange( values );
|
2019-11-01 13:56:14 +00:00
|
|
|
},
|
2020-10-27 15:39:08 +00:00
|
|
|
[ onChange, stepValue, minPriceInput, maxPriceInput ]
|
2019-11-01 13:56:14 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
const classes = classnames(
|
|
|
|
'wc-block-price-filter',
|
2020-06-17 09:53:42 +00:00
|
|
|
'wc-block-components-price-slider',
|
2019-11-01 13:56:14 +00:00
|
|
|
showInputFields && 'wc-block-price-filter--has-input-fields',
|
2020-06-17 09:53:42 +00:00
|
|
|
showInputFields && 'wc-block-components-price-slider--has-input-fields',
|
2019-11-01 13:56:14 +00:00
|
|
|
showFilterButton && 'wc-block-price-filter--has-filter-button',
|
2020-06-17 09:53:42 +00:00
|
|
|
showFilterButton &&
|
|
|
|
'wc-block-components-price-slider--has-filter-button',
|
2019-11-11 11:05:18 +00:00
|
|
|
isLoading && 'is-loading',
|
|
|
|
! hasValidConstraints && 'is-disabled'
|
2019-11-01 13:56:14 +00:00
|
|
|
);
|
|
|
|
|
2021-05-16 17:59:32 +00:00
|
|
|
const activeElement = isObject( minRange.current )
|
|
|
|
? minRange.current.ownerDocument.activeElement
|
|
|
|
: undefined;
|
2020-01-02 11:10:41 +00:00
|
|
|
const minRangeStep =
|
2021-05-16 17:59:32 +00:00
|
|
|
activeElement && activeElement === minRange.current ? stepValue : 1;
|
2020-01-02 11:10:41 +00:00
|
|
|
const maxRangeStep =
|
2021-05-16 17:59:32 +00:00
|
|
|
activeElement && activeElement === maxRange.current ? stepValue : 1;
|
2020-01-02 11:10:41 +00:00
|
|
|
|
2021-12-15 16:54:49 +00:00
|
|
|
const ariaReadableMinPrice = String(
|
|
|
|
minPriceInput / 10 ** currency.minorUnit
|
|
|
|
);
|
|
|
|
const ariaReadableMaxPrice = String(
|
|
|
|
maxPriceInput / 10 ** currency.minorUnit
|
|
|
|
);
|
2021-10-06 08:48:17 +00:00
|
|
|
|
2019-11-01 13:56:14 +00:00
|
|
|
return (
|
|
|
|
<div className={ classes }>
|
|
|
|
<div
|
2020-06-17 09:53:42 +00:00
|
|
|
className="wc-block-price-filter__range-input-wrapper wc-block-components-price-slider__range-input-wrapper"
|
2019-11-01 13:56:14 +00:00
|
|
|
onMouseMove={ findClosestRange }
|
|
|
|
onFocus={ findClosestRange }
|
|
|
|
>
|
2019-12-16 16:48:02 +00:00
|
|
|
{ hasValidConstraints && (
|
2020-01-30 10:04:39 +00:00
|
|
|
<div aria-hidden={ showInputFields }>
|
2019-11-01 13:56:14 +00:00
|
|
|
<div
|
2020-06-17 09:53:42 +00:00
|
|
|
className="wc-block-price-filter__range-input-progress wc-block-components-price-slider__range-input-progress"
|
2021-12-15 16:54:49 +00:00
|
|
|
style={ progressStyles as React.CSSProperties }
|
2019-11-01 13:56:14 +00:00
|
|
|
/>
|
|
|
|
<input
|
|
|
|
type="range"
|
2020-06-17 09:53:42 +00:00
|
|
|
className="wc-block-price-filter__range-input wc-block-price-filter__range-input--min wc-block-components-price-slider__range-input wc-block-components-price-slider__range-input--min"
|
2019-11-01 13:56:14 +00:00
|
|
|
aria-label={ __(
|
|
|
|
'Filter products by minimum price',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
2021-10-06 08:48:17 +00:00
|
|
|
aria-valuetext={ ariaReadableMinPrice }
|
2020-01-02 13:07:59 +00:00
|
|
|
value={
|
|
|
|
Number.isFinite( minPrice )
|
|
|
|
? minPrice
|
|
|
|
: minConstraint
|
|
|
|
}
|
2019-11-01 13:56:14 +00:00
|
|
|
onChange={ rangeInputOnChange }
|
2020-01-02 11:10:41 +00:00
|
|
|
step={ minRangeStep }
|
2019-11-01 13:56:14 +00:00
|
|
|
min={ minConstraint }
|
|
|
|
max={ maxConstraint }
|
|
|
|
ref={ minRange }
|
2019-12-16 16:48:02 +00:00
|
|
|
disabled={ isLoading }
|
2021-12-15 16:54:49 +00:00
|
|
|
tabIndex={ showInputFields ? -1 : 0 }
|
2019-11-01 13:56:14 +00:00
|
|
|
/>
|
|
|
|
<input
|
|
|
|
type="range"
|
2020-06-17 09:53:42 +00:00
|
|
|
className="wc-block-price-filter__range-input wc-block-price-filter__range-input--max wc-block-components-price-slider__range-input wc-block-components-price-slider__range-input--max"
|
2019-11-01 13:56:14 +00:00
|
|
|
aria-label={ __(
|
|
|
|
'Filter products by maximum price',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
2021-10-06 08:48:17 +00:00
|
|
|
aria-valuetext={ ariaReadableMaxPrice }
|
2020-01-02 13:07:59 +00:00
|
|
|
value={
|
|
|
|
Number.isFinite( maxPrice )
|
|
|
|
? maxPrice
|
|
|
|
: maxConstraint
|
|
|
|
}
|
2019-11-01 13:56:14 +00:00
|
|
|
onChange={ rangeInputOnChange }
|
2020-01-02 11:10:41 +00:00
|
|
|
step={ maxRangeStep }
|
2019-11-01 13:56:14 +00:00
|
|
|
min={ minConstraint }
|
|
|
|
max={ maxConstraint }
|
|
|
|
ref={ maxRange }
|
2019-12-16 16:48:02 +00:00
|
|
|
disabled={ isLoading }
|
2021-12-15 16:54:49 +00:00
|
|
|
tabIndex={ showInputFields ? -1 : 0 }
|
2019-11-01 13:56:14 +00:00
|
|
|
/>
|
2020-01-30 10:04:39 +00:00
|
|
|
</div>
|
2019-11-01 13:56:14 +00:00
|
|
|
) }
|
|
|
|
</div>
|
2020-06-17 09:53:42 +00:00
|
|
|
<div className="wc-block-price-filter__controls wc-block-components-price-slider__controls">
|
2019-12-18 11:29:20 +00:00
|
|
|
{ showInputFields && (
|
2020-12-14 11:54:34 +00:00
|
|
|
<>
|
2019-12-18 11:29:20 +00:00
|
|
|
<FormattedMonetaryAmount
|
|
|
|
currency={ currency }
|
|
|
|
displayType="input"
|
2020-06-17 09:53:42 +00:00
|
|
|
className="wc-block-price-filter__amount wc-block-price-filter__amount--min wc-block-form-text-input wc-block-components-price-slider__amount wc-block-components-price-slider__amount--min"
|
2019-12-18 11:29:20 +00:00
|
|
|
aria-label={ __(
|
|
|
|
'Filter products by minimum price',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
2022-01-06 14:30:34 +00:00
|
|
|
allowNegative={ false }
|
|
|
|
isAllowed={ isValidMinValue( {
|
|
|
|
minConstraint,
|
|
|
|
minorUnit: currency.minorUnit,
|
|
|
|
currentMaxValue: maxPriceInput,
|
|
|
|
} ) }
|
2019-12-18 11:29:20 +00:00
|
|
|
onValueChange={ ( value ) => {
|
|
|
|
if ( value === minPriceInput ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
setMinPriceInput( value );
|
|
|
|
} }
|
|
|
|
onBlur={ priceInputOnBlur }
|
|
|
|
disabled={ isLoading || ! hasValidConstraints }
|
|
|
|
value={ minPriceInput }
|
|
|
|
/>
|
|
|
|
<FormattedMonetaryAmount
|
|
|
|
currency={ currency }
|
|
|
|
displayType="input"
|
2020-06-17 09:53:42 +00:00
|
|
|
className="wc-block-price-filter__amount wc-block-price-filter__amount--max wc-block-form-text-input wc-block-components-price-slider__amount wc-block-components-price-slider__amount--max"
|
2019-12-18 11:29:20 +00:00
|
|
|
aria-label={ __(
|
|
|
|
'Filter products by maximum price',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
2022-01-06 14:30:34 +00:00
|
|
|
isAllowed={ isValidMaxValue( {
|
|
|
|
maxConstraint,
|
|
|
|
minorUnit: currency.minorUnit,
|
|
|
|
} ) }
|
2019-12-18 11:29:20 +00:00
|
|
|
onValueChange={ ( value ) => {
|
|
|
|
if ( value === maxPriceInput ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
setMaxPriceInput( value );
|
|
|
|
} }
|
|
|
|
onBlur={ priceInputOnBlur }
|
|
|
|
disabled={ isLoading || ! hasValidConstraints }
|
|
|
|
value={ maxPriceInput }
|
|
|
|
/>
|
2020-12-14 11:54:34 +00:00
|
|
|
</>
|
2019-11-01 13:56:14 +00:00
|
|
|
) }
|
2019-12-18 11:29:20 +00:00
|
|
|
{ ! showInputFields &&
|
|
|
|
! isLoading &&
|
|
|
|
Number.isFinite( minPrice ) &&
|
|
|
|
Number.isFinite( maxPrice ) && (
|
2020-06-17 09:53:42 +00:00
|
|
|
<div className="wc-block-price-filter__range-text wc-block-components-price-slider__range-text">
|
2020-01-30 10:04:39 +00:00
|
|
|
{ __( 'Price', 'woo-gutenberg-products-block' ) }
|
|
|
|
:
|
2019-12-18 11:29:20 +00:00
|
|
|
<FormattedMonetaryAmount
|
|
|
|
currency={ currency }
|
|
|
|
value={ minPrice }
|
|
|
|
/>
|
|
|
|
–
|
|
|
|
<FormattedMonetaryAmount
|
|
|
|
currency={ currency }
|
|
|
|
value={ maxPrice }
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
) }
|
2019-11-01 13:56:14 +00:00
|
|
|
{ showFilterButton && (
|
2019-12-12 19:16:39 +00:00
|
|
|
<FilterSubmitButton
|
2020-06-17 09:53:42 +00:00
|
|
|
className="wc-block-price-filter__button wc-block-components-price-slider__button"
|
2019-11-11 11:05:18 +00:00
|
|
|
disabled={ isLoading || ! hasValidConstraints }
|
2019-11-15 14:41:23 +00:00
|
|
|
onClick={ onSubmit }
|
2020-01-30 10:04:39 +00:00
|
|
|
screenReaderLabel={ __(
|
|
|
|
'Apply price filter',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
2019-11-01 13:56:14 +00:00
|
|
|
/>
|
|
|
|
) }
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default PriceSlider;
|