Skip to content

Commit 48c7597

Browse files
committed
minor tweaks
1 parent 0104a02 commit 48c7597

7 files changed

Lines changed: 41 additions & 35 deletions

File tree

README.md

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
Stacked card carousal component with configurable 3D transition effect.
44

5-
# Getting started
5+
## Demo
66

7-
## Install
7+
<img src="./demo/card-carousel.gif" width="300" />
88

9-
Install react-card-stack-carousel from NPM
9+
## Getting started
10+
11+
#### Install react-card-stack-carousel from NPM
1012

1113
```sh
1214
npm i react-card-stack-carousel
@@ -16,47 +18,39 @@ npm i react-card-stack-carousel
1618
yarn add react-card-stack-carousel
1719
```
1820

19-
## Import react-card-stack-carousel styles
21+
#### Import react-card-stack-carousel styles
2022

2123
```tsx
2224
// import base styles at the top of your component
2325
import "react-card-stack-carousel/dist/styles.css";
2426
```
2527

26-
# Usage
28+
## Usage
2729

2830
> NOTE: StackedCarousel requires a _height_ property to be specified
2931
3032
```tsx
3133
import React from "react";
3234
import { StackedCarousel } from "react-card-stack-carousel";
33-
34-
import "react-card-stack-carousel/dist/styles.css";
35+
import "react-card-stack-carousel/dist/styles.css"; // import base styles
3536

3637
export default function App() {
37-
const cardWidth = 500;
38-
const cardHeight = 500;
38+
// specify container height
39+
const containerHeight = 500;
3940

40-
const cardStyles = { width: cardWidth, height: cardHeight };
4141
return (
4242
<main className="container">
43-
<StackedCarousel height={cardHeight}>
44-
<div className="sample-card bg-color-1" style={cardStyles}>
45-
0
46-
</div>
47-
<div className="sample-card bg-color-2" style={cardStyles}>
48-
1
49-
</div>
50-
<div className="sample-card bg-color-3" style={cardStyles}>
51-
2
52-
</div>
43+
<StackedCarousel height={containerHeight}>
44+
<div className="sample-card bg-color-1">0</div>
45+
<div className="sample-card bg-color-2">1</div>
46+
<div className="sample-card bg-color-3">2</div>
5347
</StackedCarousel>
5448
</main>
5549
);
5650
}
5751
```
5852

59-
# Props
53+
## Props
6054

6155
| Prop | Type | Default | Required | Description |
6256
| ----------------------- | --------- | ------------------------------------ | -------- | ------------------------------------------------- |
@@ -74,7 +68,7 @@ export default function App() {
7468
| `transitionDuration` | number | 400 | No | Duration of the transitions in milliseconds. |
7569
| `verticalOffset` | number | 10 | No | % vertical offset for the carousel items. |
7670

77-
# Running locally
71+
## Running locally
7872

7973
1. Clone the repo and install the dependencies. In the repo's root, run
8074

@@ -99,7 +93,7 @@ cd ./playground
9993
yarn dev
10094
```
10195

102-
# Todo
96+
## Todo
10397

104-
[ ] Auto compute the container height based on height of the active card
105-
[ ] Plugin system to enable custom transition styles
98+
- [ ] Auto compute the container height based on height of the active card
99+
- [ ] Plugin system to enable custom transition styles

demo/card-carousel.gif

314 KB
Loading

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
{
22
"name": "react-card-stack-carousel",
3-
"version": "1.0.0",
3+
"version": "0.1.0",
44
"description": "A carousel component for React",
55
"main": "index.js",
66
"scripts": {
77
"dev": "vite ./playground"
88
},
99
"keywords": [
1010
"react",
11-
"carousel"
11+
"carousel",
12+
"image-carousel",
13+
"card-stack"
1214
],
1315
"include": [
1416
"src/**/*",
17+
"dist/**/*",
1518
"types/**/*"
1619
],
1720
"types": "types/index.d.ts",

playground/App.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import { StackedCarousel } from "react-card-stack-carousel";
33
import "react-card-stack-carousel/dist/styles.css";
44

55
export default function App() {
6-
const cardWidth = 500;
7-
const cardHeight = 500;
6+
const cardWidth = 200;
7+
const cardHeight = 200;
88

99
const cardStyles = { width: cardWidth, height: cardHeight };
10+
1011
return (
1112
<main className="container">
1213
<StackedCarousel autoplay={false} height={cardHeight}>

playground/styles.css

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,24 @@ body {
2323
}
2424

2525
.bg-color-1 {
26-
background-color: red;
26+
background-color: #eb2f06;
2727
}
2828

2929
.bg-color-2 {
30-
background-color: blue;
30+
background-color: #fa983a;
3131
}
3232

3333
.bg-color-3 {
34-
background-color: green;
34+
background-color: #079992;
3535
}
3636

3737
.bg-color-4 {
38-
background-color: violet;
38+
background-color: #1e3799;
39+
}
40+
41+
.card-image {
42+
width: auto;
43+
height: 500px;
44+
border-radius: 8px;
45+
border: 1px solid #e5e7eb;
3946
}

src/styles.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
display: flex;
1717
justify-content: center;
1818
z-index: 10;
19+
background-color: #1f2937;
1920
}
2021

2122
.rcsc-nav-icon {

src/useCardStackCarousel.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const DIRECTION = { None: 0, Next: 1, Previous: 2 };
66
const DEFAULT_AUTOPLAY = false;
77
const DEFAULT_AUTOPLAY_INTERVAL = 4000;
88
const DEFAULT_EASING_FUNCTION = "cubic-bezier(0.93, 0.01, 0.39, 1.01)";
9-
const DEFAULT_TRANSITION_DURATION = 400;
9+
const DEFAULT_TRANSITION_DURATION = 450;
1010
const DEFAULT_START_INDEX = 0;
1111
const DEFAULT_VERTICAL_OFFSET = 10;
1212
const DEFAULT_SCALE_FACTOR = 0.9;
@@ -104,7 +104,7 @@ export const useCardStackCarousel = (config) => {
104104
// reset the delay during transition setup for immediate effect
105105
delay = 0;
106106
if (virtualIndex === totalCount - 1) {
107-
tY = `-${75 + totalCount * 2}%`;
107+
tY = `-${72}%`;
108108
opacity = 0.6;
109109
rotateX = 65;
110110
} else {

0 commit comments

Comments
 (0)