Skip to content

Commit

Permalink
[Table] implementation (#2)
Browse files Browse the repository at this point in the history
* [package.json] upgrade dependencies

* [TextField.css] fix linter error

* [Table] implementation

* [Table] unit test

* [Table] allow custom className, spread additional attributes
  • Loading branch information
petermikitsh authored Jan 12, 2018
1 parent 3391355 commit a2a5e79
Show file tree
Hide file tree
Showing 14 changed files with 338 additions and 34 deletions.
4 changes: 4 additions & 0 deletions docs/components/Navigation/Shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ const items = [
label: 'Switch',
url: makeURL('/Switch')
},
{
label: 'Table',
url: makeURL('/Table')
},
{
label: 'Tabs',
url: makeURL('/Tabs')
Expand Down
4 changes: 2 additions & 2 deletions docs/components/PageWrapper/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,17 @@ import {makeURL} from '../../utils/globals';
import Paper from '../../pages/Paper';
import React from 'react';
import {Route} from 'react-router-dom';
import Scrollable from '../../../src/Scrollable';
import SelectField from '../../pages/SelectField';
import SnackBar from '../../pages/SnackBar';
import Styles from './PageWrapper.css';
import Switch from '../../pages/Switch';
import SvgIcon from '../../../src/SvgIcon';
import Table from '../../pages/Table';
import Tabs from '../../pages/Tabs';
import TextField from '../../pages/TextField';
import TypographyDocs from '../../pages/Typography';

class PageWrapper extends React.Component {

constructor(props) {
super(props);
this.onClick = this.onClick.bind(this);
Expand Down Expand Up @@ -87,6 +86,7 @@ class PageWrapper extends React.Component {
<Route path={makeURL('/SelectField')} component={SelectField} />
<Route path={makeURL('/SnackBar')} component={SnackBar} />
<Route path={makeURL('/Switch')} component={Switch} />
<Route path={makeURL('/Table')} component={Table} />
<Route path={makeURL('/Tabs')} component={Tabs} />
<Route path={makeURL('/TextField')} component={TextField} />
<Route path={makeURL('/Typography')} component={TypographyDocs} />
Expand Down
56 changes: 56 additions & 0 deletions docs/pages/Table/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import Grid, {GridItem} from '../../../src/Grid';
import Page from '../Page';
import Paper from '../../../src/Paper';
import React from 'react';
import Table, {TableBody, TableCell, TableHead, TableRow} from '../../../src/Table';
import Typography from '../../../src/Typography';

class TabsDocs extends React.Component {
render() {
return (
<Page
componentName="Table"
examples={
<Grid gutter={16}>
<GridItem xs={12}>
<Typography component="p">
Simple table.
</Typography>
<Paper elevation={3}>
<Table>
<TableHead>
<TableRow>
<TableCell>Name</TableCell>
<TableCell>Age</TableCell>
<TableCell>Street Address</TableCell>
<TableCell>ZIP Code</TableCell>
<TableCell>State</TableCell>
</TableRow>
</TableHead>
<TableBody>
<TableRow>
<TableCell>Johnathan Doe</TableCell>
<TableCell>25</TableCell>
<TableCell>700 1st Ave</TableCell>
<TableCell>90210</TableCell>
<TableCell>CA</TableCell>
</TableRow>
<TableRow>
<TableCell>Jane Doe</TableCell>
<TableCell>23</TableCell>
<TableCell>15 Spruce St</TableCell>
<TableCell>92101</TableCell>
<TableCell>CA</TableCell>
</TableRow>
</TableBody>
</Table>
</Paper>
</GridItem>
</Grid>
}
/>
);
}
}

export default TabsDocs;
54 changes: 27 additions & 27 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
},
"dependencies": {
"babel-cli": "6.26.0",
"babel-eslint": "8.0.1",
"babel-eslint": "8.2.1",
"babel-plugin-transform-object-assign": "6.22.0",
"babel-plugin-transform-object-rest-spread": "6.26.0",
"babel-preset-env": "1.6.1",
Expand All @@ -50,29 +50,29 @@
"uuid": "3.1.0"
},
"devDependencies": {
"autoprefixer": "7.1.5",
"autoprefixer": "7.2.4",
"babel-core": "6.26.0",
"babel-loader": "7.1.2",
"babel-plugin-empower-assert": "1.3.0",
"babel-plugin-espower": "2.3.2",
"babel-plugin-istanbul": "4.1.5",
"babel-plugin-transform-class-properties": "6.24.1",
"babel-plugin-transform-react-remove-prop-types": "0.4.10",
"babel-plugin-transform-react-remove-prop-types": "0.4.12",
"babel-plugin-transform-runtime": "6.23.0",
"babel-polyfill": "6.26.0",
"case-sensitive-paths-webpack-plugin": "2.1.1",
"core-js": "2.5.1",
"css-loader": "0.28.7",
"enzyme": "3.1.0",
"enzyme-adapter-react-16": "1.0.2",
"eslint": "4.9.0",
"core-js": "2.5.3",
"css-loader": "0.28.8",
"enzyme": "3.3.0",
"enzyme-adapter-react-16": "1.1.1",
"eslint": "4.15.0",
"eslint-config-airbnb": "16.1.0",
"eslint-plugin-import": "2.8.0",
"eslint-plugin-jsx-a11y": "6.0.2",
"eslint-plugin-react": "7.4.0",
"eslint-plugin-jsx-a11y": "6.0.3",
"eslint-plugin-react": "7.5.1",
"html-webpack-plugin": "2.30.1",
"isomorphic-style-loader": "3.0.0",
"karma": "1.7.1",
"isomorphic-style-loader": "4.0.0",
"karma": "2.0.0",
"karma-browserstack-launcher": "1.3.0",
"karma-chrome-launcher": "2.2.0",
"karma-coverage": "1.1.1",
Expand All @@ -81,31 +81,31 @@
"karma-mocha-reporter": "2.2.5",
"karma-safari-launcher": "1.0.0",
"karma-sourcemap-loader": "0.3.7",
"karma-webpack": "2.0.5",
"karma-webpack": "2.0.9",
"lodash": "4.17.4",
"mocha": "3.4.2",
"npm-run-all": "4.1.1",
"mocha": "4.1.0",
"npm-run-all": "4.1.2",
"phantomjs-polyfill-object-assign": "0.0.2",
"postcss-cli": "4.1.1",
"postcss-loader": "2.0.8",
"postcss-loader": "2.0.10",
"postcss-simple-vars": "4.1.0",
"power-assert": "1.4.4",
"prismjs": "1.8.3",
"prismjs": "1.9.0",
"prop-types": "15.6.0",
"raw-loader": "0.5.1",
"react": "16.0.0",
"react-dom": "16.0.0",
"react-hot-loader": "3.1.1",
"react": "16.2.0",
"react-dom": "16.2.0",
"react-hot-loader": "3.1.3",
"react-router-dom": "4.2.2",
"react-svg-loader": "2.1.0",
"react-tap-event-plugin": "3.0.2",
"react-test-renderer": "16.0.0",
"sinon": "2.3.8",
"style-loader": "0.19.0",
"stylelint": "8.2.0",
"stylelint-config-standard": "17.0.0",
"webpack": "3.8.1",
"webpack-dev-server": "2.9.3",
"react-test-renderer": "16.2.0",
"sinon": "4.1.4",
"style-loader": "0.19.1",
"stylelint": "8.4.0",
"stylelint-config-standard": "18.0.0",
"webpack": "3.10.0",
"webpack-dev-server": "2.10.1",
"webpack-node-externals": "1.6.0"
}
}
10 changes: 10 additions & 0 deletions src/Table/Table.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.container {
overflow-x: auto;
}

.table {
border-spacing: 0;
border-collapse: collapse;
overflow: hidden;
width: 100%;
}
29 changes: 29 additions & 0 deletions src/Table/Table.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import makeClass from 'classnames';
import PropTypes from 'prop-types';
import React from 'react';
import Styles from './Table.css';

class Table extends React.Component {
render() {
const {children, className, ...other} = this.props;
return (
<div className={makeClass(Styles.container, className)}>
<table className={Styles.table} {...other}>
{children}
</table>
</div>
);
}
}

Table.propTypes = {
children: PropTypes.node,
className: PropTypes.string
};

Table.defaultProps = {
children: null,
className: ''
};

export default Table;
52 changes: 52 additions & 0 deletions src/Table/Table.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/* eslint-env mocha */

import assert from 'assert';
import {createMount} from '../../test/utils';
import React from 'react';
import Table, {TableBody, TableCell, TableHead, TableRow} from './index';

describe('Tabs', () => {
let mount;

beforeEach(() => {
mount = createMount();
});

afterEach(() => {
mount.cleanUp();
});

it('should deep render', () => {
const component = (
<Table>
<TableHead>
<TableRow>
<TableCell>Name</TableCell>
<TableCell>Age</TableCell>
<TableCell>Street Address</TableCell>
<TableCell>ZIP Code</TableCell>
<TableCell>State</TableCell>
</TableRow>
</TableHead>
<TableBody>
<TableRow>
<TableCell>Johnathan Doe</TableCell>
<TableCell>25</TableCell>
<TableCell>700 1st Ave</TableCell>
<TableCell>90210</TableCell>
<TableCell>CA</TableCell>
</TableRow>
<TableRow>
<TableCell>Jane Doe</TableCell>
<TableCell>23</TableCell>
<TableCell>15 Spruce St</TableCell>
<TableCell>92101</TableCell>
<TableCell>CA</TableCell>
</TableRow>
</TableBody>
</Table>
);
const wrapper = mount(component);
assert(wrapper);
});
});
23 changes: 23 additions & 0 deletions src/Table/TableBody.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import PropTypes from 'prop-types';
import React from 'react';

class TableBody extends React.Component {
render() {
const {children, ...other} = this.props;
return (
<tbody {...other}>
{children}
</tbody>
);
}
}

TableBody.propTypes = {
children: PropTypes.node
};

TableBody.defaultProps = {
children: null
};

export default TableBody;
24 changes: 24 additions & 0 deletions src/Table/TableCell.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.cell {
border-bottom: 1px solid rgb(235, 235, 235);
color: $black87;
font-size: 13px;
height: 48px;
padding-left: 24px;
padding-right: 56px;
white-space: nowrap;
}

.cell:first-child {
text-align: left;
}

.cell:not(:first-child) {
text-align: right;
}

.head {
color: $black54;
font-size: 12px;
font-weight: 500;
height: 56px;
}
39 changes: 39 additions & 0 deletions src/Table/TableCell.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import makeClass from 'classnames';
import PropTypes from 'prop-types';
import React from 'react';
import Styles from './TableCell.css';

class TableCell extends React.Component {
render() {
const {
children,
className,
head,
...other
} = this.props;
const Component = head ? 'th' : 'td';
const classnames = makeClass(Styles.cell, {
[Styles.head]: head
}, className);

return (
<Component className={classnames} {...other}>
{children}
</Component>
);
}
}

TableCell.propTypes = {
children: PropTypes.node,
className: PropTypes.string,
head: PropTypes.bool
};

TableCell.defaultProps = {
children: null,
className: '',
head: false
};

export default TableCell;
Loading

0 comments on commit a2a5e79

Please sign in to comment.