Skip to content

Row expand animation v2 #1289

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import React from 'react';

import BootstrapTable from 'react-bootstrap-table-next';
import Code from 'components/common/code-block';
import { productsExpandRowsGenerator } from 'utils/common';

const products = productsExpandRowsGenerator();

const columns = [{
dataField: 'id',
text: 'Product ID'
}, {
dataField: 'name',
text: 'Product Name'
}, {
dataField: 'price',
text: 'Product Price'
}];

const expandRow = {
renderer: (row, rowIndex) => (
<div>
<p>{ `This Expand row is belong to rowKey ${row.id} and index: ${rowIndex}` }</p>
<p>You can render anything here, also you can add additional data on every row object</p>
<p>expandRow.renderer callback will pass the origin row object to you</p>
</div>
),
animate: false
};

const sourceCode = `\
import BootstrapTable from 'react-bootstrap-table-next';

const columns = [{
dataField: 'id',
text: 'Product ID'
}, {
dataField: 'name',
text: 'Product Name'
}, {
dataField: 'price',
text: 'Product Price'
}];

const expandRow = {
renderer: row => (
<div>
<p>{ \`This Expand row is belong to rowKey $\{row.id}\` }</p>
<p>You can render anything here, also you can add additional data on every row object</p>
<p>expandRow.renderer callback will pass the origin row object to you</p>
</div>
),
animate: false
};

<BootstrapTable
keyField='id'
data={ products }
columns={ columns }
expandRow={ expandRow }
/>
`;

export default () => (
<div>
<BootstrapTable
keyField="id"
data={ products }
columns={ columns }
expandRow={ expandRow }
/>
<Code>{ sourceCode }</Code>
</div>
);
2 changes: 2 additions & 0 deletions packages/react-bootstrap-table2-example/stories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ import SelectionColumnPositionTable from 'examples/row-selection/selection-colum

// work on row expand
import BasicRowExpand from 'examples/row-expand';
import DisableExpandAnimation from 'examples/row-expand/disable-animation';
import RowExpandManagement from 'examples/row-expand/expand-management';
import NonExpandableRows from 'examples/row-expand/non-expandable-rows';
import ExpandColumn from 'examples/row-expand/expand-column';
Expand Down Expand Up @@ -429,6 +430,7 @@ storiesOf('Row Selection', module)
storiesOf('Row Expand', module)
.addDecorator(bootstrapStyle())
.add('Basic Row Expand', () => <BasicRowExpand />)
.add('Disable Expand Animation', () => <DisableExpandAnimation />)
.add('Expand Management', () => <RowExpandManagement />)
.add('Non Expandabled Rows', () => <NonExpandableRows />)
.add('Expand Indicator', () => <ExpandColumn />)
Expand Down
2 changes: 2 additions & 0 deletions packages/react-bootstrap-table2/src/bootstrap-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ BootstrapTable.propTypes = {
}),
expandRow: PropTypes.shape({
renderer: PropTypes.func,
animate: PropTypes.bool,
expanded: PropTypes.array,
onExpand: PropTypes.func,
onExpandAll: PropTypes.func,
Expand Down Expand Up @@ -273,6 +274,7 @@ BootstrapTable.defaultProps = {
},
expandRow: {
renderer: undefined,
animate: true,
expanded: [],
nonExpandable: []
},
Expand Down
82 changes: 59 additions & 23 deletions packages/react-bootstrap-table2/src/row-expand/expand-row.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,76 @@
import cs from 'classnames';
import React from 'react';
import PropTypes from 'prop-types';
import { CSSTransition } from 'react-transition-group';
import { Transition } from 'react-transition-group';

const ExpandRow = ({ children, expanded, onClosed, className, ...rest }) => (
<tr>
<td className={ cs('reset-expansion-style', className) } { ...rest }>
<CSSTransition
appear
in={ expanded }
timeout={ 400 }
classNames="row-expand-slide"
onExited={ onClosed }
>
<div>
<div className="row-expansion-style">
{ children }
</div>
export default class ExpandRow extends React.Component {
componentDidUpdate(prevProps) {
if (!this.props.animate && !this.props.expanded && prevProps.expanded !== this.props.expanded) {
this.props.onClosed();
}
}
onEnter() {
this.expandableDiv = document.getElementById(`expansion-div-${this.props.id}`);
if (!this.elementHeight) {
this.elementHeight = this.expandableDiv.offsetHeight;
}
this.expandableDiv.style.height = '0px';
const elementHeight = this.elementHeight;
setTimeout(() => { this.expandableDiv.style.height = `${elementHeight}px`; }, 1);
}
onExit() {
this.expandableDiv.style.height = '0px';
}
render() {
const { children, expanded, onClosed, className, id, animate, ...rest } = this.props;

let expansionDiv = (
<div id={ `expansion-div-${id}` } className="row-expansion-inner">
<div className="row-expansion-style">
{children}
</div>
</CSSTransition>
</td>
</tr>
);
</div>
);

if (animate) {
expansionDiv = (
<Transition
in={ expanded }
timeout={ 460 }
onEnter={ () => this.onEnter() }
onExit={ () => this.onExit() }
onExited={ onClosed }
unmountOnExit
>
{expansionDiv}
</Transition>
);
}

return (
<tr>
<td className={ cs('reset-expansion-style', className) } { ...rest }>
{expansionDiv}
</td>
</tr>
);
}
}

ExpandRow.propTypes = {
children: PropTypes.node,
expanded: PropTypes.bool,
onClosed: PropTypes.func,
className: PropTypes.string
className: PropTypes.string,
animate: PropTypes.bool,
id: PropTypes.number
};

ExpandRow.defaultProps = {
children: null,
expanded: false,
onClosed: null,
className: ''
className: '',
animate: true,
id: null
};

export default ExpandRow;
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ export default (Component) => {
className={ cs(props.className, parentClassName) }
/>,
expanded || isClosing ? <ExpandRow
id={ key }
key={ `${key}-expanding` }
animate={ expandRow.animate }
colSpan={ props.visibleColumnSize }
expanded={ expanded }
onClosed={ () => expandRow.onClosed(key) }
Expand Down
16 changes: 2 additions & 14 deletions packages/react-bootstrap-table2/style/react-bootstrap-table2.scss
Original file line number Diff line number Diff line change
Expand Up @@ -163,20 +163,8 @@
.row-expansion-style{
padding: 8px;
}
.row-expand-slide-appear{
max-height: 0;
.row-expansion-inner{
transition: height 0.5s ease;
overflow: hidden;
}
.row-expand-slide-appear-active{
max-height: 1000px;
transition: max-height 3s linear;
}
.row-expand-slide-exit{
max-height: 1000px;
}
.row-expand-slide-exit-active{
max-height: 0;
overflow: hidden;
transition: max-height 400ms cubic-bezier(0, 0.95, 0, 0.95)
}
}