Horizontal slider UI component for JavaScript.
yarn add @algolia/ui-components-horizontal-slider-js
# or
npm install @algolia/ui-components-horizontal-slider-js
To get started, you need a container for your slider to go in. If you don’t have one already, you can insert one into your markup:
<div id="horizontal-slider"></div>
Then, you can call the horizontalSlider
function and provide the container. It can be a CSS selector or an Element.
import { horizontalSlider } from '@algolia/ui-components-horizontal-slider-js';
import '@algolia/ui-components-horizontal-slider-theme';
const items = [
{ objectID: '1', name: 'Item 1' },
{ objectID: '2', name: 'Item 2' },
];
horizontalSlider({
container: '#horizontal-slider',
items,
itemComponent({ item }) {
return item.name;
},
});
See usage for Recommend.
string | HTMLElement
The container for the component. You can either pass a CSS selector or an Element. If there are several containers matching the selector, it picks up the first one.
When undefined
, the function returns a JSX element for you to inject wherever you want.
RecordWithObjectID
| requiredtype RecordWithObjectID<TItem> = TItem & { objectID: string; };
The items to display in the component.
({ item }) => JSX.Element
| required
The item component to display.
HorizontalSliderTranslations
type HorizontalSliderTranslations = Partial<{ sliderLabel: string; previousButtonLabel: string; previousButtonTitle: string; nextButtonLabel: string; nextButtonTitle: string; }>;
The translations for the component.
HorizontalSliderClassnames
type HorizontalSliderClassnames = Partial<{ item: string; list: string; navigation: string; navigationNext: string; navigationPrevious: string; root: string; }>;
The class names for the component.
typeof window
| defaults towindow
The environment in which your application is running.
This is useful if you’re using the slider in a different context than window.