diff --git a/CHANGELOG.md b/CHANGELOG.md index b345626df5e..9690dbaf179 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ ## [`master`](https://github.com/elastic/eui/tree/master) -No public interface changes since `4.4.1`. +- Added support for nodes as column headers in `EuiBasicTable` for supporting things like tooltips and localized text. ([#1234](https://github.com/elastic/eui/pull/1234)) ## [`4.4.1`](https://github.com/elastic/eui/tree/v4.4.1) diff --git a/src-docs/src/views/tables/basic/props_info.js b/src-docs/src/views/tables/basic/props_info.js index d2f3f9ede60..8bc03b4f538 100644 --- a/src-docs/src/views/tables/basic/props_info.js +++ b/src-docs/src/views/tables/basic/props_info.js @@ -150,7 +150,7 @@ export const propsInfo = { name: { description: 'The display name of the column', required: true, - type: { name: 'string' } + type: { name: 'PropTypes.node' } }, description: { description: 'A description of the column (will be presented as a title over the column header', @@ -213,7 +213,7 @@ export const propsInfo = { name: { description: 'The display name of the column', required: false, - type: { name: 'string' } + type: { name: 'PropTypes.node' } }, description: { description: 'A description of the column (will be presented as a title over the column header', @@ -248,7 +248,7 @@ export const propsInfo = { name: { description: 'The display name of the column', required: false, - type: { name: 'string' } + type: { name: 'PropTypes.node' } }, description: { description: 'A description of the column (will be presented as a title over the column header', diff --git a/src-docs/src/views/tables/custom/compressed.js b/src-docs/src/views/tables/custom/compressed.js deleted file mode 100644 index 673589f77c3..00000000000 --- a/src-docs/src/views/tables/custom/compressed.js +++ /dev/null @@ -1,217 +0,0 @@ -import React, { - Component, -} from 'react'; - -import { - EuiCheckbox, - EuiIcon, - EuiLink, - EuiTable, - EuiTableBody, - EuiTableHeader, - EuiTableHeaderCell, - EuiTableHeaderCellCheckbox, - EuiTableRow, - EuiTableRowCell, - EuiTableRowCellCheckbox, -} from '../../../../../src/components'; - -import { - LEFT_ALIGNMENT, -} from '../../../../../src/services'; - -export default class extends Component { - constructor(props) { - super(props); - - this.state = { - itemIdToSelectedMap: { - 2: true, - }, - }; - - this.items = [{ - id: 0, - title: 'A very long line which will wrap on narrower screens and NOT become truncated using an ellipsis', - type: 'user', - dateCreated: 'Tue Dec 01 2016 12:56:15 GMT-0800 (PST)', - }, { - id: 1, - title: { - value: 'A very long line which will not wrap on narrower screens and instead will become truncated using an ellipsis', - truncateText: true, - }, - type: 'user', - dateCreated: 'Tue Dec 01 2016 12:56:15 GMT-0800 (PST)', - }, { - id: 2, - title: { - value: 'Boomerang', - isLink: true, - }, - type: 'user', - dateCreated: 'Tue Dec 28 2016 12:56:15 GMT-0800 (PST)', - }, { - id: 3, - title: { - value: 'Celebration', - isLink: true, - }, - type: 'user', - dateCreated: 'Tue Dec 16 2016 12:56:15 GMT-0800 (PST)', - }, { - id: 4, - title: { - value: 'Dog', - isLink: true, - }, - type: 'user', - dateCreated: 'Tue Dec 13 2016 12:56:15 GMT-0800 (PST)', - }]; - - this.columns = [{ - id: 'checkbox', - isCheckbox: true, - width: '20px', - }, { - id: 'title', - label: 'Title', - alignment: LEFT_ALIGNMENT, - }, { - id: 'type', - label: 'Type', - alignment: LEFT_ALIGNMENT, - width: '60px', - cellProvider: cell => , - }, { - id: 'dateCreated', - label: 'Date created', - alignment: LEFT_ALIGNMENT, - }]; - } - - toggleItem = itemId => { - const newItemIdToSelectedMap = ({ ...this.state.itemIdToSelectedMap, ...{ - [itemId]: !this.state.itemIdToSelectedMap[itemId], - } }); - - this.setState({ - itemIdToSelectedMap: newItemIdToSelectedMap, - }); - } - - toggleAll = () => { - const allSelected = this.areAllItemsSelected(); - const newItemIdToSelectedMap = {}; - this.items.forEach(item => newItemIdToSelectedMap[item.id] = !allSelected); - - - this.setState({ - itemIdToSelectedMap: newItemIdToSelectedMap, - }); - } - - isItemSelected = itemId => { - return this.state.itemIdToSelectedMap[itemId]; - } - - areAllItemsSelected = () => { - const indexOfUnselectedItem = this.items.findIndex(item => !this.isItemSelected(item.id)); - return indexOfUnselectedItem === -1; - } - - renderHeaderCells() { - return this.columns.map((column, columnIndex) => { - if (column.isCheckbox) { - return ( - - - - ); - } - - return ( - - {column.label} - - ); - }); - } - - renderRows() { - return this.items.map(item => { - const cells = this.columns.map(column => { - const cell = item[column.id]; - - let child; - - if (column.isCheckbox) { - return ( - - - - ); - } else if (column.cellProvider) { - child = column.cellProvider(cell); - } else if (cell.isLink) { - child = {cell.value}; - } else if (cell.truncateText) { - child = cell.value; - } else { - child = cell; - } - - return ( - - {child} - - ); - }); - - return ( - - {cells} - - ); - }); - } - - render() { - return ( - - - {this.renderHeaderCells()} - - - - {this.renderRows()} - - - ); - } -} diff --git a/src-docs/src/views/tables/custom/custom.js b/src-docs/src/views/tables/custom/custom.js index 204b60ed8d6..064698e564f 100644 --- a/src-docs/src/views/tables/custom/custom.js +++ b/src-docs/src/views/tables/custom/custom.js @@ -581,7 +581,6 @@ export default class extends Component { footers.push( {footer} @@ -591,7 +590,6 @@ export default class extends Component { footers.push( {undefined} diff --git a/src-docs/src/views/tables/sorting/sorting.js b/src-docs/src/views/tables/sorting/sorting.js index ac2a9f149c6..0bd282d8548 100644 --- a/src-docs/src/views/tables/sorting/sorting.js +++ b/src-docs/src/views/tables/sorting/sorting.js @@ -1,13 +1,15 @@ import React, { - Component + Component, } from 'react'; import { formatDate } from '../../../../../src/services/format'; import { createDataStore } from '../data_store'; import { EuiBasicTable, - EuiLink, EuiHealth, + EuiIcon, + EuiLink, + EuiToolTip, } from '../../../../../src/components'; /* @@ -99,7 +101,13 @@ export class Table extends Component { ) }, { field: 'github', - name: 'Github', + name: ( + + + Github + + + ), render: (username) => ( {username} @@ -107,20 +115,38 @@ export class Table extends Component { ) }, { field: 'dateOfBirth', - name: 'Date of Birth', + name: ( + + + Date of Birth + + + ), dataType: 'date', render: (date) => formatDate(date, 'dobLong'), sortable: true }, { field: 'nationality', - name: 'Nationality', + name: ( + + + Nationality + + + ), render: (countryCode) => { const country = store.getCountry(countryCode); return `${country.flag} ${country.name}`; } }, { field: 'online', - name: 'Online', + name: ( + + + Online + + + ), dataType: 'boolean', render: (online) => { const color = online ? 'success' : 'danger'; diff --git a/src/components/basic_table/__snapshots__/basic_table.test.js.snap b/src/components/basic_table/__snapshots__/basic_table.test.js.snap index d016c0be200..b6ab68d5639 100644 --- a/src/components/basic_table/__snapshots__/basic_table.test.js.snap +++ b/src/components/basic_table/__snapshots__/basic_table.test.js.snap @@ -721,7 +721,6 @@ exports[`EuiBasicTable footers render with pagination, selection, sorting, and f /> @@ -730,14 +729,12 @@ exports[`EuiBasicTable footers render with pagination, selection, sorting, and f ID diff --git a/src/components/basic_table/basic_table.js b/src/components/basic_table/basic_table.js index 9d689090f86..7ceb94c4b3d 100644 --- a/src/components/basic_table/basic_table.js +++ b/src/components/basic_table/basic_table.js @@ -98,7 +98,7 @@ export const ActionsColumnType = PropTypes.shape({ export const FieldDataColumnTypeShape = { field: PropTypes.string.isRequired, - name: PropTypes.string.isRequired, + name: PropTypes.node.isRequired, description: PropTypes.string, dataType: PropTypes.oneOf(DATA_TYPES), width: PropTypes.string, @@ -116,7 +116,7 @@ export const FieldDataColumnType = PropTypes.shape(FieldDataColumnTypeShape); export const ComputedColumnType = PropTypes.shape({ render: PropTypes.func.isRequired, // (record) => PropTypes.node - name: PropTypes.string, + name: PropTypes.node, description: PropTypes.string, width: PropTypes.string, truncateText: PropTypes.bool @@ -554,7 +554,6 @@ export class EuiBasicTable extends Component { footers.push( {footer} @@ -566,7 +565,6 @@ export class EuiBasicTable extends Component { footers.push( {undefined} @@ -820,8 +818,8 @@ export class EuiBasicTable extends Component { render, dataType, isExpander, - name, textOnly, + name, field, // eslint-disable-line no-unused-vars description, // eslint-disable-line no-unused-vars sortable, // eslint-disable-line no-unused-vars diff --git a/src/components/table/mobile/table_sort_mobile.js b/src/components/table/mobile/table_sort_mobile.js index 8af5e4f3472..cc6a601a5fa 100644 --- a/src/components/table/mobile/table_sort_mobile.js +++ b/src/components/table/mobile/table_sort_mobile.js @@ -22,10 +22,6 @@ export class EuiTableSortMobile extends Component { }; } - shouldComponentUpdate(nextProps, nextState) { - return JSON.stringify(nextProps) !== JSON.stringify(this.props) || JSON.stringify(nextState) !== JSON.stringify(this.state); - } - onButtonClick = () => { this.setState({ isPopoverOpen: !this.state.isPopoverOpen,