Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Emotion] Convert EuiDataGrid (Part 1) #7998

Merged
merged 9 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ exports[`EuiDataGrid rendering renders additional toolbar controls 1`] = `
tabindex="0"
>
<div
class="euiDataGrid__virtualized"
class="euiDataGrid__virtualized emotion-euiDataGridBody-virtualized"
style="position: relative; height: 9007199254740991px; width: 9007199254740991px; overflow: auto; will-change: transform; direction: ltr;"
>
<div
Expand Down Expand Up @@ -992,7 +992,7 @@ exports[`EuiDataGrid rendering renders control columns 1`] = `
tabindex="0"
>
<div
class="euiDataGrid__virtualized"
class="euiDataGrid__virtualized emotion-euiDataGridBody-virtualized"
style="position: relative; height: 9007199254740991px; width: 9007199254740991px; overflow: auto; will-change: transform; direction: ltr;"
>
<div
Expand Down Expand Up @@ -1592,7 +1592,7 @@ exports[`EuiDataGrid rendering renders custom column headers 1`] = `
tabindex="0"
>
<div
class="euiDataGrid__virtualized"
class="euiDataGrid__virtualized emotion-euiDataGridBody-virtualized"
style="position: relative; height: 9007199254740991px; width: 9007199254740991px; overflow: auto; will-change: transform; direction: ltr;"
>
<div
Expand Down Expand Up @@ -2000,7 +2000,7 @@ exports[`EuiDataGrid rendering renders with common and div attributes 1`] = `
tabindex="0"
>
<div
class="euiDataGrid__virtualized"
class="euiDataGrid__virtualized emotion-euiDataGridBody-virtualized"
style="position: relative; height: 9007199254740991px; width: 9007199254740991px; overflow: auto; will-change: transform; direction: ltr;"
>
<div
Expand Down
11 changes: 0 additions & 11 deletions packages/eui/src/components/datagrid/_data_grid.scss
Original file line number Diff line number Diff line change
@@ -1,11 +0,0 @@
.euiDataGrid__customRenderBody {
@include euiScrollBar($euiColorDarkShade, $euiColorEmptyShade);
height: 100%;
width: 100%;
overflow: auto;
}

.euiDataGrid__virtualized {
@include euiScrollBar($euiColorDarkShade, $euiColorEmptyShade);
scroll-padding: 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { css } from '@emotion/react';

import { UseEuiTheme } from '../../../services';
import { euiScrollBarStyles, logicalSizeCSS } from '../../../global_styling';

export const euiDataGridBodyStyles = (euiThemeContext: UseEuiTheme) => {
return {
euiDataGridBody: css`
${euiScrollBarStyles(euiThemeContext)}
`,
virtualized: css`
scroll-padding: 0;
`,
customRender: css`
${logicalSizeCSS('100%')}
overflow: auto;
`,
};
};
11 changes: 10 additions & 1 deletion packages/eui/src/components/datagrid/body/data_grid_body.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@

import React, { FunctionComponent } from 'react';

import { useEuiMemoizedStyles } from '../../../services';
import { EuiDataGridBodyProps } from '../data_grid_types';
import { EuiDataGridBodyVirtualized } from './data_grid_body_virtualized';
import { EuiDataGridBodyCustomRender } from './data_grid_body_custom';
import { euiDataGridBodyStyles } from './data_grid_body.styles';

export const EuiDataGridBody: FunctionComponent<EuiDataGridBodyProps> = ({
renderCustomGridBody,
Expand All @@ -21,12 +23,19 @@ export const EuiDataGridBody: FunctionComponent<EuiDataGridBodyProps> = ({
* + virtualization library for rendering content, or if consumers have
* passed their own custom renderer
*/
const styles = useEuiMemoizedStyles(euiDataGridBodyStyles);
const cssStyles = [
styles.euiDataGridBody,
renderCustomGridBody ? styles.customRender : styles.virtualized,
];

return renderCustomGridBody ? (
<EuiDataGridBodyCustomRender
renderCustomGridBody={renderCustomGridBody}
css={cssStyles}
{...props}
/>
) : (
<EuiDataGridBodyVirtualized {...props} />
<EuiDataGridBodyVirtualized css={cssStyles} {...props} />
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export const EuiDataGridBodyCustomRender: FunctionComponent<
rowHeightsOptions,
gridWidth,
gridStyles,
className,
}) => {
/**
* Columns & widths
Expand Down Expand Up @@ -187,6 +188,7 @@ export const EuiDataGridBodyCustomRender: FunctionComponent<
{...customGridBodyProps}
className={classNames(
'euiDataGrid__customRenderBody',
className,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL. Thanks for the note on the required className 👍

customGridBodyProps?.className
)}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export const EuiDataGridBodyVirtualized: FunctionComponent<EuiDataGridBodyProps>
gridRef,
gridItemsRendered,
wrapperRef,
className,
}) => {
/**
* Grid refs & observers
Expand Down Expand Up @@ -367,6 +368,7 @@ export const EuiDataGridBodyVirtualized: FunctionComponent<EuiDataGridBodyProps>
ref={gridRef}
className={classNames(
'euiDataGrid__virtualized',
className,
virtualizationOptions?.className
)}
onItemsRendered={onItemsRendered}
Expand Down
1 change: 1 addition & 0 deletions packages/eui/src/components/datagrid/data_grid_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ export interface EuiDataGridBodyProps {
gridRef: MutableRefObject<Grid | null>;
gridItemsRendered: MutableRefObject<GridOnItemsRenderedProps | null>;
wrapperRef: MutableRefObject<HTMLDivElement | null>;
className?: string;
}

export interface EuiDataGridCustomBodyProps {
Expand Down