blob: c907c8b29cce2fc4ef3d820f01ad93c39831af96 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
import React, { Component, PropTypes } from 'react';
import FilterHeader from './FilterHeader';
import {isMobile} from '../utils';
export default class PriceFilter extends Component {
constructor(props) {
super(props);
this.state = {
visibility: !isMobile()
};
}
static propTypes = {
minPrice: PropTypes.number,
maxPrice: PropTypes.number,
onFilterChanged: PropTypes.func.isRequired
}
checkKey = (event) => {
if (event.key === 'Enter') {
this.updateFilter();
}
}
updateFilter = () => {
const minPrice = this.minPriceInput.value;
const maxPrice = this.maxPriceInput.value;
this.props.onFilterChanged(minPrice, maxPrice);
}
changeVisibility = () => {
const { minPrice, maxPrice } = this.props;
if (!(minPrice || maxPrice)) {
this.setState({
visibility: !this.state.visibility
});
}
}
render() {
const { maxPrice, minPrice } = this.props;
const { visibility } = this.state;
return (
<div className="product-filters__price-range">
<FilterHeader
onClick={this.changeVisibility}
title={pgettext('Price filter on category page', 'Price range')}
visibility={visibility}
/>
{(visibility || minPrice || maxPrice) && (
<div>
<input
className="form-control"
defaultValue={minPrice}
min="0"
onKeyUp={this.checkKey}
placeholder={pgettext('Price filter on category page', 'from')}
ref={input => (this.minPriceInput = input)}
type="number"
/>
<span>—</span>
<input
className="form-control"
defaultValue={maxPrice}
min="0"
onKeyUp={this.checkKey}
placeholder={pgettext('Price filter on category page', 'to')}
ref={input => (this.maxPriceInput = input)}
type="number"
/>
<button className="btn primary" onClick={this.updateFilter}>{pgettext('Price filter on category page', 'Update')}</button>
</div>
)}
</div>
);
}
}
|