Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/sour-poems-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@frontify/fondue-components": patch
---

feat(Table): add stickyBackgroundColor prop
49 changes: 49 additions & 0 deletions packages/components/src/components/Table/Table.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,55 @@ export const StickyAllDirections: Story = {
),
};

export const StickyWithCustomBackground: Story = {
name: 'Sticky With Custom Background Color',
args: {
stickyBackgroundColor: 'var(--color-surface-dim)',
},
render: ({ ...args }) => (
<Table.Root {...args}>
<Table.Header sticky>
<Table.Row>
<Table.HeaderCell>Name</Table.HeaderCell>
<Table.HeaderCell>Invited by</Table.HeaderCell>
<Table.HeaderCell>Last seen</Table.HeaderCell>
<Table.HeaderCell>Initial login</Table.HeaderCell>
<Table.HeaderCell>Last login</Table.HeaderCell>
<Table.HeaderCell>Actions</Table.HeaderCell>
</Table.Row>
</Table.Header>
<Table.Body firstColumnSticky lastColumnSticky>
{[...TABLE_DATA, ...TABLE_DATA, ...TABLE_DATA].map((user, index) => (
<Table.Row key={`${user.email}-${index}`}>
<Table.RowCell>
<div className="tw-flex tw-items-center tw-gap-2">
<div>
<div className="tw-font-medium">{user.name}</div>
<div className="tw-text-small tw-text-primary-on-primary">{user.email}</div>
</div>
</div>
</Table.RowCell>
<Table.RowCell>{user.invited}</Table.RowCell>
<Table.RowCell>{user.lastSeen}</Table.RowCell>
<Table.RowCell>{user.initialLogin}</Table.RowCell>
<Table.RowCell>{user.lastLogin}</Table.RowCell>
<Table.RowCell>
<Flex gap="0.25rem">
<Button size="small" aspect="square" emphasis="weak">
<IconPen size={16} />
</Button>
<Button variant="danger" size="small" aspect="square" emphasis="weak">
<IconTrashBin size={16} />
</Button>
</Flex>
</Table.RowCell>
</Table.Row>
))}
</Table.Body>
</Table.Root>
),
};

export const Interactive: Story = {
render: ({ ...args }) => (
<Table.Root {...args}>
Expand Down
30 changes: 25 additions & 5 deletions packages/components/src/components/Table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ type TableRootProps = {
* @default '0px'
*/
gutter?: CSSProperties['borderSpacing'];
/**
* Background color used by sticky parts (header, first column, last column).
*
* Accepts any CSS color value or token (e.g., `'#000'`, `'var(--color-surface-dim)'`)
*/
stickyBackgroundColor?: CSSProperties['backgroundColor'];
/**
* Whether header should stick to the top when scrolling
* @deprecated Use `Table.Header sticky` prop instead. For sticky columns, use `Table.Body firstColumnSticky` or `lastColumnSticky` props
Expand All @@ -65,7 +71,19 @@ type TableRootProps = {
Pick<AriaAttributes, 'aria-multiselectable'>;

export const TableRoot = forwardRef<HTMLTableElement, TableRootProps>(
({ layout = 'auto', fontSize = 'medium', gutter = '0px', sticky, noBorder = false, children, ...props }, ref) => {
(
{
layout = 'auto',
fontSize = 'medium',
gutter = '0px',
stickyBackgroundColor,
sticky,
noBorder = false,
children,
...props
},
ref,
) => {
const tableRef = useRef<HTMLTableElement>(null);
const [hasHorizontalOverflow, setHasHorizontalOverflow] = useState(false);

Expand Down Expand Up @@ -110,10 +128,12 @@ export const TableRoot = forwardRef<HTMLTableElement, TableRootProps>(
<table
ref={tableRef}
className={styles.table}
style={{
// @ts-expect-error CSS custom properties are not in CSSProperties type
'--table-gutter': gutter,
}}
style={
{
'--table-gutter': gutter,
'--table-sticky-background-color': stickyBackgroundColor,
} as CSSProperties
}
data-layout={layout}
data-font-size={fontSize}
data-sticky-header={legacyStickyHeader}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
$sticky-base: (
position: sticky,
z-index: 1,
background-color: var(--color-surface-default),
background-color: var(--table-sticky-background-color, var(--color-surface-default)),
);

// Legacy support for deprecated data-sticky-header attribute
Expand Down Expand Up @@ -125,16 +125,7 @@
position: sticky;
top: 0;
z-index: 2;
background-color: var(--color-surface-default);
}
}

.header {
&[data-sticky='true'] {
position: sticky;
top: 0;
z-index: 2;
background-color: var(--color-surface-default);
background-color: var(--table-sticky-background-color, var(--color-surface-default));
}
}

Expand Down