npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

svelte-light-carousel

v1.0.5

Published

A lightweight carousel component for Svelte

Downloads

690

Readme

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

| Name | Type | Default | Description | | ---- | ---- | ------- | ----------- | | id | string | random | The base id for the carousel and its accessible properties. | | slides | $$Generic[] | [] | The slides to be rendered. | | withGrabCursor | boolean | true | Whether the cursor should change to a grab cursor when hovering over the carousel. | | key | keyof Slide | undefined | Property of the slide to use as a key in the eached block. | | axis | "x" | "y" | x | The axis of the carousel. | | dragFree | boolean | false | Whether the carousel should be able to be dragged freely. | | disableNativeScroll | ResponsiveProperty | false | Whether the native scroll should be disabled. | | oneAtTime | boolean | false | Whether only one slide should be scrolled at a time. | | autoHeight | boolean | axis === "y" | Whether the carousel should compute its height itself. This introduce a layout shift when the carousel is loaded. | | autoPlay | number | 0 | The number of seconds between each slide. 0 means it's disabled. | | layout | ResponsiveProperty | 1 | The number of slides to be displayed at a given viewport. | | gap | ResponsiveProperty | 20 | The gap between slides to be displayed at a given viewport. | | partialDelta | ResponsiveProperty | 0 | The amount of visible pixels of the next slide | | class | string | "" | The class of the carousel slider container. | | containerClass | string | "" | The class of the carousel container. | | slideClass | string | "" | The class of the carousel slide. |

Slots

slide

Render the slide inside the carousel.

| Name | Type | | ---- | ---- | | slide | $$Generic | | inView | boolean | | index | boolean |

prev

Render the previous button.

| Name | Type | | ---- | ---- | | canScrollPrev | boolean | | prev | () => void |

next

Render the next button.

| Name | Type | | ---- | ---- | | canScrollNext | boolean | | next | () => void |

pagination

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

| Name | Type | | ---- | ---- | | canScrollPrev | boolean | | prev | typeof prev | | canScrollNext | boolean | | next | typeof next | | nextA11y | ButtonsA11y['a11y'] | | prevA11y | ButtonsA11y['a11y'] |

progress

Render the progress bar indicator.

| Name | Type | | ---- | ---- | | progress | number | | scrollTo | (e: PointerEvent) => void |

dots

Render the dots navigation.

| Name | Type | | ---- | ---- | | dots | {active: boolean, a11y: DotA11y}[] | | scrollTo | (index: number) => void |