1.0.5 • Published 9 months ago

svelte-light-carousel v1.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

Svelte light carousel

A lightweight carousel component for Svelte focused on low runtime and minimalism.

npm i svelte-light-carousel
pnpm add svelte-light-carousel
yarn add svelte-light-carousel

Usage

<script>
	import Carousel from 'svelte-light-carousel';
	const slides = Array.from({ length: 10 }, (_, i) => ({ title: `${i + 1}` }));
</script>

<Carousel {slides}>
	<div slot="slide" let:slide>{slide.title}</div>
</Carousel>

Features

  • Lightweight, no dependencies < 2kb of JS and < 2kb of Svelte
  • Rely on CSS for layout => no shifting
  • Enough features to cover most basic (e-commerce) use cases
  • 100% headless and customizable
  • Slots for arrows, pagination, progress bar, and dots, so you can build your own UI
  • Rely on CSS native scroll behavior on mobile and mouse wheel on desktop
  • Accessible WAI-ARIA compliant + good semantic structure
  • Preserve trackpad and mouse wheel's native behavior
  • Performant, no complicated calculation, rely on RAF for sliding animations
  • Can show partial view of the next slide
  • Responsive properties: layout, gap, delta and native scroll disabling
  • Snapping and drag free option
  • Auto play with pause on hover option
  • Vertical layout option (with auto height calculation enabled by default, but can be disabled)
  • SSR friendly
  • Disable click on child when dragging
  • Won't crush your lighthouse score at all

Props

NameTypeDefaultDescription
idstringrandomThe base id for the carousel and its accessible properties.
slides$$Generic[][]The slides to be rendered.
withGrabCursorbooleantrueWhether the cursor should change to a grab cursor when hovering over the carousel.
keykeyof SlideundefinedProperty of the slide to use as a key in the eached block.
axis"x""y"xThe axis of the carousel.
dragFreebooleanfalseWhether the carousel should be able to be dragged freely.
disableNativeScrollResponsivePropertyfalseWhether the native scroll should be disabled.
oneAtTimebooleanfalseWhether only one slide should be scrolled at a time.
autoHeightbooleanaxis === "y"Whether the carousel should compute its height itself. This introduce a layout shift when the carousel is loaded.
autoPlaynumber0The number of seconds between each slide. 0 means it's disabled.
layoutResponsiveProperty1The number of slides to be displayed at a given viewport.
gapResponsiveProperty20The gap between slides to be displayed at a given viewport.
partialDeltaResponsiveProperty0The amount of visible pixels of the next slide
classstring""The class of the carousel slider container.
containerClassstring""The class of the carousel container.
slideClassstring""The class of the carousel slide.

Slots

slide

Render the slide inside the carousel.

NameType
slide$$Generic
inViewboolean
indexboolean

prev

Render the previous button.

NameType
canScrollPrevboolean
prev() => void

next

Render the next button.

NameType
canScrollNextboolean
next() => void

pagination

Render the pagination. Useful if you want to group prev and next together.

NameType
canScrollPrevboolean
prevtypeof prev
canScrollNextboolean
nexttypeof next
nextA11yButtonsA11y'a11y'
prevA11yButtonsA11y'a11y'

progress

Render the progress bar indicator.

NameType
progressnumber
scrollTo(e: PointerEvent) => void

dots

Render the dots navigation.

NameType
dots{active: boolean, a11y: DotA11y}[]
scrollTo(index: number) => void
1.0.5

9 months ago

1.0.4

9 months ago

1.0.3

9 months ago

1.0.2

9 months ago

1.0.1

9 months ago

0.0.113

9 months ago

0.0.112

9 months ago

0.0.111

9 months ago

0.0.110

9 months ago

0.0.109

9 months ago

0.0.108

9 months ago

0.0.106

9 months ago

0.0.104

9 months ago

0.0.102

9 months ago

0.0.49

9 months ago

0.0.47

9 months ago

0.0.45

9 months ago

0.0.43

9 months ago

0.0.41

9 months ago

0.0.39

9 months ago

0.0.37

9 months ago

0.0.35

9 months ago

0.0.33

9 months ago

0.0.31

9 months ago

0.0.29

9 months ago

0.0.27

9 months ago

0.0.25

9 months ago

0.0.22

9 months ago

0.0.19

9 months ago

0.0.17

9 months ago

0.0.15

9 months ago

0.0.13

9 months ago

0.0.9

9 months ago

0.0.7

9 months ago