summaryrefslogtreecommitdiff
path: root/saleor/static/js/components/categoryPage/SortBy.js
blob: 9e000656f93a5b934d33464a0bfeccbea15c9d5c (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import React, { Component, PropTypes } from 'react';
import InlineSVG from 'react-inlinesvg';

import arrowUpIcon from '../../../images/arrow_up.svg';
import arrowDownIcon from '../../../images/arrow_down.svg';

export default class sortBy extends Component {

  constructor(props) {
    super(props);
    this.state = {
      visibility: false
    };
  }

  static propTypes = {
    setSorting: PropTypes.func,
    sortedValue: PropTypes.string
  }

  setSorting = (event) => {
    const value = event.currentTarget.className;
    this.props.setSorting(value);
    this.changeVisibility();
  }

  changeVisibility = () => {
    this.setState({
      visibility: !this.state.visibility
    });
  }

  render() {
    const { sortedValue } = this.props;
    const { visibility } = this.state;
    return (
      <div className="sort-by">
        <div className={visibility ? ('click-area') : ('click-area hide')} onClick={this.changeVisibility}></div>
        <button className="btn btn-link" onClick={this.changeVisibility}>
          {sortedValue ? (
            sortedValue.search('-') ? (
              <div>
                <span>{pgettext('Category page filters','Sort by:')} <strong>{sortedValue}</strong></span>
                <div className="sort-order-icon">
                  <InlineSVG key="arrowUpIcon" src={arrowUpIcon} />
                </div>
              </div>
            ) : (
               <div>
                <span>{pgettext('Category page filters', 'Sort by:')} <strong>{sortedValue.replace('-', '')}</strong></span>
                <div className="sort-order-icon">
                  <InlineSVG key="arrowDownIcon" src={arrowDownIcon} />
                </div>
              </div>
            )
          ) : (
            <span>{pgettext('Category page filters', 'Sort by:')} <strong>{pgettext('Category page filters', 'default')}</strong></span>
          )}
        </button>
        {visibility && (
          <ul className="sort-list">
            <li className="name">
              <div className="row">
                <div className="col-6">{pgettext('Category page filters', 'Sort by:')} <strong>{gettext('Name')}</strong></div>
                <div className="col-6">
                    <div className="name" onClick={this.setSorting}>
                      <span>{pgettext('Category page filters', 'ascending')}</span>
                      <div className="float-right sort-order-icon">
                        <InlineSVG src={arrowUpIcon} />
                      </div>
                    </div>
                </div>
              </div>
              <div className="row">
                <div className="col-6"></div>
                <div className="col-6">
                    <div className="-name" onClick={this.setSorting}>
                      <span>{pgettext('Category page filters', 'descending')}</span>
                      <div className="float-right sort-order-icon">
                        <InlineSVG src={arrowDownIcon} />
                      </div>
                    </div>
                </div>
              </div>
            </li>
            <li className="price">
              <div className="row">
                <div className="col-6">{pgettext('Category page filters', 'Sort by:')} <strong>{pgettext('Category page filters', 'Price')}</strong></div>
                <div className="col-6">
                    <div className="price" onClick={this.setSorting}>
                      <span>{pgettext('Category page filters', 'ascending')}</span>
                      <div className="float-right sort-order-icon">
                        <InlineSVG src={arrowUpIcon} />
                      </div>
                    </div>
                </div>
              </div>
              <div className="row">
                <div className="col-6"></div>
                <div className="col-6">
                    <div className="-price" onClick={this.setSorting}>
                      <span>{pgettext('Category page filters', 'descending')}</span>
                      <div className="float-right sort-order-icon">
                        <InlineSVG src={arrowDownIcon} />
                      </div>
                    </div>
                </div>
              </div>
            </li>
          </ul>
        )}
      </div>
    );
  }
}