vic commit
This commit is contained in:
@@ -2,7 +2,7 @@ import React from 'react';
|
||||
|
||||
// Composant Image atomique
|
||||
const Image = ({ src, alt }) => {
|
||||
return <img src={src} alt={alt} />;
|
||||
return <img src={src} alt={alt} style={{ display: 'block', margin: 'auto' }} />;
|
||||
};
|
||||
|
||||
// Composant Description atomique
|
26
src/components/item/ItemGrid.jsx
Normal file
26
src/components/item/ItemGrid.jsx
Normal file
@@ -0,0 +1,26 @@
|
||||
import React from 'react';
|
||||
import { Col, Row } from 'antd';
|
||||
import { ItemBox } from './ItemBox';
|
||||
|
||||
const GridCell = () => (
|
||||
<ItemBox
|
||||
imageUrl="https://www.shutterstock.com/image-vector/default-ui-image-placeholder-wireframes-600nw-1037719192.jpg"
|
||||
brandName="GlubGlub GabGalab"
|
||||
price={666}
|
||||
modelName="Satanus"
|
||||
purchaseDate="-6 avant Marcel PAGNOL"
|
||||
/>
|
||||
);
|
||||
|
||||
export const ItemGrid = () => (
|
||||
<>
|
||||
<Row gutter={16}>
|
||||
<Col span={6}><GridCell /></Col>
|
||||
<Col span={6}><GridCell /></Col>
|
||||
<Col span={6}><GridCell /></Col>
|
||||
<Col span={6}><GridCell /></Col>
|
||||
</Row>
|
||||
</>
|
||||
);
|
||||
|
||||
export default ItemGrid;
|
53
src/components/item/ItemPage.jsx
Normal file
53
src/components/item/ItemPage.jsx
Normal file
@@ -0,0 +1,53 @@
|
||||
import React, { useState } from 'react';
|
||||
import { ItemBox } from './ItemBox'; // Assurez-vous que le chemin d'importation soit correct
|
||||
|
||||
const itemsPerPage = 4; // Nombre total d'items par page
|
||||
const itemsPerRow = 2; // Nombre d'items par rangée
|
||||
|
||||
// Fonction pour diviser le tableau d'items en rangées
|
||||
const chunkArray = (arr, size) => {
|
||||
const chunkedArr = [];
|
||||
for (let i = 0; i < arr.length; i += size) {
|
||||
chunkedArr.push(arr.slice(i, i + size));
|
||||
}
|
||||
return chunkedArr;
|
||||
};
|
||||
|
||||
// Composant d'affichage de la page
|
||||
export const ItemPage = ({ items }) => {
|
||||
const [currentPage, setCurrentPage] = useState(1);
|
||||
|
||||
const handleNextPage = () => {
|
||||
setCurrentPage(prevPage => prevPage + 1);
|
||||
};
|
||||
|
||||
const handlePrevPage = () => {
|
||||
setCurrentPage(prevPage => prevPage - 1);
|
||||
};
|
||||
|
||||
// Divise les items en rangées
|
||||
const chunkedItems = chunkArray(items, itemsPerRow);
|
||||
// Calcule l'index de la première et de la dernière rangée à afficher sur la page courante
|
||||
const startIndex = (currentPage - 1) * (itemsPerPage / itemsPerRow);
|
||||
const endIndex = startIndex + (itemsPerPage / itemsPerRow);
|
||||
// Sélectionne les rangées à afficher sur la page courante
|
||||
const rowsToDisplay = chunkedItems.slice(startIndex, endIndex);
|
||||
|
||||
return (
|
||||
<div>
|
||||
{rowsToDisplay.map((row, index) => (
|
||||
<div key={index} className="item-row">
|
||||
{row.map(item => (
|
||||
<ItemBox key={item.id} {...item} />
|
||||
))}
|
||||
</div>
|
||||
))}
|
||||
<div className="pagination">
|
||||
<button onClick={handlePrevPage} disabled={currentPage === 1}>Previous</button>
|
||||
<span>Page {currentPage}</span>
|
||||
<button onClick={handleNextPage} disabled={endIndex >= chunkedItems.length}>Next</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
Reference in New Issue
Block a user