@@ -5,25 +5,15 @@ import { motion } from "framer-motion";
5
5
6
6
const MotionBox = motion ( Box as any ) ;
7
7
8
+ const numBoxes = 100 ;
9
+ const indentations = Array . from ( { length : numBoxes } , ( _ , i ) => i * 100 ) ;
10
+
8
11
const ChakraBoxes = ( ) => {
9
- const [ numBoxes , setNumBoxes ] = useState ( 100 ) ; // Default number of boxes
10
- const [ indentations , setIndentations ] = useState ( Array . from ( { length : numBoxes } , ( _ , i ) => i * 100 ) ) ; // Initial indentations
11
12
const [ highlightedIndex , setHighlightedIndex ] = useState ( null ) ; // Index of the box in the center
12
13
const [ offset , setOffset ] = useState ( 0 ) ;
13
14
const boxRefs = useRef ( [ ] ) ; // Ref array to hold references to each box
14
15
const canvasRef = useRef ( ) ;
15
16
16
- // Function to handle number of boxes change
17
- const handleNumBoxesChange = ( e ) => {
18
- const value = parseInt ( e . target . value ) || 0 ;
19
- setNumBoxes ( value ) ;
20
-
21
- // Update the indentation array when number of boxes changes
22
- setIndentations (
23
- Array . from ( { length : value } , ( _ , i ) => i * 100 ) // Example: indentation increases by 10px per box
24
- ) ;
25
- } ;
26
-
27
17
const calculateClosestBoxToCenter = ( ) => {
28
18
if ( ! canvasRef . current ) {
29
19
return ;
@@ -64,13 +54,6 @@ const ChakraBoxes = () => {
64
54
65
55
return (
66
56
< Box overflowX = { 'hidden' } >
67
- < Input
68
- type = "number"
69
- value = { numBoxes }
70
- onChange = { handleNumBoxesChange }
71
- placeholder = "Enter number of boxes"
72
- width = "200px"
73
- />
74
57
< MotionBox
75
58
ref = { canvasRef }
76
59
animate = { { marginLeft : `${ - offset } px` } } // Animation on margin change
0 commit comments