Skip to content

Commit f12c3c9

Browse files
committed
add sort by
1 parent db8af2f commit f12c3c9

File tree

3 files changed

+68
-2
lines changed

3 files changed

+68
-2
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import React, { Component } from 'react';
2+
import Down from 'react-icons/lib/md/expand-more';
3+
import Up from 'react-icons/lib/md/expand-less';
4+
import { SortBy } from 'react-instantsearch-dom';
5+
6+
import { Container, Title, Button } from './elements';
7+
8+
class Filter extends Component {
9+
state = { open: false };
10+
11+
toggle = () => this.setState(({ open }) => ({ open: !open }));
12+
render() {
13+
const { title, defaultRefinement, items } = this.props;
14+
const { open } = this.state;
15+
return (
16+
<Container open={open}>
17+
<Title>
18+
<span>{title}</span>
19+
<Button onClick={this.toggle}>{open ? <Up /> : <Down />}</Button>
20+
</Title>
21+
<SortBy defaultRefinement={defaultRefinement} items={items} />
22+
</Container>
23+
);
24+
}
25+
}
26+
export default Filter;

packages/app/src/app/pages/Search/Filters/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
import React from 'react';
22
import getTemplate from 'common/lib/templates';
3+
import { ALGOLIA_DEFAULT_INDEX } from 'common/lib/utils/config';
34

45
import Filter from './Filter';
6+
import Sort from './Filter/Sort';
57
import { Container } from './elements';
68

79
function Filters() {
810
return (
911
<Container>
12+
<Sort
13+
title="Sort By"
14+
items={[
15+
{ value: ALGOLIA_DEFAULT_INDEX, label: 'Relevance' },
16+
{ value: `${ALGOLIA_DEFAULT_INDEX}_views`, label: 'Views' },
17+
{ value: `${ALGOLIA_DEFAULT_INDEX}_likes`, label: 'Likes' },
18+
]}
19+
defaultRefinement={ALGOLIA_DEFAULT_INDEX}
20+
/>
1021
<Filter
1122
title="Templates"
1223
operator="or"

packages/app/src/app/pages/Search/search.css

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
box-sizing: border-box;
1818
font-size: 1.125em;
1919
font-weight: 500;
20-
2120
width: 100%;
2221
}
2322

@@ -47,20 +46,24 @@
4746
padding-left: 4px;
4847
padding-bottom: 2px;
4948
}
49+
5050
.ais-SearchBox-submit::before {
5151
display: inline-block;
5252
margin-right: -4px;
5353
height: 100%;
5454
vertical-align: middle;
5555
content: '' 2;
5656
}
57+
5758
.ais-SearchBox-submit:hover,
5859
.ais-SearchBox-submit:active {
5960
cursor: pointer;
6061
}
62+
6163
.ais-SearchBox-submit:focus {
6264
outline: 0;
6365
}
66+
6467
.ais-SearchBox-submit svg {
6568
margin: 6px;
6669
width: 14px;
@@ -86,9 +89,11 @@
8689
user-select: none;
8790
fill: rgba(255, 255, 255, 0.5);
8891
}
92+
8993
.ais-SearchBox-reset:focus {
9094
outline: 0;
9195
}
96+
9297
.ais-SearchBox-reset svg {
9398
display: block;
9499
margin: 6px;
@@ -131,6 +136,7 @@
131136
color: rgba(255, 255, 255, 0.8);
132137
margin-top: 6px;
133138
}
139+
134140
.ais-RefinementList-item .ais-RefinementList-checkbox {
135141
display: inline-block;
136142
border-radius: 3.5px;
@@ -145,13 +151,15 @@
145151
-webkit-transition: all 0.15s ease;
146152
transition: all 0.15s ease;
147153
}
154+
148155
.ais-RefinementList-item input[type='checkbox']:checked {
149156
background: #40a9f3
150157
url("data:image/svg+xml;utf8,<svg viewBox='0 0 10 9' xmlns='http://www.w3.org/2000/svg'><path d='M1 4.88l2.378 2.435L9.046 1.6' stroke-width='1.6' stroke='%23FFF' fill='none' fill-rule='evenodd' stroke-linecap='round' stroke-linejoin='round'/></svg>")
151158
no-repeat 50%/10px;
152159
border-color: #40a9f3;
153160
box-shadow: none;
154161
}
162+
155163
.ais-RefinementList-item:hover .ais-RefinementList-checkbox {
156164
box-shadow: inset 0 0 0 1px rgba(108, 174, 221, 0.3);
157165
}
@@ -192,7 +200,6 @@
192200
padding: 0;
193201
margin: 0;
194202
color: rgba(255, 255, 255, 0.8);
195-
196203
margin-top: 1rem;
197204
}
198205

@@ -263,6 +270,7 @@
263270
text-align: center;
264271
font-size: 14px;
265272
}
273+
266274
.ais-Pagination-item:hover {
267275
background: rgba(108, 174, 221, 0.2);
268276
}
@@ -284,6 +292,7 @@
284292
color: #fff;
285293
background: rgba(108, 174, 221, 1);
286294
}
295+
287296
.ais-Pagination-item--selected .ais-Pagination-link {
288297
color: currentColor;
289298
font-weight: normal;
@@ -293,6 +302,7 @@
293302
visibility: visible;
294303
color: #bbbbbb;
295304
}
305+
296306
.ais-Pagination-item--disabled[disabled],
297307
.ais-Pagination-item--disabled:disabled {
298308
opacity: 0.5;
@@ -321,3 +331,22 @@
321331
-webkit-appearance: none;
322332
outline-offset: -2px;
323333
}
334+
335+
.ais-SortBy-select {
336+
transition: 0.3s ease border-color;
337+
background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciICB2aWV3Qm94PSIwIDAgNC45NSAxMCI+PHBhdGggZmlsbD0id2hpdGUiIGQ9Ik0xLjQxIDQuNjdsMS4wNy0xLjQ5IDEuMDYgMS40OUgxLjQxek0zLjU0IDUuMzNMMi40OCA2LjgyIDEuNDEgNS4zM2gyLjEzeiI+PC9wYXRoPjwvc3ZnPg==);
338+
background-color: rgba(0, 0, 0, 0.3);
339+
background-position: right;
340+
background-repeat: no-repeat;
341+
width: 100%;
342+
color: white;
343+
border: none;
344+
outline: none;
345+
border-radius: 4px;
346+
padding: 0.2em 1em 0.2em 0.2em;
347+
box-sizing: border-box;
348+
font-weight: 400;
349+
height: 1.75em;
350+
appearance: none;
351+
border: 1px solid rgba(0, 0, 0, 0.1);
352+
}

0 commit comments

Comments
 (0)