parent
b6d5b45650
commit
f339133245
@ -0,0 +1,22 @@
|
||||
import React from 'react';
|
||||
|
||||
interface TableHeaderProps {
|
||||
columns: any[];
|
||||
}
|
||||
interface TableHeaderProps {
|
||||
columns: any[];
|
||||
}
|
||||
const TableHeader = ({ columns }: TableHeaderProps) => {
|
||||
return (
|
||||
<tr>
|
||||
{columns.map((column: any, index: number) => {
|
||||
return (
|
||||
<th key={index}>
|
||||
<span className="cell-span">{column.title}</span>
|
||||
</th>
|
||||
);
|
||||
})}
|
||||
</tr>
|
||||
);
|
||||
};
|
||||
export default React.memo(TableHeader);
|
||||
@ -0,0 +1,33 @@
|
||||
.simple-table {
|
||||
table-layout: auto;
|
||||
width: 100%;
|
||||
text-align: left;
|
||||
|
||||
&.simple-table-bordered {
|
||||
border-collapse: collapse;
|
||||
border-spacing: 0;
|
||||
|
||||
td {
|
||||
border-bottom: 1px solid rgba(255, 255, 255, 10%);
|
||||
}
|
||||
|
||||
th {
|
||||
border-bottom: 1px solid rgba(255, 255, 255, 10%);
|
||||
}
|
||||
|
||||
tr:last-child td {
|
||||
border-bottom: none;
|
||||
}
|
||||
}
|
||||
|
||||
th {
|
||||
height: 36px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.cell-span {
|
||||
display: flex;
|
||||
padding: 4px 6px;
|
||||
min-height: 32px;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,38 @@
|
||||
import classNames from 'classnames';
|
||||
import React from 'react';
|
||||
import SimpleBar from 'simplebar-react';
|
||||
import 'simplebar-react/dist/simplebar.min.css';
|
||||
import TableHeader from './header';
|
||||
import './index.less';
|
||||
import TableRow from './row';
|
||||
|
||||
interface SimpleTableProps {
|
||||
columns: any[];
|
||||
dataSource: any[];
|
||||
bordered?: boolean;
|
||||
}
|
||||
const SimpleTabel: React.FC<SimpleTableProps> = (props) => {
|
||||
const { columns, dataSource, bordered = true } = props;
|
||||
return (
|
||||
<SimpleBar style={{ maxHeight: 200 }}>
|
||||
<table
|
||||
className={classNames('simple-table', {
|
||||
'simple-table-bordered': bordered
|
||||
})}
|
||||
>
|
||||
<thead>
|
||||
<TableHeader columns={columns}></TableHeader>
|
||||
</thead>
|
||||
<tbody>
|
||||
{dataSource.map((item: any, index: number) => {
|
||||
return (
|
||||
<TableRow row={item} columns={columns} key="index"></TableRow>
|
||||
);
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
</SimpleBar>
|
||||
);
|
||||
};
|
||||
|
||||
export default React.memo(SimpleTabel);
|
||||
@ -0,0 +1,25 @@
|
||||
import React from 'react';
|
||||
|
||||
interface TableRowProps {
|
||||
row: any;
|
||||
columns: any;
|
||||
}
|
||||
const TableRow = ({ row, columns }: TableRowProps) => {
|
||||
return (
|
||||
<tr>
|
||||
{columns.map((column: any, index: number) => {
|
||||
return (
|
||||
<td key={index}>
|
||||
<span className="cell-span">
|
||||
{column.render
|
||||
? column.render({ dataIndex: column.key, row: row })
|
||||
: row[column.key]}
|
||||
</span>
|
||||
</td>
|
||||
);
|
||||
})}
|
||||
</tr>
|
||||
);
|
||||
};
|
||||
|
||||
export default React.memo(TableRow);
|
||||
Loading…
Reference in new issue