Commit 369dc534 by Ari Rizzitano

headings -> columns

parent 37a01bc3
...@@ -4,11 +4,11 @@ Provides a very basic table component with col-scoped headings displayed in the ...@@ -4,11 +4,11 @@ Provides a very basic table component with col-scoped headings displayed in the
## API ## API
### `headings` (object array; required) ### `columns` (object array; required)
`headings` specifies the order and contents of the table's columns and provides display strings for each column's heading. It is composed of an ordered array of objects, each containing a string `key` and a string or element `label`. `label` contains the display string for each column's heading. `key` maps that label to its corresponding datum for each row in `data`, to ensure table data are displayed in their appropriate columns. The order of objects in `headings` specifies the order of the columns in the table. `columns` specifies the order and contents of the table's columns and provides display strings for each column's heading. It is composed of an ordered array of objects, each containing a string `key` and a string or element `label`. `label` contains the display string for each column's heading. `key` maps that label to its corresponding datum for each row in `data`, to ensure table data are displayed in their appropriate columns. The order of objects in `columns` specifies the order of the columns in the table.
### `data` (object array; required) ### `data` (object array; required)
`data` is an array of objects corresponding to the rows to display in the body of your table. The rows will display in the same order as the objects in your array. There are no real restrictions on what these rows can contain, as long as their keys are consistent. The keys are used to organize data from each row into its appropriate column, determined by the corresponding `key` property specified in each object in `headings`. `data` is an array of objects corresponding to the rows to display in the body of your table. The rows will display in the same order as the objects in your array. There are no real restrictions on what these rows can contain, as long as their keys are consistent. The keys are used to organize data from each row into its appropriate column, determined by the corresponding `key` property specified in each object in `columns`.
### `caption` (string or element; optional) ### `caption` (string or element; optional)
Specifies a descriptive caption to be applied to the entire table. Specifies a descriptive caption to be applied to the entire table.
......
...@@ -31,7 +31,7 @@ const catData = [ ...@@ -31,7 +31,7 @@ const catData = [
}, },
]; ];
const catHeadings = [ const catColumns = [
{ {
label: 'Name', label: 'Name',
key: 'name', key: 'name',
...@@ -50,14 +50,14 @@ storiesOf('Table', module) ...@@ -50,14 +50,14 @@ storiesOf('Table', module)
.add('unstyled', () => ( .add('unstyled', () => (
<Table <Table
data={catData} data={catData}
headings={catHeadings} columns={catColumns}
caption="Famous Internet Cats" caption="Famous Internet Cats"
/> />
)) ))
.add('table-striped', () => ( .add('table-striped', () => (
<Table <Table
data={catData} data={catData}
headings={catHeadings} columns={catColumns}
caption="Famous Internet Cats" caption="Famous Internet Cats"
className={['table-striped']} className={['table-striped']}
/> />
...@@ -65,7 +65,7 @@ storiesOf('Table', module) ...@@ -65,7 +65,7 @@ storiesOf('Table', module)
.add('default heading', () => ( .add('default heading', () => (
<Table <Table
data={catData} data={catData}
headings={catHeadings} columns={catColumns}
caption="Famous Internet Cats" caption="Famous Internet Cats"
headingClassName={['thead-default']} headingClassName={['thead-default']}
/> />
......
...@@ -5,7 +5,7 @@ import { shallow } from 'enzyme'; ...@@ -5,7 +5,7 @@ import { shallow } from 'enzyme';
import Table from './index'; import Table from './index';
const props = { const props = {
headings: [ columns: [
{ key: 'num', label: 'Number' }, { key: 'num', label: 'Number' },
{ key: 'x2', label: 'Number * 2' }, { key: 'x2', label: 'Number * 2' },
{ key: 'sq', label: 'Number Squared' }, { key: 'sq', label: 'Number Squared' },
...@@ -25,15 +25,15 @@ describe('<Table />', () => { ...@@ -25,15 +25,15 @@ describe('<Table />', () => {
/>, />,
); );
it('with display headings in the right order', () => { it('with display columns in the right order', () => {
wrapper.find('th').forEach((th, i) => { wrapper.find('th').forEach((th, i) => {
expect(th.text()).toEqual(props.headings[i].label); expect(th.text()).toEqual(props.columns[i].label);
}); });
}); });
it('with data in the same order as the headings', () => { it('with data in the same order as the columns', () => {
wrapper.find('tr').at(1).find('td').forEach((td, i) => { wrapper.find('tr').at(1).find('td').forEach((td, i) => {
expect(Number(td.text())).toEqual(props.data[0][props.headings[i].key]); expect(Number(td.text())).toEqual(props.data[0][props.columns[i].key]);
}); });
}); });
}); });
......
...@@ -18,12 +18,12 @@ class Table extends React.Component { ...@@ -18,12 +18,12 @@ class Table extends React.Component {
)} )}
> >
<tr> <tr>
{this.props.headings.map(heading => ( {this.props.columns.map(col => (
<th <th
key={heading.key} key={col.key}
scope="col" scope="col"
> >
{heading.label} {col.label}
</th> </th>
))} ))}
</tr> </tr>
...@@ -36,8 +36,8 @@ class Table extends React.Component { ...@@ -36,8 +36,8 @@ class Table extends React.Component {
<tbody> <tbody>
{this.props.data.map((row, i) => ( {this.props.data.map((row, i) => (
<tr key={i}> <tr key={i}>
{this.props.headings.map(heading => ( {this.props.columns.map(col => (
<td key={heading.key}>{row[heading.key]}</td> <td key={col.key}>{row[col.key]}</td>
))} ))}
</tr> </tr>
))} ))}
...@@ -67,7 +67,7 @@ Table.propTypes = { ...@@ -67,7 +67,7 @@ Table.propTypes = {
]), ]),
className: PropTypes.arrayOf(PropTypes.string), className: PropTypes.arrayOf(PropTypes.string),
data: PropTypes.arrayOf(PropTypes.object).isRequired, data: PropTypes.arrayOf(PropTypes.object).isRequired,
headings: PropTypes.arrayOf(PropTypes.shape({ columns: PropTypes.arrayOf(PropTypes.shape({
key: PropTypes.string.isRequired, key: PropTypes.string.isRequired,
label: PropTypes.oneOfType([ label: PropTypes.oneOfType([
PropTypes.string, PropTypes.string,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment