@algolia/ui-components-horizontal-slider-js

Horizontal slider UI component.

Usage no npm install needed!

<script type="module">
  import algoliaUiComponentsHorizontalSliderJs from 'https://cdn.skypack.dev/@algolia/ui-components-horizontal-slider-js';
</script>

README

@algolia/ui-components-horizontal-slider-js

Horizontal slider UI component for JavaScript.

Installation

yarn add @algolia/ui-components-horizontal-slider-js
# or
npm install @algolia/ui-components-horizontal-slider-js

Usage

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, insert your slider into it by calling the horizontalSlider function and providing 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;
  },
});

Params

container

string | HTMLElement

The container for the horizontal slider. You can either pass a CSS selector or an Element.

items

RecordWithObjectID | required
type RecordWithObjectID<TItem> = TItem & {
  objectID: string;
};

The items to display in the component.

itemComponent

({ item }) => JSX.Element | required

The item component to display.

translations

HorizontalSliderTranslations
type HorizontalSliderTranslations = Partial<{
  sliderLabel: string;
  previousButtonLabel: string;
  previousButtonTitle: string;
  nextButtonLabel: string;
  nextButtonTitle: string;
}>;

The translations for the component.

classNames

HorizontalSliderClassnames
type HorizontalSliderClassnames = Partial<{
  item: string;
  list: string;
  navigation: string;
  navigationNext: string;
  navigationPrevious: string;
  root: string;
}>;

The class names for the component.

environment

typeof window | defaults to window

The environment in which your application is running.

This is useful if you’re using the slider in a different context than window.