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

feat(Table): add sticky modifiers to Td #8391

Merged
merged 3 commits into from Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/react-table/src/components/Table/base/types.tsx
Expand Up @@ -171,6 +171,10 @@ export interface ThSelectType {
isSelected: boolean;
/** Flag indicating the select checkbox in the th is disabled */
isHeaderSelectDisabled?: boolean;
/** Whether to disable the selection */
disable?: boolean;
kmcfaul marked this conversation as resolved.
Show resolved Hide resolved
/** Additional props forwarded to select rowData */
props?: any;
}

export interface ThExpandType {
Expand Down
22 changes: 22 additions & 0 deletions packages/react-table/src/components/TableComposable/Td.tsx
@@ -1,6 +1,7 @@
import * as React from 'react';
import { css } from '@patternfly/react-styles';
import styles from '@patternfly/react-styles/css/components/Table/table';
import scrollStyles from '@patternfly/react-styles/css/components/Table/table-scrollable';
import { BaseCellProps } from './TableComposable';
import { cellActions } from '../Table/utils/decorators/cellActions';
import { selectable } from '../Table/utils/decorators/selectable';
Expand Down Expand Up @@ -57,6 +58,14 @@ export interface TdProps extends BaseCellProps, Omit<React.HTMLProps<HTMLTableDa
tooltip?: React.ReactNode;
/** Callback on mouse enter */
onMouseEnter?: (event: any) => void;
/** Indicates the column should be sticky */
isStickyColumn?: boolean;
/** Adds a border to the right side of the cell */
hasRightBorder?: boolean;
/** Minimum width for a sticky column */
stickyMinWidth?: string;
/** Left offset of a sticky column. This will typically be equal to the combined value set by stickyMinWidth of any sticky columns that precede the current sticky column. */
stickyLeftOffset?: string;
}

const TdBase: React.FunctionComponent<TdProps> = ({
Expand All @@ -80,6 +89,10 @@ const TdBase: React.FunctionComponent<TdProps> = ({
draggableRow: draggableRowProp = null,
tooltip = '',
onMouseEnter: onMouseEnterProp = () => {},
isStickyColumn = false,
hasRightBorder = false,
stickyMinWidth = '120px',
stickyLeftOffset,
...props
}: TdProps) => {
const [showTooltip, setShowTooltip] = React.useState(false);
Expand Down Expand Up @@ -239,13 +252,22 @@ const TdBase: React.FunctionComponent<TdProps> = ({
isActionCell && styles.tableAction,
textCenter && styles.modifiers.center,
noPadding && styles.modifiers.noPadding,
isStickyColumn && scrollStyles.tableStickyColumn,
hasRightBorder && scrollStyles.modifiers.borderRight,
styles.modifiers[modifier as 'breakWord' | 'fitContent' | 'nowrap' | 'truncate' | 'wrap' | undefined],
draggableParams && styles.tableDraggable,
mergedClassName
)}
ref={innerRef}
{...mergedProps}
{...props}
{...(isStickyColumn && {
style: {
'--pf-c-table__sticky-column--MinWidth': stickyMinWidth ? stickyMinWidth : undefined,
'--pf-c-table__sticky-column--Left': stickyLeftOffset ? stickyLeftOffset : undefined,
...props.style
} as React.CSSProperties
})}
>
{mergedChildren || children}
</MergedComponent>
Expand Down
5 changes: 5 additions & 0 deletions packages/react-table/src/components/TableComposable/Th.tsx
Expand Up @@ -109,6 +109,11 @@ const ThBase: React.FunctionComponent<ThProps> = ({
}
const selectParams = select
? selectable(children as IFormatterValueType, {
rowData: {
selected: select.isSelected,
disableSelection: select?.disable,
props: select?.props
},
column: {
extraParams: {
onSelect: select?.onSelect,
Expand Down