-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(React InstantSearch Hooks): introduce range slider example with …
…React Spectrum (#457)
- Loading branch information
1 parent
b00fb98
commit 0db12f3
Showing
12 changed files
with
11,436 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
react-instantsearch-hooks/range-slider-with-react-spectrum/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* |
21 changes: 21 additions & 0 deletions
21
react-instantsearch-hooks/range-slider-with-react-spectrum/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# range-slider-with-react-spectrum | ||
|
||
_This project was generated with [create-instantsearch-app](https://github.com/algolia/create-instantsearch-app) by [Algolia](https://algolia.com)._ | ||
|
||
## Get started | ||
|
||
To run this project locally, install the dependencies and run the local server: | ||
|
||
```sh | ||
npm install | ||
npm start | ||
``` | ||
|
||
Alternatively, you may use [Yarn](https://http://yarnpkg.com/): | ||
|
||
```sh | ||
yarn | ||
yarn start | ||
``` | ||
|
||
Open http://localhost:3000 to see your app. |
36 changes: 36 additions & 0 deletions
36
react-instantsearch-hooks/range-slider-with-react-spectrum/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"name": "range-slider-with-react-spectrum", | ||
"version": "0.1.0", | ||
"private": true, | ||
"dependencies": { | ||
"@adobe/react-spectrum": "3.28.0", | ||
"algoliasearch": "^4.13.0", | ||
"instantsearch.css": "^7.4.5", | ||
"react": "^18.1.0", | ||
"react-dom": "^18.1.0", | ||
"react-instantsearch-hooks-web": "6.43.0", | ||
"react-scripts": "5.0.1" | ||
}, | ||
"scripts": { | ||
"start": "react-scripts start", | ||
"build": "react-scripts build" | ||
}, | ||
"eslintConfig": { | ||
"extends": [ | ||
"react-app", | ||
"react-app/jest" | ||
] | ||
}, | ||
"browserslist": { | ||
"production": [ | ||
">0.2%", | ||
"not dead", | ||
"not op_mini all" | ||
], | ||
"development": [ | ||
"last 1 chrome version", | ||
"last 1 firefox version", | ||
"last 1 safari version" | ||
] | ||
} | ||
} |
Binary file added
BIN
+1.88 KB
react-instantsearch-hooks/range-slider-with-react-spectrum/public/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions
28
react-instantsearch-hooks/range-slider-with-react-spectrum/public/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | ||
<meta name="theme-color" content="#000000"> | ||
|
||
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.png"> | ||
|
||
<!-- | ||
Do not use @7 in production, use a complete version like x.x.x, see website for latest version: | ||
https://community.algolia.com/react-instantsearch/Getting_started.html#load-the-algolia-theme | ||
--> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/instantsearch.css@7/themes/algolia-min.css"> | ||
|
||
<title>range-slider-with-react-spectrum</title> | ||
</head> | ||
|
||
<body> | ||
<noscript> | ||
You need to enable JavaScript to run this app. | ||
</noscript> | ||
|
||
<div id="root"></div> | ||
</body> | ||
|
||
</html> |
65 changes: 65 additions & 0 deletions
65
react-instantsearch-hooks/range-slider-with-react-spectrum/src/App.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
em { | ||
background: cyan; | ||
font-style: normal; | ||
} | ||
|
||
.header { | ||
display: flex; | ||
align-items: center; | ||
min-height: 50px; | ||
padding: 0.5rem 1rem; | ||
background-image: linear-gradient(to right, #8e43e7, #00aeff); | ||
color: #fff; | ||
margin-bottom: 1rem; | ||
} | ||
|
||
.header a { | ||
color: #fff; | ||
text-decoration: none; | ||
} | ||
|
||
.header-title { | ||
font-size: 1.2rem; | ||
font-weight: normal; | ||
} | ||
|
||
.header-title::after { | ||
content: ' ▸ '; | ||
padding: 0 0.5rem; | ||
} | ||
|
||
.header-subtitle { | ||
font-size: 1.2rem; | ||
} | ||
|
||
.container { | ||
max-width: 1200px; | ||
margin: 0 auto; | ||
padding: 1rem; | ||
} | ||
|
||
.search-panel { | ||
display: flex; | ||
} | ||
|
||
.search-panel__filters { | ||
flex: 1; | ||
margin-right: 2rem; | ||
} | ||
|
||
.search-panel__results { | ||
flex: 3; | ||
} | ||
|
||
.searchbox { | ||
margin-bottom: 2rem; | ||
} | ||
|
||
.pagination { | ||
margin: 2rem auto; | ||
text-align: center; | ||
} | ||
|
||
.ais-RefinementList { | ||
margin-bottom: 2rem; | ||
} |
47 changes: 47 additions & 0 deletions
47
react-instantsearch-hooks/range-slider-with-react-spectrum/src/App.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { | ||
Hits, | ||
InstantSearch, | ||
Pagination, | ||
RefinementList, | ||
SearchBox, | ||
} from 'react-instantsearch-hooks-web'; | ||
import algoliasearch from 'algoliasearch/lite'; | ||
|
||
import { RangeSlider } from './RangeSlider'; | ||
|
||
import './App.css'; | ||
|
||
const searchClient = algoliasearch( | ||
'B1G2GM9NG0', | ||
'aadef574be1f9252bb48d4ea09b5cfe5' | ||
); | ||
|
||
function App() { | ||
return ( | ||
<div className="container"> | ||
<InstantSearch | ||
searchClient={searchClient} | ||
indexName="demo_ecommerce" | ||
insights={true} | ||
> | ||
<div className="search-panel"> | ||
<div className="search-panel__filters"> | ||
<RefinementList attribute="brand" /> | ||
<RangeSlider attribute="price" /> | ||
</div> | ||
|
||
<div className="search-panel__results"> | ||
<SearchBox className="searchbox" placeholder="Search" /> | ||
<Hits /> | ||
|
||
<div className="pagination"> | ||
<Pagination /> | ||
</div> | ||
</div> | ||
</div> | ||
</InstantSearch> | ||
</div> | ||
); | ||
} | ||
|
||
export default App; |
37 changes: 37 additions & 0 deletions
37
react-instantsearch-hooks/range-slider-with-react-spectrum/src/RangeSlider.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
[class^='spectrum-Slider_'] { | ||
width: 100% !important; | ||
} | ||
|
||
[class^='spectrum-Slider-labelContainer'] { | ||
margin-bottom: 1rem; | ||
} | ||
|
||
[class^='spectrum-Slider-value'] { | ||
width: auto !important; | ||
min-width: 0 !important; | ||
} | ||
|
||
[class^='spectrum-Slider-track'] { | ||
background-color: #dfe2ee; | ||
height: 3px; | ||
border-radius: 9999px; | ||
} | ||
|
||
[class^='spectrum-Slider-track']:last-of-type { | ||
right: 0; | ||
} | ||
|
||
[class^='spectrum-Slider-track']:nth-of-type(3) { | ||
background-color: #3a4570; | ||
} | ||
|
||
[class^='spectrum-Slider-handle'] { | ||
display: block; | ||
width: 20px; | ||
height: 20px; | ||
margin-top: 1px; | ||
background-color: #fff; | ||
border: 1px solid #c4c8d8; | ||
box-shadow: 0 2px 5px 0 #e3e5ec; | ||
border-radius: 9999px; | ||
} |
30 changes: 30 additions & 0 deletions
30
react-instantsearch-hooks/range-slider-with-react-spectrum/src/RangeSlider.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { useRange } from 'react-instantsearch-hooks-web'; | ||
import { RangeSlider as SpectrumRangeSlider } from '@adobe/react-spectrum'; | ||
|
||
import './RangeSlider.css'; | ||
|
||
export function RangeSlider(props) { | ||
const { start, range, canRefine, refine } = useRange(props); | ||
const { min, max } = range; | ||
const [value, setValue] = useState({ start: min, end: max }); | ||
|
||
const from = Math.max(min, Number.isFinite(start[0]) ? start[0] : min); | ||
const to = Math.min(max, Number.isFinite(start[1]) ? start[1] : max); | ||
|
||
useEffect(() => { | ||
setValue({ start: from, end: to }); | ||
}, [from, to]); | ||
|
||
return ( | ||
<SpectrumRangeSlider | ||
label="Price range" | ||
minValue={min} | ||
maxValue={max} | ||
value={value} | ||
onChange={setValue} | ||
onChangeEnd={({ start, end }) => refine([start, end])} | ||
isDisabled={!canRefine} | ||
/> | ||
); | ||
} |
10 changes: 10 additions & 0 deletions
10
react-instantsearch-hooks/range-slider-with-react-spectrum/src/index.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
body, | ||
h1 { | ||
margin: 0; | ||
padding: 0; | ||
} | ||
|
||
body { | ||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, | ||
Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; | ||
} |
11 changes: 11 additions & 0 deletions
11
react-instantsearch-hooks/range-slider-with-react-spectrum/src/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React from 'react'; | ||
import { render } from 'react-dom'; | ||
import './index.css'; | ||
import App from './App'; | ||
|
||
render( | ||
<React.StrictMode> | ||
<App /> | ||
</React.StrictMode>, | ||
document.getElementById('root') | ||
); |
Oops, something went wrong.