-
Notifications
You must be signed in to change notification settings - Fork 841
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
Changes from 5 commits
bbfe617
3cd50e6
8799f73
53b2cdc
8487fe6
aac55b1
04b827f
9b79975
992e826
45879ae
2ab81df
fa72330
7b1308a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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" | ||
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> | ||
); | ||
} | ||
} |
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', | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This section is no longer about just
Suggested change
|
||||||
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. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
|
||||||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { section } from './auto_section'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,6 +95,14 @@ export const propsInfo = { | |
required: false, | ||
type: { name: '(criteria: #Criteria) => void' }, | ||
}, | ||
tableLayout: { | ||
description: 'Configures table layout', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably want to explain that it's configuring the CSS |
||
required: false, | ||
type: { | ||
name: '(fixed | auto)', | ||
}, | ||
defaultValue: { value: 'fixed' }, | ||
}, | ||
}, | ||
}, | ||
}, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.