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 column vertical alignment #2547

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
128 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
65897df
alignment
shaneeza Nov 8, 2024
cee55af
remove comment
shaneeza Nov 8, 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
44ccd73
merge conflict
shaneeza Nov 18, 2024
97de5f2
merge conflict
shaneeza Nov 18, 2024
f304b79
remove ?
shaneeza Nov 18, 2024
10294cc
Merge branch 'shaneeza/table-sticky-shadow' of github.com:mongodb/lea…
shaneeza Nov 18, 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
99d748c
merge conflict
shaneeza Nov 19, 2024
9e518b8
add back color
shaneeza Nov 20, 2024
a82ddf9
Merge branch 'table-refactor-integration' of github.com:mongodb/leafy…
shaneeza Nov 20, 2024
aa24f10
update stories
shaneeza Nov 20, 2024
a6ee472
remove InternalCell file
shaneeza Nov 20, 2024
e0c26d6
new story
shaneeza Nov 20, 2024
7c7f942
fix row stories
shaneeza Nov 20, 2024
f9ca7dd
update rows stories
shaneeza Nov 20, 2024
3a13fbc
revert some story changes
shaneeza Nov 20, 2024
4de7e7b
revert some more story changes
shaneeza Nov 20, 2024
46209e3
use classname
shaneeza Nov 20, 2024
4fef4a6
revert some story changes
shaneeza Nov 20, 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
30 changes: 17 additions & 13 deletions packages/table/src/Cell/Cell.styles.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { css } from '@leafygreen-ui/emotion';
import { css, cx } from '@leafygreen-ui/emotion';
import { spacing } from '@leafygreen-ui/tokens';

import { VerticalAlignment } from '../Table/Table.types';

import { Align } from './Cell.types';

/** The base left & right padding in the table */
Expand Down Expand Up @@ -67,10 +69,12 @@ export const getCellContainerStyles = (align: Align = 'left') => css`
text-align: ${align};
`;

export const baseCellStyles = css`
export const getBaseCellStyles = (
verticalAlignment: VerticalAlignment = VerticalAlignment.Top,
) => css`
padding: 0 ${spacing[200]}px;
overflow: hidden;
vertical-align: top;
vertical-align: ${verticalAlignment};

&:focus-visible {
box-shadow: inset;
Expand All @@ -87,13 +91,13 @@ export const cellInnerStyles = css`
min-width: 100%;
`;

export const getCellEllipsisStyles = (shouldTruncate: boolean) => css`
${shouldTruncate &&
css`
flex: 1;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
contain: inline-size; // 🤯
`}
`;
export const getCellEllipsisStyles = (shouldTruncate: boolean) =>
cx({
[css`
flex: 1;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
contain: inline-size; // 🤯
`]: shouldTruncate,
});
4 changes: 2 additions & 2 deletions packages/table/src/Cell/HeaderCell/HeaderCell.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { css, cx } from '@leafygreen-ui/emotion';
import { spacing } from '@leafygreen-ui/tokens';

import {
baseCellStyles,
getBaseCellStyles,
getCellContainerStyles,
getCellPadding,
} from '../Cell.styles';
Expand All @@ -14,7 +14,7 @@ export const headerCellContentStyles = css`

export const getBaseHeaderCellStyles = (size: number, isSelectable?: boolean) =>
cx(
baseCellStyles,
getBaseCellStyles(),
css`
&:first-of-type {
${getCellPadding({ depth: 0, isExpandable: false, isSelectable })}
Expand Down
36 changes: 0 additions & 36 deletions packages/table/src/Cell/InternalCell.tsx

This file was deleted.

6 changes: 4 additions & 2 deletions packages/table/src/Cell/InternalCellBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import React, { forwardRef } from 'react';
import { cx } from '@leafygreen-ui/emotion';

import { LGIDS } from '../constants';
import { useTableContext } from '../TableContext';

import {
baseCellStyles,
cellInnerStyles,
getBaseCellStyles,
getCellContainerStyles,
} from './Cell.styles';
import { InternalCellProps } from './Cell.types';
Expand All @@ -25,10 +26,11 @@ const InternalCellBase = forwardRef<HTMLTableCellElement, InternalCellProps>(
}: InternalCellProps,
fwdRref,
) => {
const { verticalAlignment } = useTableContext();
return (
<td
data-lgid={LGIDS.cell}
className={cx(baseCellStyles, className)}
className={cx(getBaseCellStyles(verticalAlignment), className)}
Comment on lines -31 to +33
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: lately, I've been consuming @leafygreen-ui/emotion only in the *.styles.ts file and passing all variables including className into the style function. In this case, you end up with something like getCellStyles(className, verticalAlignment)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I like this pattern. However, I'm going to keep it as is. If I have extra time, I'll go back and update all table styles to match this pattern.

ref={fwdRref}
{...rest}
>
Expand Down
61 changes: 46 additions & 15 deletions packages/table/src/Row/Row.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import { StoryFn } from '@storybook/react';

import Button from '@leafygreen-ui/button';
import { css } from '@leafygreen-ui/emotion';
import LeafyGreenProvider from '@leafygreen-ui/leafygreen-provider';
import { DarkModeProps } from '@leafygreen-ui/lib';

Expand All @@ -33,21 +34,22 @@ import {
RowProps,
} from '..';

// TODO: UPDATE ME

const meta: StoryMetaType<typeof Row> = {
title: 'Components/Table/Row',
component: Row,
argTypes: {
virtualRow: { control: 'none' },
row: { control: 'none' },
className: { control: 'none' },
disabled: { control: 'boolean' },
},
parameters: {
default: null,
controls: {
exclude: [...storybookExcludedControlParams, 'ref', 'children'],
exclude: [
...storybookExcludedControlParams,
'ref',
'children',
'row',
'virtualRow',
],
},
chromatic: {
disableSnapshot: true,
Expand All @@ -61,18 +63,45 @@ const meta: StoryMetaType<typeof Row> = {
combineArgs: {
darkMode: [false, true],
disabled: [false, true],
// @ts-ignore - this is a table prop
shouldTruncate: [false, true],
verticalAlignment: ['top', 'center'],
},
args: {
children: makeData(false, 1).map(rowData =>
Object.values(rowData).map(c => <Cell>{c}</Cell>),
),
},
excludeCombinations: [
{
// @ts-ignore - this is a table prop
shouldTruncate: true,
verticalAlignment: 'center',
},
],
decorator: (Instance, ctx) => {
return (
<LeafyGreenProvider darkMode={ctx?.args.darkMode}>
<Table>
<Table
shouldTruncate={ctx?.args.shouldTruncate}
verticalAlignment={ctx?.args.verticalAlignment}
>
<TableBody>
<Instance />
<Instance>
<Cell
className={css`
width: 60px;
`}
>
1
</Cell>
<Cell
className={css`
width: 200px;
`}
>
Est mollitia laborum dolores dolorem corporis explicabo
nobis enim omnis. Minima excepturi accusantium iure culpa.
</Cell>
<Cell>MongoDB</Cell>
<Cell>7.85</Cell>
<Cell>Complicated</Cell>
</Instance>
</TableBody>
</Table>
</LeafyGreenProvider>
Expand Down Expand Up @@ -242,7 +271,6 @@ DisabledClickableRows.args = {
export const DisabledSelectableRows: StoryFn<
RowProps<Person> & DarkModeProps
> = ({ darkMode, ...args }: DarkModeProps & RowProps<Person>) => {
const tableContainerRef = React.useRef<HTMLDivElement>(null);
Copy link
Collaborator

Choose a reason for hiding this comment

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

why is this removed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's not necessary for a regular table

const data = React.useState(() => makeData(false, 100))[0];
const [rowSelection, setRowSelection] = React.useState({});

Expand Down Expand Up @@ -326,7 +354,6 @@ export const DisabledSelectableRows: StoryFn<
<Table
darkMode={darkMode}
table={table}
ref={tableContainerRef}
data-total-rows={table.getRowModel().rows.length}
>
<TableHead>
Expand Down Expand Up @@ -371,4 +398,8 @@ DisabledSelectableRows.argTypes = {
darkMode: storybookArgTypes.darkMode,
};

DisabledSelectableRows.args = {
disabled: true,
};

export const Generated = () => <></>;
31 changes: 18 additions & 13 deletions packages/table/src/Table.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Icon from '@leafygreen-ui/icon';
import IconButton from '@leafygreen-ui/icon-button';
import Pagination, { PaginationProps } from '@leafygreen-ui/pagination';

import { VerticalAlignment } from './Table/Table.types';
import {
makeData,
makeKitchenSinkData,
Expand Down Expand Up @@ -42,7 +43,18 @@ const meta: StoryMetaType<typeof Table> = {
title: 'Components/Table',
component: Table,
argTypes: {
shouldAlternateRowColor: { control: 'boolean' },
shouldAlternateRowColor: { control: 'boolean', defaultValue: false },
shouldTruncate: { control: 'boolean', defaultValue: true },
verticalAlignment: {
control: { type: 'radio' },
options: VerticalAlignment,
defaultValue: VerticalAlignment.Top,
},
},
args: {
verticalAlignment: VerticalAlignment.Top,
shouldTruncate: true,
shouldAlternateRowColor: false,
},
parameters: {
default: 'LiveExample',
Expand Down Expand Up @@ -220,12 +232,6 @@ export const LiveExample: StoryFn<StoryTableProps> = args => {
);
};

LiveExample.argTypes = {
shouldAlternateRowColor: {
control: 'none',
},
};

export const HundredsOfRows: StoryFn<StoryTableProps> = args => {
const tableContainerRef = React.useRef<HTMLDivElement>(null);
const [data] = useState(() => makeKitchenSinkData(500));
Expand Down Expand Up @@ -353,18 +359,17 @@ export const HundredsOfRows: StoryFn<StoryTableProps> = args => {
);
};

HundredsOfRows.argTypes = {
shouldAlternateRowColor: {
control: 'none',
},
};

HundredsOfRows.parameters = {
chromatic: {
disableSnapshots: true,
},
};

export const NoTruncation = LiveExample.bind({});
NoTruncation.args = {
shouldTruncate: false,
};

export const Basic = Template.bind({});

export const ZebraStripes = Template.bind({});
Expand Down
6 changes: 4 additions & 2 deletions packages/table/src/Table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,20 @@ import {
getTableStyles,
tableClassName,
} from './Table.styles';
import { TableProps } from './Table.types';
import { TableProps, VerticalAlignment } from './Table.types';

// Inferred generic type from component gets used in place of `any`
const Table = forwardRef<HTMLDivElement, TableProps<any>>(
<T extends LGRowData>(
{
table,
children,
className,
verticalAlignment = VerticalAlignment.Top,
shouldAlternateRowColor = false,
shouldTruncate = true,
baseFontSize: baseFontSizeProp,
darkMode: darkModeProp,
table,
'data-lgid': lgidProp = LGIDS.root,
...rest
}: TableProps<T>,
Expand Down Expand Up @@ -67,6 +68,7 @@ const Table = forwardRef<HTMLDivElement, TableProps<any>>(
isSelectable={isSelectable}
shouldTruncate={shouldTruncate}
virtualTable={virtualTable}
verticalAlignment={verticalAlignment}
>
<table
className={cx(tableClassName, getTableStyles(theme, baseFontSize))}
Expand Down
14 changes: 14 additions & 0 deletions packages/table/src/Table/Table.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ import { BaseFontSize } from '@leafygreen-ui/tokens';
import { LeafyGreenTable, LGRowData } from '../useLeafyGreenTable';
import { LeafyGreenVirtualTable } from '../useLeafyGreenVirtualTable/useLeafyGreenVirtualTable.types';

export const VerticalAlignment = {
Top: 'top',
Middle: 'middle',
} as const;

export type VerticalAlignment =
(typeof VerticalAlignment)[keyof typeof VerticalAlignment];

export interface TableProps<T extends LGRowData>
extends HTMLElementProps<'table'>,
DarkModeProps,
Expand All @@ -30,4 +38,10 @@ export interface TableProps<T extends LGRowData>
* @default true
*/
shouldTruncate?: boolean;

/**
* When rows are not truncated, this will determine if cells should be top or middle aligned
* @default 'top'
*/
verticalAlignment?: VerticalAlignment;
}
Loading
Loading