Card-flick is a type of card swipe user interface that allows users to interact with a stack of cards by flicking them left or right. This UI element is commonly used in mobile applications and websites to provide a more intuitive and engaging user experi
npm install card-flick-react


Card Flick React is a React component that allows you to add a card swiping effect to your web application.
To install Card Flick React, simply run the following command in your terminal:
``bash`
npm install card-flick-react
or
`bash`
yarn add card-flick-react
To use Card Flick React:
1. Import the CardFlick component from the package.
2. Pass an array of cards to the CardFlick component.
3. Define callback functions to handle the swiping effect.
4. Render the CardFlick component in your React component.
`jsx
import React from 'react'
import CardFlick from 'card-flick-react'
const cards = [
{ id: 1, content: 'Card 1' },
{ id: 2, content: 'Card 2' },
{ id: 3, content: 'Card 3' },
]
function MyComponent() {
const handleSwipeRight = (cardIndex) => {
console.log(Swiped right on cardIndex with ID ${cardIndex})
}
const handleSwipeLeft = (cardIndex) => {
console.log(Swiped left on cardIndex with ID ${cardIndex})
}
const handleSwipe = (cardIndex) => {
console.log(Swiped on cardIndex with ID ${cardIndex})
}
return (
cards={cards}
onSwipeRight={handleSwipeRight}
onSwipeLeft={handleSwipeLeft}
onSwipe={handleSwipe}
/>
)
}
`
In this example, we define an array of cards and pass it to the CardFlick component. We also define three callback functions: handleSwipeRight, handleSwipeLeft, and handleSwipe, which are called when the user swipes right, left, or either direction on a card, respectively.
The CardFlick component renders the cards and handles the swiping effect. By default, cards are swiped by dragging them with the mouse or touch gestures.
`css
.cardContainer {
width: 160px;
height: 270px;
margin: 100px auto;
box-shadow: 0px 0px 74px -31px rgba(0, 0, 0, 0.6);
-webkit-box-shadow: 0px 0px 74px -31px rgba(0, 0, 0, 0.6);
-moz-box-shadow: 0px 0px 74px -31px rgba(0, 0, 0, 0.6);
}
.card {
/ background-color: aqua; /
height: 100%;
}
.card img {
width: 100%;
height: 100%;
}
`
The CardFlick component accepts the following props:
An array of objects representing the cards to be displayed. Each object should have a unique id property and a content property, which can be any valid React element or string.
`jsx
const cards = [
{ id: 1, content: 'Card 1' },
{ id: 2, content: 'Card 2' },
{ id: 3, content: 'Card 3' },
]
...
`
The content property can also be a React element, such as a div or a component.
` Some content Some content Some contentjsx`
const cards = [
{
id: 1,
content: (
Card 1
),
},
{
id: 2,
content: (
Card 2
),
},
{
id: 3,
content: (
Card 3
),
},
]
A callback function called when the user swipes right on a card. The function is passed the card object as an argument.
`jsxSwiped right on card with ID ${card.id}
const handleSwipeRight = (card) => {
console.log()
}
...
`
A callback function called when the user swipes left on a card. The function is passed the card object as an argument.
`jsxSwiped left on card with ID ${card.id}
const handleSwipeLeft = (card) => {
console.log()
}
...
`
A callback function called when the user swipes either direction on a card. The function is passed the card object as an argument.
`jsxSwiped on card with ID ${card.id}
const handleSwipe = (card) => {
console.log()
}
...
``
If you find a bug or want to suggest a new feature, feel free to open an issue on the GitHub repository. Pull requests are also welcome.
Card-Flick is open-source software licensed under the MIT license. See the LICENSE file for more details.
