-
Notifications
You must be signed in to change notification settings - Fork 3
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
62c835b
commit f5be35d
Showing
5 changed files
with
44 additions
and
39 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
61 changes: 34 additions & 27 deletions
61
app/Dashboard/Households/HouseholdList/HouseholdTableColumn.tsx
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 |
---|---|---|
@@ -1,42 +1,49 @@ | ||
import type { HouseholdKeys, HouseholdListItem } from '@camp/domain'; | ||
import type { Icon } from '@camp/icons'; | ||
import { ArrowDownIcon, ArrowUpIcon } from '@camp/icons'; | ||
import { Text } from '@mantine/core'; | ||
import type { Table } from '@tanstack/react-table'; | ||
import { flexRender } from '@tanstack/react-table'; | ||
import { ArrowDown, ArrowUp } from 'react-feather'; | ||
|
||
interface Props { | ||
col: Table<HouseholdKeys & HouseholdListItem>; | ||
} | ||
|
||
const iconMap: Record<string, Icon> = { | ||
asc: ArrowUpIcon, | ||
desc: ArrowDownIcon, | ||
} as const; | ||
|
||
export const HouseholdTableColumn = ({ col }: Props) => { | ||
return col.getHeaderGroups().map(headerGroup => ( | ||
<tr key={headerGroup.id}> | ||
{headerGroup.headers.map(header => ( | ||
<th key={header.id} colSpan={header.colSpan}> | ||
{header.isPlaceholder ? null : ( | ||
<Text | ||
sx={{ | ||
cursor: 'pointer', | ||
display: 'flex', | ||
alignItems: 'center', | ||
gap: 5, | ||
}} | ||
{...{ | ||
className: header.column.getCanSort() | ||
? 'cursor-pointer select-none' | ||
: '', | ||
onClick: header.column.getToggleSortingHandler(), | ||
}} | ||
> | ||
{flexRender(header.column.columnDef.header, header.getContext())} | ||
{{ | ||
asc: <ArrowUp size={14} />, | ||
desc: <ArrowDown size={14} />, | ||
}[header.column.getIsSorted() as string] ?? null} | ||
</Text> | ||
)} | ||
</th> | ||
))} | ||
{headerGroup.headers.map(header => { | ||
const Icon = iconMap[header.column.getIsSorted() as string]; | ||
const canSort = header.column.getCanSort(); | ||
|
||
return ( | ||
<th key={header.id} colSpan={header.colSpan}> | ||
{header.isPlaceholder ? null : ( | ||
<Text | ||
sx={{ | ||
cursor: canSort ? 'pointer' : undefined, | ||
display: 'flex', | ||
alignItems: 'center', | ||
userSelect: canSort ? 'none' : undefined, | ||
gap: 5, | ||
}} | ||
onClick={header.column.getToggleSortingHandler()} | ||
> | ||
{flexRender( | ||
header.column.columnDef.header, | ||
header.getContext(), | ||
)} | ||
{Icon ? <Icon size={14} /> : null} | ||
</Text> | ||
)} | ||
</th> | ||
); | ||
})} | ||
</tr> | ||
)); | ||
}; |
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