-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdndkit.sh
More file actions
66 lines (52 loc) · 1.85 KB
/
dndkit.sh
File metadata and controls
66 lines (52 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
# This script will create a new React app called dndkit-demo, install the necessary dependencies for React DnDKit, create the App component file, update the index.js file to render the App
component, and start the development server. To run the script, save it to a file (e.g., dndkit.sh), make it executable (chmod +x dndkit.sh), and then run it (./dndkit.sh).
# Install Node.js and create a new React app
curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -
sudo apt-get install -y nodejs
npx create-react-app dndkit-demo
cd dndkit-demo
# Install React DnDKit dependencies
npm install react @dnd-kit/core @dnd-kit/sortable @dnd-kit/utilities
# Create the App component file
cat <<EOF > src/App.js
import React, { useState } from 'react';
import { DndContext, DragOverlay } from '@dnd-kit/core';
import { useSortable } from '@dnd-kit/sortable';
import { CSS } from '@dnd-kit/utilities';
const items = ['Item 1', 'Item 2', 'Item 3'];
function SortableItem({ id, children }) {
const { attributes, listeners, setNodeRef, transform, transition } = useSortable({
id,
});
const style = {
transform: CSS.Transform.toString(transform),
transition,
};
return (
<div ref={setNodeRef} style={style} {...attributes} {...listeners}>
{children}
</div>
);
}
function App() {
const [activeId, setActiveId] = useState(null);
return (
<DndContext onDragStart={event => setActiveId(event.active.id)}>
{items.map((item, index) => (
<SortableItem key={item} id={item}>
{item}
</SortableItem>
))}
<DragOverlay>
{activeId ? <div>{activeId}</div> : null}
</DragOverlay>
</DndContext>
);
}
export default App;
EOF
# Update the index.js file to render the App component
sed -i 's/<App \/>/<App \/><\/React.StrictMode>/g' src/index.js
# Start the development server
npm start