Skip to content

Commit 873044a

Browse files
committed
fix: as per cr and changeset
1 parent 5620538 commit 873044a

3 files changed

Lines changed: 20 additions & 12 deletions

File tree

.changeset/deep-paths-rest.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@genseki/react': patch
3+
---
4+
5+
Add sticky column pinning style

packages/react/src/react/components/primitives/tanstack-table.tsx

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ import {
1111
type SortDirection,
1212
type Table as TanstackTableCore,
1313
} from '@tanstack/react-table'
14-
import clsx from 'clsx'
1514

1615
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from './table'
1716

17+
import { cn } from '../../utils/cn'
18+
1819
type RowClickHandler<T> = (row: Row<T>, e: React.MouseEvent<HTMLTableCellElement>) => void
1920

2021
export interface TanstackTableProps<T> {
@@ -47,7 +48,7 @@ const getCommonPinningClassesAndStyle = (column: Column<any>) => {
4748
const isLastLeftPinnedColumn = isPinned === 'left' && column.getIsLastColumn('left')
4849
const isFirstRightPinnedColumn = isPinned === 'right' && column.getIsFirstColumn('right')
4950

50-
const className = clsx(
51+
const className = cn(
5152
isPinned ? 'sticky z-[1]' : 'relative',
5253
isLastLeftPinnedColumn && 'shadow-[inset_-4px_0_4px_-4px_gray]',
5354
isFirstRightPinnedColumn && 'shadow-[inset_4px_0_4px_-4px_gray]'
@@ -56,9 +57,6 @@ const getCommonPinningClassesAndStyle = (column: Column<any>) => {
5657
const style: CSSProperties = {
5758
left: isPinned === 'left' ? `${column.getStart('left')}px` : undefined,
5859
right: isPinned === 'right' ? `${column.getAfter('right')}px` : undefined,
59-
width: column.getSize(),
60-
minWidth: column.getSize(),
61-
maxWidth: column.getSize(),
6260
}
6361

6462
return { className, style }
@@ -120,12 +118,12 @@ export function TanstackTable<T>({
120118
return (
121119
<TableHead
122120
key={normalizeColumnId(header.id)}
123-
className={clsx(
121+
className={cn(
124122
'focus-visible:ring-focus ring-inset',
125123
header.colSpan > 1 && 'border-bluegray-300 border-b',
126124
classNames?.tableHead,
127-
header.column.columnDef.meta?.thClassName,
128-
pinnedHeaderClassName
125+
pinnedHeaderClassName,
126+
header.column.columnDef.meta?.thClassName
129127
)}
130128
style={pinnedHeaderStyle}
131129
onClick={
@@ -136,7 +134,7 @@ export function TanstackTable<T>({
136134
tabIndex={canSort ? 0 : -1}
137135
>
138136
<span
139-
className={clsx(
137+
className={cn(
140138
'inline-flex items-center gap-2 w-full',
141139
header.colSpan > 1 && 'justify-center'
142140
)}
@@ -150,7 +148,7 @@ export function TanstackTable<T>({
150148
</TableRow>
151149
))}
152150
</TableHeader>
153-
<TableBody className={clsx(classNames?.tableBody)}>
151+
<TableBody className={cn(classNames?.tableBody)}>
154152
{isLoading ? (
155153
<TableLoading table={table} />
156154
) : isError ? (
@@ -162,15 +160,19 @@ export function TanstackTable<T>({
162160
<TableRow
163161
key={row.id}
164162
data-state={row.getIsSelected() && 'selected'}
165-
className={clsx('border-b border-border last:border-b-0', classNames?.tableBodyRow)}
163+
className={cn('border-b border-border last:border-b-0', classNames?.tableBodyRow)}
166164
>
167165
{row.getVisibleCells().map((cell) => {
168166
const { className: pinnedCellClassName, style: pinnedCellStyle } =
169167
getCommonPinningClassesAndStyle(cell.column)
170168
return (
171169
<TableCell
172170
key={cell.id}
173-
className={clsx(classNames?.tableCell, pinnedCellClassName)}
171+
className={cn(
172+
classNames?.tableCell,
173+
pinnedCellClassName,
174+
cell.column.columnDef.meta?.tdClassName
175+
)}
174176
style={pinnedCellStyle}
175177
onClick={(e) => onRowClick?.(row, e)}
176178
>

packages/react/src/types/tanstack.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ import '@tanstack/react-table'
44
declare module '@tanstack/react-table' {
55
interface ColumnMeta<TData, TValue> {
66
thClassName?: string
7+
tdClassName?: string
78
}
89
}

0 commit comments

Comments
 (0)