poweredBy
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 only use your free usage credits, or are on a Community or Free legacy plan.
Examples
1
2
3
instantsearch.widgets.poweredBy({
container: '#powered-by',
});
Options
container
|
type: string|HTMLElement
Required
The CSS Selector or |
||
Copy
|
|||
theme
|
type: string ("light"|"dark")
default: light
Optional
The version of the logo to use, legible on light or dark backgrounds. |
||
Copy
|
|||
cssClasses
|
type: object
default: {}
Optional
The CSS classes to override.
|
||
Copy
|
HTML output
1
2
3
4
5
<div class="ais-PoweredBy ais-PoweredBy--light">
<a href="..." target="_blank" class="ais-PoweredBy-link" aria-label="Search by Algolia" rel="noopener noreferrer">
<!-- <svg> ... </svg> -->
</a>
</div>
Customize the UI with 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.addWidgets([
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.addWidgets([
customPoweredBy({
// Optional parameters
url: string,
})
]);
Instance options
url
|
type: string
default: https://algolia.com
Optional
The URL to redirect to. |
||
Copy
|
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.addWidgets([
customPoweredBy({
container: document.querySelector('#powered-by'),
})
]);