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

Table fixed layout #2545

Open
wants to merge 123 commits into
base: table-refactor-integration
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
123 commits
Select commit Hold shift + click to select a range
5c393c7
wip
shaneeza Sep 13, 2024
82f8e10
wip
shaneeza Sep 19, 2024
8a87597
updating stories
shaneeza Sep 20, 2024
1c9e15d
lg virtual item
shaneeza Sep 20, 2024
c1747ba
top styles
shaneeza Sep 24, 2024
efd7bf0
remove padding from TableBody
shaneeza Sep 24, 2024
981d823
expanded row background color
shaneeza Sep 24, 2024
b2d94ba
removing stuff
shaneeza Sep 25, 2024
7c81d49
row context
shaneeza Sep 26, 2024
4a10d1a
memoizing stuff
shaneeza Sep 26, 2024
55e5503
wip
shaneeza Oct 7, 2024
cf208fb
styled components
shaneeza Oct 8, 2024
cadf46f
comments
shaneeza Oct 9, 2024
fa7777e
more cleanup
shaneeza Oct 9, 2024
55021a4
clean up
shaneeza Oct 9, 2024
c0bf556
comments
shaneeza Oct 9, 2024
c4dcada
wip, memoize regular table
shaneeza Oct 14, 2024
26d5ff0
testing
shaneeza Oct 15, 2024
e8505d8
huh
shaneeza Oct 15, 2024
75b42d1
why does this work?
shaneeza Oct 15, 2024
90bf2ab
testing why nothing works
shaneeza Oct 16, 2024
c48994f
clean up
shaneeza Oct 16, 2024
4b3ac8c
update virtual stories
shaneeza Oct 16, 2024
dd1f7f9
clean up
shaneeza Oct 16, 2024
be313d9
cleanup
shaneeza Oct 16, 2024
3e77d51
row types
shaneeza Oct 16, 2024
3046147
types
shaneeza Oct 16, 2024
1486a8f
should truncate support
shaneeza Oct 16, 2024
187cfe2
remove memo from useLeafyGreenVirtualTable
shaneeza Oct 17, 2024
8daa4c4
remove unsed exports
shaneeza Oct 17, 2024
af75a49
merge conflict
shaneeza Oct 17, 2024
3848ba5
add a new story
shaneeza Oct 17, 2024
60d4ff1
widths and vertical align
shaneeza Oct 17, 2024
9dd750d
dynamic ellipsis
shaneeza Oct 17, 2024
da227e3
comment
shaneeza Oct 17, 2024
205ff31
combined components
shaneeza Oct 18, 2024
23fdecc
cell generic type
shaneeza Oct 18, 2024
b530196
update types
shaneeza Oct 18, 2024
6bb4c39
align styles
shaneeza Oct 18, 2024
d283f01
Merge branch 'main' of github.com:mongodb/leafygreen-ui into shaneeza…
shaneeza Oct 22, 2024
9bbeb3c
Prerelease version packages 13.0.0-beta.0
shaneeza Oct 22, 2024
f3f1838
fix install error
shaneeza Oct 22, 2024
ddeec2d
Prerelease version packages 13.0.0-beta.1
shaneeza Oct 22, 2024
53c1b2c
comment, wip
shaneeza Oct 23, 2024
4059eeb
Merge branch 'main' of github.com:mongodb/leafygreen-ui into shaneeza…
shaneeza Oct 23, 2024
d8fdc80
Merge branch 'table-refactor-integration' of github.com:mongodb/leafy…
shaneeza Oct 23, 2024
342708c
Merge branch 'shaneeza/table-memoized' of github.com:mongodb/leafygre…
shaneeza Oct 23, 2024
bcb7804
revert useLeafyGreenTable hook so its consistent with a virtual table
shaneeza Oct 29, 2024
a4a25f0
merge conflict
shaneeza Oct 29, 2024
c8cc460
add getItemKey
shaneeza Oct 31, 2024
a89ca4a
small fix
shaneeza Oct 31, 2024
ca150d9
stop mapping columns def
shaneeza Oct 31, 2024
55fbe3e
testing
shaneeza Oct 31, 2024
30517cf
debugging
shaneeza Nov 1, 2024
b5474aa
tbody updates
shaneeza Nov 1, 2024
d1571f0
css vars
shaneeza Nov 1, 2024
9c78c25
add virtual context
shaneeza Nov 4, 2024
ece7167
remove comment
shaneeza Nov 4, 2024
960be7b
remove measureElement from hook
shaneeza Nov 4, 2024
36a02ee
row context updates
shaneeza Nov 4, 2024
d1fe64c
remove overflow from regular table
shaneeza Nov 4, 2024
a71ca53
updates virtual types
shaneeza Nov 5, 2024
54b2cca
more TS docs
shaneeza Nov 5, 2024
ee73090
ts fixes
shaneeza Nov 5, 2024
317f254
row TS docs
shaneeza Nov 5, 2024
d9bd8f7
TS docs stuff
shaneeza Nov 5, 2024
5d70435
fix comment
shaneeza Nov 5, 2024
52eaa5f
add react-intersection-observer
shaneeza Nov 5, 2024
70d8399
wip
shaneeza Nov 6, 2024
89dbb96
remove original from rowCopy
shaneeza Nov 6, 2024
f311b39
story clean up
shaneeza Nov 6, 2024
59474ee
remove v10 and v11 adapter
shaneeza Nov 6, 2024
e16bbfb
remove react-virtual
shaneeza Nov 6, 2024
252d969
cell styles
shaneeza Nov 6, 2024
275805f
interrowwithRT style updates
shaneeza Nov 6, 2024
1201b29
table styles
shaneeza Nov 6, 2024
b1c5af1
comment
shaneeza Nov 6, 2024
6118304
comment
shaneeza Nov 6, 2024
a0e59b1
merge conflict
shaneeza Nov 6, 2024
e138a50
wip
shaneeza Nov 7, 2024
20f4aa7
story with less rows
shaneeza Nov 7, 2024
d2d782d
move box-shadow to headerRow
shaneeza Nov 7, 2024
94f3ebd
darken darkmode scroll shadow
shaneeza Nov 7, 2024
9f82e9b
move styles
shaneeza Nov 7, 2024
54efb57
Merge branch 'shaneeza/table-memoized' of github.com:mongodb/leafygre…
shaneeza Nov 7, 2024
56de09a
add test
shaneeza Nov 8, 2024
4387ebd
remove comments
shaneeza Nov 8, 2024
617860e
testing removing styled components
shaneeza Nov 8, 2024
a663b4c
add back styled
shaneeza Nov 8, 2024
5cff7c4
diff react-intersection-observer version
shaneeza Nov 8, 2024
7bae512
yarn lonk
shaneeza Nov 11, 2024
21d4742
cell ternary, headercell util, expandedcontent styles
shaneeza Nov 11, 2024
c3568f4
fb - toggleExpand, isVirtual boolean, type casting, tsdocs
shaneeza Nov 11, 2024
9dd632b
virtual scrolling padding util
shaneeza Nov 11, 2024
d1037c2
forgot to save
shaneeza Nov 11, 2024
9366b3b
fb - remove virtual context
shaneeza Nov 11, 2024
15ff06b
custom row model
shaneeza Nov 12, 2024
06ecf7d
styledcomponent stuff, TS still not correct
shaneeza Nov 12, 2024
bbf5642
callable virtual items
shaneeza Nov 12, 2024
6d86ca3
update ts docs
shaneeza Nov 12, 2024
53792c0
token
shaneeza Nov 12, 2024
de6b74a
use classname
shaneeza Nov 12, 2024
407af03
move interaction test
shaneeza Nov 13, 2024
deb0160
merge conflict
shaneeza Nov 13, 2024
787300b
use a classname
shaneeza Nov 13, 2024
8c32d84
remove id
shaneeza Nov 13, 2024
34a0055
add table-layout:fixed
shaneeza Nov 15, 2024
7743700
make table fixed, fix shadow and aligment
shaneeza Nov 15, 2024
4357b6d
line height
shaneeza Nov 15, 2024
97de5f2
merge conflict
shaneeza Nov 18, 2024
f304b79
remove ?
shaneeza Nov 18, 2024
b541582
Merge branch 'shaneeza/table-sticky-shadow' of github.com:mongodb/lea…
shaneeza Nov 18, 2024
d7c5333
fix error
shaneeza Nov 19, 2024
0cc8c50
fix broken stories
shaneeza Nov 19, 2024
cf14e8b
interaction rename and args
shaneeza Nov 19, 2024
8cfbc88
story heights
shaneeza Nov 19, 2024
7ef9651
merge conflict
shaneeza Nov 19, 2024
3b47aff
Merge branch 'shaneeza/table-sticky-shadow' of github.com:mongodb/lea…
shaneeza Nov 19, 2024
09f2332
merge conflict
shaneeza Nov 20, 2024
4a2458e
revert row style changes
shaneeza Nov 20, 2024
23cb494
update sizes
shaneeza Nov 20, 2024
0970103
add comment
shaneeza Nov 21, 2024
dbd8b4b
update story
shaneeza Nov 22, 2024
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
2 changes: 1 addition & 1 deletion packages/table/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 4 additions & 0 deletions packages/table/src/Cell/Cell.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
2 changes: 2 additions & 0 deletions packages/table/src/Cell/HeaderCell/HeaderCell.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export const getBaseHeaderCellStyles = (size: number, isSelectable?: boolean) =>
&:first-of-type {
${getCellPadding({ depth: 0, isExpandable: false, isSelectable })}
}
line-height: 16px;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious why this is added? also seeing an explicit height set in headerCellContentStyles so wondering if only 1 is needed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rob asked me to add it - he felt the spacing could be tighter. I tried 1, but it's tighter than 16px. Also, we don't have any tokens that match this line-height.

`,
{
[css`
Expand Down
1 change: 1 addition & 0 deletions packages/table/src/Row/HeaderRow/HeaderRow.styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 15 additions & 2 deletions packages/table/src/Table/Table.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will add in documentation PR

// 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,
});
5 changes: 4 additions & 1 deletion packages/table/src/Table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ const Table = forwardRef<HTMLDivElement, TableProps<any>>(
virtualTable={virtualTable}
>
<table
className={cx(tableClassName, getTableStyles(theme, baseFontSize))}
className={cx(
tableClassName,
getTableStyles(theme, baseFontSize, isVirtual, shouldTruncate),
)}
data-lgid={lgidProp}
data-is-sticky={!inView}
{...rest}
Expand Down
85 changes: 48 additions & 37 deletions packages/table/src/Table/TableWithVS.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Icon from '@leafygreen-ui/icon';
import IconButton from '@leafygreen-ui/icon-button';

import {
KitchenSink,
makeData,
makeKitchenSinkData,
Person,
Expand Down Expand Up @@ -58,10 +59,9 @@ export default meta;

const virtualScrollingContainerHeight = css`
max-height: calc(100vh - 200px);
/* height: calc(100vh - 200px); */
`;

const basicColumnDefs: Array<ColumnDef<Person>> = [
const basicColumnDefs: Array<LGColumnDef<Person>> = [
{
accessorKey: 'index',
header: 'index',
Expand All @@ -87,6 +87,7 @@ const basicColumnDefs: Array<ColumnDef<Person>> = [
accessorKey: 'age',
header: () => 'Age',
size: 50,
align: 'center',
},
{
accessorKey: 'visits',
Expand Down Expand Up @@ -603,7 +604,7 @@ export const DifferentHeights: StoryFn<StoryTableProps> = args => {
const tableContainerRef = React.useRef<HTMLDivElement>(null);
const [data] = useState(() => makeKitchenSinkData(10_000));

const columns = React.useMemo<Array<LGColumnDef<Person>>>(
const columns = React.useMemo<Array<LGColumnDef<KitchenSink>>>(
() => [
{
accessorKey: 'dateCreated',
Expand All @@ -615,15 +616,18 @@ export const DifferentHeights: StoryFn<StoryTableProps> = 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',
Expand All @@ -638,23 +642,16 @@ export const DifferentHeights: StoryFn<StoryTableProps> = 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 (
<div
// style={{
// height: '40px',
// display: 'flex',
// width: '125px',
// objectFit: 'contain',
// }}
>
<div>
<IconButton aria-label="Download">
<Icon glyph="Download" />
</IconButton>
Expand All @@ -672,15 +669,14 @@ export const DifferentHeights: StoryFn<StoryTableProps> = args => {
[],
);

//TODO: fix type
const table = useLeafyGreenVirtualTable<any>({
const table = useLeafyGreenVirtualTable<KitchenSink>({
containerRef: tableContainerRef,
data,
columns,
});

return (
<>
<div>
<div>
<p>{table.getRowModel().rows.length} total rows</p>
</div>
Expand All @@ -693,27 +689,42 @@ export const DifferentHeights: StoryFn<StoryTableProps> = args => {
shouldTruncate={false}
>
<TableHead isSticky>
{table.getHeaderGroups().map((headerGroup: HeaderGroup<Person>) => (
<HeaderRow key={headerGroup.id}>
{headerGroup.headers.map(header => {
return (
<HeaderCell key={header.id} header={header}>
{flexRender(
header.column.columnDef.header,
header.getContext(),
)}
</HeaderCell>
);
})}
</HeaderRow>
))}
{table
.getHeaderGroups()
.map((headerGroup: HeaderGroup<KitchenSink>) => (
<HeaderRow key={headerGroup.id}>
{headerGroup.headers.map((header, index) => {
return (
<HeaderCell
key={header.id}
header={header}
className={css`
${index === 1 &&
css`
// This overrides the default width of 150px and makes the 2nd column responsive
width: auto;
`}
`}
>
{flexRender(
header.column.columnDef.header,
header.getContext(),
)}
</HeaderCell>
);
})}
</HeaderRow>
))}
</TableHead>
<TableBody>
{table.virtual.getVirtualItems() &&
table.virtual
.getVirtualItems()
.map(
(virtualRow: LeafyGreenVirtualItem<Person>, index: number) => {
(
virtualRow: LeafyGreenVirtualItem<KitchenSink>,
index: number,
) => {
const row = virtualRow.row;
const isExpandedContent = row.isExpandedContent ?? false;

Expand All @@ -727,7 +738,7 @@ export const DifferentHeights: StoryFn<StoryTableProps> = args => {
>
{row
.getVisibleCells()
.map((cell: LeafyGreenTableCell<Person>) => {
.map((cell: LeafyGreenTableCell<KitchenSink>) => {
return (
<Cell key={cell.id} cell={cell}>
{flexRender(
Expand All @@ -748,6 +759,6 @@ export const DifferentHeights: StoryFn<StoryTableProps> = args => {
)}
</TableBody>
</Table>
</>
</div>
);
};
4 changes: 4 additions & 0 deletions packages/table/src/utils/makeData.testutils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Loading