Skip to content

Commit 87895d9

Browse files
authored
Merge pull request #193 from dcos-labs/weblancaster/feat/DCOS-39674-fixed-column-shadow
DCOS-39674: feat: add column shadow
2 parents 88cc757 + 19736d2 commit 87895d9

File tree

5 files changed

+71
-5
lines changed

5 files changed

+71
-5
lines changed

packages/shared/styles/color.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ export const customColors = (): IColors => {
124124
return {};
125125
};
126126

127-
export function hexToRgbA(hex: string, alpha: string | number = 1): string {
127+
export const hexToRgbA = (hex: string, alpha: string | number = 1): string => {
128128
let color;
129129
if (/^#([A-Fa-f0-9]{3}){1,2}$/.test(hex)) {
130130
color = hex.substring(1).split("");
@@ -141,4 +141,4 @@ export function hexToRgbA(hex: string, alpha: string | number = 1): string {
141141
);
142142
}
143143
return "rgba(0,0,0,0)";
144-
}
144+
};

packages/table/components/Table.tsx

+29-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as React from "react";
22
import { css } from "emotion";
33
import { AutoSizer, MultiGrid, GridCellProps } from "react-virtualized";
44

5-
import { headerCss, cellCss, tableCss } from "../style";
5+
import { headerCss, cellCss, tableCss, rightGrid } from "../style";
66

77
import { IColumnProps, Column } from "./Column";
88
import memoizeOne from "memoize-one";
@@ -17,11 +17,15 @@ export interface ITableProps {
1717
| React.ReactElement<IColumnProps>;
1818
}
1919

20+
export interface ITableState {
21+
isScroll: boolean;
22+
}
23+
2024
const ROW_HEIGHT = 35;
2125

2226
const DEFAULT_WIDTH = 1024;
2327
const DEFAULT_HEIGHT = 768;
24-
export class Table<T> extends React.PureComponent<ITableProps, {}> {
28+
export class Table<T> extends React.PureComponent<ITableProps, ITableState> {
2529
public multiGridRef: { recomputeGridSize?: any } = {};
2630

2731
public getData = memoizeOne(
@@ -57,6 +61,11 @@ export class Table<T> extends React.PureComponent<ITableProps, {}> {
5761
this.setRef = this.setRef.bind(this);
5862
this.updateGridSize = this.updateGridSize.bind(this);
5963
this.getGrid = this.getGrid.bind(this);
64+
this.onScrollbarPresenceChange = this.onScrollbarPresenceChange.bind(this);
65+
66+
this.state = {
67+
isScroll: false
68+
};
6069
}
6170

6271
public render() {
@@ -73,7 +82,22 @@ export class Table<T> extends React.PureComponent<ITableProps, {}> {
7382
);
7483
}
7584

85+
private onScrollbarPresenceChange({ horizontal }) {
86+
if (horizontal) {
87+
this.setState({
88+
isScroll: true
89+
});
90+
91+
return;
92+
}
93+
94+
this.setState({
95+
isScroll: false
96+
});
97+
}
98+
7699
private getGrid({ width, height }) {
100+
const rightGridStyles = this.state.isScroll ? rightGrid : "";
77101
const columnCount = React.Children.count(this.props.children);
78102
const columnSizes = this.getColumnSizes(
79103
React.Children.toArray(this.props.children) as Array<
@@ -88,6 +112,7 @@ export class Table<T> extends React.PureComponent<ITableProps, {}> {
88112

89113
return (
90114
<MultiGrid
115+
onScrollbarPresenceChange={this.onScrollbarPresenceChange}
91116
ref={this.setRef}
92117
fixedColumnCount={1}
93118
fixedRowCount={1}
@@ -102,6 +127,8 @@ export class Table<T> extends React.PureComponent<ITableProps, {}> {
102127
width={width}
103128
hideTopRightGridScrollbar={true}
104129
hideBottomLeftGridScrollbar={true}
130+
classNameTopRightGrid={rightGridStyles}
131+
classNameBottomRightGrid={rightGridStyles}
105132
/>
106133
);
107134
}

packages/table/stories/Table.stories.tsx

+27
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,33 @@ storiesOf("Table", module)
155155
</Table>
156156
</div>
157157
))
158+
.addWithInfo("no scroll", () => (
159+
<div
160+
style={{
161+
height: "175px",
162+
width: "100%",
163+
fontSize: "14px"
164+
}}
165+
>
166+
<Table data={items}>
167+
<Column
168+
header={<HeaderCell>name</HeaderCell>}
169+
cellRenderer={nameCellRenderer}
170+
width={width}
171+
/>
172+
<Column
173+
header={<HeaderCell>role</HeaderCell>}
174+
cellRenderer={roleCellRenderer}
175+
width={width}
176+
/>
177+
<Column
178+
header={<HeaderCell>state</HeaderCell>}
179+
cellRenderer={stateCellRenderer}
180+
width={width}
181+
/>
182+
</Table>
183+
</div>
184+
))
158185
.addWithInfo("changing values", () => (
159186
<div
160187
style={{

packages/table/style.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { css } from "emotion";
2-
import { coreColors } from "../shared/styles/color";
2+
import { coreColors, hexToRgbA } from "../shared/styles/color";
33
import { coreFonts } from "../shared/styles/typography";
44

55
const { black, greyLight } = coreColors();
@@ -22,3 +22,13 @@ export const tableCss = css`
2222
font-family: ${fontFamilySansSerif};
2323
font-weight: normal;
2424
`;
25+
26+
export const rightGrid = css`
27+
background: linear-gradient(
28+
to right,
29+
${hexToRgbA(black, 0.2)},
30+
${hexToRgbA(black, 0)}
31+
);
32+
background-repeat: no-repeat;
33+
background-size: 8px 100%;
34+
`;

packages/table/tests/__snapshots__/Table.test.tsx.snap

+2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ exports[`Table renders again with new data 1`] = `
5656
height={0}
5757
hideBottomLeftGridScrollbar={true}
5858
hideTopRightGridScrollbar={true}
59+
onScrollbarPresenceChange={[Function]}
5960
rowCount={4}
6061
rowHeight={35}
6162
scrollToColumn={-1}
@@ -128,6 +129,7 @@ exports[`Table renders again with new data 2`] = `
128129
height={0}
129130
hideBottomLeftGridScrollbar={true}
130131
hideTopRightGridScrollbar={true}
132+
onScrollbarPresenceChange={[Function]}
131133
rowCount={4}
132134
rowHeight={35}
133135
scrollToColumn={-1}

0 commit comments

Comments
 (0)