-
Notifications
You must be signed in to change notification settings - Fork 553
wip autocomplete public api poc #6673
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
+624
−0
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,8 @@ | ||
| root = true | ||
|
|
||
| [*] | ||
| indent_style = space | ||
| indent_size = 2 | ||
| end_of_line = lf | ||
| insert_final_newline = true | ||
| trim_trailing_whitespace = true |
This file contains hidden or 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 @@ | ||
| # Logs | ||
| logs | ||
| *.log | ||
| npm-debug.log* | ||
| yarn-debug.log* | ||
| yarn-error.log* | ||
| pnpm-debug.log* | ||
| lerna-debug.log* | ||
|
|
||
| node_modules | ||
| dist | ||
| .parcel-cache | ||
| *.local | ||
|
|
||
| # Editor directories and files | ||
| .vscode | ||
| .idea | ||
| .DS_Store | ||
| *.suo | ||
| *.ntvs* | ||
| *.njsproj | ||
| *.sln | ||
| *.sw? |
This file contains hidden or 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 @@ | ||
| # react-instantsearch-app | ||
|
|
||
| [](https://codesandbox.io/s/github/algolia/instantsearch/tree/master/examples/react/getting-started) | ||
|
|
||
| _This project was generated with [create-instantsearch-app](https://github.com/algolia/instantsearch/tree/master/packages/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. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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,22 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="utf-8" /> | ||
| <meta | ||
| name="viewport" | ||
| content="width=device-width, initial-scale=1, shrink-to-fit=no" | ||
| /> | ||
|
|
||
| <link rel="shortcut icon" href="favicon.png" /> | ||
|
|
||
| <title>React InstantSearch — Getting started</title> | ||
| </head> | ||
|
|
||
| <body> | ||
| <noscript> You need to enable JavaScript to run this app. </noscript> | ||
|
|
||
| <div id="root"></div> | ||
|
|
||
| <script type="module" src="src/index.tsx"></script> | ||
| </body> | ||
| </html> |
This file contains hidden or 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 @@ | ||
| { | ||
| "name": "example-react-autocomplete-poc", | ||
| "version": "6.97.0", | ||
| "private": true, | ||
| "scripts": { | ||
| "build": "BABEL_ENV=parcel parcel build index.html products.html", | ||
| "start": "BABEL_ENV=parcel parcel index.html products.html --port 3000" | ||
| }, | ||
| "dependencies": { | ||
| "algoliasearch": "5.1.1", | ||
| "instantsearch.css": "8.5.1", | ||
| "instantsearch.js": "4.79.1", | ||
| "react": "19.0.0", | ||
| "react-dom": "19.0.0", | ||
| "react-instantsearch": "7.16.1" | ||
| }, | ||
| "devDependencies": { | ||
| "@parcel/core": "2.10.0", | ||
| "@parcel/packager-raw-url": "2.10.0", | ||
| "@parcel/transformer-webmanifest": "2.10.0", | ||
| "@types/react": "19.0.3", | ||
| "parcel": "2.10.0", | ||
| "typescript": "5.5.2" | ||
| }, | ||
| "@parcel/resolver-default": { | ||
| "packageExports": true | ||
| } | ||
| } |
This file contains hidden or 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,22 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="utf-8" /> | ||
| <meta | ||
| name="viewport" | ||
| content="width=device-width, initial-scale=1, shrink-to-fit=no" | ||
| /> | ||
|
|
||
| <link rel="shortcut icon" href="favicon.png" /> | ||
|
|
||
| <title>React InstantSearch — Getting started</title> | ||
| </head> | ||
|
|
||
| <body> | ||
| <noscript> You need to enable JavaScript to run this app. </noscript> | ||
|
|
||
| <div id="root"></div> | ||
|
|
||
| <script type="module" src="src/products.tsx"></script> | ||
| </body> | ||
| </html> |
105 changes: 105 additions & 0 deletions
105
examples/react/autocomplete-poc/src/App (child components).jsx
This file contains hidden or 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,105 @@ | ||
| import { liteClient as algoliasearch } from 'algoliasearch/lite'; | ||
| import React from 'react'; | ||
| import { | ||
| Configure, | ||
| Highlight, | ||
| Hits, | ||
| Index, | ||
| InstantSearch, | ||
| RefinementList, | ||
| SearchBox, | ||
| useHits, | ||
| } from 'react-instantsearch'; | ||
|
|
||
| import { AutoComplete, AutoCompletePanel } from './AutoComplete'; | ||
| import { Panel } from './Panel'; | ||
|
|
||
| import 'instantsearch.css/themes/satellite.css'; | ||
|
|
||
| import './App.css'; | ||
|
|
||
| const searchClient = algoliasearch( | ||
| 'latency', | ||
| '6be0576ff61c053d5f9a3225e2a90f76' | ||
| ); | ||
|
|
||
| export function App() { | ||
| return ( | ||
| <div> | ||
| <header className="header"> | ||
| <h1 className="header-title"> | ||
| <a href="/">Getting started</a> | ||
| </h1> | ||
| <p className="header-subtitle"> | ||
| using{' '} | ||
| <a href="https://github.com/algolia/instantsearch/tree/master/packages/react-instantsearch"> | ||
| React InstantSearch | ||
| </a> | ||
| </p> | ||
| </header> | ||
|
|
||
| <div className="container"> | ||
| <InstantSearch searchClient={searchClient} indexName="instant_search"> | ||
| <Configure hitsPerPage={8} /> | ||
| <div className="search-panel"> | ||
| <div className="search-panel__filters"> | ||
| <Panel header="brand"> | ||
| <RefinementList attribute="brand" /> | ||
| </Panel> | ||
| </div> | ||
|
|
||
| <div className="search-panel__results"> | ||
| <AutoComplete | ||
| openOnFocus={true} | ||
| insights={true} | ||
| onOpen={() => {}} | ||
| > | ||
| <AutoComplete.SearchBox> | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use autocomplete's searchbox |
||
| <SearchBox /> | ||
| </AutoComplete.SearchBox> | ||
|
|
||
| {/* Custom layouts */} | ||
| <AutoComplete.Layout> | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. change to dropdown |
||
| <div className="two-column-layout"> | ||
| <Index indexName="index1"> | ||
| <Hits hitComponent={HitComponent} /> | ||
| </Index> | ||
|
|
||
| <Index indexName="index2"> | ||
| <Hits hitComponent={HitComponent} /> | ||
| </Index> | ||
| </div> | ||
| </AutoComplete.Layout> | ||
|
|
||
| {/* Premade layouts */} | ||
| <AutoComplete.TwoColumnLayout major="index1" minor="index2" /> | ||
|
|
||
| <AutoComplete.DefaultLayout | ||
| querySuggestions={true} | ||
| recentSearches={true} | ||
| classNames={{}} | ||
| /> | ||
| </AutoComplete> | ||
| </div> | ||
| </div> | ||
| </InstantSearch> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| function HitComponent({ hit }) { | ||
| return ( | ||
| <article> | ||
| <h1> | ||
| <a href={`/products.html?pid=${hit.objectID}`}> | ||
| <Highlight attribute="name" hit={hit} /> | ||
| </a> | ||
| </h1> | ||
| <p> | ||
| <Highlight attribute="description" hit={hit} /> | ||
| </p> | ||
| <a href={`/products.html?pid=${hit.objectID}`}>See product</a> | ||
| </article> | ||
| ); | ||
| } | ||
112 changes: 112 additions & 0 deletions
112
examples/react/autocomplete-poc/src/App (mapped indices).jsx
This file contains hidden or 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,112 @@ | ||
| import { liteClient as algoliasearch } from 'algoliasearch/lite'; | ||
| import React from 'react'; | ||
| import { | ||
| Configure, | ||
| Highlight, | ||
| InstantSearch, | ||
| RefinementList, | ||
| SearchBox, | ||
| } from 'react-instantsearch'; | ||
|
|
||
| import { AutoComplete, QuerySuggestions } from './AutoComplete'; | ||
| import { Panel } from './Panel'; | ||
|
|
||
| import 'instantsearch.css/themes/satellite.css'; | ||
|
|
||
| import './App.css'; | ||
|
|
||
| const searchClient = algoliasearch( | ||
| 'latency', | ||
| '6be0576ff61c053d5f9a3225e2a90f76' | ||
| ); | ||
|
|
||
| export function App() { | ||
| return ( | ||
| <div> | ||
| <header className="header"> | ||
| <h1 className="header-title"> | ||
| <a href="/">Getting started</a> | ||
| </h1> | ||
| <p className="header-subtitle"> | ||
| using{' '} | ||
| <a href="https://github.com/algolia/instantsearch/tree/master/packages/react-instantsearch"> | ||
| React InstantSearch | ||
| </a> | ||
| </p> | ||
| </header> | ||
|
|
||
| <div className="container"> | ||
| <InstantSearch searchClient={searchClient} indexName="instant_search"> | ||
| <Configure hitsPerPage={8} /> | ||
| <div className="search-panel"> | ||
| <div className="search-panel__filters"> | ||
| <Panel header="brand"> | ||
| <RefinementList attribute="brand" /> | ||
| </Panel> | ||
| </div> | ||
|
|
||
| <div className="search-panel__results"> | ||
| <AutoComplete | ||
| indices={{ | ||
| instant_search_1: { | ||
| name: 'instant_search', | ||
| config: {}, | ||
| template: List, | ||
| }, | ||
| instant_search_2: { | ||
| name: 'instant_search', | ||
| config: {}, | ||
| template: List, | ||
| }, | ||
| query_suggestions: { | ||
| config: {}, | ||
| template: QuerySuggestions, | ||
| }, | ||
| }} | ||
| layout={CustomLayout} | ||
| /> | ||
| </div> | ||
| </div> | ||
| </InstantSearch> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| function CustomLayout({ indices }) { | ||
| const { instant_search_1, instant_search_2, query_suggestions } = indices; | ||
|
|
||
| return ( | ||
| <div className="two-column-layout"> | ||
| <div className="first-column"> | ||
| <instant_search_1.template /> | ||
| </div> | ||
| <div className="second-column"> | ||
| <instant_search_2.template /> | ||
| </div> | ||
| <div className="third-column"> | ||
| <query_suggestions.template /> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| function SearchBoxComponent({ searchBoxProps }) { | ||
| return <SearchBox {...searchBoxProps} />; | ||
| } | ||
|
|
||
| function HitComponent({ hit }) { | ||
| return ( | ||
| <article> | ||
| <h1> | ||
| <a href={`/products.html?pid=${hit.objectID}`}> | ||
| <Highlight attribute="name" hit={hit} /> | ||
| </a> | ||
| </h1> | ||
| <p> | ||
| <Highlight attribute="description" hit={hit} /> | ||
| </p> | ||
| <a href={`/products.html?pid=${hit.objectID}`}>See product</a> | ||
| </article> | ||
| ); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add all autocomplete props here