Product View Buttons
Overview
The SDK includes a feature that allows users to customize the product display on the Search Results Page (SRP) by selecting from various view options. For example, if the user provides options such as "grid" and "list," the products will be arranged accordingly—displayed in a grid layout when "grid" is selected, or in a list format when "list" is chosen. This flexibility ensures that the product presentation aligns with the user's preferences.
How it Works ?
When the user selects an option from the product view, the state is updated with the corresponding view. The Products component then applies this view from the state as a class to the wrapper, allowing CSS to adjust the appearance and alignment of the products accordingly.
Usage
// importing component
import { ProductViewButtons } from "@unbxd-ui/react-search-components";
// import the style for the component
import "@unbxd-ui/react-search-components/styles/productViewButtons.css";
If the styles import does not work, use the following code to import it:
require.resolve("@unbxd-ui/react-search-components/styles/productViewButtons.css");
The ProductViewButtons component must be used within the wrapper (in CSR, SSR and Custom Hooks approaches) to ensure that the component and the search functionality work properly.
Live Demo
Props
The component that will be rendered for each button.
Example component:
const CustomComponent = (props) => {
const { item } = props;
return item.label;
};
A boolean value which indicates if the label must be shown or not. By default, the value is true
.
The text that must be shown as the label to the view component.
The options that must be displayed in the dropdown. The options must be of the form:
options={[{ value: "GRID", label: "GRID" }, {value: "LIST", label: "LIST"}]}
This prop will be used to style the component. The value must use a defined structure (the structure can be seen in the following example). The keys in the structure must be the same while the values can changed as per the user's choice.
styles={{
wrapper: "view-root",
label: "view-label",
optionContainer: "view-option-container",
option: "view-option",
selected: "view-selected",
text: "text"
}}
Related Hook
To use the Unbxd React Search SDK without the pre-built SortButtons component, add the functionality to your custom component using the useSorting hook. Refer to the documentation for more details.