# react-card-swiper

> A Tinder Like - Card Swiper

Latest version **1.1.25** (published 2024-02-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-card-swiper
pnpm add react-card-swiper
yarn add react-card-swiper
bun add react-card-swiper
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.25 |
| Published | 2024-02-14 |
| First published | 2023-11-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 71 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 17 |
| Author | Nativ Sibony |
| Maintainers | nativsibony |
| Keywords | react, swiper, card, tinder, card swiper, react swiper, tinder swiper, react card swiper, tinder card swiper, react-card-swiper |

## Links

- npm: https://www.npmjs.com/package/react-card-swiper
- Repository: https://github.com/nativsibony/react-card-swiper
- Homepage: https://react-card-swiper.netlify.app/
- Issues: https://github.com/nativsibony/react-card-swiper/issues
- npm.io page: https://npm.io/package/react-card-swiper

## Dependencies (2)

- [react](https://npm.io/package/react.md) ^18.2.0
- [react-dom](https://npm.io/package/react-dom.md) ^18.2.0

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.1.25 (latest) — 2024-02-14
- 1.1.24 — 2024-02-14
- 1.1.23 — 2024-02-06
- 1.1.22 — 2024-01-28
- 1.1.20 — 2023-12-21
- 1.1.19 — 2023-12-20
- 1.1.18 — 2023-12-20
- 1.1.17 — 2023-12-20
- 1.1.16 — 2023-12-20
- 1.1.15 — 2023-12-20
- 1.1.14 — 2023-12-19
- 1.1.13 — 2023-12-18
- 1.1.12 — 2023-12-18
- 1.1.11 — 2023-12-18
- 1.1.10 — 2023-12-18
- … 30 more at https://npm.io/package/react-card-swiper/versions

## README

## <h1 align="center">react-card-swiper</h1>

<h3>A Tinder Like Card Swiper</h6>

[![npm package](https://img.shields.io/npm/v/react-card-swiper/latest.svg)](https://www.npmjs.com/package/react-card-swiper)
[![npm downloads](https://img.shields.io/npm/dm/react-card-swiper.svg)](https://www.npmjs.com/package/react-card-swiper)

## <img src="https://i.ibb.co/StTp25Y/Screenshot-2023-12-20-at-10-00-58.png" alt="demo" />

**[Demo](https://react-card-swiper.netlify.app/)**

## 📦 Installation

```shell
  npm i --save react-card-swiper
```

---

## 🔗 Props

- `data`: Card Data Array of Objects
- `onDismiss`: Card Event of Card Dismiss
- `onEnter`: Card Event of Card Enter
- `onFinish`: When All Cards Have Been Dismissed
- `dislikeButton`: your custom react dislike button
- `likeButton`: your custom react like button
- `withActionButtons`: with action buttons flag - if set to true, both like and dislike buttons must be passed as props, otherwise the default one's will appear
- `emptyState`: your custom empty state when all cards have been dismissed

| parameter         | type                                   | default | required | description                                         |
| ----------------- | -------------------------------------- | ------- | -------- | --------------------------------------------------- |
| data              | CardData[]                             |         | true     | data to be passed to the card                       |
| onDismiss         | CardEvent                              |         | false    | When card is dismissed by swipe or by click         |
| onEnter           | CardEnterEvent                         |         | false    | When new card is entered                            |
| onFinish          | (status: SwipeAction.FINISHED) => void |         | false    | onFinish event                                      |
| dislikeButton     | React.JSX.Element                      |         | false    | your custom dislike button                          |
| likeButton        | React.JSX.Element                      |         | false    | your custom like button                             |
| withActionButtons | Boolean                                | false   | false    | with action buttons flag                            |
| withRibbons       | Boolean                                | false   | false    | with ribbons flag                                   |
| likeRibbonText    | Boolean                                | LIKE    | false    | ribbon like text                                    |
| dislikeRibbonText | Boolean                                | PASS    | false    | ribbon dislike text                                 |
| ribbonColors      | CardRibbonColors                       |         | false    | ribbon background & text colors                     |
| emptyState        | React.JSX.Element                      |         | false    | will be rendered when all cards have been dismissed |

---

## 🔨 Usage

```tsx
import { Stack, Typography } from '@mui/material'

import bubbleShooter from '@/assets/images/bubble-shooter.png'
import candyCrash from '@/assets/images/candy-crash.png'
import clashRoyal from '@/assets/images/clash-royal.jpg'
import EmptyState from '@/assets/images/empty-state.svg'

import { CardData, CardEvent, CardSwiper } from 'react-card-swiper'

const Content = () => (
  <Typography px={2} variant="h6">
    Lorem ipsum dolor sit amet.
  </Typography>
)

const mockData: CardData[] = [
  { id: '88552078', meta: { apk: 'some-apk-a.apk' }, src: bubbleShooter, content: <Content /> },
  { id: 'fc7e0bd4', meta: { apk: 'some-apk-b.apk' }, src: candyCrash, content: <Content /> },
  { id: 'da9a7067', meta: { apk: 'some-apk-c.apk' }, src: clashRoyal, content: <Content /> },
]

export default function SwipeSelectionPage() {
  const handleDismiss: CardEvent = (el, meta, id, action, operation) => {
    console.log({ el, meta, id, action, operation }) // event data to be handled
  }

  const handleFinish = (status: string) => {
    console.log(status) // 'finished'
  }

  const handleEnter: CardEnterEvent = (el, meta, id) => {
    console.log(el, meta, id)
  }

  return (
    <Stack height={'100%'} width={'100%'} direction="column" alignItems="center" justifyContent={'end'} p={2}>
      <CardSwiper
        data={mockData}
        onEnter={handleEnter}
        onFinish={handleFinish}
        onDismiss={handleDismiss}
        dislikeButton={<div>Left</div>}
        likeButton={<div>Right</div>}
        withActionButtons
        withRibbons
        likeRibbonText="INSTALL"
        dislikeRibbonText="PASS"
        ribbonColors={{ bgLike: 'green', bgDislike: 'red', textColor: 'white' }}
        emptyState={
          <Stack direction={'column'} alignItems={'center'} justifyContent={'center'} textAlign={'center'} gap={2}>
            <Box component={'img'} width={250} src={EmptyState} />
            <Typography variant={'subtitle2'}>
              You've reached the <br /> end of the list
            </Typography>
          </Stack>
        }
      />
    </Stack>
  )
}
```

---
_Source: https://npm.io/package/react-card-swiper · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
