mirror of
https://github.com/gosticks/react-table.git
synced 2025-10-16 11:55:36 +00:00
109 lines
2.7 KiB
JavaScript
109 lines
2.7 KiB
JavaScript
import React from 'react'
|
|
import _ from 'lodash'
|
|
import namor from 'namor'
|
|
|
|
import ReactTable from '../src/index'
|
|
|
|
class Story extends React.Component {
|
|
render () {
|
|
const data = _.map(_.range(5553), d => {
|
|
const statusChance = Math.random()
|
|
return {
|
|
firstName: namor.generate({ words: 1, numLen: 0 }),
|
|
lastName: namor.generate({ words: 1, numLen: 0 }),
|
|
progress: Math.floor(Math.random() * 100),
|
|
status: statusChance > 0.66 ? 'relationship'
|
|
: statusChance > 0.33 ? 'complicated'
|
|
: 'single'
|
|
}
|
|
})
|
|
|
|
const columns = [{
|
|
Header: 'Name',
|
|
columns: [{
|
|
Header: 'First Name',
|
|
accessor: 'firstName'
|
|
}, {
|
|
Header: 'Last Name',
|
|
id: 'lastName',
|
|
accessor: d => d.lastName
|
|
}]
|
|
}, {
|
|
Header: 'Info',
|
|
columns: [{
|
|
Header: 'Profile Progress',
|
|
accessor: 'progress',
|
|
Cell: row => (
|
|
<div
|
|
style={{
|
|
width: '100%',
|
|
height: '100%',
|
|
backgroundColor: '#dadada',
|
|
borderRadius: '2px'
|
|
}}
|
|
>
|
|
<div
|
|
style={{
|
|
width: `${row.value}%`,
|
|
height: '100%',
|
|
backgroundColor: row.value > 66 ? '#85cc00'
|
|
: row.value > 33 ? '#ffbf00'
|
|
: '#ff2e00',
|
|
borderRadius: '2px',
|
|
transition: 'all .2s ease-out'
|
|
}}
|
|
/>
|
|
</div>
|
|
)
|
|
}, {
|
|
Header: 'Status',
|
|
accessor: 'status',
|
|
Cell: row => (
|
|
<span>
|
|
<span style={{
|
|
color: row.value === 'relationship' ? '#ff2e00'
|
|
: row.value === 'complicated' ? '#ffbf00'
|
|
: '#57d500',
|
|
transition: 'all .3s ease'
|
|
}}>
|
|
●
|
|
</span> {
|
|
row.value === 'relationship' ? 'In a relationship'
|
|
: row.value === 'complicated' ? `It's complicated`
|
|
: 'Single'
|
|
}
|
|
</span>
|
|
)
|
|
}]
|
|
}]
|
|
|
|
return (
|
|
<div>
|
|
<div className='table-wrap'>
|
|
<ReactTable
|
|
className='-striped -highlight'
|
|
data={data}
|
|
columns={columns}
|
|
defaultPageSize={10}
|
|
/>
|
|
</div>
|
|
<div style={{textAlign: 'center'}}>
|
|
<br />
|
|
<em>Tip: Hold shift when sorting to multi-sort!</em>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
}
|
|
|
|
// Source Code
|
|
const CodeHighlight = require('./components/codeHighlight').default
|
|
const source = require('!raw-loader!./CellRenderers')
|
|
|
|
export default () => (
|
|
<div>
|
|
<Story />
|
|
<CodeHighlight>{() => source}</CodeHighlight>
|
|
</div>
|
|
)
|