Cleaned up, extracted List to a component
This commit is contained in:
parent
423dadec0b
commit
76fb43b9d6
File diff suppressed because one or more lines are too long
@ -2,7 +2,7 @@ import "./App.css";
|
|||||||
import Playground from "./components/Playground";
|
import Playground from "./components/Playground";
|
||||||
import Logo from "./components/Logo";
|
import Logo from "./components/Logo";
|
||||||
import Workplace from "./components/Workplace";
|
import Workplace from "./components/Workplace";
|
||||||
|
// <Playground title="👨🏻💻" />
|
||||||
function App() {
|
function App() {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@ -11,7 +11,7 @@ function App() {
|
|||||||
<Logo />
|
<Logo />
|
||||||
</header>
|
</header>
|
||||||
<h1>Guillotine-cutter App</h1>
|
<h1>Guillotine-cutter App</h1>
|
||||||
<Playground title="👨🏻💻" />
|
|
||||||
<Workplace />
|
<Workplace />
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
|
10
src/components/List.js
Normal file
10
src/components/List.js
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
export default function List(props) {
|
||||||
|
const rectangles = props.rectangles;
|
||||||
|
const listItems = rectangles.map((rectangle) => (
|
||||||
|
<li>
|
||||||
|
{rectangle.w} x {rectangle.h}
|
||||||
|
</li>
|
||||||
|
));
|
||||||
|
|
||||||
|
return <> {listItems}</>;
|
||||||
|
}
|
@ -1,18 +1,24 @@
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
|
import List from "./List";
|
||||||
|
|
||||||
export default function Workplace() {
|
export default function Workplace() {
|
||||||
let figurki = [{ w: "100px", h: "100px", c: "red" }];
|
|
||||||
const [width, setWidth] = useState("");
|
const [width, setWidth] = useState("");
|
||||||
const [height, setHeight] = useState("");
|
const [height, setHeight] = useState("");
|
||||||
|
const [rectangleArray, setRectangleArray] = useState("");
|
||||||
|
|
||||||
const handleSubmit = (evt) => {
|
const numbers = [{ w: "100px", h: "100px", c: "red" }];
|
||||||
evt.preventDefault();
|
numbers.push({ w: "200px", h: "300px", c: "cyan" });
|
||||||
figurki.push({ w: width + "px", h: height + "px", c: "blue" });
|
|
||||||
console.log(figurki);
|
const handleFormSubmit = (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
numbers.push({ w: width + "px", h: height + "px", c: "blue" });
|
||||||
|
console.log(numbers);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<form onSubmit={handleSubmit}>
|
<br />
|
||||||
|
<form onSubmit={handleFormSubmit}>
|
||||||
<label>
|
<label>
|
||||||
Dimensions:
|
Dimensions:
|
||||||
<input
|
<input
|
||||||
@ -28,15 +34,7 @@ export default function Workplace() {
|
|||||||
</label>
|
</label>
|
||||||
<input type="submit" value="Submit" />
|
<input type="submit" value="Submit" />
|
||||||
</form>
|
</form>
|
||||||
<ul>
|
<List rectangles={rectangles} />
|
||||||
{figurki.map((figurka, index) => {
|
|
||||||
return (
|
|
||||||
<li key={index}>
|
|
||||||
{figurka.w} x {figurka.h}
|
|
||||||
</li>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</ul>
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user