New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

swipe-simple

Package Overview
Dependencies
Maintainers
0
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

swipe-simple

This is a lightweight library for creating a swiper in your project.

latest
npmnpm
Version
1.0.1
Version published
Weekly downloads
2
-33.33%
Maintainers
0
Weekly downloads
 
Created
Source

Swiper React Library

It's a customizable React component that allows you to create a swipeable, interactive carousel. This component supports navigation buttons, loop functionality, and reverse transitions.

Installation

To install in your React project, run:

npm install swiper-react

or if you are using Yarn:

yarn add swiper-react

Usage

Basic Usage

Here is a simple example of using the Swiper component in your React application:

import React from "react";
import { Swiper, SwiperSlide } from "swiper-react";

const App = () => {
  return (
    <Swiper>
      <SwiperSlide>Slide 1</SwiperSlide>
      <SwiperSlide>Slide 2</SwiperSlide>
      <SwiperSlide>Slide 3</SwiperSlide>
    </Swiper>
  );
};

export default App;

Configuration Options

Swiper accepts several props that allow you to customize its behavior.

Props for Swiper

PropTypeDefault ValueDescription
childrenReact.ReactNodeN/AThe slides to display inside the swiper.
defaultIndexnumber0The initial slide index.
allowLoopbooleantrueDetermines whether looping between the first and last slides is allowed.
classNamestring""Custom class name for the container element.
onActiveIndexChange(index: number) => voidCallback function to be triggered when the active slide index changes.
showNavigationbooleantrueShow or hide the navigation buttons (previous and next).
activeIndexnumberControlled active slide index. If provided, overrides defaultIndex.
enableLogsbooleantrueEnable or disable console logging for slide changes.
prevButton(props: { prevSlid: () => void; index: number; slideTo: (index: number) => void }) => React.ReactNodeCustom previous button renderer.
nextButton(props: { nextSlid: () => void; index: number; slideTo: (index: number) => void }) => React.ReactNodeCustom next button renderer.
showDisabledButtonsbooleantrueDetermines whether to show the navigation buttons when they are disabled.

Props for SwiperSlide

PropTypeDefault ValueDescription
childrenReact.ReactNodeN/AThe content of the slide.

Methods

The Swiper component exposes several methods that can be accessed via ref:

MethodDescription
nextSlideProgrammatically moves to the next slide.
prevSlideProgrammatically moves to the previous slide.
slideToProgrammatically slides to a specific index.
getActiveIndexReturns the current active slide index.

Example with Custom Navigation Buttons

You can customize the navigation buttons by passing your own components to the prevButton and nextButton props.

import React from "react";
import { Swiper, SwiperSlide } from "swiper-react";

const App = () => {
  return (
    <Swiper
      prevButton={({ prevSlid }) => (
        <button onClick={prevSlid}>Custom Prev</button>
      )}
      nextButton={({ nextSlid }) => (
        <button onClick={nextSlid}>Custom Next</button>
      )}
    >
      <SwiperSlide>Slide 1</SwiperSlide>
      <SwiperSlide>Slide 2</SwiperSlide>
      <SwiperSlide>Slide 3</SwiperSlide>
    </Swiper>
  );
};

export default App;

Example with Looping and Logs

This example demonstrates how you can enable looping and view logs for slide changes.

import React from "react";
import { Swiper, SwiperSlide } from "swiper-react";

const App = () => {
  return (
    <Swiper
      allowLoop={true}
      enableLogs={true}
      onActiveIndexChange={(index) => console.log(`Active index: ${index}`)}
    >
      <SwiperSlide>Slide 1</SwiperSlide>
      <SwiperSlide>Slide 2</SwiperSlide>
      <SwiperSlide>Slide 3</SwiperSlide>
    </Swiper>
  );
};

export default App;

CSS Customization

.swiper-container {
  width: 100%;
  height: 100%;
}

.swiper-wrapper {
  display: flex;
  transition: transform 0.3s ease-in-out;
}

.swiper-slide {
  width: 100%;
  flex-shrink: 0;
}

Conclusion

The Swiper React component provides a flexible and customizable way to implement a swipeable carousel in your React application. You can configure it with features such as looped navigation, custom buttons, and console logs to help with debugging or enhance the user experience.

For more details on customization, refer to the source code or consult the React documentation.

Keywords

swiper

FAQs

Package last updated on 10 Mar 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts