ReactiveSearch provides React UI components for Elasticsearch. This document explains the different kinds of components offered by the library and walks throughs scenarios of when to use which component.
Components are divided into four broad categories:
List componentsrepresent all kinds of list related UI components which typically create a term query.
Range componentsrepresent all kinds of numbers and dates related UI components which typically create a range based query.
Search componentsrepresent searchbar UIs, which typically apply search on full-text data.
Result componentsare components for displaying results (aka hits) from queries created by other components.
Besides these four specific categories, we also have
Base components that are useful primitives and components that don’t belong to any of the above categories.
1. List Components
List is one of the most used data-driven UI displays and hence naturally, we offer a variety of ways to use this UI style.
String or Text Datatype
The following are all the possible UI components for a
String datatype field in your appbase.io app. These apply a term or terms database query on the selected item(s).
The components can also be used with
Numeric datatype fields.
SingleList is useful for displaying a list of values where only one item can be selected at a time, and the values are retrieved by a database query on the field specified in the dataField prop.
MultiList is useful for displaying a list of values where multiple values can be selected at a time. Similar to SingleList, these values are retrieved by a database query on the field specified in the dataField prop.
SingleDataList is useful for displaying a list of user defined values where only one value item can be selected at a time. Unlike SingleList and MultiList where the values are auto-fetched, here the data prop allows curation of which values to display.
MultiDataList is useful for displaying a list of user defined values where multiple value items can be selected at a time. Similar to the SingleDataList component, the data prop allows curation of which values to display.
List vs DataList
Use-cases where curation is important and only a few items need to be shown should use DataList components. Since it doesn’t need to auto-fetch the results, it also saves a network request.
SingleDropdownList displays a dropdown list UI where only one item can be selected at a time. It is similar to SingleList but is presented in a dropdown format to save space.
MultiDropdownList displays a dropdown list UI where multiple items can be selected at a time. It is similar to MultiList.
When to use dropdown lists
Dropdown lists take up less space. If you have many filters to display or a smaller display area (like on phones), it is better to use dropdown lists.
2. Range Components
The following are all the possible UI components for a numeric datatype field in your appbase.io app. These apply a range database query on the selected item(s).
SingleRange displays a curated list of items where only one item can be selected at a time. Each item represents a range of values, specified in the data prop of the component.
Its counterpart for a String datatype would be SingleDataList component.
MultiRange displays a curated list of items where multiple items can be selected at a time. Each item represents a range of values, specified in the data prop of the component.
Its counterpart for a String datatype would be MultiDataList component.
SingleDropdownRange displays a dropdown list UI where only one item can be selected at a time. Each item in this dropdown list represents a range, specified in the data prop of the component.
MultiDropdownRange displays a dropdown list UI where only multiple items can be selected at a time. Each item in this dropdown list represents a range, specified in the data prop of the component.
RangeSlider component applies on a numeric datatype (ideally an integer) field and displays a slider UI.
RangeSlider vs Range lists
A RangeSlider is useful when the selection of values is homogeneous, e.g. price across a set of products.
NumberBox component applies on a numeric datatype field where you want to display a selectable field value that can be incrementally increased or decreased, e.g. no of guests field in a hotel booking app.
DatePicker and DateRange
RatingsFilter is useful for showing a UI selection choice based on ratings score. To be applied on a numeric datatype field.
3. Search Components
The following are UI components that represent searchbar UIs. The datatype for the
dataField in these components should be a
Keyword, along with custom analyzer (like ngrams) based mappings defined in sub-fields.
DataSearch displays a search input box. It supports autosuggestions, highlighting of results and querying against more than one fields via props.
If you are looking to apply a query on a user input, DataSearch is preferable over TextField.
CategorySearch is a more specific version of the DataSearch component. The main difference is that it can show suggestions within specific categories besides the general auto-suggestions that appear in the search dropdown.
4. Result Components
Result components are used for displaying the results (aka hits).
How do result components fetch results by combining queries from multiple components?
They do this via react prop, which allows each component to specify their dependent components using a DSL that mirrors Elasticsearch’s compound query DSL for bool clause.
ResultList displays the results in a list layout.
ResultCard displays the results in a card layout.
ReactiveList displays the results in a configurable list layout. This is a more flexible display component (used internally by both ResultList and ResultCard) that allows more customization than ResultList and ResultCard.
ReactiveComponent is a wrapper component that allows you to connect custom component(s) (passed as children) with the Reactivesearch ecosystem, e.g. if we are building an e-commerce store where we have a react component called
ColorPicker which renders the
colors passed to it as tiles, allowing us to filter the products by their colors.
5. Base Components
TextField displays a text input field. It applies a match database query on the entered text.
ToggleButton component applies on a String or Text datatype field where you want users to select a choice (or choices) amongst a small number of total choices.
TagCloud is useful for showing a weighted tag cloud of items based on the frequency of occurrences.
DataController is a UI optional component for adding additional queries, e.g. a query based on current URL page path, a default query, a query based on user’s global profile preferences. At the same time, it can also have a UI - this is a catchall component to display something that doesn’t fit within other components.
SelectedFilters is a selection component to render the selected values from other components with a “Clear All” option.