Skip to content

Commit 05afaf5

Browse files
committed
Add interval mode
1 parent 7393d09 commit 05afaf5

File tree

4 files changed

+51
-12
lines changed

4 files changed

+51
-12
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ export default props =>
4141

4242
| Name | Type | Description |
4343
| - | - | - |
44-
| `atBottom` | Boolean | `true` if the panel is currently near bottom (see `threshold`) |
45-
| `atEnd` | Boolean | `true` if the panel is currently near the end (see `mode` and `threshold` |
46-
| `atTop` | Boolean | `true` if the panel is currently near top (see `threshold`) |
47-
| `mode` | String | `"bottom"` for scroll-to-bottom, `"top"` for scroll-to-top |
48-
| `scrollToBottom` | Function | Call to scroll panel to bottom |
49-
| `scrollToEnd` | Function | Call to scroll panel to end |
50-
| `scrollToTop` | Function | Call to scroll panel to top |
51-
| `threshold` | Number | Threshold in pixels to consider the panel is near top/bottom, read-only and only set thru `props` |
44+
| `atBottom` | `boolean` | `true` if the panel is currently near bottom (see `threshold`) |
45+
| `atEnd` | `boolean` | `true` if the panel is currently near the end (see `mode` and `threshold` |
46+
| `atTop` | `boolean` | `true` if the panel is currently near top (see `threshold`) |
47+
| `mode` | `string` | `"bottom"` for scroll-to-bottom, `"top"` for scroll-to-top |
48+
| `scrollToBottom` | `function` | Call to scroll panel to bottom |
49+
| `scrollToEnd` | `function` | Call to scroll panel to end |
50+
| `scrollToTop` | `function` | Call to scroll panel to top |
51+
| `threshold` | `number` | Threshold in pixels to consider the panel is near top/bottom, read-only and only set thru `props` |
5252

5353
# Contributions
5454

package-lock.json

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/playground/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44
"homepage": "/react-scroll-to-bottom",
55
"private": true,
66
"dependencies": {
7+
"classnames": "^2.2.6",
78
"component": "^1.0.0",
9+
"glamor": "^2.20.40",
810
"lorem-ipsum": "^1.0.4",
911
"react": "^16.4.1",
1012
"react-dom": "^16.4.1",
13+
"react-interval": "^2.0.2",
1114
"react-scripts": "1.1.4"
1215
},
1316
"scripts": {

packages/playground/src/App.js

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import React, { Component } from 'react';
2-
31
import { css } from 'glamor';
2+
import Interval from 'react-interval';
43
import loremIpsum from 'lorem-ipsum';
4+
import React from 'react';
55
import ScrollToBottom from 'component';
66

77
const FADE_IN_ANIMATION = css.keyframes({
@@ -51,15 +51,18 @@ const SCROLL_VIEW_PADDING_CSS = css({
5151
}
5252
});
5353

54-
class App extends Component {
54+
class App extends React.Component {
5555
constructor(props) {
5656
super(props);
5757

5858
this.handleAdd1 = this.handleAdd.bind(this, 1);
5959
this.handleAdd10 = this.handleAdd.bind(this, 10);
6060
this.handleClear = this.handleClear.bind(this);
61+
this.handleIntervalCallback = this.handleIntervalCallback.bind(this);
62+
this.handleIntervalEnabledChange = this.handleIntervalEnabledChange.bind(this);
6163

6264
this.state = {
65+
intervalEnabled: false,
6366
paragraphs: []
6467
};
6568
}
@@ -78,7 +81,15 @@ class App extends Component {
7881
}
7982

8083
handleClear() {
81-
this.setState(state => ({ paragraphs: [] }));
84+
this.setState(() => ({ paragraphs: [] }));
85+
}
86+
87+
handleIntervalCallback() {
88+
this.handleAdd(1);
89+
}
90+
91+
handleIntervalEnabledChange({ target: { checked: intervalEnabled } }) {
92+
this.setState(() => ({ intervalEnabled }));
8293
}
8394

8495
render() {
@@ -94,6 +105,16 @@ class App extends Component {
94105
<li>
95106
<button onClick={ this.handleClear }>Clear</button>
96107
</li>
108+
<li>
109+
<label>
110+
<input
111+
checked={ this.state.intervalEnabled }
112+
onChange={ this.handleIntervalEnabledChange }
113+
type="checkbox"
114+
/>
115+
Add one every second
116+
</label>
117+
</li>
97118
</ul>
98119
<div className="panes">
99120
<ScrollToBottom className={ SCROLL_VIEW_CSS + '' }>
@@ -107,6 +128,13 @@ class App extends Component {
107128
</div>
108129
</ScrollToBottom>
109130
</div>
131+
{ this.state.intervalEnabled &&
132+
<Interval
133+
callback={ this.handleIntervalCallback }
134+
enabled={ true }
135+
timeout={ 1000 }
136+
/>
137+
}
110138
</div>
111139
);
112140
}

0 commit comments

Comments
 (0)