-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor Table to use flex layouts (#2622)
- Loading branch information
1 parent
29a0d7e
commit 60e3500
Showing
4 changed files
with
136 additions
and
231 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
47 changes: 24 additions & 23 deletions
47
packages/gitbook/src/components/DocumentView/Table/RecordRow.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,43 @@ | ||
import { DocumentTableViewGrid } from '@gitbook/api'; | ||
|
||
import { tcls } from '@/lib/tailwind'; | ||
import React from 'react'; | ||
|
||
import { RecordColumnValue } from './RecordColumnValue'; | ||
import { TableRecordKV, TableViewProps } from './Table'; | ||
import styles from './table.module.css'; | ||
import { getColumnWidth } from './ViewGrid'; | ||
|
||
export async function RecordRow( | ||
export function RecordRow( | ||
props: TableViewProps<DocumentTableViewGrid> & { | ||
record: TableRecordKV; | ||
autoSizedColumns: string[]; | ||
fixedColumns: string[]; | ||
}, | ||
) { | ||
const { view } = props; | ||
const columnsLengthThreshold = view.columns.length >= 7; | ||
|
||
const tableTR = columnsLengthThreshold | ||
? ['[&>*+*]:border-l', '[&>*]:px-4'] | ||
: ['[&>*+*]:border-l', '[&>*+*]:pl-4']; | ||
const { view, autoSizedColumns, fixedColumns } = props; | ||
|
||
return ( | ||
<tr className={tcls(tableTR, 'border-dark/3', 'dark:border-light/2')}> | ||
<div className={styles.row} role="row"> | ||
{view.columns.map((column) => { | ||
const columnWidth = getColumnWidth({ | ||
column, | ||
columnWidths: view.columnWidths, | ||
autoSizedColumns, | ||
fixedColumns, | ||
}); | ||
return ( | ||
<td | ||
<div | ||
key={column} | ||
className={tcls( | ||
'align-middle', | ||
'min-w-[8rem]', | ||
'border-dark/2', | ||
'py-3', | ||
'text-sm', | ||
'lg:text-base', | ||
'dark:border-light/2', | ||
)} | ||
role="cell" | ||
className={styles.cell} | ||
style={{ | ||
width: columnWidth, | ||
minWidth: columnWidth || '100px', | ||
}} | ||
> | ||
<RecordColumnValue key={column} {...props} column={column} /> | ||
</td> | ||
<RecordColumnValue {...props} column={column} /> | ||
</div> | ||
); | ||
})} | ||
</tr> | ||
</div> | ||
); | ||
} |
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
Oops, something went wrong.