Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(react-grid): Material UI detail row (#115)
- Loading branch information
1 parent
81353bc
commit c161c66
Showing
19 changed files
with
294 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Route } from 'react-router-dom'; | ||
|
||
import { SimpleDetailRowDemo } from './detail-row/simple-detail-row'; | ||
import { DetailRowControlledDemo } from './detail-row/detail-row-controlled'; | ||
|
||
const AllDemos = () => ( | ||
<div> | ||
<h2>Detail Row Demos</h2> | ||
<h3>Simple Uncontrolled Detail Row</h3> | ||
<SimpleDetailRowDemo /> | ||
<h3>Expanded State Controlled Mode</h3> | ||
<DetailRowControlledDemo /> | ||
</div> | ||
); | ||
|
||
export const DetailRowDemos = ({ match }) => ( | ||
<div> | ||
<Route exact path={`${match.url}/`} component={AllDemos} /> | ||
<Route path={`${match.url}/simple-detail-row`} component={SimpleDetailRowDemo} /> | ||
<Route path={`${match.url}/detail-row-controlled`} component={DetailRowControlledDemo} /> | ||
</div> | ||
); | ||
DetailRowDemos.propTypes = { | ||
match: PropTypes.shape({ | ||
url: PropTypes.string, | ||
}).isRequired, | ||
}; |
54 changes: 54 additions & 0 deletions
54
packages/dx-react-demos/src/material-ui/detail-row/detail-row-controlled.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import React from 'react'; | ||
import { | ||
RowDetailState, | ||
} from '@devexpress/dx-react-grid'; | ||
import { | ||
Grid, | ||
TableView, | ||
TableHeaderRow, | ||
TableRowDetail, | ||
} from '@devexpress/dx-react-grid-material-ui'; | ||
|
||
import { | ||
generateRows, | ||
} from '../../demoData'; | ||
|
||
export class DetailRowControlledDemo extends React.PureComponent { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.state = { | ||
columns: [ | ||
{ name: 'name', title: 'Name' }, | ||
{ name: 'sex', title: 'Sex' }, | ||
{ name: 'city', title: 'City' }, | ||
{ name: 'car', title: 'Car' }, | ||
], | ||
rows: generateRows({ length: 7 }), | ||
expandedRows: [2, 5], | ||
}; | ||
|
||
this.changeExpandedDetails = expandedRows => this.setState({ expandedRows }); | ||
this.rowTemplate = ({ row }) => <div>Details for {row.name} from {row.city}</div>; | ||
} | ||
render() { | ||
const { rows, columns, expandedRows } = this.state; | ||
|
||
return ( | ||
<Grid | ||
rows={rows} | ||
columns={columns} | ||
> | ||
<RowDetailState | ||
expandedRows={expandedRows} | ||
onExpandedRowsChange={this.changeExpandedDetails} | ||
/> | ||
<TableView /> | ||
<TableHeaderRow /> | ||
<TableRowDetail | ||
template={this.rowTemplate} | ||
/> | ||
</Grid> | ||
); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
packages/dx-react-demos/src/material-ui/detail-row/detail-row-controlled.test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
import { MuiThemeProvider, createMuiTheme } from 'material-ui/styles'; | ||
import { DetailRowControlledDemo } from './detail-row-controlled'; | ||
|
||
describe('MUI: detail row controlled demo', () => { | ||
test('should work', () => { | ||
mount( | ||
<MuiThemeProvider theme={createMuiTheme()}> | ||
<DetailRowControlledDemo /> | ||
</MuiThemeProvider>, | ||
); | ||
|
||
expect(true).toBeTruthy(); | ||
}); | ||
}); |
52 changes: 52 additions & 0 deletions
52
packages/dx-react-demos/src/material-ui/detail-row/simple-detail-row.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import React from 'react'; | ||
import { | ||
RowDetailState, | ||
} from '@devexpress/dx-react-grid'; | ||
import { | ||
Grid, | ||
TableView, | ||
TableHeaderRow, | ||
TableRowDetail, | ||
} from '@devexpress/dx-react-grid-material-ui'; | ||
|
||
import { | ||
generateRows, | ||
} from '../../demoData'; | ||
|
||
export class SimpleDetailRowDemo extends React.PureComponent { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.state = { | ||
columns: [ | ||
{ name: 'name', title: 'Name' }, | ||
{ name: 'sex', title: 'Sex' }, | ||
{ name: 'city', title: 'City' }, | ||
{ name: 'car', title: 'Car' }, | ||
], | ||
rows: generateRows({ length: 7 }), | ||
}; | ||
|
||
this.changeExpandedDetails = expandedRows => this.setState({ expandedRows }); | ||
this.rowTemplate = ({ row }) => <div>Details for {row.name} from {row.city}</div>; | ||
} | ||
render() { | ||
const { rows, columns } = this.state; | ||
|
||
return ( | ||
<Grid | ||
rows={rows} | ||
columns={columns} | ||
> | ||
<RowDetailState | ||
defaultExpandedRows={[2, 5]} | ||
/> | ||
<TableView /> | ||
<TableHeaderRow /> | ||
<TableRowDetail | ||
template={this.rowTemplate} | ||
/> | ||
</Grid> | ||
); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
packages/dx-react-demos/src/material-ui/detail-row/simple-detail-row.test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
import { MuiThemeProvider, createMuiTheme } from 'material-ui/styles'; | ||
import { SimpleDetailRowDemo } from './simple-detail-row'; | ||
|
||
describe('MUI: simple detail row demo', () => { | ||
test('should work', () => { | ||
mount( | ||
<MuiThemeProvider theme={createMuiTheme()}> | ||
<SimpleDetailRowDemo /> | ||
</MuiThemeProvider>, | ||
); | ||
|
||
expect(true).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
packages/dx-react-grid-material-ui/src/plugins/table-row-detail.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React from 'react'; | ||
import { TableRowDetail as TableRowDetailBase } from '@devexpress/dx-react-grid'; | ||
import { TableDetailToggleCell } from '../templates/table-detail-toggle-cell'; | ||
import { TableDetailCell } from '../templates/table-detail-cell'; | ||
|
||
const detailToggleTemplate = props => <TableDetailToggleCell {...props} />; | ||
const detailCellTemplate = props => <TableDetailCell {...props} />; | ||
|
||
export const TableRowDetail = props => ( | ||
<TableRowDetailBase | ||
detailToggleTemplate={detailToggleTemplate} | ||
detailCellTemplate={detailCellTemplate} | ||
detailToggleCellWidth={42} | ||
{...props} | ||
/> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
packages/dx-react-grid-material-ui/src/templates/table-detail-cell.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { TableCell } from 'material-ui'; | ||
import { withStyles, createStyleSheet } from 'material-ui/styles'; | ||
|
||
const styleSheet = createStyleSheet('TableDetailCell', theme => ({ | ||
active: { | ||
backgroundColor: theme.palette.background.contentFrame, | ||
}, | ||
})); | ||
|
||
const TableDetailCellBase = ({ colspan, style, template, classes }) => | ||
<TableCell | ||
style={style} | ||
colSpan={colspan} | ||
className={classes.active} | ||
> | ||
{template()} | ||
</TableCell>; | ||
|
||
TableDetailCellBase.propTypes = { | ||
style: PropTypes.shape(), | ||
colspan: PropTypes.number, | ||
template: PropTypes.func.isRequired, | ||
classes: PropTypes.object.isRequired, | ||
}; | ||
|
||
TableDetailCellBase.defaultProps = { | ||
style: null, | ||
colspan: 1, | ||
}; | ||
|
||
export const TableDetailCell = withStyles(styleSheet)(TableDetailCellBase); |
Oops, something went wrong.