0.1.28 • Published 3 months ago

ontario-ca-search-autosuggest v0.1.28

Weekly downloads
-
License
MIT
Repository
-
Last release
3 months ago

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.

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 nameTypeRequired/OptionalDescription
searchKeystringrequiredUsed for the API Connector for the Elastic Search UI instance. Credential found in your App Search Dashboard.
engineNamestringrequiredUsed for the API Connector for the Elastic Search UI instance. Engine to query, found in your App Search Dashboard
hostIdentifierstringrequiredUsed for the API Connector for the Elastic Search UI instance. Used when proxying the Swiftype API or developing against a local API server.
resultTitleKeystringrequiredThe 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.
resultLinkKeystringrequiredThe key for the URL of a search result in the search data.
resultDescriptionKeystringrequiredThe 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.
iconCategoriesArrayoptionalThe iconCategories array is used to create categorizations of results in the dropdown results. More details can be found under the iconCategories section below.
languageen | froptionalThe default language for the web components to load with. If nothing is passed, English (en) will be presumed.
headerReactNoderequiredUsed 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.
childrenReactNodeoptionalUsed to generate a view for the body of the application. Note that this will only render if the isSearchResultsPage prop is set to false.
isSearchResultsPagebooleanrequiredUsed 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.
generateResultViewReactNoderequiredUsed to generate a view for a single result. This will be displayed in the body of the application.
footerReactNodeoptionalUsed 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 nameTypeRequired/OptionalDescription
inputWidthstringoptionalUsed 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%.
resultIdKeystringrequiredUsed as the key value for the autocomplete and search result dropdown items.
resultTitleKeystringrequiredUsed to display the title for the autocomplete and search result dropdown items.
resultLinkKeystringrequiredUsed to link the results for the search result dropdown items.
iconCategoriesArrayoptionalThe 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 nameTypeRequired/OptionalDescription
keystringrequiredThe key in the search data for the categorization to be based upon.
valuestringrequiredThe value the key must have for the icon specified to be displayed.
iconReactNoderequiredThe 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.

0.1.10

3 months ago

0.1.11

3 months ago

0.1.12

3 months ago

0.1.13

3 months ago

0.1.14

3 months ago

0.1.15

3 months ago

0.1.27

3 months ago

0.1.28

3 months ago

0.1.20

3 months ago

0.1.21

3 months ago

0.1.22

3 months ago

0.1.23

3 months ago

0.1.24

3 months ago

0.1.25

3 months ago

0.1.26

3 months ago

0.1.16

3 months ago

0.1.8

3 months ago

0.1.17

3 months ago

0.1.7

3 months ago

0.1.18

3 months ago

0.1.9

3 months ago

0.1.4

3 months ago

0.1.6

3 months ago

0.1.5

3 months ago

0.1.3

3 months ago

0.1.2

3 months ago

0.1.1

3 months ago

0.1.0

3 months ago