Skip to content

Commit 26c96ee

Browse files
Rework frozen column shadow (#3969)
* Rework frozen column shadow * Update screenshots Co-authored-by: nstepien * tweak shadow * Update screenshots Co-authored-by: nstepien * rework * removed unused var * would you look at that, we already had totalFrozenColumnWidth --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent da265d3 commit 26c96ee

File tree

10 files changed

+90
-18
lines changed

10 files changed

+90
-18
lines changed

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,6 @@ The DataGrid supports the following CSS variables for customization:
187187
--rdg-summary-border-width: calc(var(--rdg-border-width) * 2);
188188
--rdg-summary-border-color: light-dark(#aaa, #555);
189189

190-
/* Frozen columns */
191-
--rdg-cell-frozen-box-shadow: 2px 0 5px -2px rgba(136, 136, 136, 0.3);
192-
193190
/* Checkboxes */
194191
--rdg-checkbox-focus-color: hsl(207deg 100% 69%);
195192
}

src/DataGrid.tsx

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,12 @@ import type { PartialPosition } from './ScrollToCell';
6969
import ScrollToCell from './ScrollToCell';
7070
import { default as defaultRenderSortStatus } from './sortStatus';
7171
import { cellDragHandleClassname, cellDragHandleFrozenClassname } from './style/cell';
72-
import { rootClassname, viewportDraggingClassname } from './style/core';
72+
import {
73+
rootClassname,
74+
frozenColumnShadowClassname,
75+
viewportDraggingClassname,
76+
frozenColumnShadowTopClassname
77+
} from './style/core';
7378
import SummaryRow from './SummaryRow';
7479

7580
export interface SelectCellState extends Position {
@@ -368,6 +373,10 @@ export function DataGrid<R, SR = unknown, K extends Key = Key>(props: DataGridPr
368373
const minRowIdx = -headerAndTopSummaryRowsCount;
369374
const mainHeaderRowIdx = minRowIdx + groupedColumnHeaderRowsCount;
370375
const maxRowIdx = rows.length + bottomSummaryRowsCount - 1;
376+
const frozenShadowStyles: React.CSSProperties = {
377+
gridColumnStart: lastFrozenColumnIndex + 2,
378+
insetInlineStart: totalFrozenColumnWidth
379+
};
371380

372381
const [selectedPosition, setSelectedPosition] = useState(
373382
(): SelectCellState | EditCellState<R> => ({ idx: -1, rowIdx: minRowIdx - 1, mode: 'SELECT' })
@@ -1269,11 +1278,11 @@ export function DataGrid<R, SR = unknown, K extends Key = Key>(props: DataGridPr
12691278
const isSummaryRowSelected = selectedPosition.rowIdx === summaryRowIdx;
12701279
const top =
12711280
clientHeight > totalRowHeight
1272-
? gridHeight - summaryRowHeight * (bottomSummaryRows.length - rowIdx)
1281+
? gridHeight - summaryRowHeight * (bottomSummaryRowsCount - rowIdx)
12731282
: undefined;
12741283
const bottom =
12751284
top === undefined
1276-
? summaryRowHeight * (bottomSummaryRows.length - 1 - rowIdx)
1285+
? summaryRowHeight * (bottomSummaryRowsCount - 1 - rowIdx)
12771286
: undefined;
12781287

12791288
return (
@@ -1298,6 +1307,47 @@ export function DataGrid<R, SR = unknown, K extends Key = Key>(props: DataGridPr
12981307
)}
12991308
</DataGridDefaultRenderersContext>
13001309

1310+
{lastFrozenColumnIndex > -1 && (
1311+
<>
1312+
<div
1313+
className={frozenColumnShadowTopClassname}
1314+
style={{
1315+
...frozenShadowStyles,
1316+
gridRowStart: 1,
1317+
gridRowEnd: headerRowsCount + 1 + topSummaryRowsCount,
1318+
insetBlockStart: 0
1319+
}}
1320+
/>
1321+
1322+
{rows.length > 0 && (
1323+
<div
1324+
className={frozenColumnShadowClassname}
1325+
style={{
1326+
...frozenShadowStyles,
1327+
gridRowStart: headerAndTopSummaryRowsCount + rowOverscanStartIdx + 1,
1328+
gridRowEnd: headerAndTopSummaryRowsCount + rowOverscanEndIdx + 2
1329+
}}
1330+
/>
1331+
)}
1332+
1333+
{bottomSummaryRows != null && bottomSummaryRowsCount > 0 && (
1334+
<div
1335+
className={frozenColumnShadowTopClassname}
1336+
style={{
1337+
...frozenShadowStyles,
1338+
gridRowStart: headerAndTopSummaryRowsCount + rows.length + 1,
1339+
gridRowEnd: headerAndTopSummaryRowsCount + rows.length + 1 + bottomSummaryRowsCount,
1340+
insetBlockStart:
1341+
clientHeight > totalRowHeight
1342+
? gridHeight - summaryRowHeight * bottomSummaryRowsCount
1343+
: undefined,
1344+
insetBlockEnd: clientHeight > totalRowHeight ? undefined : 0
1345+
}}
1346+
/>
1347+
)}
1348+
</>
1349+
)}
1350+
13011351
{getDragHandle()}
13021352

13031353
{/* render empty cells that span only 1 column so we can safely measure column widths, regardless of colSpan */}

src/style/cell.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@ export const cellFrozen = css`
3535
position: sticky;
3636
/* Should have a higher value than 0 to show up above unfrozen cells */
3737
z-index: 1;
38-
39-
/* Add box-shadow on the last frozen cell */
40-
&:nth-last-child(1 of &) {
41-
box-shadow: var(--rdg-cell-frozen-box-shadow);
42-
}
4338
}
4439
`;
4540

src/style/core.ts

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ const root = css`
1616
--rdg-selection-width: 2px;
1717
--rdg-selection-color: hsl(207, 75%, 66%);
1818
--rdg-font-size: 14px;
19-
--rdg-cell-frozen-box-shadow: 2px 0 5px -2px rgba(136, 136, 136, 0.3);
2019
--rdg-border-width: 1px;
2120
--rdg-summary-border-width: calc(var(--rdg-border-width) * 2);
2221
--rdg-color: light-dark(#000, #ddd);
@@ -38,10 +37,6 @@ const root = css`
3837
color-scheme: light;
3938
}
4039
41-
&:dir(rtl) {
42-
--rdg-cell-frozen-box-shadow: -2px 0 5px -2px rgba(136, 136, 136, 0.3);
43-
}
44-
4540
display: grid;
4641
4742
accent-color: light-dark(hsl(207deg 100% 29%), hsl(207deg 100% 79%));
@@ -59,6 +54,9 @@ const root = css`
5954
color: var(--rdg-color);
6055
font-size: var(--rdg-font-size);
6156
57+
container-name: rdg-root;
58+
container-type: scroll-state;
59+
6260
/* needed on Firefox to fix scrollbars */
6361
&::before {
6462
content: '';
@@ -92,3 +90,35 @@ const viewportDragging = css`
9290
`;
9391

9492
export const viewportDraggingClassname = `rdg-viewport-dragging ${viewportDragging}`;
93+
94+
// Add shadow after the last frozen cell
95+
export const frozenColumnShadowClassname = css`
96+
position: sticky;
97+
width: 10px;
98+
background-image: linear-gradient(
99+
to right,
100+
light-dark(rgb(0 0 0 / 15%), rgb(0 0 0 / 40%)),
101+
transparent
102+
);
103+
pointer-events: none;
104+
z-index: 1;
105+
106+
opacity: 1;
107+
transition: opacity 0.1s;
108+
109+
/* TODO: reverse 'opacity' and remove 'not' */
110+
@container rdg-root not scroll-state(scrollable: inline-start) {
111+
opacity: 0;
112+
}
113+
114+
&:dir(rtl) {
115+
transform: scaleX(-1);
116+
}
117+
`;
118+
119+
const topShadowClassname = css`
120+
/* render above header and summary rows */
121+
z-index: 2;
122+
`;
123+
124+
export const frozenColumnShadowTopClassname = `${frozenColumnShadowClassname} ${topShadowClassname}`;
-2.26 KB
Loading
-1.26 KB
Loading
-2.38 KB
Loading
-1.65 KB
Loading

website/routes/CommonFeatures.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const dialogContainerClassname = css`
3434
inset: 0;
3535
display: flex;
3636
place-items: center;
37-
background: rgba(0, 0, 0, 0.1);
37+
background: rgb(0 0 0 / 10%);
3838
3939
> dialog {
4040
width: 300px;

website/routes/NoRows.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const gridClassname = css`
1515

1616
function EmptyRowsRenderer() {
1717
return (
18-
<div style={{ textAlign: 'center', gridColumn: '1/-1' }}>
18+
<div style={{ gridColumn: '1/-1', placeSelf: 'center' }}>
1919
Nothing to show{' '}
2020
<span lang="ja" title="ショボーン">
2121
(´・ω・`)

0 commit comments

Comments
 (0)