diff --git a/docs/src/Table.doc.js b/docs/src/Table.doc.js index 6b9b4d04a89..e17a9d6f1da 100644 --- a/docs/src/Table.doc.js +++ b/docs/src/Table.doc.js @@ -264,8 +264,8 @@ card( id="stickyColumn" name="Example: Sticky Column" defaultCode={` - - + +
@@ -357,8 +357,8 @@ card( id="stickyColumn2" name="Example: Sticky 2nd or 3rd Column" defaultCode={` - -
+ +
diff --git a/packages/gestalt/src/Table.css b/packages/gestalt/src/Table.css index 3572d248888..a6b2d230eb7 100644 --- a/packages/gestalt/src/Table.css +++ b/packages/gestalt/src/Table.css @@ -2,6 +2,7 @@ border-collapse: separate; border-spacing: 0; width: 100%; + isolation: isolate; } .th { @@ -13,24 +14,64 @@ .td { composes: paddingY3 from "./boxWhitespace.css"; composes: paddingX3 from "./boxWhitespace.css"; + position: relative; +} + +td div{ + z-index: 1; + position: relative; } .sticky tr th { background-color: var(--g-colorGray0); position: sticky; top: 0; - z-index: 2; + z-index: 6; } .columnSticky { - background-color: yellow; + background-color: var(--g-colorGray0); position:sticky; left: 0; - z-index: 1; + z-index: 3; } -.sticky th.columnSticky { +.columnSticky div { + z-index: 4; + isolation: isolate; +} + +.columnStickyShadow div { z-index: 3; + position: relative; +} + + +.columnStickyShadow::before { + content: ""; + position: absolute; + top: 0; + bottom: 0; + left: 0; + right: 0; + box-shadow: 8px 0px 8px -8px var(--g-colorGray150); +} + + +.columnStickyShadow + td::before { + content: ""; + position: absolute; + top: 0; + bottom: 0; + left: 0; + right: 0; + z-index: 4; + background-color: transparent; + box-shadow: inset 8px -8px white; +} + +.sticky th.columnSticky { + z-index: 7; } .thead tr:last-child th { diff --git a/packages/gestalt/src/Table.js b/packages/gestalt/src/Table.js index 2e7db03d3b3..03baf9fdc30 100644 --- a/packages/gestalt/src/Table.js +++ b/packages/gestalt/src/Table.js @@ -16,11 +16,11 @@ type Props = {| children: Node, borderStyle?: 'sm' | 'none', maxHeight?: number | string, - stickyColumn?: number, + stickyColumns?: number, |}; export default function Table(props: Props): Node { - const { borderStyle, children, maxHeight, stickyColumn = -1 } = props; + const { borderStyle, children, maxHeight, stickyColumns } = props; return (
- {children} + {children}
); diff --git a/packages/gestalt/src/TableCell.js b/packages/gestalt/src/TableCell.js index 6efbb571643..a6b4ff77fc2 100644 --- a/packages/gestalt/src/TableCell.js +++ b/packages/gestalt/src/TableCell.js @@ -8,12 +8,24 @@ type Props = {| colSpan?: number, rowSpan?: number, shouldBeSticky?: boolean, + shouldHaveShadow?: boolean, previousTotalWidth?: number, |}; export default function TableCell(props: Props): Node { - const { children, colSpan, rowSpan, shouldBeSticky, previousTotalWidth } = props; - const cs = cx(styles.td, shouldBeSticky && styles.columnSticky); + const { + children, + colSpan, + rowSpan, + shouldBeSticky, + previousTotalWidth, + shouldHaveShadow, + } = props; + const cs = cx( + styles.td, + shouldBeSticky && styles.columnSticky, + shouldHaveShadow && styles.columnStickyShadow, + ); return ( = createContext(initialState); diff --git a/packages/gestalt/src/TableHeaderCell.js b/packages/gestalt/src/TableHeaderCell.js index 8e9d9802e08..fde04e463fd 100644 --- a/packages/gestalt/src/TableHeaderCell.js +++ b/packages/gestalt/src/TableHeaderCell.js @@ -5,7 +5,8 @@ import styles from './Table.css'; type Props = {| children: Node, - shouldBeSticky?: Boolean, + shouldBeSticky?: boolean, + shouldHaveShadow?: boolean, colSpan?: number, rowSpan?: number, scope?: 'col' | 'colgroup' | 'row' | 'rowgroup', @@ -13,8 +14,20 @@ type Props = {| |}; export default function TableHeaderCell(props: Props): Node { - const { children, colSpan, scope, rowSpan, shouldBeSticky, previousTotalWidth } = props; - const cs = cx(styles.th, shouldBeSticky && styles.columnSticky); + const { + children, + colSpan, + scope, + rowSpan, + shouldBeSticky, + previousTotalWidth, + shouldHaveShadow, + } = props; + const cs = cx( + styles.th, + shouldBeSticky && styles.columnSticky, + shouldHaveShadow && styles.columnStickyShadow, + ); return ( { - if (rowRef && rowRef.current && stickyColumn > 0) { + if (rowRef && rowRef.current && stickyColumns) { const colWidths = []; const tableRowChildrenArray = [...rowRef.current.children]; tableRowChildrenArray.forEach((child) => { @@ -20,21 +20,22 @@ export default function TableRow(props: Props): Node { }); setColumnWidths(colWidths); } - }, [rowRef, stickyColumn]); + }, [rowRef, stickyColumns]); const renderCellsWithIndex = () => { const cells = []; const tableRowChildrenArray = Children.toArray(props.children); tableRowChildrenArray.forEach((child, index) => { - const shouldBeSticky = stickyColumn >= 0 && index < stickyColumn; + const shouldBeSticky = stickyColumns >= 0 && index < stickyColumns; + const shouldHaveShadow = stickyColumns - 1 === index; const previousWidths = columnWidths.slice(0, index); const previousTotalWidth = previousWidths.length > 0 ? previousWidths.reduce((a, b) => a + b) : 0; - cells.push(cloneElement(child, { shouldBeSticky, previousTotalWidth })); + cells.push(cloneElement(child, { shouldBeSticky, previousTotalWidth, shouldHaveShadow })); }); return cells; }; - return {stickyColumn > 0 ? renderCellsWithIndex() : props.children}; + return {stickyColumns > 0 ? renderCellsWithIndex() : props.children}; } diff --git a/packages/gestalt/src/TableRowExpandable.js b/packages/gestalt/src/TableRowExpandable.js index ae79ebf8fa6..c4bffe8b027 100644 --- a/packages/gestalt/src/TableRowExpandable.js +++ b/packages/gestalt/src/TableRowExpandable.js @@ -36,7 +36,7 @@ export default function TableRowExpandable(props: Props): Node { const [expanded, setExpanded] = useState(false); const hoverStyle = props.hoverStyle || 'gray'; const cs = hoverStyle === 'gray' ? cx(styles.hoverShadeGray) : null; - const { stickyColumn = -1 } = useContext(TableContext); + const { stickyColumns } = useContext(TableContext); const handleButtonClick = ({ event }) => { setExpanded(!expanded); @@ -48,7 +48,7 @@ export default function TableRowExpandable(props: Props): Node { return ( - 0} previousTotalWidth={0}> + 0} previousTotalWidth={0}>