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

Add tableLayout prop to EuiTable, EuiBasicTable and EuiInMemoryTable #2697

Merged
merged 13 commits into from
Dec 20, 2019
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- Converted `EuiHighlight` to Typescript ([#2681](https://github.com/elastic/eui/pull/2681))
- Converted `EuiPage` and related child components to TypeScript ([#2669](https://github.com/elastic/eui/pull/2669))
- Added `tableLayout` prop to `EuiTable`, `EuiBasicTable` and `EuiInMemoryTable` to provide the option of auto layout ([#2697](https://github.com/elastic/eui/pull/2697))

**Bug fixes**

Expand Down
128 changes: 128 additions & 0 deletions src-docs/src/views/tables/auto/auto.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import React, { Component } from 'react';

import { createDataStore } from '../data_store';

import {
EuiBasicTable,
EuiLink,
EuiSpacer,
EuiSwitch,
} from '../../../../../src/components';

/*
Example user object:

{
id: '1',
firstName: 'john',
lastName: 'doe',
github: 'johndoe',
dateOfBirth: Date.now(),
nationality: 'NL',
online: true
}

Example country object:

{
code: 'NL',
name: 'Netherlands',
flag: '🇳🇱'
}
*/

const store = createDataStore();

const columns = [
{
field: 'firstName',
name: 'First Name',
sortable: true,
'data-test-subj': 'firstNameCell',
mobileOptions: {
render: item => (
<span>
{item.firstName}{' '}
<EuiLink href="#" target="_blank">
{item.lastName}
</EuiLink>
</span>
),
header: false,
truncateText: false,
enlarge: true,
fullWidth: true,
},
},
{
field: 'lastName',
name: 'Last Name',
truncateText: true,
render: name => (
<EuiLink href="#" target="_blank">
{name}
</EuiLink>
),
mobileOptions: {
show: false,
},
},
{
field: 'github',
name: 'Github',
},
];

const items = store.users.filter((user, index) => index < 10);

const getRowProps = item => {
const { id } = item;
return {
'data-test-subj': `row-${id}`,
className: 'customRowClass',
onClick: () => console.log(`Clicked row ${id}`),
};
};

const getCellProps = (item, column) => {
const { id } = item;
const { field } = column;
return {
className: 'customCellClass',
'data-test-subj': `cell-${id}-${field}`,
textOnly: true,
};
};

export class Table extends Component {
constructor(props) {
super(props);
this.state = {
autoLayout: true,
};
}

toggleTableLayout = () => {
this.setState(prevState => ({ autoLayout: !prevState.autoLayout }));
};

render() {
return (
<div>
<EuiSwitch
label="Show auto layout"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
label="Show auto layout"
label="Auto layout"

checked={this.state.autoLayout}
onChange={this.toggleTableLayout}
/>
<EuiSpacer size="m" />
<EuiBasicTable
items={items}
columns={columns}
tableLayout={this.state.autoLayout ? 'auto' : 'fixed'}
rowProps={getRowProps}
cellProps={getCellProps}
/>
</div>
);
}
}
32 changes: 32 additions & 0 deletions src-docs/src/views/tables/auto/auto_section.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React from 'react';
import { GuideSectionTypes } from '../../../components';
import { renderToHtml } from '../../../services';
import { EuiCode } from '../../../../../src/components';

import { Table } from './auto';

const source = require('!!raw-loader!./auto');
const html = renderToHtml(Table);

export const section = {
title: 'A BasicTable with auto layout',
Copy link
Contributor

Choose a reason for hiding this comment

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

This section is no longer about just auto layout but layout in general

Suggested change
title: 'A BasicTable with auto layout',
title: 'Table layout',

source: [
{
type: GuideSectionTypes.JS,
code: source,
},
{
type: GuideSectionTypes.HTML,
code: html,
},
],
text: (
<div>
<p>
<EuiCode>EuiBasicTable</EuiCode> has a fixed layout by default. You can
change it to auto using the <EuiCode>tableLayout</EuiCode> prop.
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like this description isn't enough to warrant an entire example in the docs? Consider beefing up this explanation or removing the example and just relying on props comments to explain the prop.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree that a props comment is likely enough and this concept doesn't need a full example. Only alternative (which should be handled in a separate PR) would be to do something similar to EuiDataGrid where we devote a full section to styling concerns and add an example with lots of toggles.

Copy link
Contributor

Choose a reason for hiding this comment

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

That was going to be my third suggestion, but figured it out of scope of this PR. So probably best to just remove this example for now.

</p>
</div>
),
demo: <Table />,
cchaos marked this conversation as resolved.
Show resolved Hide resolved
};
1 change: 1 addition & 0 deletions src-docs/src/views/tables/auto/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { section } from './auto_section';
8 changes: 8 additions & 0 deletions src-docs/src/views/tables/basic/props_info.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ export const propsInfo = {
required: false,
type: { name: '(criteria: #Criteria) => void' },
},
tableLayout: {
description: 'Configures table layout',
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably want to explain that it's configuring the CSS table-layout property.

required: false,
type: {
name: '(fixed | auto)',
},
defaultValue: { value: 'fixed' },
},
},
},
},
Expand Down
2 changes: 2 additions & 0 deletions src-docs/src/views/tables/tables_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React from 'react';
import { EuiCode, EuiSpacer, EuiCallOut } from '../../../../src/components';

import { section as basicSection } from './basic';
import { section as autoSection } from './auto';
import { section as paginatedSection } from './paginated';
import { section as sortingSection } from './sorting';
import { section as selectionSection } from './selection';
Expand Down Expand Up @@ -44,6 +45,7 @@ export const TableExample = {
),
sections: [
basicSection,
autoSection,
cchaos marked this conversation as resolved.
Show resolved Hide resolved
paginatedSection,
sortingSection,
selectionSection,
Expand Down
23 changes: 23 additions & 0 deletions src/components/basic_table/__snapshots__/basic_table.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ exports[`EuiBasicTable cellProps renders cells with custom props from a callback
</EuiTableHeaderMobile>
<EuiTable
responsive={true}
tableLayout="fixed"
>
<EuiScreenReaderOnly>
<caption
Expand Down Expand Up @@ -141,6 +142,7 @@ exports[`EuiBasicTable cellProps renders rows with custom props from an object 1
</EuiTableHeaderMobile>
<EuiTable
responsive={true}
tableLayout="fixed"
>
<EuiScreenReaderOnly>
<caption
Expand Down Expand Up @@ -263,6 +265,7 @@ exports[`EuiBasicTable empty is rendered 1`] = `
</EuiTableHeaderMobile>
<EuiTable
responsive={true}
tableLayout="fixed"
>
<EuiScreenReaderOnly>
<caption
Expand Down Expand Up @@ -332,6 +335,7 @@ exports[`EuiBasicTable empty renders a node as a custom message 1`] = `
</EuiTableHeaderMobile>
<EuiTable
responsive={true}
tableLayout="fixed"
>
<EuiScreenReaderOnly>
<caption
Expand Down Expand Up @@ -409,6 +413,7 @@ exports[`EuiBasicTable empty renders a string as a custom message 1`] = `
</EuiTableHeaderMobile>
<EuiTable
responsive={true}
tableLayout="fixed"
>
<EuiScreenReaderOnly>
<caption
Expand Down Expand Up @@ -478,6 +483,7 @@ exports[`EuiBasicTable footers do not render without a column footer definition
</EuiTableHeaderMobile>
<EuiTable
responsive={true}
tableLayout="fixed"
>
<EuiScreenReaderOnly>
<caption
Expand Down Expand Up @@ -702,6 +708,7 @@ exports[`EuiBasicTable footers render with pagination, selection, sorting, and f
</EuiTableHeaderMobile>
<EuiTable
responsive={true}
tableLayout="fixed"
>
<EuiScreenReaderOnly>
<caption
Expand Down Expand Up @@ -991,6 +998,7 @@ exports[`EuiBasicTable itemIdToExpandedRowMap renders an expanded row 1`] = `
</EuiTableHeaderMobile>
<EuiTable
responsive={true}
tableLayout="fixed"
>
<EuiScreenReaderOnly>
<caption
Expand Down Expand Up @@ -1116,6 +1124,7 @@ exports[`EuiBasicTable rowProps renders rows with custom props from a callback 1
</EuiTableHeaderMobile>
<EuiTable
responsive={true}
tableLayout="fixed"
>
<EuiScreenReaderOnly>
<caption
Expand Down Expand Up @@ -1242,6 +1251,7 @@ exports[`EuiBasicTable rowProps renders rows with custom props from an object 1`
</EuiTableHeaderMobile>
<EuiTable
responsive={true}
tableLayout="fixed"
>
<EuiScreenReaderOnly>
<caption
Expand Down Expand Up @@ -1368,6 +1378,7 @@ exports[`EuiBasicTable with pagination - 2nd page 1`] = `
</EuiTableHeaderMobile>
<EuiTable
responsive={true}
tableLayout="fixed"
>
<EuiScreenReaderOnly>
<caption
Expand Down Expand Up @@ -1473,6 +1484,7 @@ exports[`EuiBasicTable with pagination 1`] = `
</EuiTableHeaderMobile>
<EuiTable
responsive={true}
tableLayout="fixed"
>
<EuiScreenReaderOnly>
<caption
Expand Down Expand Up @@ -1595,6 +1607,7 @@ exports[`EuiBasicTable with pagination and error 1`] = `
</EuiTableHeaderMobile>
<EuiTable
responsive={true}
tableLayout="fixed"
>
<EuiScreenReaderOnly>
<caption
Expand Down Expand Up @@ -1676,6 +1689,7 @@ exports[`EuiBasicTable with pagination and selection 1`] = `
</EuiTableHeaderMobile>
<EuiTable
responsive={true}
tableLayout="fixed"
>
<EuiScreenReaderOnly>
<caption
Expand Down Expand Up @@ -1842,6 +1856,7 @@ exports[`EuiBasicTable with pagination, hiding the per page options 1`] = `
</EuiTableHeaderMobile>
<EuiTable
responsive={true}
tableLayout="fixed"
>
<EuiScreenReaderOnly>
<caption
Expand Down Expand Up @@ -1986,6 +2001,7 @@ exports[`EuiBasicTable with pagination, selection and sorting 1`] = `
</EuiTableHeaderMobile>
<EuiTable
responsive={true}
tableLayout="fixed"
>
<EuiScreenReaderOnly>
<caption
Expand Down Expand Up @@ -2176,6 +2192,7 @@ exports[`EuiBasicTable with pagination, selection, sorting and a single record a
</EuiTableHeaderMobile>
<EuiTable
responsive={true}
tableLayout="fixed"
>
<EuiScreenReaderOnly>
<caption
Expand Down Expand Up @@ -2459,6 +2476,7 @@ exports[`EuiBasicTable with pagination, selection, sorting and column dataType 1
</EuiTableHeaderMobile>
<EuiTable
responsive={true}
tableLayout="fixed"
>
<EuiScreenReaderOnly>
<caption
Expand Down Expand Up @@ -2649,6 +2667,7 @@ exports[`EuiBasicTable with pagination, selection, sorting and column renderer 1
</EuiTableHeaderMobile>
<EuiTable
responsive={true}
tableLayout="fixed"
>
<EuiScreenReaderOnly>
<caption
Expand Down Expand Up @@ -2839,6 +2858,7 @@ exports[`EuiBasicTable with pagination, selection, sorting and multiple record a
</EuiTableHeaderMobile>
<EuiTable
responsive={true}
tableLayout="fixed"
>
<EuiScreenReaderOnly>
<caption
Expand Down Expand Up @@ -3140,6 +3160,7 @@ exports[`EuiBasicTable with pagination, selection, sorting, column renderer and
</EuiTableHeaderMobile>
<EuiTable
responsive={true}
tableLayout="fixed"
>
<EuiScreenReaderOnly>
<caption
Expand Down Expand Up @@ -3309,6 +3330,7 @@ exports[`EuiBasicTable with sortable columns and sorting disabled 1`] = `
</EuiTableHeaderMobile>
<EuiTable
responsive={true}
tableLayout="fixed"
>
<EuiScreenReaderOnly>
<caption
Expand Down Expand Up @@ -3434,6 +3456,7 @@ exports[`EuiBasicTable with sorting 1`] = `
</EuiTableHeaderMobile>
<EuiTable
responsive={true}
tableLayout="fixed"
>
<EuiScreenReaderOnly>
<caption
Expand Down
Loading