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

[EuiDataGrid] Auto-fit rows to content #4958

Merged
merged 74 commits into from
Sep 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
83bb0c3
Add auto height possibility to row
VladLasitsa Jul 16, 2021
39bfc86
Fix eslint
VladLasitsa Jul 16, 2021
40c2cf0
Fix some problems with hiding column
VladLasitsa Jul 19, 2021
e76129d
Fix example
VladLasitsa Jul 19, 2021
c2de611
Fix example
VladLasitsa Jul 19, 2021
d06b9fa
Merge branch 'master' into auto_height_data_grid
VladLasitsa Jul 19, 2021
428860f
fix calculation height so that work for images and fix problems with …
VladLasitsa Jul 22, 2021
05c52a8
Fix tests
VladLasitsa Jul 23, 2021
eca4c2b
fix eslint
VladLasitsa Jul 23, 2021
82f698a
fix some problems
VladLasitsa Jul 26, 2021
253f16a
use resizeObserver instead of handling height in didMount method
VladLasitsa Jul 27, 2021
9fe0270
Fix some remarks
VladLasitsa Jul 28, 2021
8027a88
Merge remote-tracking branch 'upstream/master' into auto_height_data_…
VladLasitsa Jul 28, 2021
2664080
fix some problems with shrinking
VladLasitsa Jul 30, 2021
517ebcb
Fix scrolling
VladLasitsa Jul 30, 2021
6f97f54
Merge remote-tracking branch 'upstream/master' into auto_height_data_…
VladLasitsa Jul 30, 2021
752b354
Some performance improvements
VladLasitsa Aug 4, 2021
ce4ffa4
use callback ref for setting grid in rowHeigthsUtils instead of useEf…
VladLasitsa Aug 5, 2021
d79e523
Add new properties
VladLasitsa Aug 9, 2021
b4abd60
Merge remote-tracking branch 'upstream/master' into auto_height_data_…
VladLasitsa Aug 9, 2021
e949d6b
add changelog
VladLasitsa Aug 9, 2021
ffa0926
Fix lint
VladLasitsa Aug 9, 2021
4a7fdda
convert autoheight example to TS
chandlerprall Aug 13, 2021
a7bdaef
Merge branch 'master' into auto_height_data_grid
chandlerprall Aug 18, 2021
1457544
With data
chandlerprall Aug 19, 2021
8fc8edc
examples cleanup
chandlerprall Aug 19, 2021
081d786
Merge remote-tracking branch 'upstream/master' into auto_height_data_…
VladLasitsa Aug 30, 2021
0c3926e
Some fixes
VladLasitsa Aug 30, 2021
3fdb852
Add virtualizationOptions
VladLasitsa Aug 31, 2021
55b650b
Improve performance
VladLasitsa Sep 3, 2021
7ea6b88
Fix useEffect
VladLasitsa Sep 3, 2021
0425428
Merge remote-tracking branch 'upstream/master' into auto_height_data_…
VladLasitsa Sep 3, 2021
5d470bd
Merge remote-tracking branch 'upstream/master' into auto_height_data_…
VladLasitsa Sep 6, 2021
00bf264
Fix tests
VladLasitsa Sep 6, 2021
e12aeff
Fix lint
VladLasitsa Sep 6, 2021
2d670d0
Remove unnecessary changes
VladLasitsa Sep 6, 2021
fb162ce
Remove unnecessary changes
VladLasitsa Sep 6, 2021
fdf5756
Fix tests
VladLasitsa Sep 6, 2021
99a4d9e
Cleaned up lastUpdatedRow a bit
chandlerprall Sep 9, 2021
875d5e9
example cleanup
chandlerprall Sep 9, 2021
b45b17f
Merge remote-tracking branch 'upstream/master' into auto_height_data_…
VladLasitsa Sep 13, 2021
ebe3ccf
Fix lint
VladLasitsa Sep 13, 2021
7a6a0d6
DRY out mock rowHeightUtils
cee-chen Sep 14, 2021
9536362
[EuiGridCell] Refactor + write test for new componentDidUpdate logic
cee-chen Sep 14, 2021
f58d629
[EuiGridCell] PR feedback: destructure props for readability
cee-chen Sep 14, 2021
1ec69e9
Merge branch 'master' into auto_height_data_grid
cee-chen Sep 14, 2021
b2e9976
fix nit's
VladLasitsa Sep 15, 2021
c1c52d4
Making datagrid matching the top snippet and improving demo
miukimiu Sep 15, 2021
9231c30
Fixing comments line
miukimiu Sep 15, 2021
f664e6d
Merge remote-tracking branch 'upstream/master' into auto_height_data_…
miukimiu Sep 15, 2021
425de96
Removing HTML code
miukimiu Sep 15, 2021
e5d766f
New section title
miukimiu Sep 15, 2021
8bc5aac
Small logic optimization
chandlerprall Sep 15, 2021
4ac0a88
Improving texts
miukimiu Sep 15, 2021
968ee10
Renaming files and improving "fixed heights rows" demo
miukimiu Sep 15, 2021
16fcec5
Merge branch 'auto_height_data_grid' of https://github.com/VladLasits…
miukimiu Sep 15, 2021
1a015b6
Better text :D
miukimiu Sep 15, 2021
6e46f05
Merge branch 'master' into auto_height_data_grid
chandlerprall Sep 15, 2021
b8bce9c
Text again
miukimiu Sep 15, 2021
34a38c3
Merge branch 'auto_height_data_grid' of https://github.com/VladLasits…
miukimiu Sep 15, 2021
8f3d3df
Correctly identify the row heights page in the a11y test skipping
chandlerprall Sep 15, 2021
0c13260
Small copy cleanup
chandlerprall Sep 15, 2021
4744bf1
small example cleanup
chandlerprall Sep 15, 2021
6969933
Fix calculating defaultHeight after using density
VladLasitsa Sep 16, 2021
77bcbb2
Update mock
VladLasitsa Sep 16, 2021
d1d4305
make visibility property depends on calculating cell height
VladLasitsa Sep 16, 2021
110b903
Merge branch 'master' into auto_height_data_grid
chandlerprall Sep 16, 2021
5d589cc
make lint happy
chandlerprall Sep 16, 2021
675ebad
Merge branch 'master' into auto_height_data_grid
constancecchen Sep 16, 2021
9441e39
Revert "make visibility property depends on calculating cell height"
VladLasitsa Sep 16, 2021
9e3fc6d
snapshot
chandlerprall Sep 16, 2021
dbe8cf6
Updating example to make density work
miukimiu Sep 20, 2021
0dff342
Merge remote-tracking branch 'upstream/master' into auto_height_data_…
miukimiu Sep 20, 2021
a82612d
Better `gridStyle` font size explanation
miukimiu Sep 20, 2021
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## [`master`](https://github.com/elastic/eui/tree/master)

- Updated `barSeriesStyle.displayValue` of the elastic-charts `Theme` for better default styles ([#4845](https://github.com/elastic/eui/pull/4845))
- Added `auto` as value for `defaultHeight` in prop `rowHeightsOptions` in `EuiDataGrid` that allows to content auto-fit to row ([#4958](https://github.com/elastic/eui/pull/4958))
- Updated `titleProps` and `descriptionProps` on `EuiDescriptionList` to extend `CommonProps` ([#5166](https://github.com/elastic/eui/pull/5166))
- Added the ability to return `visibleOptions` from `EuiSelectable` by using `onSearch` ([#5178](https://github.com/elastic/eui/pull/5178))

Expand Down
2 changes: 1 addition & 1 deletion scripts/a11y-testing.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const docsPages = async (root, page) => {
`${root}#/tabular-content/data-grid-control-columns`,
`${root}#/tabular-content/data-grid-footer-row`,
`${root}#/tabular-content/data-grid-virtualization`,
`${root}#/tabular-content/data-grid-row-height-options`,
`${root}#/tabular-content/data-grid-row-heights-options`,
];

return [
Expand Down
205 changes: 168 additions & 37 deletions src-docs/src/views/datagrid/datagrid_height_options_example.js
Original file line number Diff line number Diff line change
@@ -1,80 +1,211 @@
import React, { Fragment } from 'react';

import { renderToHtml } from '../../services';
import { GuideSectionTypes } from '../../components';
import {
EuiDataGrid,
EuiCallOut,
EuiCode,
EuiCodeBlock,
EuiSpacer,
EuiText,
} from '../../../../src/components';

import DataGridRowHeightOptions from './row_height_options';
const dataGridRowHeightOptionsSource = require('!!raw-loader!./row_height_options');
const dataGridRowHeightOptionsHtml = renderToHtml(DataGridRowHeightOptions);
import { EuiDataGridRowHeightsOptions } from '!!prop-loader!../../../../src/components/datagrid/data_grid_types';

import DataGridRowHeightOptions from './row_height_fixed';
const dataGridRowHeightOptionsSource = require('!!raw-loader!./row_height_fixed');
import DataGridRowAutoHeight from './row_height_auto';
const dataGridRowAutoHeightSource = require('!!raw-loader!./row_height_auto');

const rowHeightsSnippet = `rowHeightsOptions = {
defaultHeight: {
lineCount: 2, // default every row to 2 lines of text. Also we can provide height in pixels
},
defaultHeight: 140, // default every row to 140px
rowHeights: {
1: {
lineCount: 5, // for row which have index 1 we allow to show 5 lines after that we truncate
},
4: 140, // for row which have index 4 we set 140 pixel
4: 200, // for row which have index 4 we set 140 pixel
5: 80,
},
}`;

const rowHeightsFullSnippet = `const rowHeightsOptions = useMemo(
() => ({
defaultHeight: {
lineCount: 2,
}),
[]
);

<EuiDataGrid
aria-label="Data grid with fixed height for rows"
columns={columns}
columnVisibility={{ visibleColumns, setVisibleColumns }}
rowCount={rowCount}
height={400}
renderCellValue={renderCellValue}
inMemory={{ level: 'sorting' }}
sorting={{ columns: sortingColumns, onSort }}
rowHeightsOptions={rowHeightsOptions}
pagination={{
...pagination,
pageSizeOptions: [50, 250, 1000],
onChangeItemsPerPage: onChangeItemsPerPage,
onChangePage: onChangePage,
}}
/>
`;

const autoRowHeightsSnippet = `// the demo below matches this snippet
rowHeightsOptions = {
defaultHeight: 'auto', // all rows will automatically adjust the height except rows defined in 'rowHeights'
rowHeights: {
1: {
lineCount: 5, // row at index 1 will show 5 lines
},
4: 140, // row at index 4 will adjust the height to 140px
},
}

// you can also automatically adjust the height for a specific row
rowHeightsOptions = {
rowHeights: {
1: 'auto', // row at index 1 will automatically adjust the height
4: 140, // row at index 4 will adjust the height to 140px
}
}
`;

const autoRowHeightsFullSnippet = `const rowHeightsOptions = useMemo(
() => ({
defaultHeight: 'auto'
}),
[]
);

<EuiDataGrid
aria-label="Data grid with auto height for rows"
columns={columns}
columnVisibility={{ visibleColumns, setVisibleColumns }}
rowCount={rowCount}
height={400}
renderCellValue={renderCellValue}
inMemory={{ level: 'sorting' }}
sorting={{ columns: sortingColumns, onSort }}
rowHeightsOptions={rowHeightsOptions}
pagination={{
...pagination,
pageSizeOptions: [50, 250, 1000],
onChangeItemsPerPage: onChangeItemsPerPage,
onChangePage: onChangePage,
}}
/>
`;

export const DataGridRowHeightOptionsExample = {
title: 'Data grid row height options',
title: 'Data grid row heights options',
intro: (
<Fragment>
<EuiText>
<p>
By default, all rows get a height of <strong>34 pixels</strong>, but
there are scenarios where you might want to adjust the height to fit
more content. To do that, you can pass an object to the{' '}
<EuiCode>rowHeightsOptions</EuiCode> prop. This object accepts two
properties:
</p>
<ul>
<li>
<EuiCode>defaultHeight</EuiCode> - defines the default size for all
rows
</li>
<li>
<EuiCode>rowHeights</EuiCode> - overrides the height for a specific
row
</li>
</ul>
<p>
Each of these can be configured with an exact pixel height, a line
count, or <EuiCode>&quot;auto&quot;</EuiCode> to fit all of the
content. See the examples below for more details.
</p>
</EuiText>
<EuiSpacer />
<EuiCallOut color="warning" title="Rows have minimum height requirements">
<p>
Rows must be at least <strong>34 pixels</strong> tall so they can
render at least one line of text. If you provide a smaller height the
row will default to <strong>34 pixels</strong>.
</p>
</EuiCallOut>
<EuiSpacer />
</Fragment>
),
sections: [
{
source: [
{
type: GuideSectionTypes.JS,
code: dataGridRowHeightOptionsSource,
},
{
type: GuideSectionTypes.HTML,
code: dataGridRowHeightOptionsHtml,
},
],
title: 'Fixed heights for rows',
text: (
<Fragment>
<p>
Row height options can be passed down to the grid through the{' '}
<EuiCode>rowHeightsOptions</EuiCode> prop. It accepts an object
configuring the default height and/or specific row heights:
You can change the default height for all rows by passing a line
count or pixel value to the <EuiCode>defaultHeight</EuiCode>{' '}
property.
</p>
<p>
You can also override the height of a specific row by passing a
<EuiCode>rowHeights</EuiCode> object associating the row&apos;s
index with a specific height configuration.
</p>
<ul>
<li>
<EuiCode>defaultHeight</EuiCode> - defines the default size for
all rows
</li>
<li>
<EuiCode>rowHeights</EuiCode> - overrides the height for a
specific row
</li>
</ul>
<EuiCallOut
color="warning"
title="Rows have minimum height requirements"
>
<p>
Rows must be at least <strong>34 pixels</strong> tall so they can
render at least one line of text. If you provide a smaller height
the row will default to 34 pixels.
</p>
</EuiCallOut>
<EuiSpacer />
<EuiCodeBlock language="javascript" paddingSize="s" isCopyable>
{rowHeightsSnippet}
</EuiCodeBlock>
</Fragment>
),
components: { DataGridRowHeightOptions },
props: {
EuiDataGrid,
EuiDataGridRowHeightsOptions,
},
demo: <DataGridRowHeightOptions />,
snippet: rowHeightsFullSnippet,
},
{
source: [
{
type: GuideSectionTypes.JS,
code: dataGridRowAutoHeightSource,
},
],
title: 'Auto heights for rows',
text: (
<Fragment>
<p>
To enable automatically fitting rows to their content you can set{' '}
<EuiCode>defaultHeight=&quot;auto&quot;</EuiCode>. This ensures
every row automatically adjusts its height to fit the contents.
</p>
<p>
You can also override the height of a specific row by passing a
<EuiCode>rowHeights</EuiCode> object associating the row&apos;s
index with an <EuiCode>&quot;auto&quot;</EuiCode> value.
</p>
<EuiCodeBlock language="javascript" paddingSize="s" isCopyable>
{autoRowHeightsSnippet}
</EuiCodeBlock>
</Fragment>
),
components: { DataGridRowAutoHeight },
props: {
EuiDataGrid,
EuiDataGridRowHeightsOptions,
},
demo: <DataGridRowAutoHeight />,
snippet: autoRowHeightsFullSnippet,
},
],
};
5 changes: 4 additions & 1 deletion src-docs/src/views/datagrid/datagrid_styling_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,10 @@ export const DataGridStylingExample = {
With the default settings, the <EuiCode>showStyleSelector</EuiCode>{' '}
setting in <EuiCode>toolbarVisibility</EuiCode> means the user has
the ability to override the padding and font size passed into{' '}
<EuiCode>gridStyle</EuiCode> by the engineer.
<EuiCode>gridStyle</EuiCode> by the engineer. The font size
overriding only works with text or elements that can inherit the
parent font size or elements that use units relative to the parent
container.
</p>
<EuiCodeBlock language="javascript" paddingSize="s" isCopyable>
{gridSnippet}
Expand Down
Loading