@ashbuk/spark-slider
v1.0.3
Published
Lightweight, fast, and accessible React carousel slider component powered by Framer Motion. Framework-agnostic with full TypeScript support, drag gestures, keyboard navigation, and auto-play. Works with Next.js, Vite, Remix, and any React framework.
Maintainers
Readme
Spark Slider
Lightweight and fast React carousel slider powered by Framer Motion animations
Try the live demo: spark-slider.vercel.app
Project repo: github.com/AshBuk/framer-motion-spark-slider
Lightweight React carousel built with Framer Motion. Framework-agnostic by default (renders with <img>), with an escape hatch to inject next/image. Designed as a modern and highly optimized solution for large image datasets, it works seamlessly across laptops, tablets, and phones.
Features
- Smooth drag-to-swipe with momentum-free, precise control
- Click on center card to select (single tap on touch)
- Auto-play with pause on interaction and hidden tab detection
- Responsive layout using viewport units (
svh/svmin) - Keyboard navigation (arrow keys)
- Accessibility features with ARIA support
- Performance: renders only visible cards, lazy loading for non-center images
- Framework-agnostic: works with Next.js, Vite, Create React App, Remix, Gatsby, and any React framework
✦ Installation
npm install @ashbuk/spark-slider
# or
yarn add @ashbuk/spark-slider
# or
pnpm add @ashbuk/spark-sliderPeer dependencies (install separately if not already in your project):
npm install framer-motion react react-domRequirements: React 18+, Framer Motion 12+
✦ Usage
import { SparkSlider, SLIDER_CONFIG } from '@ashbuk/spark-slider';
import '@ashbuk/spark-slider/dist/spark-slider.css';
export default function Example() {
const images = [
'https://picsum.photos/id/1015/1600/1200',
'https://picsum.photos/id/1016/1600/1200',
'https://picsum.photos/id/1018/1600/1200',
];
return (
<SparkSlider
images={images}
alt='Image'
autoPlayInterval={SLIDER_CONFIG.DEFAULT_AUTOPLAY_INTERVAL_MS}
className='[--spark-slider-h:60svh]'
/>
);
}API Reference
Note: Public API is annotated with TSDoc. Most editors will show inline documentation on hover.
SparkSlider Props
| Prop | Type | Description |
| -------------------- | ----------------------------------- | ---------------------------------- |
| images | string[] | Array of image URLs or paths |
| alt? | string | Alt text for images |
| autoPlayInterval? | number | Auto-play interval in milliseconds |
| className? | string | CSS classes for container |
| cardClassName? | string | CSS classes for each card wrapper |
| renderImage? | (src, alt, isCenter) => ReactNode | Custom image renderer |
| onSlideSelect? | (index: number) => void | Called when slide is selected |
| onSelectionChange? | (index: number) => void | Called when selection changes |
Package Breakdown
Component:
SparkSlider– Main slider componentSLIDER_CONFIG– Configuration constants and defaultsuseSparkSlider– Core slider state management hookuseSparkKeyboard– Keyboard navigation hookuseSparkTransforms– Card positioning and transforms hookuseSparkFullscreen– Fullscreen overlay management hookcomputeSwipeTarget– Swipe gesture calculation utilityCardPosition– TypeScript type for card positions
Styling
- Ships with a prebuilt stylesheet:
@ashbuk/spark-slider/dist/spark-slider.css(import required) - Height can be set via CSS var
--spark-slider-husing svh units - Custom styling via
classNameandcardClassNameprops
Development (monorepo)
- This package is developed inside a Next.js demo app. In dev, the package sources under
packages/spark-slider/src/sparkare a symbolic link to the app sourcessrc/components/SparkSlider/*to avoid duplication. - The app imports by package name and Next is configured with
transpilePackages: ['@ashbuk/spark-slider']for hot reload. - Build locally:
npm -w packages/spark-slider run buildSupport
- GitHub Issues: Report bugs or request features
- Contributions welcome! See CONTRIBUTING.md
License
MIT — see LICENSE
