Skip to content

Commit

Permalink
Merge pull request #209 from dcos-labs/mp/fix/DCOS-40355-tablerow-hover
Browse files Browse the repository at this point in the history
DCOS-40355: add hover style for Table rows
  • Loading branch information
DanielMSchmidt authored Aug 21, 2018
2 parents de0fe9a + 744f160 commit 773927a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
19 changes: 16 additions & 3 deletions packages/table/components/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
cellCss,
tableCss,
rightGrid,
hideScrollbarCss
hideScrollbarCss,
rowHoverCss
} from "../style";

import { IColumnProps, Column } from "./Column";
Expand All @@ -25,6 +26,7 @@ export interface ITableProps {

export interface ITableState {
isScrolling: boolean;
hoveredRowIndex: number;
}

const ROW_HEIGHT = 35;
Expand Down Expand Up @@ -70,7 +72,8 @@ export class Table<T> extends React.PureComponent<ITableProps, ITableState> {
this.onScroll = this.onScroll.bind(this);

this.state = {
isScrolling: false
isScrolling: false,
hoveredRowIndex: -1
};
}

Expand Down Expand Up @@ -183,8 +186,18 @@ export class Table<T> extends React.PureComponent<ITableProps, ITableState> {
const className = css(cellCss, {
...style
});
const updateHoveredRowIndex = () => {
this.setState({ hoveredRowIndex: rowIndex });
};

return (
<div className={className} key={key}>
<div
className={cx(className, {
[rowHoverCss]: rowIndex === this.state.hoveredRowIndex
})}
key={key}
onMouseOver={updateHoveredRowIndex}
>
{column.props.cellRenderer(data[rowIndex])}
</div>
);
Expand Down
8 changes: 7 additions & 1 deletion packages/table/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { css } from "emotion";
import { coreColors, hexToRgbA } from "../shared/styles/color";
import { coreFonts } from "../shared/styles/typography";

const { black, greyLight } = coreColors();
const { black, greyLight, greyLightLighten5 } = coreColors();
const { fontFamilySansSerif } = coreFonts();

export const headerCss = css`
Expand Down Expand Up @@ -40,3 +40,9 @@ export const hideScrollbarCss = css`
display: none;
}
`;

export const rowHoverCss = css`
background-color: ${greyLightLighten5};
mix-blend-mode: multiply;
will-change: left;
`;

0 comments on commit 773927a

Please sign in to comment.