Quick Search Widget (JS)
A Vanilla JS widget that enables users to perform real-time product searches with instant results, enhancing product discoverability and conversion.
Use this library when you want to display a widget without using a transpiler
like Babel and without using JSX. This library exports a htm
HTML factory
to assemble custom elements of the widget.
This widget library is version 0.0.12 and the API can change. Please specify exact version when installing.
Installation
Install @recombee/quick-search-widget-js@0.0.12
and
recombee-js-api-client
packages using your preferred NPM package manager.
This example is using pnpm
.
pnpm add @recombee/quick-search-widget-js@0.0.12 recombee-js-api-client
Client Initialization
The widget loads recommendation data using Recombee API Client. Here is how to initialize the client with necessary configuration for a specific database:
import { class ApiClient
Client for sending requests to Recombee and getting repliesApiClient } from "recombee-js-api-client";
const const DATABASE_ID: "[database-id]"
DATABASE_ID = "[database-id]";
const const PUBLIC_TOKEN: "[database-public-token]"
PUBLIC_TOKEN = "[database-public-token]";
const const REGION: "[database-region]"
REGION = "[database-region]";
export const const apiClient: ApiClient
apiClient = new new ApiClient(databaseId: string, publicToken: string, options?: ApiClientOptions): ApiClient
ApiClient(const DATABASE_ID: "[database-id]"
DATABASE_ID, const PUBLIC_TOKEN: "[database-public-token]"
PUBLIC_TOKEN, {
region?: string | undefined
region: const REGION: "[database-region]"
REGION,
});
The Database Public Token can be found in the Admin UI Database Settings Page.
The widget also needs to be provided a createRequest
function, which
instantiates a client request class to define which data to pull from the
database. Use Scenario ID which can be found on Admin GUI
Database Scenarios Page.
import { type type CreateRequestFunction = (options: FetchContentOptions) => Request
Factory for creating Recombee API Request to load data into a Widget.CreateRequestFunction } from "@recombee/carousel-widget-react";
import { class RecommendItemsToUser
Based on the user's past interactions (purchases, ratings, etc.) with the items, recommends top-N items that are most likely to be of high value for the given user.
The most typical use cases are recommendations on the homepage, in some "Picked just for you" section, or in email.
The returned items are sorted by relevance (the first item being the most relevant).
Besides the recommended items, also a unique `recommId` is returned in the response. It can be used to:
- Let Recombee know that this recommendation was successful (e.g., user clicked one of the recommended items). See [Reported metrics](https://docs.recombee.com/admin_ui.html#reported-metrics).
- Get subsequent recommended items when the user scrolls down (*infinite scroll*) or goes to the next page. See [Recommend Next Items](https://docs.recombee.com/api.html#recommend-next-items).
It is also possible to use POST HTTP method (for example in the case of a very long ReQL filter) - query parameters then become body parameters.RecommendItemsToUser } from "recombee-js-api-client";
const const createRequest: CreateRequestFunction
createRequest: type CreateRequestFunction = (options: FetchContentOptions) => Request
Factory for creating Recombee API Request to load data into a Widget.CreateRequestFunction = ({ count: number
Number of items to fetch for the widget. Pass it to the appropriate
Request constructor.count }) => {
const const SCENARIO_ID: "recommend-items-to-user"
SCENARIO_ID = "recommend-items-to-user";
return new new RecommendItemsToUser(userId: string, count: number, optional?: {
scenario?: string;
cascadeCreate?: boolean;
returnProperties?: boolean;
includedProperties?: string[];
filter?: string;
booster?: string;
logic?: string | object;
diversity?: number;
minRelevance?: string;
rotationRate?: number;
rotationTime?: number;
expertSettings?: {
[key: string]: unknown;
};
returnAbGroup?: boolean;
}): RecommendItemsToUser
RecommendItemsToUser(userId, count: number
Number of items to fetch for the widget. Pass it to the appropriate
Request constructor.count, {
scenario?: string | undefined
Scenario defines a particular application of recommendations. It can be, for example, "homepage", "cart", or "emailing".scenario: const SCENARIO_ID: "recommend-items-to-user"
SCENARIO_ID,
cascadeCreate?: boolean | undefined
If the user does not exist in the database, returns a list of non-personalized recommendations and creates the user in the database. This allows, for example, rotations in the following recommendations for that user, as the user will be already known to the system.cascadeCreate: true,
returnProperties?: boolean | undefined
With `returnProperties=true`, property values of the recommended items are returned along with their IDs in a JSON dictionary. The acquired property values can be used to easily display the recommended items to the user.returnProperties: true,
});
};
Please ensure that you provide the user ID (typically obtained from your existing user tracking system), along with other relevant parameters - such as an item ID or Item Segment ID - depending on the specific type of recommendation request.
Basic Example
The widget in this example uses the DefaultItem component to render each recommendation in a consistent layout.
The resulting widget is inserted into the element specified by the
container
field.
Values of the recommended items - such as title, image URL, or link URL - are
obtained from the API response and accessed via props.result?.values
.
Ensure that returnProperties: true is set in the request, and optionally use includedProperties to control which item properties are returned.
import {
const QuickSearchWidget: ({ container, ...props }: QuickSearchWidgetOptions) => null | undefined
Quick Search widgetQuickSearchWidget,
function addRecommIdQueryParam(url: string, recommId: string | undefined): string
Utility function to append `recombee_recomm_id` parameter to an url string.
For usage in widget template to construct item link URL.addRecommIdQueryParam,
const DefaultInput: ((props: {
state: QuickSearchWidgetState;
}) => React.JSX.Element) & {
displayName: string;
}
DefaultInput,
const DefaultItem: ((props: DefaultItemProps) => React.JSX.Element) & {
displayName: string;
}
Default Item component provided for basic usage.DefaultItem,
function SearchIcon(): React.JSX.Element
SearchIcon,
function CloseIcon(): React.JSX.Element
CloseIcon,
const html: (strings: TemplateStringsArray, ...values: any[]) => React.ReactElement
html,
} from "@recombee/quick-search-widget-js";
import "@recombee/quick-search-widget-js/dist/styles.css";
function QuickSearchWidget({ container, ...props }: QuickSearchWidgetOptions): null | undefined
Quick Search widgetQuickSearchWidget({
container: string
CSS Selector to target the element where the widget should be inserted.container: "#widget-root",
WidgetConfigurationBase<CR extends (...args: any[]) => Request = CreateRequestFunction>.apiClient: ApiClient
Instance of Recombee JS API Client. See
{@link
file://./#client-initialization Example
}
.apiClient: const apiClient: ApiClient
apiClient,
WidgetConfigurationBase<CR extends (...args: any[]) => Request = CreateRequestFunction>.createRequest: CreateRequestFunction
Request factory function. See
{@link
file://./#client-initialization Quick Example
}
or visit
{@link
file:///api API Reference
}
for overview of available requests.createRequest: const createRequest: CreateRequestFunction
createRequest,
minSearchCharactersCount: number
minSearchCharactersCount: 3,
desktopMediaQuery: string
desktopMediaQuery: "(min-width: 1000px)",
type InputComponent: React.FC<InputProps>
InputComponent: (props: InputProps
props) =>
const html: (strings: TemplateStringsArray, ...values: any[]) => React.ReactElement
html`<form className="flex w-[400px] text-[#374040]">
<${const DefaultInput: ((props: {
state: QuickSearchWidgetState;
}) => React.JSX.Element) & {
displayName: string;
}
DefaultInput} state=${props: InputProps
props.state: QuickSearchWidgetState
state} />
</form>`,
type TriggerComponent: React.FC<TriggerProps>
TriggerComponent: (props: TriggerProps
props) =>
const html: (strings: TemplateStringsArray, ...values: any[]) => React.ReactElement
html`<button
...${props: TriggerProps
props.state: QuickSearchWidgetState
state.QuickSearchWidgetState.triggerProps: {
ref: (element: HTMLElement | null) => void;
onClick: () => void;
}
triggerProps}
className="flex size-[38px] items-center justify-center rounded-sm bg-[#3bc4a1] text-white"
>
<${function SearchIcon(): React.JSX.Element
SearchIcon} />
</button>`,
type DropdownComponent: React.FC<DropdownProps>
DropdownComponent: (props: DropdownProps
props) =>
const html: (strings: TemplateStringsArray, ...values: any[]) => React.ReactElement
html`<div
className="mt-1 flex h-full max-h-full min-h-0 flex-col rounded-sm bg-white text-[#374040] shadow-2xl lg:h-auto lg:max-w-[900px] lg:min-w-[600px]"
>
${!props: DropdownProps
props.state: QuickSearchWidgetState
state.QuickSearchWidgetState.isDesktop: boolean
isDesktop &&
const html: (strings: TemplateStringsArray, ...values: any[]) => React.ReactElement
html`<form className="flex items-center gap-2 p-2">
<div className="flex-grow">
<${const DefaultInput: ((props: {
state: QuickSearchWidgetState;
}) => React.JSX.Element) & {
displayName: string;
}
DefaultInput} state=${props: DropdownProps
props.state: QuickSearchWidgetState
state} />
</div>
<button
...${props: DropdownProps
props.state: QuickSearchWidgetState
state.QuickSearchWidgetState.closeButtonProps: {
type: "button";
onClick: () => void;
onTouchEnd: () => void;
}
closeButtonProps}
className="flex size-[38px] items-center justify-center"
>
<${function CloseIcon(): React.JSX.Element
CloseIcon} />
</button>
</form>`}
<div className="flex min-h-0 flex-grow flex-col">
<div className="px-4 py-4 pb-2 text-sm font-semibold text-[#3bc4a1]">
Results
</div>
<div className="overflow-auto p-2">
${props: DropdownProps
props.state: QuickSearchWidgetState
state
.QuickSearchWidgetState.items: (index: number) => {
key: string;
id: string;
recommId: string;
values: {
[key: string]: any;
};
itemProps: {
onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
"data-search-result-id": string;
tabIndex: number;
};
}[]
items(0)
.Array<{ key: string; id: string; recommId: string; values: { [key: string]: any; }; itemProps: { onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void; "data-search-result-id": string; tabIndex: number; }; }>.map<React.ReactElement<unknown, string | React.JSXElementConstructor<any>>>(callbackfn: (value: {
key: string;
id: string;
recommId: string;
values: {
[key: string]: any;
};
itemProps: {
onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
"data-search-result-id": string;
tabIndex: number;
};
}, index: number, array: {
key: string;
id: string;
recommId: string;
values: {
[key: string]: any;
};
itemProps: {
onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
"data-search-result-id": string;
tabIndex: number;
};
}[]) => React.ReactElement<...>, thisArg?: any): React.ReactElement<...>[]
Calls a defined callback function on each element of an array, and returns an array that contains the results.map(
(item: {
key: string;
id: string;
recommId: string;
values: {
[key: string]: any;
};
itemProps: {
onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
"data-search-result-id": string;
tabIndex: number;
};
}
item) =>
const html: (strings: TemplateStringsArray, ...values: any[]) => React.ReactElement
html`<${const DefaultItem: ((props: DefaultItemProps) => React.JSX.Element) & {
displayName: string;
}
Default Item component provided for basic usage.DefaultItem}
key=${item: {
key: string;
id: string;
recommId: string;
values: {
[key: string]: any;
};
itemProps: {
onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
"data-search-result-id": string;
tabIndex: number;
};
}
item.key: string
key}
href=${function addRecommIdQueryParam(url: string, recommId: string | undefined): string
Utility function to append `recombee_recomm_id` parameter to an url string.
For usage in widget template to construct item link URL.addRecommIdQueryParam(
`${item: {
key: string;
id: string;
recommId: string;
values: {
[key: string]: any;
};
itemProps: {
onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
"data-search-result-id": string;
tabIndex: number;
};
}
item.values: {
[key: string]: any;
}
values?.__type[string]: any
link}`,
item: {
key: string;
id: string;
recommId: string;
values: {
[key: string]: any;
};
itemProps: {
onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
"data-search-result-id": string;
tabIndex: number;
};
}
item.recommId: string
recommId,
)}
primaryContent=${item: {
key: string;
id: string;
recommId: string;
values: {
[key: string]: any;
};
itemProps: {
onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
"data-search-result-id": string;
tabIndex: number;
};
}
item.values: {
[key: string]: any;
}
values?.__type[string]: any
product_title}
secondaryContent=${item: {
key: string;
id: string;
recommId: string;
values: {
[key: string]: any;
};
itemProps: {
onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
"data-search-result-id": string;
tabIndex: number;
};
}
item.values: {
[key: string]: any;
}
values?.__type[string]: any
category}
...${item: {
key: string;
id: string;
recommId: string;
values: {
[key: string]: any;
};
itemProps: {
onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
"data-search-result-id": string;
tabIndex: number;
};
}
item.itemProps: {
onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
"data-search-result-id": string;
tabIndex: number;
}
itemProps}
/>`,
)}
</div>
</div>
</div>`,
});
Batch request
To fetch results from multiple Scenarios, such as segments in addition to items, use Batch request.
import {
const QuickSearchWidget: ({ container, ...props }: QuickSearchWidgetOptions) => null | undefined
Quick Search widgetQuickSearchWidget,
function addRecommIdQueryParam(url: string, recommId: string | undefined): string
Utility function to append `recombee_recomm_id` parameter to an url string.
For usage in widget template to construct item link URL.addRecommIdQueryParam,
const DefaultInput: ((props: {
state: QuickSearchWidgetState;
}) => React.JSX.Element) & {
displayName: string;
}
DefaultInput,
const DefaultItem: ((props: DefaultItemProps) => React.JSX.Element) & {
displayName: string;
}
Default Item component provided for basic usage.DefaultItem,
function SearchIcon(): React.JSX.Element
SearchIcon,
function CloseIcon(): React.JSX.Element
CloseIcon,
const html: (strings: TemplateStringsArray, ...values: any[]) => React.ReactElement
html,
} from "@recombee/quick-search-widget-js";
import "@recombee/quick-search-widget-js/dist/styles.css";
const const createRequest: CreateRequestFunction
createRequest: type CreateRequestFunction = (options: {
searchQuery: string;
isFullScreen?: boolean;
}) => Request
CreateRequestFunction = ({ searchQuery: string
searchQuery }) => {
return new new Batch(requests: Request[], optional?: {
distinctRecomms?: boolean;
}): Batch
Batch(
[
new new SearchItems(userId: string, searchQuery: string, count: number, optional?: {
scenario?: string;
cascadeCreate?: boolean;
returnProperties?: boolean;
includedProperties?: string[];
filter?: string;
booster?: string;
logic?: string | object;
expertSettings?: {
[key: string]: unknown;
};
returnAbGroup?: boolean;
}): SearchItems
SearchItems("userId", searchQuery: string
searchQuery, 5, {
scenario?: string | undefined
Scenario defines a particular search field in your user interface.scenario: "search",
cascadeCreate?: boolean | undefined
If the user does not exist in the database, returns a list of non-personalized search results and creates the user in the database. This allows, for example, rotations in the following recommendations for that user, as the user will be already known to the system.cascadeCreate: true,
returnProperties?: boolean | undefined
With `returnProperties=true`, property values of the recommended items are returned along with their IDs in a JSON dictionary. The acquired property values can be used to easily display the recommended items to the user.returnProperties: true,
}),
new new SearchItemSegments(userId: string, searchQuery: string, count: number, optional?: {
scenario?: string;
cascadeCreate?: boolean;
filter?: string;
booster?: string;
logic?: string | object;
expertSettings?: {
[key: string]: unknown;
};
returnAbGroup?: boolean;
}): SearchItemSegments
SearchItemSegments("userId", searchQuery: string
searchQuery, 5, {
scenario?: string | undefined
Scenario defines a particular application of recommendations. It can be, for example, "homepage", "cart", or "emailing".scenario: "search-brands",
cascadeCreate?: boolean | undefined
If the user does not exist in the database, returns a list of non-personalized recommendations and creates the user in the database. This allows, for example, rotations in the following recommendations for that user, as the user will be already known to the system.cascadeCreate: true,
}),
],
{
distinctRecomms?: boolean | undefined
distinctRecomms: true,
},
);
};
function QuickSearchWidget({ container, ...props }: QuickSearchWidgetOptions): null | undefined
Quick Search widgetQuickSearchWidget({
container: string
CSS Selector to target the element where the widget should be inserted.container: "#widget-root",
WidgetConfigurationBase<CR extends (...args: any[]) => Request = CreateRequestFunction>.apiClient: ApiClient
Instance of Recombee JS API Client. See
{@link
file://./#client-initialization Example
}
.apiClient: const apiClient: ApiClient
apiClient,
WidgetConfigurationBase<CR extends (...args: any[]) => Request = CreateRequestFunction>.createRequest: CreateRequestFunction
Request factory function. See
{@link
file://./#client-initialization Quick Example
}
or visit
{@link
file:///api API Reference
}
for overview of available requests.createRequest: const createRequest: CreateRequestFunction
createRequest,
minSearchCharactersCount: number
minSearchCharactersCount: 3,
desktopMediaQuery: string
desktopMediaQuery: "(min-width: 1000px)",
type InputComponent: React.FC<InputProps>
InputComponent: (props: InputProps
props) =>
const html: (strings: TemplateStringsArray, ...values: any[]) => React.ReactElement
html`<form className="flex w-[400px] text-[#374040]">
<${const DefaultInput: ((props: {
state: QuickSearchWidgetState;
}) => React.JSX.Element) & {
displayName: string;
}
DefaultInput} state=${props: InputProps
props.state: QuickSearchWidgetState
state} />
</form>`,
type TriggerComponent: React.FC<TriggerProps>
TriggerComponent: (props: TriggerProps
props) =>
const html: (strings: TemplateStringsArray, ...values: any[]) => React.ReactElement
html`<button
...${props: TriggerProps
props.state: QuickSearchWidgetState
state.QuickSearchWidgetState.triggerProps: {
ref: (element: HTMLElement | null) => void;
onClick: () => void;
}
triggerProps}
className="flex size-[38px] items-center justify-center rounded-sm bg-[#3bc4a1] text-white"
>
<${function SearchIcon(): React.JSX.Element
SearchIcon} />
</button>`,
type DropdownComponent: React.FC<DropdownProps>
DropdownComponent: (props: DropdownProps
props) =>
const html: (strings: TemplateStringsArray, ...values: any[]) => React.ReactElement
html`<div
className="mt-1 flex h-full max-h-full min-h-0 flex-col rounded-sm bg-white text-[#374040] shadow-2xl lg:h-auto lg:max-w-[900px] lg:min-w-[600px]"
>
${!props: DropdownProps
props.state: QuickSearchWidgetState
state.QuickSearchWidgetState.isDesktop: boolean
isDesktop &&
const html: (strings: TemplateStringsArray, ...values: any[]) => React.ReactElement
html`<form className="flex items-center gap-2 p-2">
<div className="flex-grow">
<${const DefaultInput: ((props: {
state: QuickSearchWidgetState;
}) => React.JSX.Element) & {
displayName: string;
}
DefaultInput} state=${props: DropdownProps
props.state: QuickSearchWidgetState
state} />
</div>
<button
...${props: DropdownProps
props.state: QuickSearchWidgetState
state.QuickSearchWidgetState.closeButtonProps: {
type: "button";
onClick: () => void;
onTouchEnd: () => void;
}
closeButtonProps}
className="flex size-[38px] items-center justify-center"
>
<${function CloseIcon(): React.JSX.Element
CloseIcon} />
</button>
</form>`}
<div className="flex">
<div className="flex min-h-0 flex-col">
<div className="px-4 py-4 pb-2 text-sm font-semibold text-[#3bc4a1]">
Segments
</div>
<div className="overflow-auto p-2">
${props: DropdownProps
props.state: QuickSearchWidgetState
state.QuickSearchWidgetState.items: (index: number) => {
key: string;
id: string;
recommId: string;
values: {
[key: string]: any;
};
itemProps: {
onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
"data-search-result-id": string;
tabIndex: number;
};
}[]
items(1).Array<{ key: string; id: string; recommId: string; values: { [key: string]: any; }; itemProps: { onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void; "data-search-result-id": string; tabIndex: number; }; }>.map<React.ReactElement<unknown, string | React.JSXElementConstructor<any>>>(callbackfn: (value: {
key: string;
id: string;
recommId: string;
values: {
[key: string]: any;
};
itemProps: {
onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
"data-search-result-id": string;
tabIndex: number;
};
}, index: number, array: {
key: string;
id: string;
recommId: string;
values: {
[key: string]: any;
};
itemProps: {
onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
"data-search-result-id": string;
tabIndex: number;
};
}[]) => React.ReactElement<...>, thisArg?: any): React.ReactElement<...>[]
Calls a defined callback function on each element of an array, and returns an array that contains the results.map(
(item: {
key: string;
id: string;
recommId: string;
values: {
[key: string]: any;
};
itemProps: {
onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
"data-search-result-id": string;
tabIndex: number;
};
}
item) =>
const html: (strings: TemplateStringsArray, ...values: any[]) => React.ReactElement
html`<a
key=${item: {
key: string;
id: string;
recommId: string;
values: {
[key: string]: any;
};
itemProps: {
onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
"data-search-result-id": string;
tabIndex: number;
};
}
item.key: string
key}
href=${function addRecommIdQueryParam(url: string, recommId: string | undefined): string
Utility function to append `recombee_recomm_id` parameter to an url string.
For usage in widget template to construct item link URL.addRecommIdQueryParam(
`${item: {
key: string;
id: string;
recommId: string;
values: {
[key: string]: any;
};
itemProps: {
onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
"data-search-result-id": string;
tabIndex: number;
};
}
item.values: {
[key: string]: any;
}
values?.__type[string]: any
link}`,
item: {
key: string;
id: string;
recommId: string;
values: {
[key: string]: any;
};
itemProps: {
onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
"data-search-result-id": string;
tabIndex: number;
};
}
item.recommId: string
recommId,
)}
...${item: {
key: string;
id: string;
recommId: string;
values: {
[key: string]: any;
};
itemProps: {
onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
"data-search-result-id": string;
tabIndex: number;
};
}
item.itemProps: {
onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
"data-search-result-id": string;
tabIndex: number;
}
itemProps}
className="flex items-center gap-2 rounded-sm p-2 outline-hidden hover:bg-[#f7f7f7] focus:bg-[#f7f7f7]"
><div className="flex-grow">
<div className="font-semibold">${item: {
key: string;
id: string;
recommId: string;
values: {
[key: string]: any;
};
itemProps: {
onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
"data-search-result-id": string;
tabIndex: number;
};
}
item.id: string
id}</div>
</div></a
>`,
)}
</div>
</div>
<div className="flex min-h-0 flex-grow flex-col">
<div className="px-4 py-4 pb-2 text-sm font-semibold text-[#3bc4a1]">
Results
</div>
<div className="overflow-auto p-2">
${props: DropdownProps
props.state: QuickSearchWidgetState
state
.QuickSearchWidgetState.items: (index: number) => {
key: string;
id: string;
recommId: string;
values: {
[key: string]: any;
};
itemProps: {
onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
"data-search-result-id": string;
tabIndex: number;
};
}[]
items(0)
.Array<{ key: string; id: string; recommId: string; values: { [key: string]: any; }; itemProps: { onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void; "data-search-result-id": string; tabIndex: number; }; }>.map<React.ReactElement<unknown, string | React.JSXElementConstructor<any>>>(callbackfn: (value: {
key: string;
id: string;
recommId: string;
values: {
[key: string]: any;
};
itemProps: {
onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
"data-search-result-id": string;
tabIndex: number;
};
}, index: number, array: {
key: string;
id: string;
recommId: string;
values: {
[key: string]: any;
};
itemProps: {
onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
"data-search-result-id": string;
tabIndex: number;
};
}[]) => React.ReactElement<...>, thisArg?: any): React.ReactElement<...>[]
Calls a defined callback function on each element of an array, and returns an array that contains the results.map(
(item: {
key: string;
id: string;
recommId: string;
values: {
[key: string]: any;
};
itemProps: {
onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
"data-search-result-id": string;
tabIndex: number;
};
}
item) =>
const html: (strings: TemplateStringsArray, ...values: any[]) => React.ReactElement
html`<${const DefaultItem: ((props: DefaultItemProps) => React.JSX.Element) & {
displayName: string;
}
Default Item component provided for basic usage.DefaultItem}
key=${item: {
key: string;
id: string;
recommId: string;
values: {
[key: string]: any;
};
itemProps: {
onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
"data-search-result-id": string;
tabIndex: number;
};
}
item.key: string
key}
href=${function addRecommIdQueryParam(url: string, recommId: string | undefined): string
Utility function to append `recombee_recomm_id` parameter to an url string.
For usage in widget template to construct item link URL.addRecommIdQueryParam(
`${item: {
key: string;
id: string;
recommId: string;
values: {
[key: string]: any;
};
itemProps: {
onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
"data-search-result-id": string;
tabIndex: number;
};
}
item.values: {
[key: string]: any;
}
values?.__type[string]: any
link}`,
item: {
key: string;
id: string;
recommId: string;
values: {
[key: string]: any;
};
itemProps: {
onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
"data-search-result-id": string;
tabIndex: number;
};
}
item.recommId: string
recommId,
)}
primaryContent=${item: {
key: string;
id: string;
recommId: string;
values: {
[key: string]: any;
};
itemProps: {
onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
"data-search-result-id": string;
tabIndex: number;
};
}
item.values: {
[key: string]: any;
}
values?.__type[string]: any
product_title}
secondaryContent=${item: {
key: string;
id: string;
recommId: string;
values: {
[key: string]: any;
};
itemProps: {
onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
"data-search-result-id": string;
tabIndex: number;
};
}
item.values: {
[key: string]: any;
}
values?.__type[string]: any
category}
...${item: {
key: string;
id: string;
recommId: string;
values: {
[key: string]: any;
};
itemProps: {
onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
"data-search-result-id": string;
tabIndex: number;
};
}
item.itemProps: {
onKeyDown: (event: React.KeyboardEvent<HTMLInputElement | HTMLAnchorElement | HTMLDivElement>) => void;
"data-search-result-id": string;
tabIndex: number;
}
itemProps}
/>`,
)}
</div>
</div>
</div>
</div>`,
});
API Reference
DefaultItem
Default Item component provided for basic usage.
DefaultItemProps
Recommended item component properties.
Properties
classNameDisableBase
Disables default classes of item wrapper element.
There are some default class names with essential styles applied to the item wrapper element. This setting disables them as an escape hatch for customization. See Custom CSS.
imageWrapperClassName
Custom classes of item image wrapper element. See Custom CSS.
imageWrapperClassNameDisableBase
Disables default classes of item image wrapper element.
There are some default class names with essential styles applied to the item image wrapper element. This setting disables them as an escape hatch for customization. See Custom CSS.
result
A single item recommedation.
href
Item link URL.
image
Item Image element.
labelContent
Item content above title. Sets the entire content of an item aside from an image.
labelContentWrapperClassName
Custom classes of label content wrapper element. See Custom CSS.
labelContentWrapperClassNameDisableBase
Disables default classes of label content wrapper element.
There are some default class names with essential styles applied to the label content wrapper element. This setting disables them as an escape hatch for customization. See Custom CSS.
title
Item title.
titleWrapperClassNameDisableBase
Disables default classes of title wrapper element.
There are some default class names with essential styles applied to the title wrapper element. This setting disables them as an escape hatch for customization. See Custom CSS.
highlightedContent
Item content under title. Sets the entire content of an item aside from an image.
highlightedContentWrapperClassName
Custom classes of highlighted content wrapper element. See Custom CSS.
highlightedContentWrapperClassNameDisableBase
Disables default classes of highlighted content wrapper element.
There are some default class names with essential styles applied to the highlighted content wrapper element. This setting disables them as an escape hatch for customization. See Custom CSS.
bottomContent
Any custom content to display at the bottom of the item.
QuickSearchWidget
Quick Search widget
QuickSearchWidgetOptions
Quick Search widget options
Properties
container
CSS Selector to target the element where the widget should be inserted.
createRequest
Request factory function. See Quick Example or visit API Reference for overview of available requests.
onRecommResponse
Callback function allowing to intercept and inspect recommendation request+response made by widget.
import React from "react";
import { const CarouselWidget: ({ container, ...props }: CarouselWidgetOptions) => CarouselWidgetState | null | undefined
Carousel Widget initialization functionCarouselWidget } from "@recombee/carousel-widget-js";
function CarouselWidget({ container, ...props }: CarouselWidgetOptions): CarouselWidgetState | null | undefined
Carousel Widget initialization functionCarouselWidget({
// ...ommited code...
WidgetConfigurationBase<CreateRequestFunction>.onRecommResponse?: WidgetRecommResponseCallback | undefined
Callback function allowing to intercept and inspect recommendation
request+response made by widget.
```tsx|-react
import React from "react";
import { CarouselWidget } from "@recombee/carousel-widget-react";
//onRecommResponse: ({ recombeeRequest: Request
recombeeRequest, recombeeResponse: any
recombeeResponse }) => {
// use data from request and response for any purpose, i.e. internal tracking
},
});
initialQuery
minSearchCharactersCount
primaryResultsIndex
InputComponent
TriggerComponent
DropdownComponent
desktopMediaQuery
QuickSearchComponent
QuickSearchWidgetProps
Quick Search component configuration options
Properties
createRequest
Request factory function. See Quick Example or visit API Reference for overview of available requests.
onRecommResponse
Callback function allowing to intercept and inspect recommendation request+response made by widget.
import React from "react";
import { const CarouselWidget: ({ container, ...props }: CarouselWidgetOptions) => CarouselWidgetState | null | undefined
Carousel Widget initialization functionCarouselWidget } from "@recombee/carousel-widget-js";
function CarouselWidget({ container, ...props }: CarouselWidgetOptions): CarouselWidgetState | null | undefined
Carousel Widget initialization functionCarouselWidget({
// ...ommited code...
WidgetConfigurationBase<CreateRequestFunction>.onRecommResponse?: WidgetRecommResponseCallback | undefined
Callback function allowing to intercept and inspect recommendation
request+response made by widget.
```tsx|-react
import React from "react";
import { CarouselWidget } from "@recombee/carousel-widget-react";
//onRecommResponse: ({ recombeeRequest: Request
recombeeRequest, recombeeResponse: any
recombeeResponse }) => {
// use data from request and response for any purpose, i.e. internal tracking
},
});
initialQuery
minSearchCharactersCount
primaryResultsIndex
InputComponent
TriggerComponent
DropdownComponent
desktopMediaQuery
QuickSearchComponent
QuickSearchWidgetState
Class exposing quick search widget state for use in custom templates
Properties
isDesktop
inputRef
triggerRef
dropdownRef
handleInputChange
handleInputClick
inputProps
triggerProps
closeButtonProps
handleInteractionKeyDown
items
isExpanded
isLoading
ItemImage
Item image component
ItemImageProps
Item Image properties
Properties
src
Image URL
missingImageSrc
URL of an image to display when the main image could not be loaded.
className
Image wrapper class name
imgClassName
Image class name
width
Image width in pixels
height
Image height in pixels
verticalAlignment
Image vertical alignment
horizontalAlignment
Image horizontal alignment
fittingAlgorithm
Image fitting algorithm
addRecommIdQueryParam
Utility function to append recombee_recomm_id
parameter to an url string.
For usage in widget template to construct item link URL.