Skip to content

Commit cfa56ed

Browse files
committed
Simplify boxes experiment
1 parent 7246e49 commit cfa56ed

File tree

1 file changed

+3
-20
lines changed

1 file changed

+3
-20
lines changed

example/components/chakra-boxes.tsx

+3-20
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,15 @@ import { motion } from "framer-motion";
55

66
const MotionBox = motion(Box as any);
77

8+
const numBoxes = 100;
9+
const indentations = Array.from({ length: numBoxes }, (_, i) => i * 100);
10+
811
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
1112
const [highlightedIndex, setHighlightedIndex] = useState(null); // Index of the box in the center
1213
const [offset, setOffset] = useState(0);
1314
const boxRefs = useRef([]); // Ref array to hold references to each box
1415
const canvasRef = useRef();
1516

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-
2717
const calculateClosestBoxToCenter = () => {
2818
if (!canvasRef.current) {
2919
return;
@@ -64,13 +54,6 @@ const ChakraBoxes = () => {
6454

6555
return (
6656
<Box overflowX={'hidden'}>
67-
<Input
68-
type="number"
69-
value={numBoxes}
70-
onChange={handleNumBoxesChange}
71-
placeholder="Enter number of boxes"
72-
width="200px"
73-
/>
7457
<MotionBox
7558
ref={canvasRef}
7659
animate={{ marginLeft: `${-offset}px` }} // Animation on margin change

0 commit comments

Comments
 (0)