Skip to content

Commit 92a7d1e

Browse files
committed
[Utils] Remove getStylesForCell
- in favor of a more agnostic height-type util - We'll be replacing the line count styles with the new `EuiTextBlockTruncate` component - NOTE: the `height: 100%` style needs to be retained for `lineCount` and `numerical` height types, hence the new util that will be passed to a CSS class
1 parent 7f14f18 commit 92a7d1e

3 files changed

Lines changed: 28 additions & 55 deletions

File tree

src/components/datagrid/utils/__mocks__/row_heights.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,7 @@ export const RowHeightUtils = jest.fn().mockImplementation(() => {
2424

2525
const rowHeightUtilsMock: RowHeightUtilsPublicAPI = {
2626
cacheStyles: jest.fn(),
27-
getStylesForCell: jest.fn(() => ({
28-
wordWrap: 'break-word',
29-
wordBreak: 'break-word',
30-
flexGrow: 1,
31-
})),
27+
getHeightType: jest.fn(rowHeightUtils.getHeightType),
3228
isAutoHeight: jest.fn(() => false),
3329
setRowHeight: jest.fn(),
3430
pruneHiddenColumnHeights: jest.fn(),

src/components/datagrid/utils/row_heights.test.ts

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -184,34 +184,22 @@ describe('RowHeightUtils', () => {
184184
});
185185
});
186186
});
187+
});
187188

188-
describe('getStylesForCell (returns inline CSS styles based on height config)', () => {
189-
describe('auto height', () => {
190-
it('returns empty styles object', () => {
191-
expect(
192-
rowHeightUtils.getStylesForCell({ defaultHeight: 'auto' }, 0)
193-
).toEqual({});
194-
});
195-
});
196-
197-
describe('lineCount height', () => {
198-
it('returns line-clamp CSS', () => {
199-
expect(
200-
rowHeightUtils.getStylesForCell(
201-
{ defaultHeight: { lineCount: 5 } },
202-
0
203-
)
204-
).toEqual(expect.objectContaining({ WebkitLineClamp: 5 }));
205-
});
206-
});
207-
208-
describe('numeric heights', () => {
209-
it('returns default CSS', () => {
210-
expect(
211-
rowHeightUtils.getStylesForCell({ defaultHeight: 34 }, 0)
212-
).toEqual({ height: '100%', overflow: 'hidden' });
213-
});
214-
});
189+
describe('getHeightType', () => {
190+
it('returns a string enum based on rowHeightsOptions', () => {
191+
expect(rowHeightUtils.getHeightType(undefined)).toEqual('default');
192+
expect(rowHeightUtils.getHeightType('auto')).toEqual('auto');
193+
expect(rowHeightUtils.getHeightType({ lineCount: 3 })).toEqual(
194+
'lineCount'
195+
);
196+
expect(rowHeightUtils.getHeightType({ lineCount: 0 })).toEqual(
197+
'lineCount'
198+
);
199+
expect(rowHeightUtils.getHeightType({ height: 100 })).toEqual(
200+
'numerical'
201+
);
202+
expect(rowHeightUtils.getHeightType(100)).toEqual('numerical');
215203
});
216204
});
217205

src/components/datagrid/utils/row_heights.ts

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*/
88

99
import {
10-
CSSProperties,
1110
MutableRefObject,
1211
useCallback,
1312
useContext,
@@ -107,31 +106,21 @@ export class RowHeightUtils {
107106
};
108107
}
109108

110-
getStylesForCell = (
111-
rowHeightsOptions: EuiDataGridRowHeightsOptions,
112-
rowIndex: number
113-
): CSSProperties => {
114-
const height = this.getRowHeightOption(rowIndex, rowHeightsOptions);
109+
/**
110+
* Height types
111+
*/
115112

116-
if (height === AUTO_HEIGHT) {
117-
return {};
113+
getHeightType = (option?: EuiDataGridRowHeightOption) => {
114+
if (option == null) {
115+
return 'default';
118116
}
119-
120-
const lineCount = this.getLineCount(height);
121-
if (lineCount) {
122-
return {
123-
WebkitLineClamp: lineCount,
124-
display: '-webkit-box',
125-
WebkitBoxOrient: 'vertical',
126-
height: '100%',
127-
overflow: 'hidden',
128-
};
117+
if (option === AUTO_HEIGHT) {
118+
return 'auto';
129119
}
130-
131-
return {
132-
height: '100%',
133-
overflow: 'hidden',
134-
};
120+
if (this.getLineCount(option) != null) {
121+
return 'lineCount';
122+
}
123+
return 'numerical';
135124
};
136125

137126
/**

0 commit comments

Comments
 (0)