Skip to content

Commit b3f665d

Browse files
committed
Merge pull request facebookarchive#305 from facebook/v6-docs
v0.6 docs
2 parents fb7b6f4 + a285a6f commit b3f665d

21 files changed

+1189
-160
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ __build__
77
__site__
88
__site_prerender__
99
internal
10-
docs
10+
docs/api
1111
dist
1212
*.swp

build_helpers/buildAPIDocs.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ var generateMarkdown = require('./react_documentation/generateMarkdown');
77
var path = require('path');
88
var ReactDocGen = require('react-docgen');
99

10-
var docsPath = path.join(__dirname, '../docs');
10+
var docsPath = path.join(__dirname, '../docs/api');
1111
if (!fs.existsSync(docsPath)) {
1212
fs.mkdirSync(docsPath);
1313
}
@@ -28,6 +28,11 @@ var FILES_TO_READ = [
2828
path: path.join(PROJECT_ROOT, 'src/FixedDataTableColumnGroupNew.react.js'),
2929
name: 'ColumnGroup',
3030
markdownFileName: 'ColumnGroupAPI.md'
31+
},
32+
{
33+
path: path.join(PROJECT_ROOT, 'src/FixedDataTableCellDefault.react.js'),
34+
name: 'Cell',
35+
markdownFileName: 'CellAPI.md'
3136
}
3237
];
3338

build_helpers/buildSiteIndexPages.sh

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,27 @@ if (process.env.NODE_ENV === 'production') {
3636
});
3737
}
3838

39-
var locations = [
40-
Constants.APIPages,
41-
Constants.ExamplePages,
42-
Constants.OtherPages
43-
].reduce(function(paths, pages) {
44-
return paths.concat(
45-
Object.keys(pages).map(function(key) {
46-
return pages[key].location;
47-
})
48-
);
39+
function getAllLocations(pages) {
40+
var locations = [];
41+
for (var key in pages) {
42+
if (!pages.hasOwnProperty(key) || typeof pages[key] !== 'object') {
43+
continue;
44+
}
45+
46+
if (pages[key].groupTitle) {
47+
locations = [].concat(locations, getAllLocations(pages[key]));
48+
}
49+
50+
if (pages[key].location) {
51+
locations.push(pages[key].location);
52+
}
53+
}
54+
55+
return locations;
56+
}
57+
58+
var locations = Constants.ALL_PAGES.reduce(function(allPages, pages) {
59+
return [].concat(allPages, getAllLocations(pages));
4960
}, []);
5061

5162
locations.forEach(function(fileName) {

docs/README.md

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
Getting Started
2+
===============
3+
4+
The easiest way to start using on FixedDataTable is to install it via npm:
5+
6+
```shell
7+
npm install react --save
8+
npm install fixed-data-table --save
9+
```
10+
11+
If your using a standard build system such as [`browserify`](http://browserify.org/) or [`webpack`](https://webpack.github.io/) it can then be required directly:
12+
```
13+
const React = require('react');
14+
const {Table, Column, Cell} = require('fixed-data-table');
15+
```
16+
17+
For layout and styling the default stylesheet will need to be added: `fixed-data-table/dist/fixed-data-table.min.css`.
18+
19+
## Create your `Table`
20+
Setting up your table can be done via the `Table` component. To be able to handle large amounts of data the table only renders the parts that are visible to the user, in order to calculate this a static `width`, `height`, `rowsCount` and `rowHeight` are required:
21+
22+
```javascript
23+
const React = require('react');
24+
const {Table} = require('fixed-data-table');
25+
26+
class MyTable extends React.Component {
27+
render() {
28+
return (
29+
<Table
30+
rowsCount={100}
31+
rowHeight={50}
32+
width={1000}
33+
height={500}>
34+
// TODO: Add columns
35+
</Table>
36+
);
37+
}
38+
}
39+
```
40+
41+
## Create your `Column`s
42+
For each column that needs to be displayed a `Column` config with 2 important props are required. The `width` of the column and the `cell` content to render. The `Cell` component can wrap any content to provide default table styles and centering.
43+
44+
```javascript
45+
const React = require('react');
46+
const {Table, Column, Cell} = require('fixed-data-table');
47+
48+
class MyTable extends React.Component {
49+
render() {
50+
return (
51+
<Table
52+
rowsCount={100}
53+
rowHeight={50}
54+
width={1000}
55+
height={500}>
56+
<Column
57+
cell={<Cell>Basic content</Cell>}
58+
width={200}
59+
/>
60+
</Table>
61+
);
62+
}
63+
}
64+
```
65+
66+
## Provide Custom Data
67+
Typically you will want to render custom data per row, let's add some data to our table and add a header to the column.
68+
69+
```javascript
70+
const React = require('react');
71+
const {Table, Column, Cell} = require('fixed-data-table');
72+
73+
class MyTable extends React.Component {
74+
constructor(props) {
75+
super(props);
76+
77+
this.state = {
78+
myTableData: [
79+
{name: 'Rylan'},
80+
{name: 'Amelia'},
81+
{name: 'Estevan'},
82+
{name: 'Florence'},
83+
{name: 'Tressa'},
84+
],
85+
};
86+
}
87+
88+
render() {
89+
return (
90+
<Table
91+
rowsCount={this.state.myTableData.length}
92+
rowHeight={50}
93+
headerHeight={50}
94+
width={1000}
95+
height={500}>
96+
<Column
97+
header={<Cell>Name</Cell>}
98+
cell={props => (
99+
<Cell {...props}>
100+
{this.state.myTableData[props.rowIndex].name}
101+
</Cell>
102+
)}
103+
width={200}
104+
/>
105+
</Table>
106+
);
107+
}
108+
}
109+
```
110+
111+
Instead of providing a static `cell` we can use a function for our `cell`, this function will be passed the `rowIndex` plus the `width` and `height` of the cell. By using the `rowIndex` and we can get different data from `this.state.myTableData` for each cell.
112+
113+
## Create Reusable Cells
114+
115+
With larger table setups you will want to reuse the `cell` render functions. To do this you can create your own React Component for each unique `Cell`. Let's add another column that displays emails with links.
116+
117+
```javascript
118+
const React = require('react');
119+
const {Table, Column, Cell} = require('fixed-data-table');
120+
121+
class MyTextCell extends React.Component {
122+
render() {
123+
const {rowIndex, field, data, ...props} = this.props;
124+
return (
125+
<Cell {...props}>
126+
{data[rowIndex][field]}
127+
</Cell>
128+
);
129+
}
130+
}
131+
132+
class MyLinkCell extends React.Component {
133+
render() {
134+
const {rowIndex, field, data, ...props} = this.props;
135+
const link = data[rowIndex][field];
136+
return (
137+
<Cell {...props}>
138+
<a href={link}>{link}</a>
139+
</Cell>
140+
);
141+
}
142+
}
143+
144+
class MyTable extends React.Component {
145+
constructor(props) {
146+
super(props);
147+
148+
this.state = {
149+
myTableData: [
150+
{name: 'Rylan', email: '[email protected]'},
151+
{name: 'Amelia', email: '[email protected]'},
152+
{name: 'Estevan', email: '[email protected]'},
153+
{name: 'Florence', email: '[email protected]'},
154+
{name: 'Tressa', email: '[email protected]'},
155+
],
156+
};
157+
}
158+
159+
render() {
160+
return (
161+
<Table
162+
rowsCount={this.state.myTableData.length}
163+
rowHeight={50}
164+
headerHeight={50}
165+
width={1000}
166+
height={500}>
167+
<Column
168+
header={<Cell>Name</Cell>}
169+
cell={
170+
<MyTextCell
171+
data={this.state.myTableData}
172+
field="name"
173+
/>
174+
}
175+
width={200}
176+
/>
177+
<Column
178+
header={<Cell>Email</Cell>}
179+
cell={
180+
<MyLinkCell
181+
data={this.state.myTableData}
182+
field="email"
183+
/>
184+
}
185+
width={200}
186+
/>
187+
</Table>
188+
);
189+
}
190+
}
191+
```
192+
193+
## Next Steps
194+
195+
The FixedDataTable has many more options, for more information see the [examples section](http://facebook.github.io/fixed-data-table/example-object-data.html) or the [API docs](http://facebook.github.io/fixed-data-table/api-table.html).

0 commit comments

Comments
 (0)