A reusable React component that lets users drag and resize a box from all 8 directions. Built with TypeScript and styled using Tailwind CSS.
- β Fully draggable
- β Resizable from all sides and corners
- β Customizable dimensions and positions
- β Clean and reusable component
- β No external dependencies (besides React)
- β Written in TypeScript
A resizable and draggable React component...
components/ βββ ResizableDraggableBox.tsx pages/ βββ index.tsx (example usage)
import ResizableDraggableBox from "@/components/ResizableDraggableBox";
export default function Home() {
return (
<ResizableDraggableBox
initialWidth={400}
initialHeight={300}
initialTop={100}
initialLeft={150}
minWidth={100}
minHeight={100}
>
<p>This is a draggable and resizable box!</p>
</ResizableDraggableBox>
);
}
## π§± Installation
This component is self-contained. Just copy the `ResizableDraggableBox.tsx` file into your React project:
```bash
/components
βββ ResizableDraggableBox.tsx
---
### 2. Make sure Tailwind CSS is installed
This component uses Tailwind CSS utility classes.
If Tailwind is not already installed in your project, you can follow the official installation guide here:
π [Tailwind CSS Installation Guide](https://tailwindcss.com/docs/installation)
Quick install:
```bash
npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p
// tailwind.config.js
module.exports = {
content: ["./src/**/*.{js,ts,jsx,tsx}"], // adjust path to your project
theme: {
extend: {},
},
plugins: [],
};
/* globals.css */
@tailwind base;
@tailwind components;
@tailwind utilities;
---
Let me know if you'd like the `ResizableDraggableBox.tsx` source code included **in the README** itself (as a full inline code block), or if you want a version formatted for publishing on npm.