I'll create a file tree editor using React, Framer Motion, and shadcn/ui components. This component will allow you to add, remove, rename, and reorder folders and files using drag and drop functionality.
Here's the implementation:
file-tree-editor.tsx
This component creates a file tree editor with the following features:
The component uses Framer Motion's Reorder
component to handle the drag and drop functionality. The file tree structure is managed using a nested array of objects, where each object represents a file or folder.
To use this component, you'll need to install the following dependencies:
npm install framer-motion lucide-react
Make sure you have the shadcn/ui components (Button
and Input
) set up in your project as well.
You can further customize the styling and behavior of this component to fit your specific needs. Let me know if you want any modifications or have any questions!
I'll modify the component to have all folders open by default and adjust the animation to prevent unwanted scaling. Here's the updated version:
file-tree-editor.tsx
Here are the key changes I've made to address your requirements:
Open all folders by default:
useEffect
hook that runs once when the component mounts. It collects all folder IDs using the getAllFolderIds
function and sets them as expanded in the expandedFolders
state.Prevent unwanted scaling during animations:
Reorder.Item
and its children to use spring animations with custom stiffness and damping values. This provides a smoother animation without scaling effects.layout
prop is now applied to the motion.div
that wraps the item content, which helps maintain the layout during animations.AnimatePresence
component to handle the appearance and disappearance of folder contents when expanding or collapsing.Smoother animations:
layoutTransition
prop is added to the Reorder.Item
to ensure smooth transitions when items are reordered.These changes should result in a file tree editor where all folders are initially expanded, and the animations are smoother without unwanted scaling effects. The drag-and-drop functionality remains intact, and you can still collapse and expand folders as needed.
Let me know if you want any further adjustments or have any questions about the implementation!