Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions examples/react/autocomplete-poc/.editorconfig
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
23 changes: 23 additions & 0 deletions examples/react/autocomplete-poc/.gitignore
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?
23 changes: 23 additions & 0 deletions examples/react/autocomplete-poc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# react-instantsearch-app

[![Edit getting-started](https://codesandbox.io/static/img/play-codesandbox.svg)](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.
Binary file added examples/react/autocomplete-poc/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions examples/react/autocomplete-poc/index.html
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>
28 changes: 28 additions & 0 deletions examples/react/autocomplete-poc/package.json
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
}
}
22 changes: 22 additions & 0 deletions examples/react/autocomplete-poc/products.html
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 examples/react/autocomplete-poc/src/App (child components).jsx
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
Copy link
Contributor Author

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

openOnFocus={true}
insights={true}
onOpen={() => {}}
>
<AutoComplete.SearchBox>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use autocomplete's searchbox
change to autocomplete.searchbox

<SearchBox />
</AutoComplete.SearchBox>

{/* Custom layouts */}
<AutoComplete.Layout>
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 examples/react/autocomplete-poc/src/App (mapped indices).jsx
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>
);
}
Loading