Skip to content

Commit 449da30

Browse files
committed
2-DR2-TP2.09
1 parent 5852225 commit 449da30

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

2-desenvolvimento-front-end/DR2-fundamentos-de-react/DR2-TP2.00-biblioteca-crud/src/App.jsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,16 @@ function App() {
1515
setLivros([...livros, novoLivro]);
1616
};
1717

18+
const removerLivro = (index) => {
19+
setLivros(livros.filter((_, i) => i !== index));
20+
};
21+
1822
return (
1923
<>
2024
<Header />
2125
<main>
2226
<BookForm onAddBook={adicionarLivro} />
23-
<BookList livros={livros} />
27+
<BookList livros={livros} onRemoveBook={removerLivro} />
2428
</main>
2529
</>
2630
)

2-desenvolvimento-front-end/DR2-fundamentos-de-react/DR2-TP2.00-biblioteca-crud/src/components/booklist/index.jsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import "./styles.css";
22

3-
export default function BookList({ livros }) {
3+
export default function BookList({ livros, onRemoveBook }) {
44
return (
55
<table>
66
<thead>
77
<tr>
88
<th>Título</th>
99
<th>Autor</th>
1010
<th>Ano</th>
11+
<th></th>
1112
</tr>
1213
</thead>
1314
<tbody>
@@ -16,6 +17,14 @@ export default function BookList({ livros }) {
1617
<td>{livro.titulo}</td>
1718
<td>{livro.autor}</td>
1819
<td>{livro.ano}</td>
20+
<td>
21+
<button
22+
className="btn-excluir"
23+
onClick={() => onRemoveBook(index)}
24+
>
25+
Excluir
26+
</button>
27+
</td>
1928
</tr>
2029
))}
2130
</tbody>

2-desenvolvimento-front-end/DR2-fundamentos-de-react/DR2-TP2.00-biblioteca-crud/src/components/booklist/styles.css

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ table {
2020

2121
&:last-child {
2222
border-radius: 0 6px 6px 0;
23+
width: 0;
24+
white-space: nowrap;
2325
}
2426
}
2527
}
@@ -44,7 +46,24 @@ table {
4446

4547
&:last-child {
4648
border-radius: 0 6px 6px 0;
49+
width: 0;
50+
white-space: nowrap;
4751
}
4852
}
4953
}
5054
}
55+
56+
.btn-excluir {
57+
background-color: #a84848;
58+
color: #f8f4f0;
59+
border: none;
60+
padding: 8px 16px;
61+
border-radius: 4px;
62+
cursor: pointer;
63+
font-size: 14px;
64+
font-weight: 500;
65+
66+
&:hover {
67+
background-color: #c05555;
68+
}
69+
}

0 commit comments

Comments
 (0)