Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
120 changes: 60 additions & 60 deletions packages/gamut/src/DataList/Tables/Rows/TableHeaderRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,75 +35,75 @@ export const TableHeaderRow: HeaderComponent = ({
const { expandable, selectable, onSelect, onFilter, onSort, prefixId } =
useControlContext();
const { variant, listType } = useListContext();
const dataTablePadding = listType === 'table' && variant === 'table';
const headerRowDirections = useListState().query?.sort;

return (
<StyledHeaderRow
invisible={invisible}
isDataList={listType === 'table' && variant !== 'table'}
>
<>
{selectable && (
<ListCol size="content">
{!hideSelectAll && (
<SelectControl
disabled={empty}
label="Select All"
name={prefixId('all')}
rowId="header"
selected={selected}
onSelect={onSelect}
/>
)}
</ListCol>
)}
{columns.map(({ key, header, sortable, filters, ...colProps }) => {
const rowProperty = key as string;
const renderKey = prefixId(`header-col-${rowProperty}`);
const columnText = String(header || key);
const sortDirection = headerRowDirections?.[rowProperty] ?? 'none';
const ariaSortDirection =
sortDirection === 'none'
? 'none'
: sortDirection === 'asc'
? 'ascending'
: 'descending';

return (
<ListCol
key={renderKey}
{...colProps}
aria-sort={sortable ? ariaSortDirection : undefined}
columnHeader
dataTablePadding={dataTablePadding}
{selectable && (
Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed the fragment b.c. it was interfering with the addition of data-first-col for the first element in the TableHeader
Also doesn't seem necessary

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not using data-*-col approach anymore, so re-adding is fine, but it's also not necessary from what I can tell

<ListCol size="content">
{!hideSelectAll && (
<SelectControl
disabled={empty}
label="Select All"
name={prefixId('all')}
rowId="header"
selected={selected}
onSelect={onSelect}
/>
)}
</ListCol>
)}
{columns.map(({ key, header, sortable, filters, ...colProps }) => {
const rowProperty = key as string;
const renderKey = prefixId(`header-col-${rowProperty}`);
const columnText = String(header || key);
const sortDirection = headerRowDirections?.[rowProperty] ?? 'none';
const ariaSortDirection =
sortDirection === 'none'
? 'none'
: sortDirection === 'asc'
? 'ascending'
: 'descending';
return (
<ListCol
key={renderKey}
{...colProps}
aria-sort={sortable ? ariaSortDirection : undefined}
columnHeader
>
<FlexBox
alignItems={selectable ? 'center' : 'flex-end'}
gap={8}
height="100%"
width="100%"
>
<FlexBox alignItems="flex-end" gap={8} height="100%" width="100%">
{filters && (
<FilterControl
columnKey={rowProperty}
justify={colProps.justify}
options={filters}
onFilter={onFilter}
/>
)}
{sortable ? (
<SortControl columnKey={rowProperty} onSort={onSort}>
{columnText}
</SortControl>
) : (
columnText
)}
</FlexBox>
</ListCol>
);
})}
{expandable && (
<ListCol ghost size="content">
<ExpandControl />
{filters && (
<FilterControl
columnKey={rowProperty}
justify={colProps.justify}
options={filters}
onFilter={onFilter}
/>
)}
{sortable ? (
<SortControl columnKey={rowProperty} onSort={onSort}>
{columnText}
</SortControl>
) : (
columnText
)}
</FlexBox>
</ListCol>
)}
</>
);
})}
{expandable && (
<ListCol ghost size="content">
<ExpandControl />
</ListCol>
)}
</StyledHeaderRow>
);
};
Expand Down
7 changes: 1 addition & 6 deletions packages/gamut/src/DataList/Tables/Rows/TableRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
import { Text } from '../../..';
import { ListCol, ListRow } from '../../../List';
import { ColProps } from '../../../List/elements';
import { useListContext } from '../../../List/ListProvider';
import { Shimmer } from '../../../Loading/Shimmer';
import { ExpandControl, SelectControl } from '../../Controls';
import { useControlContext } from '../../hooks/useListControls';
Expand Down Expand Up @@ -48,10 +47,7 @@ export const TableRow: DataRow = ({
prefixId,
} = useControlContext();

const { variant, listType } = useListContext();
const dataTablePadding = listType === 'table' && variant === 'table';

const listColProps = { dataTablePadding, showOverflow };
const listColProps = { showOverflow };

const controlIndices = useMemo(() => {
const controlIndices = new Map<number, number>();
Expand Down Expand Up @@ -113,7 +109,6 @@ export const TableRow: DataRow = ({
fill,
type,
};

if (type === 'control') {
const controlIndex = controlIndices.get(index) ?? 0;

Expand Down
1 change: 0 additions & 1 deletion packages/gamut/src/List/ListCol.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export const ListCol = forwardRef<HTMLDivElement, ListColProps>(
as={colEl}
columnHeader={columnHeader}
delimiter={sticky && activeVariants.variant === 'table'}
lastChildPadding={!(type === 'expandControl')}
ref={ref}
sticky={sticky}
type={isOrderedHeader ? 'orderedHeader' : type}
Expand Down
5 changes: 3 additions & 2 deletions packages/gamut/src/List/__tests__/List.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,12 @@ describe('List', () => {
: 'paddingRight';

const { view } = renderView();
const rowEl = view.getByRole('listitem');
const colEl = view.getByText('Hello');

expect(colEl).not.toHaveStyle({ py: 16 });
expect(colEl).toHaveStyle({ [paddingLeft]: theme.spacing[8] });
expect(colEl).toHaveStyle({ [paddingRight]: theme.spacing[8] });
expect(rowEl).toHaveStyle({ [paddingLeft]: theme.spacing[8] });
expect(rowEl).toHaveStyle({ [paddingRight]: theme.spacing[8] });
expect(colEl).not.toHaveStyle({ position: 'sticky' });
});

Expand Down
26 changes: 5 additions & 21 deletions packages/gamut/src/List/elements.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ const interactiveState = states({

const spacingVariants = variant({
prop: 'spacing',
base: {
px: { _: 8, c_base: 0, c_sm: 8 },
},
variants: {
normal: {
rowGap: { _: 0, c_base: 8, c_sm: 0 },
Expand All @@ -110,7 +113,6 @@ const spacingVariants = variant({
columnGap: { _: 32, c_base: 8, c_sm: 32 },
gap: { _: 40, c_base: 8, c_sm: 40 },
},

compact: {
gap: 0,
py: 0,
Expand Down Expand Up @@ -374,23 +376,6 @@ const columnStates = states({
whiteSpace: 'normal',
alignItems: 'flex-end',
},
dataTablePadding: {
'&:first-of-type': {
pl: 8,
},
'&:last-of-type': {
pr: 8,
},
},
/**
* We add this to every RowEl except expandable DataList because it causes a layout shift.
* In that case, the padding is instead added directly to the Expandable control.
*/
lastChildPadding: {
'&:last-of-type': {
pr: 8,
},
},
wrap: {
whiteSpace: 'normal',
},
Expand All @@ -407,9 +392,6 @@ const columnSpacing = variant({
prop: 'spacing',
base: {
px: { _: 0, c_base: 8, c_sm: 0 },
'&:first-of-type': {
pl: 8,
},
},
variants: {
normal: {
Expand Down Expand Up @@ -485,6 +467,8 @@ export const StickyHeaderColWrapper = styled.th(
left: 0,
zIndex: -1,
},
// p: 0 removes the browser's default padding of 1px
p: 0,
display: 'flex',
flexShrink: 0,
position: 'sticky',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export const Table: Story = {
export const Plain: Story = {
args: { spacing: 'condensed', variant: 'plain' },
render: (args) => (
<Box bg="red" width={1}>
<Box width={1}>
<ListExample {...args} />
</Box>
),
Expand Down
Loading