1.0.0 • Published 3 months ago

slider-controller v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
3 months ago

Slider Controller

The SliderController is a custom web component built using the LitElement library. It provides a slider functionality for a collection of SlideItem elements.

Installation

You can install the SliderController using npm.

npm install slider-controller

Then, you need to import the SliderController and SlideItem in your project.

import "slider-controller"
import "slide-item"

Usage

To use the SliderController, you need to include it in your HTML as a custom element. The SlideItem elements should be nested inside the SliderController.

<slider-controller>
  <slide-item>Slide 1</slide-item>
  <slide-item>Slide 2</slide-item>
  <slide-item>Slide 3</slide-item>
  <!-- Add more slide items as needed -->
</slider-controller>

Each SlideItem represents a single slide in the slider. You can put any content inside a SlideItem.

The SliderController automatically handles the scrolling behavior of the slides. It also emits custom events SLIDER_SCROLLING and SLIDER_SCROLLING_DONE which you can listen to for custom behavior.

Methods

MethodTypeDescription
next()methodSlides to next slide-item
previous()methodSlides to previous slide-item

Getters

MethodTypeDescription
currentIndexgetterGets the current index of the active slider
totalItemsgetterGets the total number of slide-items
hasPreviousgetterIs there a previous slide-item? Good for disabling buttons fx.
hasNextgetterIs there a next slide-item? Good for disabling buttons fx.

Event Listeners

EventTypeDescription
SLIDER_SCROLLINGeventFires on each DOM scroll event
SLIDER_SCROLLING_DONEeventFires after scroll is done

Cleanup

The SliderController automatically cleans up its event listeners when it is disconnected from the DOM. You don't need to manually remove the event listeners.

Note

The SliderController uses a debounced scroll and resize event to improve performance. The debounce delay is currently set to 300ms.

Styling

The SliderController component uses CSS variables for some of its styles, which you can override in your own CSS. Here's how you can do it:

  1. --slider-controller-gap: This variable controls the gap between the slides. You can set it to any valid CSS length value. For example, to set the gap to 20px, you would do:
slider-controller {
  --slider-controller-gap: 20px;
}
  1. --slider-controller-item-size: This variable controls the size of the slides. You can set it to any valid CSS length value. The default is auto meaning that the items retain their natural size. For example, to set the size to 200px, you would do:
slider-controller {
  --slider-controller-item-size: 200px;
}

Note that these variables should be set on the slider-controller element itself, not on the :host selector inside the slider-controller's CSS.

In addition to these variables, you can also apply any other CSS styles to the slider-controller element as you would with any other HTML element. However, keep in mind that due to the Shadow DOM, styles applied outside the slider-controller will not affect the internal elements of the slider-controller (like the .container div). If you need to style these internal elements, you would need to modify the slider-controller.css.ts file directly.

1.0.0

3 months ago

0.1.2

5 months ago

0.1.1

7 months ago

0.1.0

7 months ago