A responsive, touch-enabled carousel component for React with Next.js support
npm install kedo-react-carousel




A responsive, touch-enabled carousel component for React with Next.js support and comprehensive test coverage.
- ๐ฑ Responsive Design - Adapts to different screen sizes
- ๐ Touch/Swipe Support - Mobile-friendly touch gestures
- โก Next.js Compatible - SSR support out of the box
- ๐ฏ Auto Play - Optional automatic slide progression
- ๐จ Customizable - Custom navigation buttons and dots
- ๐งช Well Tested - 80%+ test coverage
- ๐ฆ Lightweight - Minimal dependencies
- โฟ Accessible - ARIA compliant
Our carousel component is thoroughly tested with comprehensive unit tests:
| Metric | Coverage |
|--------|----------|
| Statements | 85%+ |
| Branches | 80%+ |
| Functions | 90%+ |
| Lines | 85%+ |
``bash`
npm install kedo-react-carousel
`jsx
import React from 'react';
import Carousel from 'kedo-react-carousel';
function App() {
return (
Slide 1
Slide 2
Slide 3
);
}
`
`jsx
import React from 'react';
import Carousel from 'kedo-react-carousel';
function App() {
const handleSlideChange = (slideIndex, direction) => {
console.log(Moved to slide ${slideIndex} via ${direction});
};
return (
slidesToScroll={1}
autoPlay={true}
autoPlayTimer={3000}
pauseOnHover={true}
showDots={true}
responsive={[
{
breakpoint: 768,
settings: {
slidesToShow: 2,
slidesToScroll: 1
}
},
{
breakpoint: 480,
settings: {
slidesToShow: 1,
slidesToScroll: 1
}
}
]}
onSlideChange={handleSlideChange}
>
๐ง Props
| Prop | Type | Default | Description |
|------|------|---------|-------------|
|
children | ReactNode | - | Slides content |
| slidesToShow | number | 1 | Number of slides to show |
| slidesToScroll | number | 1 | Number of slides to scroll |
| autoPlay | boolean | false | Enable auto play |
| autoPlayTimer | number | 1000 | Auto play interval (ms) |
| pauseOnHover | boolean | false | Pause auto play on hover |
| showDots | boolean | false | Show navigation dots |
| responsive | ResponsiveSettings[] | [] | Responsive breakpoints |
| nextButton | ReactElement | - | Custom next button |
| prevButton | ReactElement | - | Custom prev button |
| dotComponent | ComponentType | - | Custom dot component |
| onSlideChange | function | - | Slide change callback |๐งช Testing
Run the test suite:
`bash
Run all tests
npm testRun tests with coverage
npm run test:coverageRun tests in CI mode
npm run test:ciGenerate test report
npm run test:report
`$3
Our test suite covers:
- โ
Component Rendering - Ensures all components render correctly
- โ
Navigation Logic - Tests next/prev button functionality
- โ
Auto Play - Validates automatic slide progression
- โ
Touch/Swipe - Tests mobile touch interactions
- โ
Responsive Behavior - Validates breakpoint handling
- โ
Custom Components - Tests custom button and dot components
- โ
Edge Cases - Handles empty slides, single slides, etc.
- โ
Cleanup - Ensures proper cleanup of timers and listeners
๐ Quality Metrics
- Test Coverage: 85%+ overall coverage
- Code Quality: ESLint compliant
- Performance: Optimized for minimal re-renders
- Accessibility: ARIA compliant navigation
- Browser Support: Modern browsers + IE11
๐ CI/CD Pipeline
Our package includes automated testing and publishing:
$3
1. Test Workflow (
.github/workflows/test.yml)
- Runs on Node.js 16.x, 18.x, 20.x
- Executes full test suite
- Generates coverage reports
- Uploads to Codecov
- Comments coverage on PRs2. Publish Workflow (
.github/workflows/publish.yml)
- Triggers on GitHub releases
- Runs tests before publishing
- Publishes to NPM automatically
- Updates release with publish status$3
1. Add NPM Token: Add
NPM_TOKEN to GitHub repository secrets
2. Enable Codecov: Connect your repository to Codecov
3. Configure Badges: Update badge URLs in README๐ค Contributing
1. Fork the repository
2. Create your feature branch (
git checkout -b feature/amazing-feature)
3. Write tests for your changes
4. Ensure tests pass (npm test)
5. Commit your changes (git commit -m 'Add amazing feature')
6. Push to the branch (git push origin feature/amazing-feature)
7. Open a Pull Request$3
`bash
Clone the repository
git clone https://github.com/ppuneet64/kedo-react-carousel.gitInstall dependencies
npm installRun tests
npm testBuild the package
npm run buildRun example
npm run dev
``This project is licensed under the MIT License - see the LICENSE file for details.
- React team for the amazing framework
- Testing Library for excellent testing utilities
- All contributors who help improve this package
---
Made with โค๏ธ by Puneet Pandey