* add basic stories

* add google-prettify

* add google-code-prettify-theme

* add code example for each story

* add column stories

* add header column stories
This commit is contained in:
Allen
2017-09-02 01:54:09 -05:00
committed by GitHub
parent c09bf7c2f1
commit 60d4e7e5d2
20 changed files with 977 additions and 27 deletions

View File

@@ -0,0 +1,56 @@
/* eslint no-unused-vars: 0 */
import React from 'react';
import { BootstrapTable } from 'react-bootstrap-table2';
const products = [];
function addProducts(quantity) {
const startId = products.length;
for (let i = 0; i < quantity; i += 1) {
const id = startId + i;
products.push({
id,
name: `Item name ${id}`,
price: 2100 + i
});
}
}
addProducts(5);
const columns = [{
dataField: 'id',
text: 'Product ID',
headerAlign: 'center'
}, {
dataField: 'name',
text: 'Product Name',
headerAlign: (column, colIndex) => 'right'
}, {
dataField: 'price',
text: 'Product Price'
}];
export default () => (
<div>
<BootstrapTable keyField="id" data={ products } columns={ columns } />
<pre className="prettyprint lang-js"><code className="language-javascript">{`
const columns = [{
dataField: 'id',
text: 'Product ID',
headerAlign: 'center'
}, {
dataField: 'name',
text: 'Product Name',
headerAlign: (column, colIndex) => 'right'
}, {
dataField: 'price',
text: 'Product Price'
}];
<BootstrapTable keyField='id' data={ products } columns={ columns } />
`}
</code></pre>
</div>
);

View File

@@ -0,0 +1,60 @@
/* eslint no-unused-vars: 0 */
/* eslint no-alert: 0 */
import React from 'react';
import { BootstrapTable } from 'react-bootstrap-table2';
const products = [];
function addProducts(quantity) {
const startId = products.length;
for (let i = 0; i < quantity; i += 1) {
const id = startId + i;
products.push({
id,
name: `Item name ${id}`,
price: 2100 + i
});
}
}
addProducts(5);
const columns = [{
dataField: 'id',
text: 'Product ID',
headerEvents: {
onClick: () => alert('Click on Product ID header column')
}
}, {
dataField: 'name',
text: 'Product Name'
}, {
dataField: 'price',
text: 'Product Price'
}];
export default () => (
<div>
<h3>Try to Click on Product ID header column</h3>
<BootstrapTable keyField="id" data={ products } columns={ columns } />
<pre className="prettyprint lang-js"><code className="language-javascript">{`
const columns = [{
dataField: 'id',
text: 'Product ID',
events: {
onClick: () => alert('Click on Product ID header column')
}
}, {
dataField: 'name',
text: 'Product Name'
}, {
dataField: 'price',
text: 'Product Price'
}];
<BootstrapTable keyField='id' data={ products } columns={ columns } />
`}
</code></pre>
</div>
);

View File

@@ -0,0 +1,71 @@
/* eslint no-unused-vars: 0 */
import React from 'react';
import { BootstrapTable } from 'react-bootstrap-table2';
const products = [];
function addProducts(quantity) {
const startId = products.length;
for (let i = 0; i < quantity; i += 1) {
const id = startId + i;
products.push({
id,
name: `Item name ${id}`,
price: 2100 + i,
onSale: Math.random() >= 0.5
});
}
}
addProducts(5);
function priceFormatter(column, colIndex) {
return (
<h5><strong>$$ { column.text } $$</strong></h5>
);
}
const columns = [{
dataField: 'id',
text: 'Product ID'
}, {
dataField: 'name',
text: 'Product Name'
}, {
dataField: 'price',
text: 'Product Price',
headerFormatter: priceFormatter
}];
export default () => (
<div>
<BootstrapTable
keyField="id"
data={ products }
columns={ columns }
/>
<pre className="prettyprint lang-js"><code className="language-javascript">{`
function priceFormatter(column, colIndex) {
return (
<h5><strong>$$ { column.text } $$</strong></h5>
);
}
const columns = [
// omit...
{
dataField: 'price',
text: 'Product Price',
headerFormatter: priceFormatter
}];
<BootstrapTable
keyField="id"
data={ products }
columns={ columns }
/>
`}
</code></pre>
</div>
);

View File

@@ -0,0 +1,56 @@
/* eslint no-unused-vars: 0 */
import React from 'react';
import { BootstrapTable } from 'react-bootstrap-table2';
const products = [];
function addProducts(quantity) {
const startId = products.length;
for (let i = 0; i < quantity; i += 1) {
const id = startId + i;
products.push({
id,
name: `Item name ${id}`,
price: 2100 + i
});
}
}
addProducts(5);
const columns = [{
dataField: 'id',
text: 'Product ID',
headerTitle: true
}, {
dataField: 'name',
text: 'Product Name',
headerTitle: (column, colIndex) => `this is custom title for ${column.text}`
}, {
dataField: 'price',
text: 'Product Price'
}];
export default () => (
<div>
<BootstrapTable keyField="id" data={ products } columns={ columns } />
<pre className="prettyprint lang-js"><code className="language-javascript">{`
const columns = [{
dataField: 'id',
text: 'Product ID',
headerTitle: true
}, {
dataField: 'name',
text: 'Product Name',
headerTitle: (column, colIndex) => \`this is custom title for \${column.text}\`
}, {
dataField: 'price',
text: 'Product Price'
}];
<BootstrapTable keyField='id' data={ products } columns={ columns } />
`}
</code></pre>
</div>
);