Skip to content

Commit cd0b7b2

Browse files
authored
Merge pull request #8 from ryanhefner/release/0.2.2
Release v0.2.2
2 parents 0b60c49 + f022bef commit cd0b7b2

File tree

6 files changed

+50
-44
lines changed

6 files changed

+50
-44
lines changed

.babelrc

Lines changed: 0 additions & 13 deletions
This file was deleted.

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ In addition to these properties, all other standard React properites like `class
8282
`key`, etc. can be passed in as well and will be applied to the `<div>` that will
8383
be rendered by the `ScrollTrigger`.
8484

85+
* `component` - Node (Default: `div`)
86+
* `throttleResize` - Number (Default: `100`)
87+
* `throttleScroll` - Number (Default: `100`)
8588
* `triggerOnLoad` - Boolean (Default: `true`)
8689
* `onEnter` - Callback `({progress, velocity}, ref) => {}`
8790
* `onExit` - Callback `({progress, velocity}, ref) => {}`

package-lock.json

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

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
},
3434
"dependencies": {
3535
"clean-react-props": "^0.1.1",
36-
"lodash.omit": "^4.5.0",
3736
"lodash.throttle": "^4.1.1",
37+
"lomit": "^0.1.1",
3838
"prop-types": "^15.5.10"
3939
},
4040
"devDependencies": {
@@ -51,9 +51,9 @@
5151
"react": "^15.6.1",
5252
"rollup": "^0.45.2",
5353
"rollup-plugin-babel": "^2.7.1",
54-
"rollup-plugin-commonjs": "^8.0.2",
54+
"rollup-plugin-commonjs": "^8.3.0",
5555
"rollup-plugin-json": "^2.3.0",
56-
"rollup-plugin-node-resolve": "^3.0.0",
56+
"rollup-plugin-node-resolve": "^3.0.2",
5757
"rollup-plugin-uglify": "^2.0.1",
5858
"rollup-watch": "^4.3.1"
5959
},

src/index.js

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { Component } from 'react';
22
import PropTypes from 'prop-types';
33
import ReactDOM from 'react-dom';
4-
import omit from 'lodash.omit';
4+
import omit from 'lomit';
55
import throttle from 'lodash.throttle';
66
import cleanProps from 'clean-react-props';
77

@@ -10,11 +10,11 @@ class ScrollTrigger extends Component {
1010
constructor(props) {
1111
super(props);
1212

13-
this.onScroll = throttle(this.onScroll.bind(this), 100, {
13+
this.onScroll = throttle(this.onScroll.bind(this), props.throttleScroll, {
1414
trailing: false,
1515
});
1616

17-
this.onResize = throttle(this.onResize.bind(this), 100, {
17+
this.onResize = throttle(this.onResize.bind(this), props.throttleResize, {
1818
trailing: false,
1919
});
2020

@@ -35,6 +35,18 @@ class ScrollTrigger extends Component {
3535
}
3636
}
3737

38+
componentWillReceiveProps(nextProps) {
39+
if (nextProps.throttleScroll !== this.props.throttleScroll) {
40+
this.onScroll = throttle(this.onScroll.bind(this, nextProps.throttleScroll));
41+
addEventListener('scroll', this.onScroll);
42+
}
43+
44+
if (nextProps.throttleResize !== this.props.throttleResize) {
45+
this.onResize = throttle(this.onResize.bind(this, nextProps.throttleResize));
46+
addEventListener('resize', this.onResize);
47+
}
48+
}
49+
3850
componentWillUnmount() {
3951
removeEventListener('resize', this.onResize);
4052
removeEventListener('scroll', this.onScroll);
@@ -123,29 +135,34 @@ class ScrollTrigger extends Component {
123135
render() {
124136
const {
125137
children,
138+
component,
126139
} = this.props;
127140

128-
return (
129-
<div
130-
{...omit(cleanProps(this.props), ['onProgress'])}
131-
ref={(element) => {
141+
return React.createElement(component, {
142+
...omit(cleanProps(this.props), ['onProgress']),
143+
ref: (element) => {
132144
this.element = element;
133-
}}
134-
>
135-
{children}
136-
</div>
145+
},
146+
},
147+
children,
137148
);
138149
}
139150
}
140151

141152
ScrollTrigger.propTypes = {
153+
component: PropTypes.node,
154+
throttleResize: PropTypes.number,
155+
throttleScroll: PropTypes.number,
142156
triggerOnLoad: PropTypes.bool,
143157
onEnter: PropTypes.func,
144158
onExit: PropTypes.func,
145159
onProgress: PropTypes.func,
146160
};
147161

148162
ScrollTrigger.defaultProps = {
163+
component: 'div',
164+
throttleResize: 100,
165+
throttleScroll: 100,
149166
triggerOnLoad: true,
150167
onEnter: () => {},
151168
onExit: () => {},

tools/babel-preset.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const BABEL_ENV = process.env.BABEL_ENV;
22
const building = BABEL_ENV != undefined && BABEL_ENV !== 'cjs';
33

4-
const plugins = [];
4+
const plugins = ['transform-object-rest-spread'];
55

66
if (BABEL_ENV === 'umd') {
77
plugins.push('external-helpers');

0 commit comments

Comments
 (0)