diff --git a/packages/table/package.json b/packages/table/package.json index ed469448cc..ccfd24c577 100644 --- a/packages/table/package.json +++ b/packages/table/package.json @@ -1,6 +1,6 @@ { "name": "@leafygreen-ui/table", - "version": "12.7.0-test.9", + "version": "12.7.0-test.10", "description": "leafyGreen UI Kit Table", "main": "./dist/index.js", "module": "./dist/esm/index.js", diff --git a/packages/table/src/Cell/Cell.styles.ts b/packages/table/src/Cell/Cell.styles.ts index 5726a6825d..a3c07a2f0f 100644 --- a/packages/table/src/Cell/Cell.styles.ts +++ b/packages/table/src/Cell/Cell.styles.ts @@ -65,6 +65,10 @@ export const getCellContainerStyles = (align: Align = 'left') => css` overflow: hidden; justify-content: ${align}; text-align: ${align}; + + > div { + justify-content: ${align}; + } `; export const baseCellStyles = css` diff --git a/packages/table/src/Cell/HeaderCell/HeaderCell.styles.ts b/packages/table/src/Cell/HeaderCell/HeaderCell.styles.ts index c3bc272bf5..416475278a 100644 --- a/packages/table/src/Cell/HeaderCell/HeaderCell.styles.ts +++ b/packages/table/src/Cell/HeaderCell/HeaderCell.styles.ts @@ -19,6 +19,8 @@ export const getBaseHeaderCellStyles = (size: number, isSelectable?: boolean) => &:first-of-type { ${getCellPadding({ depth: 0, isExpandable: false, isSelectable })} } + + line-height: 16px; `, { [css` diff --git a/packages/table/src/Row/HeaderRow/HeaderRow.styles.tsx b/packages/table/src/Row/HeaderRow/HeaderRow.styles.tsx index 6fb29ea037..315933cfca 100644 --- a/packages/table/src/Row/HeaderRow/HeaderRow.styles.tsx +++ b/packages/table/src/Row/HeaderRow/HeaderRow.styles.tsx @@ -4,6 +4,7 @@ import { palette } from '@leafygreen-ui/palette'; export const getBaseStyles = (theme: Theme) => css` background-color: inherit; + position: relative; &:last-of-type { box-shadow: 0 4px diff --git a/packages/table/src/Table/Table.styles.ts b/packages/table/src/Table/Table.styles.ts index 5859a9386c..7adb763dbc 100644 --- a/packages/table/src/Table/Table.styles.ts +++ b/packages/table/src/Table/Table.styles.ts @@ -34,5 +34,18 @@ export const getTableContainerStyles = (isVirtual = false) => }, ); -export const getTableStyles = (theme: Theme, baseFontSize: BaseFontSize) => - cx(baseStyles, themeStyles[theme], bodyTypeScaleStyles[baseFontSize]); +export const getTableStyles = ( + theme: Theme, + baseFontSize: BaseFontSize, + isVirtual = false, + shouldTruncate = false, +) => + cx(baseStyles, themeStyles[theme], bodyTypeScaleStyles[baseFontSize], { + [css` + //TODO: add to documentation + // If this is a virtual table that does not truncate the table needs to have a fixed layout. + // Without a fixed layout, column widths may change during scrolling, which can cause row heights to shift. This can lead to an infinite loop, ultimately crashing the application. 🙃 + // A fixed layout prevents this because it prevents columns widths from changing. + table-layout: fixed; + `]: isVirtual && !shouldTruncate, + }); diff --git a/packages/table/src/Table/Table.tsx b/packages/table/src/Table/Table.tsx index c19ad1bf90..2e9099f1b3 100644 --- a/packages/table/src/Table/Table.tsx +++ b/packages/table/src/Table/Table.tsx @@ -69,7 +69,10 @@ const Table = forwardRef>( virtualTable={virtualTable} > > = [ +const basicColumnDefs: Array> = [ { accessorKey: 'index', header: 'index', @@ -87,6 +87,7 @@ const basicColumnDefs: Array> = [ accessorKey: 'age', header: () => 'Age', size: 50, + align: 'center', }, { accessorKey: 'visits', @@ -603,7 +604,7 @@ export const DifferentHeights: StoryFn = args => { const tableContainerRef = React.useRef(null); const [data] = useState(() => makeKitchenSinkData(10_000)); - const columns = React.useMemo>>( + const columns = React.useMemo>>( () => [ { accessorKey: 'dateCreated', @@ -615,15 +616,18 @@ export const DifferentHeights: StoryFn = args => { month: 'short', day: 'numeric', }), - }, - { - accessorKey: 'frequency', - header: 'Frequency', + size: 180, }, { accessorKey: 'clusterType', header: 'Cluster Type', }, + { + accessorKey: 'frequency', + header: 'Frequency', + align: 'center', + size: 140, + }, { accessorKey: 'encryptorEnabled', header: 'Encryptor', @@ -638,23 +642,16 @@ export const DifferentHeights: StoryFn = args => { accessorKey: 'mdbVersion', header: 'MongoDB Version', enableSorting: true, - size: 90, + size: 120, }, { id: 'actions', header: '', - size: 90, + size: 120, // eslint-disable-next-line react/display-name cell: _ => { return ( -
+
@@ -672,15 +669,14 @@ export const DifferentHeights: StoryFn = args => { [], ); - //TODO: fix type - const table = useLeafyGreenVirtualTable({ + const table = useLeafyGreenVirtualTable({ containerRef: tableContainerRef, data, columns, }); return ( - <> +

{table.getRowModel().rows.length} total rows

@@ -693,27 +689,42 @@ export const DifferentHeights: StoryFn = args => { shouldTruncate={false} > - {table.getHeaderGroups().map((headerGroup: HeaderGroup) => ( - - {headerGroup.headers.map(header => { - return ( - - {flexRender( - header.column.columnDef.header, - header.getContext(), - )} - - ); - })} - - ))} + {table + .getHeaderGroups() + .map((headerGroup: HeaderGroup) => ( + + {headerGroup.headers.map((header, index) => { + return ( + + {flexRender( + header.column.columnDef.header, + header.getContext(), + )} + + ); + })} + + ))} {table.virtual.getVirtualItems() && table.virtual .getVirtualItems() .map( - (virtualRow: LeafyGreenVirtualItem, index: number) => { + ( + virtualRow: LeafyGreenVirtualItem, + index: number, + ) => { const row = virtualRow.row; const isExpandedContent = row.isExpandedContent ?? false; @@ -727,7 +738,7 @@ export const DifferentHeights: StoryFn = args => { > {row .getVisibleCells() - .map((cell: LeafyGreenTableCell) => { + .map((cell: LeafyGreenTableCell) => { return ( {flexRender( @@ -748,6 +759,6 @@ export const DifferentHeights: StoryFn = args => { )}
- + ); }; diff --git a/packages/table/src/utils/makeData.testutils.tsx b/packages/table/src/utils/makeData.testutils.tsx index fb09d6442a..5075e28e62 100644 --- a/packages/table/src/utils/makeData.testutils.tsx +++ b/packages/table/src/utils/makeData.testutils.tsx @@ -115,6 +115,10 @@ const createKitchenSinkData: (depth?: number) => KitchenSink = (depth = 0) => { { value: 'Replica set', weight: 0.45 }, { value: 'Sharded cluster', weight: 0.45 }, { value: faker.lorem.lines(2), weight: 0.1 }, + { + value: faker.string.alpha({ length: { min: 25, max: 45 } }), + weight: 0.1, + }, ]), encryptorEnabled: faker.datatype.boolean(0.75), mdbVersion: faker.system.semver(),