From 29166aa38f08f81930c2c9b30d54ca509eb55c24 Mon Sep 17 00:00:00 2001 From: Michael Jewell Date: Mon, 18 Jun 2018 15:10:23 -0700 Subject: [PATCH] mj - support className on sortable table column --- src/components/SortableTable.js | 19 +++++++++++++++---- test/components/SortableTable.spec.js | 26 ++++++++++++++++++++------ 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/src/components/SortableTable.js b/src/components/SortableTable.js index 26ae4a827..d260a69eb 100644 --- a/src/components/SortableTable.js +++ b/src/components/SortableTable.js @@ -1,8 +1,16 @@ import React from 'react'; import PropTypes from 'prop-types'; +import classnames from 'classnames'; import Header from './SortableTable/Header.js'; import Table from './Table.js'; +function generateColumnClassName(column) { + return classnames( + column.align && `text-${column.align}`, + column.className + ); +} + class SortableTable extends React.Component { static propTypes = { ...Table.propTypes, @@ -38,7 +46,7 @@ class SortableTable extends React.Component { const expanded = rowExpanded(row); return [ rowOnClick(row)}> - {columns.map(column => {column.cell(row)})} + {columns.map(column => {column.cell(row)})} , expanded && , expanded && ( @@ -71,7 +79,7 @@ class SortableTable extends React.Component {
column.onSort(!column.ascending) : null} > @@ -87,9 +95,12 @@ class SortableTable extends React.Component { {columns.map(column => ( - + {column.footer} - + ))} diff --git a/test/components/SortableTable.spec.js b/test/components/SortableTable.spec.js index 70d44ffcd..55f8ef447 100644 --- a/test/components/SortableTable.spec.js +++ b/test/components/SortableTable.spec.js @@ -242,12 +242,26 @@ describe('', () => { assert.equal(wrapper.find('thead th.text-center').length, 1, 'thead th.text-center incorrect'); assert.equal(wrapper.find('thead th.text-right').length, 1, 'thead th.text-right incorrect'); - assert.equal(wrapper.find('td.text-left').length, 3, 'td.text-left incorrect'); - assert.equal(wrapper.find('td.text-center').length, 3, 'td.text-center incorrect'); - assert.equal(wrapper.find('td.text-right').length, 3, 'td.text-right incorrect'); + assert.equal(wrapper.find('tbody td.text-left').length, 3, 'tbody td.text-left incorrect'); + assert.equal(wrapper.find('tbody td.text-center').length, 3, 'tbody td.text-center incorrect'); + assert.equal(wrapper.find('tbody td.text-right').length, 3, 'tbody td.text-right incorrect'); - assert.equal(wrapper.find('tfoot th.text-left').length, 1, 'tfoot th.text-left incorrect'); - assert.equal(wrapper.find('tfoot th.text-center').length, 1, 'tfoot th.text-center incorrect'); - assert.equal(wrapper.find('tfoot th.text-right').length, 1, 'tfoot th.text-right incorrect'); + assert.equal(wrapper.find('tfoot td.text-left').length, 1, 'tfoot td.text-left incorrect'); + assert.equal(wrapper.find('tfoot td.text-center').length, 1, 'tfoot td.text-center incorrect'); + assert.equal(wrapper.find('tfoot td.text-right').length, 1, 'tfoot td.text-right incorrect'); + }); + + it('should render correct column classnames when present', () => { + const columns = [ + { header: 'Default', cell: () => '-', footer: '-' }, + { header: 'Left', cell: () => '-', footer: '-', className: 'whatever' } + ]; + const wrapper = mount(); + + assert.equal(wrapper.find('thead th.whatever').length, 1, 'thead th.whatever incorrect'); + + assert.equal(wrapper.find('tbody td.whatever').length, 3, 'tbody td.whatever incorrect'); + + assert.equal(wrapper.find('tfoot td.whatever').length, 1, 'tfoot td.whatever incorrect'); }); });