update src/components/Testt/index.js

master
mahdi 2 years ago
parent f5fb40dc07
commit 26ab2153e2
  1. 60
      src/components/Testt/App.css
  2. 92
      src/components/Testt/index.js

@ -0,0 +1,60 @@
.App {
text-align: center;
}
.App-header {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 1.5vmin);
}
.App-link {
color: #61dafb;
}
@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
.characters {
list-style: none;
padding-left: 0;
}
.characters li {
display: flex;
align-items: center;
border: solid 2px #d0d0d0;
border-radius: 0.2em;
padding: 0.5em 0.8em 0.5em 0.5em;
margin-bottom: 1em;
}
.characters p {
max-width: none;
font-weight: bold;
margin: 0;
}
.characters-thumb {
overflow: hidden;
flex-shrink: 0;
width: 2em;
height: 2em;
background-color: #e8e8e8;
padding: 0.5em;
margin-right: 0.5em;
}
.characters-thumb img {
display: block;
width: 100%;
height: auto;
}

@ -0,0 +1,92 @@
import React, { useState } from "react";
import { DragDropContext, Droppable, Draggable } from "react-beautiful-dnd";
import "./App.css";
const finalSpaceCharacters = [
{
id: "gary",
name: "Gary Goodspeed",
thumb: "/images/gary.png",
},
{
id: "cato",
name: "Little Cato",
thumb: "/images/cato.png",
},
{
id: "kvn",
name: "KVN",
thumb: "/images/kvn.png",
},
{
id: "mooncake",
name: "Mooncake",
thumb: "/images/mooncake.png",
},
{
id: "quinn",
name: "Quinn Ergon",
thumb: "/images/quinn.png",
},
];
function Testt() {
const [characters, updateCharacters] = useState(finalSpaceCharacters);
function handleOnDragEnd(result) {
if (!result.destination) return;
const items = Array.from(characters);
const [reorderedItem] = items.splice(result.source.index, 1);
items.splice(result.destination.index, 0, reorderedItem);
updateCharacters(items);
}
return (
<div className="App">
<header className="App-header">
<h1>Final Space Characters</h1>
<DragDropContext onDragEnd={handleOnDragEnd}>
<Droppable droppableId="characters">
{(provided) => (
<ul
className="characters"
{...provided.droppableProps}
ref={provided.innerRef}
>
{characters.map(({ id, name, thumb }, index) => {
return (
<Draggable key={id} draggableId={id} index={index}>
{(provided) => (
<li
ref={provided.innerRef}
{...provided.draggableProps}
{...provided.dragHandleProps}
>
<div className="characters-thumb">
<img src={thumb} alt={`${name} Thumb`} />
</div>
<p>{name}</p>
</li>
)}
</Draggable>
);
})}
{provided.placeholder}
</ul>
)}
</Droppable>
</DragDropContext>
</header>
<p>
Images from{" "}
<a href="https://final-space.fandom.com/wiki/Final_Space_Wiki">
Final Space Wiki
</a>
</p>
</div>
);
}
export default Testt;
Loading…
Cancel
Save