react-bootstrap-table2/packages/react-bootstrap-table2-example/examples/basic/table-with-caption.js
Esa Juhana 3d6a293e5e fix #77
* Implement basic usage of table <caption> element

Add tableCaption prop, which can be a component / string

Add simple test and an example to Storybook

* Fix Caption example & Code syle fix for return statement

* Rename tableCaption > caption
2017-10-10 02:10:54 -05:00

48 lines
1.4 KiB
JavaScript

import React from 'react';
import { BootstrapTableful } from 'react-bootstrap-table2';
import Code from 'components/common/code-block';
import { productsGenerator } from 'utils/common';
const products = productsGenerator();
const columns = [{
dataField: 'id',
text: 'Product ID'
}, {
dataField: 'name',
text: 'Product Name'
}, {
dataField: 'price',
text: 'Product Price'
}];
const sourceCode = `\
const columns = [{
dataField: 'id',
text: 'Product ID'
}, {
dataField: 'name',
text: 'Product Name'
}, {
dataField: 'price',
text: 'Product Price'
}];
const CaptionElement = () => <h3 style={{ borderRadius: '0.25em', textAlign: 'center', color: 'purple', border: '1px solid purple', padding: '0.5em' }}>Component as Header</h3>;
<BootstrapTableful keyField="id" data={ products } caption="Plain text header" columns={ columns } />
<BootstrapTableful keyField="id" data={ products } caption={<CaptionElement />} columns={ columns } />
`;
const Caption = () => <h3 style={{ borderRadius: '0.25em', textAlign: 'center', color: 'purple', border: '1px solid purple', padding: '0.5em' }}>Component as Header</h3>;
export default () => (
<div>
<BootstrapTableful keyField="id" data={ products } caption="Plain text header" columns={ columns } />
<BootstrapTableful keyField="id" data={ products } caption={<Caption />} columns={ columns } />
<Code>{ sourceCode }</Code>
</div>
);