instantsearch.widgets.poweredBy({
container: string|HTMLElement,
// Optional parameters
theme: string,
cssClasses: object,
});
About this widget #
The poweredBy widget is used to display the Algolia logo to redirect to our website.
Algolia requires that you use this widget if you are on a Community or Free plan.
Examples #
1
2
3
instantsearch.widgets.poweredBy({
container: '#powered-by',
});
Options #
container
# |
type: string|HTMLElement
Required
The CSS Selector or |
||
|
|
|||
theme
# |
type: string ("light"|"dark")
default: light
Optional
The version of the logo to use, legible on light or dark backgrounds. |
||
|
|
|||
cssClasses
# |
type: object
default: {}
Optional
The CSS classes to override.
|
||
|
Edit
Copy
|
|||
Customize the UI - connectPoweredBy#
If you want to create your own UI of the poweredBy widget, you can use connectors.
It’s a 3-step process:
// 1. Create a render function
const renderPoweredBy = (renderOptions, isFirstRender) => {
// Rendering logic
};
// 2. Create the custom widget
const customPoweredBy = instantsearch.connectors.connectPoweredBy(
renderPoweredBy
);
// 3. Instantiate
search.addWidget(
customPoweredBy({
// instance params
})
);
Create a render function#
This rendering function is called before the first search (init lifecycle step)
and each time results come back from Algolia (render lifecycle step).
const renderPoweredBy = (renderOptions, isFirstRender) => {
const { string url, object widgetParams } = renderOptions;
if (isFirstRender) {
// Do some initial rendering and bind events
}
// Render the widget
}
Rendering options #
url
# |
type: string
The URL to redirect to. |
||
|
Copy |
|||
widgetParams
# |
type: object
All original widget options forwarded to the render function. |
||
|
Copy |
|||
Create and instantiate the custom widget#
We first create custom widgets from our rendering function, then we instantiate them. When doing that, there are two types of parameters you can give:
- Instance parameters: they are predefined parameters that you can use to configure the behavior of Algolia.
- Your own parameters: to make the custom widget generic.
Both instance and custom parameters are available in connector.widgetParams, inside the renderFunction.
const customPoweredBy = instantsearch.connectors.connectPoweredBy(
renderPoweredBy
);
search.addWidget(
customPoweredBy({
// Optional parameters
url: string,
})
);
Instance options #
Full example#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// Create the render function
const renderPoweredBy = (renderOptions, isFirstRender) => {
const { url, widgetParams } = renderOptions;
widgetParams.container.innerHTML = `
<a href="${url}">Powered by Algolia</a>
`;
};
// Create the custom widget
const customPoweredBy = instantsearch.connectors.connectPoweredBy(
renderPoweredBy
);
// Instantiate the custom widget
search.addWidget(
customPoweredBy({
container: document.querySelector('#powered-by'),
})
);
HTML output#
1
2
3
4
5
6
<div class="ais-PoweredBy">
<span class="ais-PoweredBy-text">Search by</span>
<a href="..." class="ais-PoweredBy-link" aria-label="Algolia">
<!-- <svg> ... </svg> -->
</a>
</div>