From 6a8460037a5588f3ef8481c0b91a150ec4fee1cf Mon Sep 17 00:00:00 2001 From: pstachula Date: Mon, 15 Jul 2024 20:43:49 +0200 Subject: [PATCH] feat: update examples --- package.json | 16 ++-- src/App.tsx | 88 ++++++++----------- src/examples/singleStep.tsx | 70 +++++++++++++++ .../components/Carousel.tsx | 5 -- 4 files changed, 115 insertions(+), 64 deletions(-) create mode 100644 src/examples/singleStep.tsx diff --git a/package.json b/package.json index 9ae0635..97ebf19 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "author": "Paweł Stachula", "license": "MIT", "homepage": "https://simple-headless-carousel.onrender.com/", - "version": "0.0.16", + "version": "0.0.17", "sideEffects": false, "description": "React simple headless carousel", "keywords": [ @@ -38,7 +38,9 @@ "build:css": "NODE_ENV=production tailwindcss -o dist/styles.min.css -m", "build:npm": "npm run build:lib && LIB_MODE=lib npm run build:css" }, - "files": ["/dist"], + "files": [ + "/dist" + ], "main": "dist/simple-headless-carousel.umd.cjs", "module": "dist/simple-headless-carousel.js", "types": "dist/index.d.ts", @@ -55,25 +57,25 @@ "react-dom": "16.x || 17.x || 18.x" }, "devDependencies": { + "@testing-library/jest-dom": "^6.4.2", + "@testing-library/react": "^13.2.0", + "@testing-library/user-event": "^14.5.2", "@types/node": "^20.14.3", "@types/react": "^18.2.66", "@types/react-dom": "^18.2.22", "@typescript-eslint/eslint-plugin": "^7.2.0", "@typescript-eslint/parser": "^7.2.0", "@vitejs/plugin-react": "^4.2.1", + "@vitest/ui": "latest", "autoprefixer": "^10.4.19", "eslint": "^8.57.0", - "@testing-library/jest-dom": "^6.4.2", - "@testing-library/react": "^13.2.0", - "@testing-library/user-event": "^14.5.2", - "@vitest/ui": "latest", - "jsdom": "^24.0.0", "eslint-config-airbnb": "^19.0.4", "eslint-config-airbnb-typescript": "^18.0.0", "eslint-config-prettier": "^9.1.0", "eslint-plugin-react": "^7.33.2", "eslint-plugin-react-hooks": "^4.6.0", "eslint-plugin-react-refresh": "^0.4.6", + "jsdom": "^24.0.0", "postcss": "^8.4.38", "prettier": "^3.0.3", "prettier-plugin-tailwindcss": "^0.5.14", diff --git a/src/App.tsx b/src/App.tsx index 6397921..64df347 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,62 +1,46 @@ -import { - Carousel, - CarouselProvider, - Counter, - DotsGroup, - NextButton, - PrevButton, - Slide, -} from './lib/simple-headless-carousel'; +import { ExampleCarousel } from './examples/singleStep'; function App() { return ( -
+

React Simple Headless Carousel Demo

- - - - - - - - - - - - - - - - - - +
+

Basic example

+ +
+            
+              {`
+
+  
+    
+      
+    
+    
+      
+    
+    
+      
+    
+    
+      
+    
+    
+      
+    
+  
 
-          
- -
- -
- Counter: - -
-
- - Prev - - - Next - -
-
+ + + Prev + Next +`} +
+
+
); diff --git a/src/examples/singleStep.tsx b/src/examples/singleStep.tsx new file mode 100644 index 0000000..7c62a92 --- /dev/null +++ b/src/examples/singleStep.tsx @@ -0,0 +1,70 @@ +import { + CarouselProvider, + Carousel, + Slide, + DotsGroup, + Counter, + PrevButton, + NextButton, + type CarouselState, +} from '../lib/simple-headless-carousel'; + +export const ExampleCarousel = ({ + autoPlayDelay, + autoPlay, + slidesVisible, + infinite, + step, + disableTouch, + lazy, + threshold, + currentIndex, +}: Partial) => { + return ( +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ +
+ Counter: + +
+
+ Prev + Next +
+
+
+ ); +}; diff --git a/src/lib/simple-headless-carousel/components/Carousel.tsx b/src/lib/simple-headless-carousel/components/Carousel.tsx index 2e8c91d..b0d331f 100644 --- a/src/lib/simple-headless-carousel/components/Carousel.tsx +++ b/src/lib/simple-headless-carousel/components/Carousel.tsx @@ -61,9 +61,6 @@ export const Carousel = memo( }; const setCurrentIndex = useCallback( - - - (value: number) => { dispatch({ action: 'setCurrentIndex', value }); }, @@ -72,8 +69,6 @@ export const Carousel = memo( const setTranslateX = useCallback( (diffX: number) => { - // diffX = X% - // fullSize = 100%(fullSize) animationRef.current = requestAnimationFrame(() => { const percentX = (diffX * fullSize) / width / total;