This commit is contained in:
Philippe Torrel
2026-10-23 10:41:47 +02:00
parent 62b63ff196
commit 7489f4288c
16 changed files with 10144 additions and 18 deletions
File diff suppressed because it is too large Load Diff
+8 -2
View File
@@ -1,12 +1,18 @@
import Badge from './components/Badge';
import ProductList from './components/ProductList';
function App() {
return (
<main>
<div className="container py-5">
<h1>Badges</h1>
{/* <Badge text="Neu" variant="success" />
<Badge text="Neu" variant="success" />
<Badge text="Oh oh" variant="danger" />
<Badge text="new idea" variant="info" />
<Badge text="Rabatt" variant="warning" /> */}
<Badge text="Rabatt" variant="warning" />
<br />
<h2>Product List</h2>
<ProductList />
</div>
</main>
);
@@ -0,0 +1,7 @@
const Badge = (props) => {
const { text = '', variant = 'secondary' } = props;
return <span className={`badge text-bg-${variant} m-1`}>{text}</span>;
};
export default Badge;
@@ -9,6 +9,10 @@ const ProductList = (props) => {
<ProductListItem title="Product 2" price={20}>
Ipsum lorem
</ProductListItem>
<ProductListItem title="Product 2">Ipsum lorem</ProductListItem>
<ProductListItem title="Product 2" price={20}>
Ipsum lorem
</ProductListItem>
</ul>
);
};
@@ -1,6 +1,8 @@
// Übung 5: Erweiterung der ProductListItem-Komponente
// Passe die ProductListItem-Komponente wie folgt an:
import Badge from './Badge';
// Erweitere die ProductListItem-Komponente um ein weiteres Prop namens description, so dass der Produktbeschreibungstext entweder über das description-Prop oder als Kind-Komponente übergeben werden kann.
// Verwende das description-Prop, um den Beschreibungstext anzuzeigen, wenn er übergeben wird.
@@ -8,8 +10,20 @@
// Erweitere die Komponente um eine optionale Prop namens price, um den Preis des Produkts übergeben und anzuzeigen.
const ProductListItem = (props) => {
// const { } = props;
const { title, children, description, price = 0 } = props;
return <></>;
return (
<li className="list-group-item list-item-product">
<h3>{title}</h3>
<p>{children || description}</p>
{price ? (
<span className="price">
<strong>Price:</strong> <Badge text={price.toFixed(2)} variant="dark" />
</span>
) : (
''
)}
</li>
);
};
export default ProductListItem;