mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Move TableHeader to its own component
Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
parent
bd965c93f4
commit
3df4c306e5
@ -3,10 +3,10 @@
|
|||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import styles from "./react-table.module.scss";
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { flexRender } from '@tanstack/react-table'
|
import { flexRender } from '@tanstack/react-table'
|
||||||
import type { Table } from "@tanstack/react-table";
|
import type { Table } from "@tanstack/react-table";
|
||||||
|
import { TableHeader } from "./table-header";
|
||||||
|
|
||||||
interface TableProps<T> {
|
interface TableProps<T> {
|
||||||
table: Table<T>;
|
table: Table<T>;
|
||||||
@ -17,35 +17,7 @@ export function Table<Data>({ className, table }: TableProps<Data>) {
|
|||||||
return (
|
return (
|
||||||
<div className={className}>
|
<div className={className}>
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<TableHeader table={table}/>
|
||||||
{table.getHeaderGroups().map(headerGroup => (
|
|
||||||
<tr key={headerGroup.id}>
|
|
||||||
{headerGroup.headers.map(header => (
|
|
||||||
<th key={header.id}>
|
|
||||||
{header.isPlaceholder ? null : (
|
|
||||||
<div
|
|
||||||
{...{
|
|
||||||
className: header.column.getCanSort()
|
|
||||||
? styles.sortableColumn
|
|
||||||
: '',
|
|
||||||
onClick: header.column.getToggleSortingHandler(),
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{flexRender(
|
|
||||||
header.column.columnDef.header,
|
|
||||||
header.getContext()
|
|
||||||
)}
|
|
||||||
{{
|
|
||||||
asc: ' 🔼',
|
|
||||||
desc: ' 🔽',
|
|
||||||
}[header.column.getIsSorted() as string] ?? null}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</th>
|
|
||||||
))}
|
|
||||||
</tr>
|
|
||||||
))}
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
<tbody>
|
||||||
{table.getRowModel().rows.map(row => (
|
{table.getRowModel().rows.map(row => (
|
||||||
<tr key={row.id}>
|
<tr key={row.id}>
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
.sortableColumn {
|
.sortableColumn {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
user-select: none;
|
user-select: none;
|
||||||
42
src/renderer/components/table/table-header.tsx
Normal file
42
src/renderer/components/table/table-header.tsx
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
import styles from "./table-header.module.scss";
|
||||||
|
import React from "react";
|
||||||
|
import type { Table } from "@tanstack/react-table";
|
||||||
|
import { flexRender } from '@tanstack/react-table';
|
||||||
|
|
||||||
|
interface TableHeaderProps<Data> {
|
||||||
|
table: Table<Data>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TableHeader<Data>({ table }: TableHeaderProps<Data>) {
|
||||||
|
return (
|
||||||
|
<thead>
|
||||||
|
{table.getHeaderGroups().map(headerGroup => (
|
||||||
|
<tr key={headerGroup.id}>
|
||||||
|
{headerGroup.headers.map(header => (
|
||||||
|
<th key={header.id}>
|
||||||
|
{header.isPlaceholder ? null : (
|
||||||
|
<div
|
||||||
|
{...{
|
||||||
|
className: header.column.getCanSort()
|
||||||
|
? styles.sortableColumn
|
||||||
|
: '',
|
||||||
|
onClick: header.column.getToggleSortingHandler(),
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{flexRender(
|
||||||
|
header.column.columnDef.header,
|
||||||
|
header.getContext()
|
||||||
|
)}
|
||||||
|
{{
|
||||||
|
asc: ' 🔼',
|
||||||
|
desc: ' 🔽',
|
||||||
|
}[header.column.getIsSorted() as string] ?? null}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</th>
|
||||||
|
))}
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
</thead>
|
||||||
|
)
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user