ontario-ca-search-autosuggest v0.1.28
Ontario Autosuggest Web Components
NOTE: This document is out of date and will need to be updated to reflect the current state of this project
This package is used to build an autosuggest search input and related results. It is designed to be dynamic so that any Elastic data can be connected, but still generate the same functioanlity, look and feel.
- This package is built in React and leverages packages and features of the @elastic/search-ui project for various search functionalities.
- This package uses Styled Components and leverages styles from the Ontario Design System.
- Translations are handled through react-i18next.
Components
All components in this package are intended to be used together in order for all the search functionalities to work.
SearchLayout
The SearchLayout
component is the main component of this package. It acts as
the wrapper for the Elastic Search UI core.
Example:
import SearchLayout from '../components/search-layout'
import SVG from '../svg-file'
const iconCategories = [
{
key: 'world_heritage_site',
value: 'true',
icon: SVG,
},
]
const resultView = (results) => {
return (
<div key={results.id.raw}>
<h2>{results.title.raw}</h2>
<p>{results.description.raw}</p>
</div>
)
}
const App = () => {
return (
<SearchLayout
searchKey="search-1111"
engineName="search-ui-examples"
hostIdentifier="host-1111"
resultTitleKey="title"
resultLinkKey="url_link"
resultDescriptionKey="description"
iconCategories={iconCategories}
isSearchResultsPage={true}
header={
<header>
<SearchInputComponent
...props
/>
</heaader>
}
generateResultView={resultView}
/>
)
}
export default App;
Property name | Type | Required/Optional | Description |
---|---|---|---|
searchKey | string | required | Used for the API Connector for the Elastic Search UI instance. Credential found in your App Search Dashboard. |
engineName | string | required | Used for the API Connector for the Elastic Search UI instance. Engine to query, found in your App Search Dashboard |
hostIdentifier | string | required | Used for the API Connector for the Elastic Search UI instance. Used when proxying the Swiftype API or developing against a local API server. |
resultTitleKey | string | required | The key for the title of a search result in the search data. This is used to provide relevant results, as well as query suggestions for incomplete queries. |
resultLinkKey | string | required | The key for the URL of a search result in the search data. |
resultDescriptionKey | string | required | The key for the description of a search result in the search data. This is used to provide relevant results, as well as query suggestions for incomplete queries. |
iconCategories | Array | optional | The iconCategories array is used to create categorizations of results in the dropdown results. More details can be found under the iconCategories section below. |
language | en | fr | optional | The default language for the web components to load with. If nothing is passed, English (en ) will be presumed. |
header | ReactNode | required | Used to generate a view for the header of the application. Note that the header view should include the SearchInputComponent to display the Search Input and include autosuggest/autocomplete dropdown functionality. |
children | ReactNode | optional | Used to generate a view for the body of the application. Note that this will only render if the isSearchResultsPage prop is set to false . |
isSearchResultsPage | boolean | required | Used to determine whether or not to display the results from the generateResultView prop or not. If set to false , it will display whatever children elements are passed. |
generateResultView | ReactNode | required | Used to generate a view for a single result. This will be displayed in the body of the application. |
footer | ReactNode | optional | Used to generate a view for the footer of the application. |
SearchInputComponent
The SearchInputComponent
renders an input element which accepts search terms
and triggers search queries through the Elastic Search UI functionality. It also
displays a dropdown for autocomplete suggestions, categorization of result and
results based on search suggestions.
Example:
import SearchInputComponent from '../components/search-bar/search-input'
import SVG from '../svg-file'
const iconCategories = [
{
key: 'world_heritage_site',
value: 'true',
icon: SVG,
},
]
const SearchInput = () => {
return (
<SearchInputComponent
resultTitleKey="title"
resultLinkKey="description"
resultIdKey="id"
iconCategories={iconCategories}
/>
)
}
export default SearchInput;
Property name | Type | Required/Optional | Description |
---|---|---|---|
inputWidth | string | optional | Used to determine the width of the input element. It expects a string, but for that string to represent a percentage, i.e: 80% . If nothing is passed, it will default to 100% . |
resultIdKey | string | required | Used as the key value for the autocomplete and search result dropdown items. |
resultTitleKey | string | required | Used to display the title for the autocomplete and search result dropdown items. |
resultLinkKey | string | required | Used to link the results for the search result dropdown items. |
iconCategories | Array | optional | The iconCategories array is used to create categorizations of results in the dropdown results. More details can be found under the iconCategories section below. |
iconCategories
The iconCategories
prop is used to create categorizations of results in the
dropdown result of the SearchInputComponent
. Each object takes a key
,
value
and icon
key. When the key that is passed matches the value that is
passed, the icon specified will display before the autosuggest query results in
the dropdown.
Property name | Type | Required/Optional | Description |
---|---|---|---|
key | string | required | The key in the search data for the categorization to be based upon. |
value | string | required | The value the key must have for the icon specified to be displayed. |
icon | ReactNode | required | The icon to display if the key and value of the iconCategory object match. |
Translations
Translations for this project are handled through react-i18next.
The package has it's own internal set of translations used in common components
(ex: search input toggles, result totals, back to top buttons, etc.) but can be
set externally through either the language
or languageLogic
props in the
SearchLayout
component.
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago