Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Fix filters styles and visibility

Krzysztof Białogłowicz64746a8bd73d
diff --git a/saleor/static/js/components/PriceFilter.js b/saleor/static/js/components/PriceFilter.js
index f7c9bd8f92..ec6c6727f9 100644
--- a/saleor/static/js/components/PriceFilter.js
+++ b/saleor/static/js/components/PriceFilter.js
@@ -2,6 +2,13 @@ import React, { Component, PropTypes } from 'react';
export default class PriceFilter extends Component {
+ constructor(props) {
+ super(props);
+ this.state = {
+ visibility: true
+ };
+ }
+
static propTypes = {
minPrice: PropTypes.number,
maxPrice: PropTypes.number,
@@ -12,7 +19,7 @@ export default class PriceFilter extends Component {
if (event.key === 'Enter') {
this.updateFilter();
}
- };
+ }
updateFilter = () => {
const minPrice = this.minPriceInput.value;
@@ -20,31 +27,45 @@ export default class PriceFilter extends Component {
this.props.onFilterChanged(minPrice, maxPrice);
}
+ changeVisibility = () => {
+ this.setState({
+ visibility: !this.state.visibility
+ });
+ }
+
render() {
const { maxPrice, minPrice } = this.props;
+ const { visibility } = this.state;
return (
<div className="price-range">
- <h3>Price range</h3>
- <input
- className="form-control"
- defaultValue={minPrice}
- min="0"
- onKeyUp={this.checkKey}
- placeholder="min"
- ref={input => this.minPriceInput = input}
- type="number"
- />
- <span>&#8212;</span>
- <input
- className="form-control"
- defaultValue={maxPrice}
- min="0"
- onKeyUp={this.checkKey}
- placeholder="max"
- ref={input => this.maxPriceInput = input}
- type="number"
- />
- <button className="btn" onClick={this.updateFilter}>Update</button>
+ <h3>
+ Price range
+ <i className={visibility ? ('fa fa-chevron-up pull-right') : ('fa fa-chevron-down pull-right')} aria-hidden="true" onClick={this.changeVisibility}></i>
+ </h3>
+ {visibility ? (
+ <div>
+ <input
+ className="form-control"
+ defaultValue={minPrice}
+ min="0"
+ onKeyUp={this.checkKey}
+ placeholder="min"
+ ref={input => this.minPriceInput = input}
+ type="number"
+ />
+ <span>&#8212;</span>
+ <input
+ className="form-control"
+ defaultValue={maxPrice}
+ min="0"
+ onKeyUp={this.checkKey}
+ placeholder="max"
+ ref={input => this.maxPriceInput = input}
+ type="number"
+ />
+ <button className="btn" onClick={this.updateFilter}>Update</button>
+ </div>
+ ) : (null)}
</div>
);
}
diff --git a/saleor/static/js/components/ProductFilters.js b/saleor/static/js/components/ProductFilters.js
index 7269a0c0f9..6d3b28e7a0 100644
--- a/saleor/static/js/components/ProductFilters.js
+++ b/saleor/static/js/components/ProductFilters.js
@@ -6,11 +6,18 @@ import AttributeInput from './AttributeInput';
class ProductFilters extends Component {
+ constructor(props) {
+ super(props);
+ this.state = {
+ visibility: {}
+ };
+ }
+
static propTypes = {
attributes: PropTypes.array,
checkedAttributes: PropTypes.array,
onFilterChanged: PropTypes.func.isRequired
- };
+ }
getFilterKey(attributeName, valueSlug) {
return `${attributeName}:${valueSlug}`;
@@ -18,17 +25,37 @@ class ProductFilters extends Component {
onClick = (attributeName, valueSlug) => {
this.props.onFilterChanged(this.getFilterKey(attributeName, valueSlug));
- };
+ }
+
+ changeVisibility = (target) => {
+ this.setState({
+ visibility: Object.assign(this.state.visibility, {[target] : !this.state.visibility[target]})
+ });
+ }
+
+ componentWillMount() {
+ this.props.attributes.map((attribute) => {
+ const attrValue = `${attribute.name}`;
+ this.setState({
+ visibility: Object.assign(this.state.visibility, {[attrValue] : true})
+ });
+ })
+ }
render() {
const { attributes, checkedAttributes } = this.props;
+ const { visibility } = this.state;
return (
<div className="attributes">
{attributes && (attributes.map((attribute) => {
return (
- <div key={attribute.id} className={attribute.name}>
- <ul>
- <h3>{attribute.display}</h3>
+ <div key={attribute.id}>
+ <h3 className={attribute.name}>
+ {attribute.display}
+ <i className={visibility[attribute.name] ? ('fa fa-chevron-up pull-right') : ('fa fa-chevron-down pull-right')} aria-hidden="true" onClick={() => this.changeVisibility(attribute.name)}></i>
+ </h3>
+ {visibility[attribute.name] ? (
+ <ul id={attribute.name}>
{attribute.values.map((value) => {
const key = this.getFilterKey(attribute.name, value.slug);
return (
@@ -43,6 +70,7 @@ class ProductFilters extends Component {
);
})}
</ul>
+ ) : (null)}
</div>
);
}))}
diff --git a/saleor/static/scss/demo/components/_category-page.scss b/saleor/static/scss/demo/components/_category-page.scss
index 1d57871acf..02cd2fda21 100644
--- a/saleor/static/scss/demo/components/_category-page.scss
+++ b/saleor/static/scss/demo/components/_category-page.scss
@@ -1,16 +1,29 @@
#category-page {
h2 {
+ font-size: 1rem;
+ color: $gray;
font-weight: bold;
- padding-bottom: $global-padding;
+ padding-bottom: $global-padding/2;
}
.product-filters {
+ .hide {
+ display: none;
+ }
h3 {
- padding-bottom: $global-padding;
+ background: $light-gray;
+ padding: $global-padding;
+ font-size: 1rem;
+ font-weight: bold;
+ i {
+ cursor: pointer;
+ }
}
ul {
padding: $global-padding/2 0;
list-style: none;
+ margin-bottom: 0;
li {
+ padding-left: $global-padding;
input {
margin-right: $global-margin;
}
@@ -27,6 +40,12 @@
}
}
.price-range {
+ h3 {
+ margin-bottom: $global-margin;
+ span {
+ margin: 0;
+ }
+ }
input {
width: 7.6rem;
display: inline-block;