Skip to content

Commit 2ecd47c

Browse files
committed
[website] add pagination
1 parent 80cd476 commit 2ecd47c

File tree

11 files changed

+92
-209
lines changed

11 files changed

+92
-209
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ The simplest way is overriding the default styles (assuming you are using `scss`
5959
// override default variables for BaseTable
6060
$table-prefix: AdvanceTable;
6161

62-
$table-font-size: $bim-font-size-small;
63-
$table-border-radius: 4px;
62+
$table-font-size: 13px;
6463
$table-padding-left: 15px;
6564
$table-padding-right: 15px;
6665
$column-padding: 7.5px;

docs/advance.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ The simplest way is overriding the default styles (assuming you are using `scss`
1010
// override default variables for BaseTable
1111
$table-prefix: AdvanceTable;
1212

13-
$table-font-size: $bim-font-size-small;
14-
$table-border-radius: 4px;
13+
$table-font-size: 13px;
1514
$table-padding-left: 15px;
1615
$table-padding-right: 15px;
1716
$column-padding: 7.5px;

docs/inline-editing.md

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55
## The Problem
66

7-
`Inline Editing` would be a bit tricky in `BaseTable` because of it's using the `virtualization` technology to render the rows, so there are `overflow: hidden` for the table and rows and cells, so if your editing content is larger then the cell area, the content would be cut, you genius would find that you could override the `overflow: hidden` via style to prevent the content to be cut, but **PLEASE DON"T DO THAT**, as there would be always problems with this solution, e.g. what would happens if it's in the last row?
7+
`Inline Editing` would be a bit tricky in `BaseTable` because of it's using the virtualization technology to render the rows, there is `overflow: hidden` for the table and rows and cells, so if your editing content is larger than the cell area, the content would be cut, you genius would find that you could override the `overflow: hidden` via style to prevent the content to be clipped, but **PLEASE DON'T DO THAT**, as there would be always problems with this solution, e.g. what would happens if it's in the last row?
88

99
## How
1010

11-
The suggested solution is using something like `Portal` to render the editing content out of the cell, then it won't be constrained in the cell. As `Portal` needs a container to attach the target to, most of the custom renderers provide a param `container` to be used in this case, the `container` is table itself.
11+
The recommended solution is using something like `Portal` to render the editing content out of the cell, then it won't be constrained in the cell. As `Portal` needs a container to attach the target to, most of the custom renderers provide a param `container` to be used in this case, the `container` is the table itself.
1212

1313
Internally we are using the `Overlay` component from [react-overlays](https://github.com/react-bootstrap/react-overlays) to do that, `react-overlays` is based on [Popper.js](https://github.com/FezVrasta/popper.js) which provides excellent positioning mechanism.
1414

15-
If you are using fixed mode with frozen columns, there will be a problem with the `Popper.js`. As the default `boundariesElement` for `preventOverflow` is `scrollParent`, but there would be three tables internal tables to mimic the frozen feature, and those tables are all scrollable, then the positioning could be not expected, you could change the `boundariesElement` to `viewport` or the `container` to fix that.
15+
If you are using fixed mode(fixed=true) with frozen columns, there will be a problem with the `Popper.js`. As the default `boundariesElement` for `preventOverflow` is `scrollParent`, but there would be three tables internal tables to implement the frozen feature, and those tables are all scrollable, then the positioning could be not expected, you could change the `boundariesElement` to `viewport` or the `container` to fix that.
1616

1717
## API Design
1818

@@ -26,7 +26,7 @@ _The following is really a rough one, will improve it later_
2626

2727
```jsx
2828
// import { Overlay } from 'react-overlays'
29-
const { Overlay } = ReactOverlays
29+
const { Overlay } = ReactOverlays;
3030

3131
const CellContainer = styled.div`
3232
display: flex;
@@ -37,7 +37,7 @@ const CellContainer = styled.div`
3737
margin: 0 -5px;
3838
padding: 5px;
3939
border: 1px dashed transparent;
40-
`
40+
`;
4141

4242
const GlobalStyle = createGlobalStyle`
4343
.BaseTable__row:hover,
@@ -46,60 +46,50 @@ const GlobalStyle = createGlobalStyle`
4646
border: 1px dashed #ccc;
4747
}
4848
}
49-
`
49+
`;
5050

5151
const Select = styled.select`
5252
width: 100%;
5353
height: 30px;
5454
margin-top: 10px;
55-
`
55+
`;
5656

5757
class EditableCell extends React.PureComponent {
5858
state = {
5959
value: this.props.cellData,
6060
editing: false,
61-
}
61+
};
6262

63-
setTargetRef = ref => (this.targetRef = ref)
63+
setTargetRef = ref => (this.targetRef = ref);
6464

65-
getTargetRef = () => this.targetRef
65+
getTargetRef = () => this.targetRef;
6666

67-
handleClick = () => this.setState({ editing: true })
67+
handleClick = () => this.setState({ editing: true });
6868

69-
handleHide = () => this.setState({ editing: false })
69+
handleHide = () => this.setState({ editing: false });
7070

7171
handleChange = e =>
7272
this.setState({
7373
value: e.target.value,
7474
editing: false,
75-
})
75+
});
7676

7777
render() {
78-
const { container, rowIndex, columnIndex } = this.props
79-
const { value, editing } = this.state
78+
const { container, rowIndex, columnIndex } = this.props;
79+
const { value, editing } = this.state;
8080

8181
return (
8282
<CellContainer ref={this.setTargetRef} onClick={this.handleClick}>
8383
{!editing && value}
8484
{editing && this.targetRef && (
85-
<Overlay
86-
show
87-
flip
88-
rootClose
89-
container={container}
90-
target={this.getTargetRef}
91-
onHide={this.handleHide}
92-
>
85+
<Overlay show flip rootClose container={container} target={this.getTargetRef} onHide={this.handleHide}>
9386
{({ props, placement }) => (
9487
<div
9588
{...props}
9689
style={{
9790
...props.style,
9891
width: this.targetRef.offsetWidth,
99-
top:
100-
placement === 'top'
101-
? this.targetRef.offsetHeight
102-
: -this.targetRef.offsetHeight,
92+
top: placement === 'top' ? this.targetRef.offsetHeight : -this.targetRef.offsetHeight,
10393
}}
10494
>
10595
<Select value={value} onChange={this.handleChange}>
@@ -113,22 +103,24 @@ class EditableCell extends React.PureComponent {
113103
</Overlay>
114104
)}
115105
</CellContainer>
116-
)
106+
);
117107
}
118108
}
119109

120-
const columns = generateColumns(5)
121-
const data = generateData(columns, 100)
110+
const columns = generateColumns(5);
111+
const data = generateData(columns, 100);
122112

123-
columns[0].cellRenderer = EditableCell
124-
columns[0].width = 300
113+
columns[0].cellRenderer = EditableCell;
114+
columns[0].width = 300;
125115

126116
export default () => (
127117
<>
128118
<GlobalStyle />
129119
<Table fixed columns={columns} data={data} />
130120
</>
131-
)
121+
);
132122
```
133123

124+
## Example
125+
134126
Check the live example [here](https://autodesk.github.io/react-base-table/examples/inline-editing).

docs/selection.md

Lines changed: 2 additions & 165 deletions
Original file line numberDiff line numberDiff line change
@@ -153,169 +153,6 @@ SelectableTable.defaultProps = {
153153
};
154154
```
155155

156-
## Playground
156+
## Example
157157

158-
```jsx live editorHeight=400
159-
const StyledTable = styled(BaseTable)`
160-
.row-selected {
161-
background-color: #e3e3e3;
162-
}
163-
`;
164-
165-
class SelectionCell extends React.PureComponent {
166-
_handleChange = e => {
167-
const { rowData, rowIndex, column } = this.props;
168-
const { onChange } = column;
169-
170-
onChange({ selected: e.target.checked, rowData, rowIndex });
171-
};
172-
173-
render() {
174-
const { rowData, column } = this.props;
175-
const { selectedRowKeys, rowKey } = column;
176-
const checked = selectedRowKeys.includes(rowData[rowKey]);
177-
178-
return <input type="checkbox" checked={checked} onChange={this._handleChange} />;
179-
}
180-
}
181-
182-
class SelectableTable extends React.PureComponent {
183-
constructor(props) {
184-
super(props);
185-
186-
const { selectedRowKeys, defaultSelectedRowKeys, expandedRowKeys, defaultExpandedRowKeys } = props;
187-
this.state = {
188-
selectedRowKeys: (selectedRowKeys !== undefined ? selectedRowKeys : defaultSelectedRowKeys) || [],
189-
expandedRowKeys: (expandedRowKeys !== undefined ? expandedRowKeys : defaultExpandedRowKeys) || [],
190-
};
191-
}
192-
193-
/**
194-
* Set `selectedRowKeys` manually.
195-
* This method is available only if `selectedRowKeys` is uncontrolled.
196-
*
197-
* @param {array} selectedRowKeys
198-
*/
199-
setSelectedRowKeys(selectedRowKeys) {
200-
// if `selectedRowKeys` is controlled
201-
if (this.props.selectedRowKeys !== undefined) return;
202-
203-
this.setState({
204-
selectedRowKeys: cloneArray(selectedRowKeys),
205-
});
206-
}
207-
208-
/**
209-
* See BaseTable#setExpandedRowKeys
210-
*/
211-
setExpandedRowKeys(expandedRowKeys) {
212-
// if `expandedRowKeys` is controlled
213-
if (this.props.expandedRowKeys !== undefined) return;
214-
215-
this.setState({
216-
expandedRowKeys: cloneArray(expandedRowKeys),
217-
});
218-
}
219-
220-
/* some other custom methods and proxy methods */
221-
222-
/**
223-
* Remove rowKeys from inner state manually, it's useful to purge dirty state after rows removed.
224-
* This method is available only if `selectedRowKeys` or `expandedRowKeys` is uncontrolled.
225-
*
226-
* @param {array} rowKeys
227-
*/
228-
removeRowKeysFromState(rowKeys) {
229-
if (!Array.isArray(rowKeys)) return;
230-
231-
const state = {};
232-
if (this.props.selectedRowKeys === undefined && this.state.selectedRowKeys.length > 0) {
233-
state.selectedRowKeys = this.state.selectedRowKeys.filter(key => !rowKeys.includes(key));
234-
}
235-
if (this.props.expandedRowKeys === undefined && this.state.expandedRowKeys.length > 0) {
236-
state.expandedRowKeys = this.state.expandedRowKeys.filter(key => !rowKeys.includes(key));
237-
}
238-
if (state.selectedRowKeys || state.expandedRowKeys) {
239-
this.setState(state);
240-
}
241-
}
242-
243-
_handleSelectChange = ({ selected, rowData, rowIndex }) => {
244-
const selectedRowKeys = [...this.state.selectedRowKeys];
245-
const key = rowData[this.props.rowKey];
246-
247-
if (selected) {
248-
if (!selectedRowKeys.includes(key)) selectedRowKeys.push(key);
249-
} else {
250-
const index = selectedRowKeys.indexOf(key);
251-
if (index > -1) {
252-
selectedRowKeys.splice(index, 1);
253-
}
254-
}
255-
256-
// if `selectedRowKeys` is uncontrolled, update internal state
257-
if (this.props.selectedRowKeys === undefined) {
258-
this.setState({ selectedRowKeys });
259-
}
260-
this.props.onRowSelect({ selected, rowData, rowIndex });
261-
this.props.onSelectedRowsChange(selectedRowKeys);
262-
};
263-
264-
_rowClassName = ({ rowData, rowIndex }) => {
265-
const { rowClassName, rowKey } = this.props;
266-
const { selectedRowKeys } = this.state;
267-
268-
const rowClass = rowClassName ? callOrReturn(rowClassName, { rowData, rowIndex }) : '';
269-
const key = rowData[rowKey];
270-
271-
return [rowClass, selectedRowKeys.includes(key) && 'row-selected'].filter(Boolean).concat(' ');
272-
};
273-
274-
render() {
275-
const { columns, children, selectable, selectionColumnProps, ...rest } = this.props;
276-
const { selectedRowKeys } = this.state;
277-
278-
// you'd better memoize this operation
279-
let _columns = columns || normalizeColumns(children);
280-
if (selectable) {
281-
const selectionColumn = {
282-
width: 40,
283-
flexShrink: 0,
284-
resizable: false,
285-
frozen: Column.FrozenDirection.LEFT,
286-
cellRenderer: SelectionCell,
287-
...selectionColumnProps,
288-
key: '__selection__',
289-
rowKey: this.props.rowKey,
290-
selectedRowKeys: selectedRowKeys,
291-
onChange: this._handleSelectChange,
292-
};
293-
_columns = [selectionColumn, ..._columns];
294-
}
295-
296-
return <StyledTable {...rest} columns={_columns} rowClassName={this._rowClassName} />;
297-
}
298-
}
299-
300-
SelectableTable.defaultProps = {
301-
...BaseTable.defaultProps,
302-
onRowSelect: noop,
303-
onSelectedRowsChange: noop,
304-
};
305-
306-
// Use case
307-
const columns = generateColumns(10);
308-
const data = generateData(columns, 200);
309-
310-
export default () => (
311-
<SelectableTable
312-
width={700}
313-
height={400}
314-
selectable
315-
columns={columns}
316-
data={data}
317-
onRowSelect={action('onRowSelect')}
318-
onSelectedRowsChange={action('onSelectedRowsChange')}
319-
/>
320-
);
321-
```
158+
Check the live example [here](https://autodesk.github.io/react-base-table/examples/selection).

website/src/components/Methods.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const Methods = ({ title = 'Methods', methods, ...rest }) => (
4242
<Anchor>{title}</Anchor>
4343
{Array.isArray(methods) &&
4444
methods.map((method, idx) => (
45-
<Method key={method.name}>
45+
<Method key={method.name} id={`methods-${method.name}`}>
4646
<Name>
4747
{method.name}
4848
<Tag>{getSignature(method.params)}</Tag>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import React from 'react'
2+
import styled from 'styled-components'
3+
import { Link } from 'gatsby'
4+
5+
const Container = styled.div`
6+
display: flex;
7+
align-items: center;
8+
justify-content: space-between;
9+
height: 50px;
10+
margin-top: 20px;
11+
border-top: 1px solid #edf0f2;
12+
`
13+
14+
const StyledLink = styled(Link)`
15+
display: block;
16+
text-decoration: none;
17+
white-space: nowrap;
18+
text-overflow: ellipsis;
19+
overflow: hidden;
20+
font-size: 16px;
21+
color: #888;
22+
23+
&:hover,
24+
&:active {
25+
color: #222;
26+
}
27+
`
28+
29+
const Pagination = ({ links, link, ...rest }) => {
30+
const index = links.indexOf(link)
31+
if (index < 0) return null
32+
const prevLink = index === 0 ? null : links[index - 1]
33+
const nextLink = index === links.length - 1 ? null : links[index + 1]
34+
35+
return (
36+
<Container {...rest}>
37+
<div>
38+
{prevLink && (
39+
<StyledLink to={prevLink.to}>{prevLink.title}</StyledLink>
40+
)}
41+
</div>
42+
<div>
43+
{nextLink && (
44+
<StyledLink to={nextLink.to}>{nextLink.title}</StyledLink>
45+
)}
46+
</div>
47+
</Container>
48+
)
49+
}
50+
51+
export default Pagination

0 commit comments

Comments
 (0)