-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e27a182
commit b91dc2e
Showing
39 changed files
with
1,439 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import React, { FC } from "react"; | ||
import { BodyLoadingPros } from "../type"; | ||
|
||
const BodyLoading: FC<BodyLoadingPros> = ({ columns, limit }) => { | ||
const generateRows = () => { | ||
const rows = []; | ||
|
||
for (let i = 0; i < limit; i++) { | ||
rows.push( | ||
<tr key={i}> | ||
{columns.map((column) => ( | ||
<td key={column.name}> | ||
<div className="skeleton h-5 w-20"></div> | ||
</td> | ||
))} | ||
</tr> | ||
); | ||
} | ||
|
||
return rows; | ||
}; | ||
|
||
return <tbody>{generateRows()}</tbody>; | ||
}; | ||
|
||
export default BodyLoading; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import React, { FC } from "react"; | ||
import { BodyProps } from "../type"; | ||
import { Column } from "@/services/types"; | ||
import classNames from "classnames"; | ||
|
||
const Body: FC<BodyProps> = ({ data, columns, actions, showFooter }) => { | ||
const renderCellContent = (column: Column<any>, row: any) => { | ||
return <>{column.filed(row)}</>; | ||
}; | ||
|
||
const renderCell = (column: Column<any>, row: any, index: number) => { | ||
const style = | ||
column.styled && typeof column.styled === "function" | ||
? column.styled(row) | ||
: column.styled || {}; | ||
|
||
return ( | ||
<td | ||
className={ | ||
column.classes && typeof column.classes === "function" | ||
? column.classes(row) | ||
: column.classes || "" | ||
} | ||
style={style} | ||
key={index} | ||
> | ||
{renderCellContent(column, row)} | ||
</td> | ||
); | ||
}; | ||
|
||
const renderRow = (row: any, rowIndex: number) => ( | ||
<tr key={rowIndex} className="hover"> | ||
{columns.map((column, columnIndex) => | ||
renderCell(column, row, columnIndex) | ||
)} | ||
{actions && actions.length && ( | ||
<th className="flex items-center justify-center"> | ||
{actions.map((action) => ( | ||
<button | ||
key={action.name} | ||
className="ml-2" | ||
onClick={() => action.handler(row)} | ||
> | ||
{action.icon} | ||
</button> | ||
))} | ||
</th> | ||
)} | ||
</tr> | ||
); | ||
|
||
return ( | ||
<> | ||
<tbody>{data.map((row, rowIndex) => renderRow(row, rowIndex))}</tbody> | ||
{showFooter && ( | ||
<tfoot> | ||
<tr> | ||
{columns.map((column) => ( | ||
<th key={column.name}>{column.label}</th> | ||
))} | ||
</tr> | ||
</tfoot> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export default Body; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { FC } from "react"; | ||
import Pagination from "./pagination"; | ||
import { FooterProps } from "../type"; | ||
|
||
const Footer: FC<FooterProps> = ({ | ||
limit, | ||
handleLimitChange, | ||
totalPages, | ||
page, | ||
handleChangeParams, | ||
}) => { | ||
return ( | ||
<> | ||
<div className="flex items-center justify-between mt-4"> | ||
{!!totalPages && ( | ||
<div className="mx-2"> | ||
<label className="mr-2">Rows per page:</label> | ||
<select | ||
value={limit} | ||
onChange={(e) => handleLimitChange(Number(e.target.value))} | ||
className="px-2 py-1 border border-gray-500 rounded" | ||
> | ||
{[10, 20, 30, 40, 50].map((size) => ( | ||
<option key={size} value={size}> | ||
{size} | ||
</option> | ||
))} | ||
</select> | ||
</div> | ||
)} | ||
<div className="flex items-center"> | ||
{totalPages !== undefined && ( | ||
<> | ||
<Pagination | ||
totalPages={totalPages} | ||
page={page} | ||
handlePageChange={handleChangeParams} | ||
/> | ||
</> | ||
)} | ||
</div> | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
export default Footer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { FC } from "react"; | ||
import { HeaderProps } from "../type"; | ||
|
||
const Header: FC<HeaderProps> = ({ | ||
columns, | ||
handleSortChange, | ||
sortBy, | ||
sortOrder, | ||
actions, | ||
}) => { | ||
return ( | ||
<> | ||
<thead> | ||
<tr> | ||
{columns.map((column) => ( | ||
<th key={column.name}> | ||
{column.label} | ||
{sortBy === column.name && ( | ||
<span | ||
onClick={() => handleSortChange(column.name)} | ||
className="cursor-pointer" | ||
> | ||
{sortOrder === "asc" ? " ▲" : " ▼"} | ||
</span> | ||
)} | ||
<span | ||
onClick={() => handleSortChange(column.name)} | ||
className="cursor-pointer" | ||
> | ||
{sortBy !== column.name && " ▲"} | ||
</span> | ||
</th> | ||
))} | ||
{actions && actions.length > 0 && ( | ||
<th className="text-center">Actions</th> | ||
)} | ||
</tr> | ||
</thead> | ||
</> | ||
); | ||
}; | ||
|
||
export default Header; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { FC } from "react"; | ||
import { PaginationProps } from "../type"; | ||
|
||
const Pagination: FC<PaginationProps> = ({ | ||
totalPages, | ||
page, | ||
handlePageChange, | ||
}) => { | ||
const buttons = []; | ||
const maxButtons = 5; | ||
const startPage = Math.max(1, page - Math.floor(maxButtons / 2)); | ||
|
||
const pageChang = (newPage: number) => { | ||
handlePageChange({ | ||
page: newPage, | ||
}); | ||
}; | ||
|
||
const addEllipsis = (key: string, onClick: any) => { | ||
buttons.push( | ||
<span key={key} className="join-item btn btn-square" onClick={onClick}> | ||
... | ||
</span> | ||
); | ||
}; | ||
|
||
if (startPage > 1) { | ||
buttons.push( | ||
<button | ||
key="first" | ||
onClick={() => pageChang(1)} | ||
className={`join-item btn btn-square ${ | ||
1 === Number(page) ? "btn-active" : "" | ||
}`} | ||
> | ||
1 | ||
</button> | ||
); | ||
if (startPage > 2) { | ||
addEllipsis("firstEllipsis", () => pageChang(startPage - maxButtons)); | ||
} | ||
} | ||
|
||
for ( | ||
let i = 0; | ||
i < maxButtons && | ||
startPage + i <= Math.min(totalPages, startPage + maxButtons - 1); | ||
i++ | ||
) { | ||
const pageNumber = startPage + i; | ||
buttons.push( | ||
<button | ||
key={pageNumber} | ||
onClick={() => pageChang(pageNumber)} | ||
className={`join-item btn btn-square ${ | ||
pageNumber === Number(page) ? "btn-active" : "" | ||
}`} | ||
> | ||
{pageNumber} | ||
</button> | ||
); | ||
} | ||
|
||
if (startPage + maxButtons - 1 < totalPages) { | ||
if (startPage + maxButtons < totalPages) { | ||
addEllipsis("lastEllipsis", () => pageChang(startPage + maxButtons)); | ||
} | ||
buttons.push( | ||
<button | ||
key="last" | ||
onClick={() => pageChang(totalPages)} | ||
className={`join-item btn btn-square ${ | ||
totalPages === Number(page) ? "btn-active" : "" | ||
}`} | ||
> | ||
{totalPages} | ||
</button> | ||
); | ||
} | ||
|
||
return <div className="join">{buttons}</div>; | ||
}; | ||
|
||
export default Pagination; |
Oops, something went wrong.