add story for #1006

This commit is contained in:
AllenFang 2019-08-24 14:59:49 +08:00
parent c12d3faba3
commit 056957b0b5
3 changed files with 111 additions and 3 deletions

View File

@ -0,0 +1,106 @@
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 expandRow1 = {
className: 'expanding-foo',
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>
)
};
const expandRow2 = {
className: (isExpanded, row, rowIndex) => {
if (rowIndex > 2) return 'expanding-foo';
return 'expanding-bar';
},
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>
)
};
const sourceCode1 = `\
import BootstrapTable from 'react-bootstrap-table-next';
const columns = // omit...
const expandRow = {
className: 'expanding-foo',
renderer: row => (
<div>.....</div>
)
};
<BootstrapTable
keyField='id'
data={ products }
columns={ columns }
expandRow={ expandRow }
/>
`;
const sourceCode2 = `\
import BootstrapTable from 'react-bootstrap-table-next';
const columns = // omit...
const expandRow = {
className: (isExpanded, row, rowIndex) => {
if (rowIndex > 2) return 'expanding-foo';
return 'expanding-bar';
},
renderer: row => (
<div>...</div>
)
};
<BootstrapTable
keyField='id'
data={ products }
columns={ columns }
expandRow={ expandRow }
/>
`;
export default () => (
<div>
<BootstrapTable
keyField="id"
data={ products }
columns={ columns }
expandRow={ expandRow1 }
/>
<Code>{ sourceCode1 }</Code>
<BootstrapTable
keyField="id"
data={ products }
columns={ columns }
expandRow={ expandRow2 }
/>
<Code>{ sourceCode2 }</Code>
</div>
);

View File

@ -167,6 +167,7 @@ import CustomExpandColumn from 'examples/row-expand/custom-expand-column';
import ExpandColumnPosition from 'examples/row-expand/expand-column-position';
import ExpandHooks from 'examples/row-expand/expand-hooks';
import ParentRowClassName from 'examples/row-expand/parent-row-classname';
import ExpandingRowClassName from 'examples/row-expand/expanding-row-classname';
// pagination
import PaginationTable from 'examples/pagination';
@ -420,7 +421,8 @@ storiesOf('Row Expand', module)
.add('Custom Expand Indicator', () => <CustomExpandColumn />)
.add('Expand Column Position', () => <ExpandColumnPosition />)
.add('Expand Hooks', () => <ExpandHooks />)
.add('Custom Parent Row ClassName', () => <ParentRowClassName />);
.add('Custom Parent Row ClassName', () => <ParentRowClassName />)
.add('Custom Expanding Row ClassName', () => <ExpandingRowClassName />);
storiesOf('Pagination', module)
.addDecorator(bootstrapStyle())

View File

@ -1,7 +1,7 @@
.parent-expand-foo {
.expanding-foo, .parent-expand-foo {
background-color: coral;
}
.parent-expand-bar {
.expanding-bar, .parent-expand-bar {
background-color: aqua;
}