Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Table fill level #662

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions src/components/table/FillerRows.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import type { Row } from '@tanstack/react-table'
import type { VirtualItem } from '@tanstack/react-virtual'

import { type TableFillLevel } from './Table'
import { Td } from './Td'
import { Tr } from './Tr'

function FillerRow({
columns,
height,
index,
stickyColumn,
selectable,
fillLevel,
...props
}: {
columns: unknown[]
height: number
index: number
stickyColumn: boolean
selectable?: boolean
fillLevel: TableFillLevel
}) {
return (
<Tr
aria-hidden="true"
$raised={index % 2 === 1}
$selected={false}
$selectable={selectable}
$fillLevel={fillLevel}
>
<Td
aria-hidden="true"
$fillLevel={fillLevel}
$stickyColumn={stickyColumn}
style={{
height,
minHeight: height,
maxHeight: height,
padding: 0,
gridColumn: '1 / -1',
}}
colSpan={columns.length}
$truncateColumn={false}
$center={false}
{...props}
/>
</Tr>
)
}

export function FillerRows({
rows,
height,
position,
fillLevel,
...props
}: {
rows: Row<unknown>[] | VirtualItem[]
columns: unknown[]
height: number
position: 'top' | 'bottom'
stickyColumn: boolean
clickable?: boolean
selectable?: boolean
fillLevel: TableFillLevel
}) {
return (
<>
<FillerRow
height={position === 'top' ? 0 : height}
index={
position === 'top'
? rows[0].index - 2
: rows[rows.length - 1].index + 1
}
fillLevel={fillLevel}
{...props}
/>
<FillerRow
height={position === 'top' ? height : 0}
index={
position === 'top'
? rows[0].index - 1
: rows[rows.length - 1].index + 2
}
fillLevel={fillLevel}
{...props}
/>
</>
)
}
28 changes: 28 additions & 0 deletions src/components/table/SortIndicator.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import type { SortDirection } from '@tanstack/react-table'

import ArrowRightIcon from '../icons/ArrowRightIcon'

export function SortIndicator({
direction = false,
}: {
direction: false | SortDirection
}) {
switch (direction) {
case 'asc':
return (
<ArrowRightIcon
size={12}
transform="rotate(-90deg)"
/>
)
case 'desc':
return (
<ArrowRightIcon
size={12}
transform="rotate(90deg)"
/>
)
case false:
return null
}
}
13 changes: 13 additions & 0 deletions src/components/table/T.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import styled from 'styled-components'

export const T = styled.table<{ $gridTemplateColumns: string }>(
({ theme, $gridTemplateColumns }) => ({
gridTemplateColumns: $gridTemplateColumns,
borderSpacing: 0,
display: 'grid',
borderCollapse: 'collapse',
minWidth: '100%',
width: '100%',
...theme.partials.text.body2LooseLineHeight,
})
)
Loading
Loading