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

Commit 2b5c814

Browse files
authored
New block: Filter Products by Price (#853)
* Basic component setup * Working slider * Validation * styling * Update webpack config to fix ie11 * ie progress * styling improvements * improve events * IE shim * Fix samsung internet styles * Add aria * remove old methods * event handling * Tweak size and width of inputs * reset progress * shorthand notation for setstate * Inline comment for textare usage * Remove pointless comparison * destruct from state * zindex comment * Move out currency settings and validation * enforce int for min and max state * Use woocommerce/settings * showInputFields prop * Filter Products by Price: Block creation (#865) * Prevent interaction with slider * Show input fields toggle * Placeholder content and icons * Update dependency rimraf to v2.7.0 (#858) * placeholder styling * remove unnecessary config (#862) * Filter button and styling * Show/hide placeholder based on product count * Update dependency rimraf to v2.7.1 (#867) * Use correct parameter order for implode. Solves deprecation notice in PHP 7.4 (#857) * Add description to blocks added in last releases (#869) * Limit max width * Prevent wrap * handles src file * Introduce withCategory HOC for featured category block (#846) * Introduce withCategory hoc * Refactor featured category to use new hoc * Update docblocks * Add README note for PHP deprecation notices * Remove screen-reader-text css rules (#849) * Align stars left (#866) * bool * Create Reviews by Product block (#658) * Create Reviews by Product block * Honor Content settings * Fix wrong className * Load new wc-packages file * Add reviews-by-product JS files to webpack config * Cleanup * Remove error messages * Add Reviews by Product icon * Update sort options * Allow additional CSS classes attribute * Refactor block styles * Fix wrong default for reviews_orderby * Don't enforce CSS chunks * Add reviews count to Reviews by Product controls (#671) * Add label to Reviews by Product controls count (#677) * Add reviews count to Reviews by Product controls * Add label to Reviews by Product controls count * Add label to Reviews by Product controls count * Update components package * Review ordering and placeholders (#688) * Add support for comment_count ordering and add to productcontrol * Add a placeholder if rating count is 0 * Update assets/js/components/utils/index.js Co-Authored-By: Albert Juhé Lluveras <[email protected]> * Update assets/js/blocks/reviews-by-product/block.js Co-Authored-By: Albert Juhé Lluveras <[email protected]> * grammar * Fix some linting errors and warnings (#693) * Create Reviews by Product block placeholder (#691) * Create Reviews by Product block placeholder * Reviews by Product: load and render reviews with JS (#696) * Reviews by Product: load and render reviews with JS * Add dangerouslySetInnerHTML explanatory comment * Fix wrong dependency source * Debounce getReviews call when creating the Reviews by Product block * Rename 'Reviewer Picture' with 'Avatar' (#702) * Lint errors * Replace stringify query with addQueryArgs (#707) * Add reviews endpoint (#705) * Prevent state updates on unmounted components (#715) * Add Order by and Load more controls in Reviews by Product frontend (#716) * Export IconReviewsByProduct (#721) * Fix Reviews by Product layout in IE11 (#723) * Set minimum to per page input field (#731) * Hide avatars in Reviews by Products if 'show_avatars' settings is false (#730) * Blocks API - Reviews endpoint with rating sort and category filtering (#726) * Move file to correct location * We are only using the reviews endpoint not revioews/id * Remove sensistive data and make endpoint public * Allow guest access to approved reviews * Add support for rating sorting * category filtering * update arg name * fix category query * Reviews by Product: add placeholders when loading reviews (#732) * Add placeholder animation (#733) * Hook up Reviews by Product 'Order by' with endpoint (#736) * Hook up Reviews by Product 'Order by' with endpoint * Use onChange instead of onBlur in select control * Reviews by Product: Hide ratings if they are disabled in settings (#740) * Hide ratings in Reviews by Product if disabled in settings * Hide order by select if ratings are disabled * Reviews by Product cleanup (#773) * Fix wrong method name * Reduce the number of dependencies used in Reviews by Product (#774) * Reduce the number of dependencies used in Reviews by Product * Use 'withComponentId' HOC * Remove debounce * Fix wrong proptype * Get rid of JS warning * Load render from react-dom * Add formatted_date_created item schema (#788) * Fix import of WithComponentID * Add new settings to Reviews by Product block (#787) * Add new settings to Reviews by Product block * Remove helpText and add notices * Use RangeControl for numeric settings * Prevent fetching new reviews if all were already fetched * Enable product image in reviews * Remove unnecessary catch * Refactor getReviews * Move getReviews back to block's code * Cleanup * Fix wrong order in editor * Hide 'Load More Reviews' if showLoadMore is false * Move getReviews to utils.js * Add @woocommerce/navigation to package.json * Make notices non-dismissable * Reviews by Product: prevent importing all HOCs and import only withComponentId (#811) * Reviews by product: Update review styling and content (#806) * Add new settings to Reviews by Product block * Remove helpText and add notices * Use RangeControl for numeric settings * Prevent fetching new reviews if all were already fetched * Enable product image in reviews * Remove unnecessary catch * Refactor getReviews * Move getReviews back to block's code * Cleanup * Fix wrong order in editor * Hide 'Load More Reviews' if showLoadMore is false * Move getReviews to utils.js * Add @woocommerce/navigation to package.json * Make notices non-dismissable * Review design/layout * verified icons * Read more component * remove comment * expanded -> isExpanded * Localise and change default elipses * Simplify ReadMore * Support children rather than passing content * remove outside * remove list style * Update assets/js/components/read-more/index.js Co-Authored-By: Albert Juhé Lluveras <[email protected]> * Update assets/js/components/read-more/index.js Co-Authored-By: Albert Juhé Lluveras <[email protected]> * merge set state * Add missing parameter doc in renderReview (#820) * Fix Reviews by Product order by select not honoring default setting (#818) * Read more component - change how clamped content is shown (#821) * Pass review as components * Build summary from content and track both * Toggle display after inital load * remove unused variable * remove componentDidUpdate * Simplify clampLines * Put back componentDidUpdate, but store final summary in state * clampEnabled * Call clampLines from componentDidMount (#826) * truncate html tests * implement trimHTML and pass test * Feedback * test short content * Use withProduct HOC in ReviewsByProductEditor (#828) * Use withProduct HOC * Convert ReviewsByProductEditor to a functional component * Add loading and error states * Prevent loading screen appearing when changing products * Reviews: only save wrapper element to post (#830) * Fix bundlesize config not picking frontend files (#840) * Reviews by Product: split 'block.js' into smaller chunks (#841) * Split 'block.js' into smaller chunks * Move frontend blocks to their specific folder * Order imports * Typo * Add frontend components proptypes * Fix indentation * Call 'this.getDefaultArgs' directly inside 'getReviews' * Move access to wc_product_block_data to the top of the file * Rename 'frontend' folder to 'base' * Rename base components and move styles to their folder * Fix Reviews by Product using rating count instead of review count (#860) * Improve Reviews by Product accessibility (#861) * Improve Reviews by Product accessibility * Make 'onClick' prop not required in <LoadMoreButton> * Wrap Reviews by Product editor block with <Disabled> * Reviews: fix reviews without rating not appearing when sorting by rating (#863) * Update assets/css/style.scss Co-Authored-By: Albert Juhé Lluveras <[email protected]> * Pin dependencies (#872) * Update dependency webpack to v4.39.2 (#855) * Update dependency @woocommerce/components to v3.2.0 (#875) * Update Reviews styles so it looks the same in the editor and the frontend (#871) * Update Node.js to v10.16.3 (#874) * Move wc_product_block_data variables to constants file (#870) * Update dependency webpack-cli to v3.3.7 (#880) * Add changelog script (#878) * Add changelog script * Adapt changelog script to WooCommerce Blocks * Minor improvements * Update dependency lint-staged to v9.2.3 (#879) * Pin dependencies (#883) * Update dependency eslint to v6.2.0 (#881) * Reviews by category block (#804) * Create Reviews by Product block * Honor Content settings * Fix wrong className * Load new wc-packages file * Add reviews-by-product JS files to webpack config * Cleanup * Remove error messages * Add Reviews by Product icon * Update sort options * Allow additional CSS classes attribute * Refactor block styles * Fix wrong default for reviews_orderby * Don't enforce CSS chunks * Add reviews count to Reviews by Product controls (#671) * Add label to Reviews by Product controls count (#677) * Add reviews count to Reviews by Product controls * Add label to Reviews by Product controls count * Add label to Reviews by Product controls count * Update components package * Review ordering and placeholders (#688) * Add support for comment_count ordering and add to productcontrol * Add a placeholder if rating count is 0 * Update assets/js/components/utils/index.js Co-Authored-By: Albert Juhé Lluveras <[email protected]> * Update assets/js/blocks/reviews-by-product/block.js Co-Authored-By: Albert Juhé Lluveras <[email protected]> * grammar * Fix some linting errors and warnings (#693) * Create Reviews by Product block placeholder (#691) * Create Reviews by Product block placeholder * Reviews by Product: load and render reviews with JS (#696) * Reviews by Product: load and render reviews with JS * Add dangerouslySetInnerHTML explanatory comment * Fix wrong dependency source * Debounce getReviews call when creating the Reviews by Product block * Rename 'Reviewer Picture' with 'Avatar' (#702) * Lint errors * Replace stringify query with addQueryArgs (#707) * Add reviews endpoint (#705) * Prevent state updates on unmounted components (#715) * Add Order by and Load more controls in Reviews by Product frontend (#716) * Export IconReviewsByProduct (#721) * Fix Reviews by Product layout in IE11 (#723) * Set minimum to per page input field (#731) * Hide avatars in Reviews by Products if 'show_avatars' settings is false (#730) * Blocks API - Reviews endpoint with rating sort and category filtering (#726) * Move file to correct location * We are only using the reviews endpoint not revioews/id * Remove sensistive data and make endpoint public * Allow guest access to approved reviews * Add support for rating sorting * category filtering * update arg name * fix category query * Reviews by Product: add placeholders when loading reviews (#732) * Add placeholder animation (#733) * Hook up Reviews by Product 'Order by' with endpoint (#736) * Hook up Reviews by Product 'Order by' with endpoint * Use onChange instead of onBlur in select control * Reviews by Product: Hide ratings if they are disabled in settings (#740) * Hide ratings in Reviews by Product if disabled in settings * Hide order by select if ratings are disabled * Reviews by Product cleanup (#773) * Fix wrong method name * Reduce the number of dependencies used in Reviews by Product (#774) * Reduce the number of dependencies used in Reviews by Product * Use 'withComponentId' HOC * Remove debounce * Fix wrong proptype * Get rid of JS warning * Load render from react-dom * Add formatted_date_created item schema (#788) * Inital block setup * Fix import of WithComponentID * Render the category reviews * Add new settings to Reviews by Product block (#787) * Add new settings to Reviews by Product block * Remove helpText and add notices * Use RangeControl for numeric settings * Prevent fetching new reviews if all were already fetched * Enable product image in reviews * Remove unnecessary catch * Refactor getReviews * Move getReviews back to block's code * Cleanup * Fix wrong order in editor * Hide 'Load More Reviews' if showLoadMore is false * Move getReviews to utils.js * Add @woocommerce/navigation to package.json * Make notices non-dismissable * Reviews by Product: prevent importing all HOCs and import only withComponentId (#811) * Reviews by product: Update review styling and content (#806) * Add new settings to Reviews by Product block * Remove helpText and add notices * Use RangeControl for numeric settings * Prevent fetching new reviews if all were already fetched * Enable product image in reviews * Remove unnecessary catch * Refactor getReviews * Move getReviews back to block's code * Cleanup * Fix wrong order in editor * Hide 'Load More Reviews' if showLoadMore is false * Move getReviews to utils.js * Add @woocommerce/navigation to package.json * Make notices non-dismissable * Review design/layout * verified icons * Read more component * remove comment * expanded -> isExpanded * Localise and change default elipses * Simplify ReadMore * Support children rather than passing content * remove outside * remove list style * Update assets/js/components/read-more/index.js Co-Authored-By: Albert Juhé Lluveras <[email protected]> * Update assets/js/components/read-more/index.js Co-Authored-By: Albert Juhé Lluveras <[email protected]> * merge set state * Add missing parameter doc in renderReview (#820) * Fix Reviews by Product order by select not honoring default setting (#818) * Read more component - change how clamped content is shown (#821) * Pass review as components * Build summary from content and track both * Toggle display after inital load * remove unused variable * remove componentDidUpdate * Simplify clampLines * Put back componentDidUpdate, but store final summary in state * clampEnabled * Call clampLines from componentDidMount (#826) * truncate html tests * implement trimHTML and pass test * Feedback * test short content * Use withProduct HOC in ReviewsByProductEditor (#828) * Use withProduct HOC * Convert ReviewsByProductEditor to a functional component * Add loading and error states * Prevent loading screen appearing when changing products * Reviews: only save wrapper element to post (#830) * Update based on product reviews * Cleanup after master merge * Implement content hiding and placeholder states for reviews blocks * Output product names and adjust css * Review permalink * Remove old read-more component which was moved * showProductName is already part of passed attributes * CSS tweaks for missing elements * Move dir * Move product reviews block * Move shared uitils * update paths * frontend paths * Update paths * shared attributes * switch to constants * Shared review block code * Replace constants * Fix hidden content bug * star alignment * Update dependency eslint to v6.2.1 (#890) * remove JSON parse * remove comment * No need for important rules * Fix error appearing on Reviews by Product when there were no reviews (#884) * Fix error appearing on Reviews by Product when there were no reviews * Revert "Fix error appearing on Reviews by Product when there were no reviews" This reverts commit 73e95b3. * Move withProduct() HOC to editor-block.js * Revert "Move withProduct() HOC to editor-block.js" This reverts commit ae95157. * Move renderNoReviews back to edit.js * Move no reviews placeholder to its own component * Remove usage of 'RawHTML' * Fix propTypes * Remove unnecessary escapeHTML * revise labels * Move component to base * Add price text * Update design to latest figma * update from master * Fixed merge conflicts with settings * Fix formatting * Update to use react hooks * Progress hooking up price slider * Fixes usage of data store for min/max * Added loading state * Fix useQueryStateByKey setter * Product list integration * Inital state and preventing too many queries * Style fixes * Button loading styles * Package conflict * useCallback * Remove duplication * variable name feedback * Implement useCallback on functions * useMemo for getProgressStyle * Block feedback * Use get_block_asset_build_path * Remove old settings from merge conflict * Move sketch file to .prefixed dir * Removed render methods * Exclude price filter from legacy build * Feedback
1 parent c0c3819 commit 2b5c814

File tree

30 files changed

+1405
-48
lines changed

30 files changed

+1405
-48
lines changed

.sources/handles.sketch

7.57 KB
Binary file not shown.

assets/css/abstracts/_mixins.scss

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@
2828
}
2929

3030
// Adds animation to placeholder section
31-
@mixin placeholder( $lighten-percentage: 30% ) {
32-
animation: loading-fade 1.6s ease-in-out infinite;
33-
background-color: $core-grey-light-500;
31+
@mixin placeholder() {
32+
animation: loading-fade 1.2s ease-in-out infinite;
33+
background-color: $core-grey-light-500 !important;
3434
color: transparent;
35+
border: 0;
36+
box-shadow: none;
3537

3638
&::after {
3739
content: "\00a0";
Lines changed: 366 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,366 @@
1+
/**
2+
* External dependencies
3+
*/
4+
import { __ } from '@wordpress/i18n';
5+
import {
6+
Fragment,
7+
useState,
8+
useEffect,
9+
useCallback,
10+
useMemo,
11+
useRef,
12+
} from '@wordpress/element';
13+
import PropTypes from 'prop-types';
14+
import classnames from 'classnames';
15+
import { useDebounce } from '@woocommerce/base-hooks';
16+
17+
/**
18+
* Internal dependencies
19+
*/
20+
import './style.scss';
21+
import { constrainRangeSliderValues, formatCurrencyForInput } from './utils';
22+
import SubmitButton from './submit-button';
23+
import PriceLabel from './price-label';
24+
import PriceInput from './price-input';
25+
26+
const PriceSlider = ( {
27+
initialMin,
28+
initialMax,
29+
minConstraint,
30+
maxConstraint,
31+
onChange,
32+
step,
33+
currencySymbol,
34+
priceFormat,
35+
showInputFields,
36+
showFilterButton,
37+
isLoading,
38+
} ) => {
39+
const minRange = useRef();
40+
const maxRange = useRef();
41+
const [ minPrice, setMinPrice ] = useState( initialMin );
42+
const [ maxPrice, setMaxPrice ] = useState( initialMax );
43+
const [ formattedMinPrice, setFormattedMinPrice ] = useState(
44+
formatCurrencyForInput( minPrice, priceFormat, currencySymbol )
45+
);
46+
const [ formattedMaxPrice, setFormattedMaxPrice ] = useState(
47+
formatCurrencyForInput( maxPrice, priceFormat, currencySymbol )
48+
);
49+
const debouncedChangeValue = useDebounce( [ minPrice, maxPrice ], 500 );
50+
51+
useEffect( () => {
52+
if ( minPrice === undefined || minConstraint > minPrice ) {
53+
setMinPrice( minConstraint );
54+
}
55+
}, [ minConstraint ] );
56+
57+
useEffect( () => {
58+
if ( maxPrice === undefined || maxConstraint < maxPrice ) {
59+
setMaxPrice( maxConstraint );
60+
}
61+
}, [ maxConstraint ] );
62+
63+
useEffect( () => {
64+
setFormattedMinPrice(
65+
formatCurrencyForInput( minPrice, priceFormat, currencySymbol )
66+
);
67+
}, [ minPrice, priceFormat, currencySymbol ] );
68+
69+
useEffect( () => {
70+
setFormattedMaxPrice(
71+
formatCurrencyForInput( maxPrice, priceFormat, currencySymbol )
72+
);
73+
}, [ maxPrice, priceFormat, currencySymbol ] );
74+
75+
useEffect( () => {
76+
if ( ! showFilterButton && ! isLoading ) {
77+
triggerChange();
78+
}
79+
}, [ debouncedChangeValue ] );
80+
81+
/**
82+
* Handles styles for the shaded area of the range slider.
83+
*/
84+
const getProgressStyle = useMemo( () => {
85+
const low =
86+
Math.round(
87+
100 *
88+
( ( minPrice - minConstraint ) /
89+
( maxConstraint - minConstraint ) )
90+
) - 0.5;
91+
const high =
92+
Math.round(
93+
100 *
94+
( ( maxPrice - minConstraint ) /
95+
( maxConstraint - minConstraint ) )
96+
) + 0.5;
97+
98+
return {
99+
'--low': low + '%',
100+
'--high': high + '%',
101+
};
102+
}, [ minPrice, minConstraint, maxPrice, maxConstraint ] );
103+
104+
/**
105+
* Trigger the onChange prop callback with new values.
106+
*/
107+
const triggerChange = useCallback( () => {
108+
onChange( [ minPrice, maxPrice ] );
109+
}, [ minPrice, maxPrice ] );
110+
111+
/**
112+
* Works around an IE issue where only one range selector is visible by changing the display order
113+
* based on the mouse position.
114+
*
115+
* @param {obj} event event data.
116+
*/
117+
const findClosestRange = useCallback(
118+
( event ) => {
119+
if ( isLoading ) {
120+
return;
121+
}
122+
const bounds = event.target.getBoundingClientRect();
123+
const x = event.clientX - bounds.left;
124+
const minWidth = minRange.current.offsetWidth;
125+
const minValue = minRange.current.value;
126+
const maxWidth = maxRange.current.offsetWidth;
127+
const maxValue = maxRange.current.value;
128+
129+
const minX = minWidth * ( minValue / maxConstraint );
130+
const maxX = maxWidth * ( maxValue / maxConstraint );
131+
132+
const minXDiff = Math.abs( x - minX );
133+
const maxXDiff = Math.abs( x - maxX );
134+
135+
/**
136+
* The default z-index in the stylesheet as 20. 20 vs 21 is just for determining which range
137+
* slider should be at the front and has no meaning beyond
138+
*/
139+
if ( minXDiff > maxXDiff ) {
140+
minRange.current.style.zIndex = 20;
141+
maxRange.current.style.zIndex = 21;
142+
} else {
143+
minRange.current.style.zIndex = 21;
144+
maxRange.current.style.zIndex = 20;
145+
}
146+
},
147+
[ isLoading, maxConstraint ]
148+
);
149+
150+
/**
151+
* Called when the slider is dragged.
152+
* @param {obj} event Event object.
153+
*/
154+
const rangeInputOnChange = useCallback(
155+
( event ) => {
156+
const isMin = event.target.classList.contains(
157+
'wc-block-price-filter__range-input--min'
158+
);
159+
const targetValue = event.target.value;
160+
const currentValues = isMin
161+
? [ targetValue, maxPrice ]
162+
: [ minPrice, targetValue ];
163+
const values = constrainRangeSliderValues(
164+
currentValues,
165+
minConstraint,
166+
maxConstraint,
167+
step,
168+
isMin
169+
);
170+
setMinPrice( parseInt( values[ 0 ], 10 ) );
171+
setMaxPrice( parseInt( values[ 1 ], 10 ) );
172+
},
173+
[ minPrice, maxPrice, minConstraint, maxConstraint, step ]
174+
);
175+
176+
/**
177+
* Called when a price input loses focus - commit changes to slider.
178+
* @param {obj} event Event object.
179+
*/
180+
const priceInputOnBlur = useCallback(
181+
( event ) => {
182+
const isMin = event.target.classList.contains(
183+
'wc-block-price-filter__amount--min'
184+
);
185+
const targetValue = event.target.value.replace( /[^0-9.-]+/g, '' );
186+
const currentValues = isMin
187+
? [ targetValue, maxPrice ]
188+
: [ minPrice, targetValue ];
189+
const values = constrainRangeSliderValues(
190+
currentValues,
191+
minConstraint,
192+
maxConstraint,
193+
step,
194+
isMin
195+
);
196+
setMinPrice( parseInt( values[ 0 ], 10 ) );
197+
setMaxPrice( parseInt( values[ 1 ], 10 ) );
198+
},
199+
[ minPrice, maxPrice, minConstraint, maxConstraint, step ]
200+
);
201+
202+
/**
203+
* Called when a price input is typed in - store value but don't update slider.
204+
* @param {obj} event Event object.
205+
*/
206+
const priceInputOnChange = useCallback(
207+
( event ) => {
208+
const newValue = event.target.value.replace( /[^0-9.-]+/g, '' );
209+
const isMin = event.target.classList.contains(
210+
'wc-block-price-filter__amount--min'
211+
);
212+
if ( isMin ) {
213+
setFormattedMinPrice(
214+
formatCurrencyForInput(
215+
newValue,
216+
priceFormat,
217+
currencySymbol
218+
)
219+
);
220+
} else {
221+
setFormattedMaxPrice(
222+
formatCurrencyForInput(
223+
newValue,
224+
priceFormat,
225+
currencySymbol
226+
)
227+
);
228+
}
229+
},
230+
[ priceFormat, currencySymbol ]
231+
);
232+
233+
const classes = classnames(
234+
'wc-block-price-filter',
235+
showInputFields && 'wc-block-price-filter--has-input-fields',
236+
showFilterButton && 'wc-block-price-filter--has-filter-button',
237+
isLoading && 'is-loading'
238+
);
239+
240+
return (
241+
<div className={ classes }>
242+
<div
243+
className="wc-block-price-filter__range-input-wrapper"
244+
onMouseMove={ findClosestRange }
245+
onFocus={ findClosestRange }
246+
>
247+
{ ! isLoading && (
248+
<Fragment>
249+
<div
250+
className="wc-block-price-filter__range-input-progress"
251+
style={ getProgressStyle }
252+
/>
253+
<input
254+
type="range"
255+
className="wc-block-price-filter__range-input wc-block-price-filter__range-input--min"
256+
aria-label={ __(
257+
'Filter products by minimum price',
258+
'woo-gutenberg-products-block'
259+
) }
260+
value={ minPrice || 0 }
261+
onChange={ rangeInputOnChange }
262+
step={ step }
263+
min={ minConstraint }
264+
max={ maxConstraint }
265+
ref={ minRange }
266+
/>
267+
<input
268+
type="range"
269+
className="wc-block-price-filter__range-input wc-block-price-filter__range-input--max"
270+
aria-label={ __(
271+
'Filter products by maximum price',
272+
'woo-gutenberg-products-block'
273+
) }
274+
value={ maxPrice || 0 }
275+
onChange={ rangeInputOnChange }
276+
step={ step }
277+
min={ minConstraint }
278+
max={ maxConstraint }
279+
ref={ maxRange }
280+
/>
281+
</Fragment>
282+
) }
283+
</div>
284+
<div className="wc-block-price-filter__controls">
285+
{ showInputFields ? (
286+
<PriceInput
287+
disabled={ isLoading }
288+
onChange={ priceInputOnChange }
289+
onBlur={ priceInputOnBlur }
290+
minPrice={ formattedMinPrice }
291+
maxPrice={ formattedMaxPrice }
292+
/>
293+
) : (
294+
<PriceLabel
295+
minPrice={ formattedMinPrice }
296+
maxPrice={ formattedMaxPrice }
297+
/>
298+
) }
299+
{ showFilterButton && (
300+
<SubmitButton
301+
disabled={ isLoading }
302+
onClick={ triggerChange }
303+
/>
304+
) }
305+
</div>
306+
</div>
307+
);
308+
};
309+
310+
PriceSlider.propTypes = {
311+
/**
312+
* Callback fired when prices changes.
313+
*/
314+
onChange: PropTypes.func.isRequired,
315+
/**
316+
* Initial min value.
317+
*/
318+
initialMin: PropTypes.number,
319+
/**
320+
* Initial max value.
321+
*/
322+
initialMax: PropTypes.number,
323+
/**
324+
* Minimum allowed price.
325+
*/
326+
minConstraint: PropTypes.number,
327+
/**
328+
* Maximum allowed price.
329+
*/
330+
maxConstraint: PropTypes.number,
331+
/**
332+
* Step for slider inputs.
333+
*/
334+
step: PropTypes.number,
335+
/**
336+
* Currency symbol to use when formatting prices for display.
337+
*/
338+
currencySymbol: PropTypes.string,
339+
/**
340+
* Price format to use when formatting prices for display.
341+
*/
342+
priceFormat: PropTypes.string,
343+
/**
344+
* Whether or not to show input fields above the slider.
345+
*/
346+
showInputFields: PropTypes.bool,
347+
/**
348+
* Whether or not to show filter button above the slider.
349+
*/
350+
showFilterButton: PropTypes.bool,
351+
/**
352+
* Whether or not to show filter button above the slider.
353+
*/
354+
isLoading: PropTypes.bool,
355+
};
356+
357+
PriceSlider.defaultProps = {
358+
step: 1,
359+
currencySymbol: '$',
360+
priceFormat: '%1$s%2$s',
361+
showInputFields: true,
362+
showFilterButton: false,
363+
isLoading: false,
364+
};
365+
366+
export default PriceSlider;

0 commit comments

Comments
 (0)