Skip to content

Commit

Permalink
Add a loading option
Browse files Browse the repository at this point in the history
  • Loading branch information
joshleblanc committed Sep 25, 2019
1 parent f0ea9e5 commit 9107a9a
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/MUIDataTable.js
Expand Up @@ -18,10 +18,13 @@ import TableToolbar from './components/TableToolbar';
import TableToolbarSelect from './components/TableToolbarSelect';
import textLabels from './textLabels';
import { buildMap, getCollatorComparator, sortCompare } from './utils';
import LoaderOverlay from './components/LoaderOverlay';

const defaultTableStyles = theme => ({
root: {},
paper: {},
paper: {
position: 'relative'
},
tableRoot: {
outline: 'none',
},
Expand Down Expand Up @@ -141,6 +144,7 @@ class MUIDataTable extends React.Component {
customToolbarSelect: PropTypes.oneOfType([PropTypes.func, PropTypes.element]),
customFooter: PropTypes.oneOfType([PropTypes.func, PropTypes.element]),
customSearchRender: PropTypes.oneOfType([PropTypes.func, PropTypes.element]),
loading: PropTypes.bool,
customRowRender: PropTypes.func,
onRowClick: PropTypes.func,
onRowsSelect: PropTypes.func,
Expand Down Expand Up @@ -285,6 +289,7 @@ class MUIDataTable extends React.Component {
selectableRowsOnClick: false,
selectableRowsHeader: true,
caseSensitive: false,
loading: false,
serverSide: false,
rowHover: true,
fixedHeader: true,
Expand Down Expand Up @@ -1338,6 +1343,9 @@ class MUIDataTable extends React.Component {
changeRowsPerPage={this.changeRowsPerPage}
changePage={this.changePage}
/>
{
this.options.loading && <LoaderOverlay />
}
<div className={classes.liveAnnounce} aria-live={'polite'}>
{announceText}
</div>
Expand Down
35 changes: 35 additions & 0 deletions src/components/LoaderOverlay.js
@@ -0,0 +1,35 @@
import React from 'react';
import { withStyles } from '@material-ui/core/styles';
import CircularProgress from '@material-ui/core/CircularProgress';
import { fade } from '@material-ui/core/styles/colorManipulator';

const styles = theme => ({
overlay: {
position: 'absolute',
top: 0,
left: 0,
zIndex: 110,
display: 'flex',
width: '100%',
height: '100%',
backgroundColor: fade(theme.palette.background.paper, 0.7)
},
progressContainer: {
margin: 'auto'
}
})

class LoaderOverlay extends React.Component {
render() {
const { classes } = this.props;
return(
<div className={classes.overlay}>
<div className={classes.progressContainer}>
<CircularProgress />
</div>
</div>
)
}
}

export default withStyles(styles, { withTheme: true })(LoaderOverlay);
5 changes: 5 additions & 0 deletions test/MUIDataTable.test.js
Expand Up @@ -84,6 +84,11 @@ describe('<MUIDataTable />', function() {
);
});

it('should render a loader', () => {
const wrapper = mount(<MUIDataTable columns={columns} data={data} options={{ loading: true }} />);
assert.equal(wrapper.find('LoaderOverlay').length, 1)
});

it('should correctly build internal columns data structure', () => {
const shallowWrapper = shallow(<MUIDataTable columns={columns} data={data} />);
const actualResult = shallowWrapper.dive().state().columns;
Expand Down

0 comments on commit 9107a9a

Please sign in to comment.