11import React from 'react' ;
22import PropTypes from 'prop-types' ;
3- import { animateScroll } from './utils' ;
3+ import { animateScroll , updateHistory } from './utils' ;
44
55export default class Scrollchor extends React . Component {
6- constructor ( props ) {
6+ constructor ( props ) {
77 super ( props ) ;
88 this . _setup ( props ) ;
99 this . simulateClick = this . _handleClick ;
@@ -17,8 +17,9 @@ export default class Scrollchor extends React.Component {
1717 easing : PropTypes . func
1818 } ) ,
1919 beforeAnimate : PropTypes . func ,
20- afterAnimate : PropTypes . func
21- } ;
20+ afterAnimate : PropTypes . func ,
21+ disableHistory : PropTypes . bool
22+ }
2223
2324 _setup = props => {
2425 this . _to = ( props . to && props . to . replace ( / ^ # / , '' ) ) || '' ;
@@ -30,23 +31,25 @@ export default class Scrollchor extends React.Component {
3031 } =
3132 props . animate || { } ;
3233 this . _animate = { offset, duration, easing } ;
33- this . _beforeAnimate = props . beforeAnimate || function ( ) { } ;
34- this . _afterAnimate = props . afterAnimate || function ( ) { } ;
35- } ;
34+ this . _beforeAnimate = props . beforeAnimate || function ( ) { } ;
35+ this . _afterAnimate = props . afterAnimate || function ( ) { } ;
36+ this . _disableHistory = props . disableHistory ;
37+ }
3638
3739 _handleClick = event => {
3840 this . _beforeAnimate ( event ) ;
3941 event && event . preventDefault ( ) ;
40- animateScroll ( this . _to , this . _animate ) ;
42+ const id = animateScroll ( this . _to , this . _animate ) ;
43+ this . _disableHistory || updateHistory ( id ) ;
4144 this . _afterAnimate ( event ) ;
42- } ;
45+ }
4346
44- componentWillReceiveProps ( props ) {
47+ componentWillReceiveProps ( props ) {
4548 this . _setup ( props ) ;
4649 }
4750
48- render ( ) {
49- const { to, animate, beforeAnimate, afterAnimate, ...props } = this . props ; // eslint-disable-line no-unused-vars
51+ render ( ) {
52+ const { to, animate, beforeAnimate, afterAnimate, disableHistory , ...props } = this . props ; // eslint-disable-line no-unused-vars
5053
5154 return ! this . props . children
5255 ? null
@@ -56,6 +59,6 @@ export default class Scrollchor extends React.Component {
5659
5760// Default easing function
5861// jQuery easing 'swing'
59- function easeOutQuad ( x , t , b , c , d ) {
62+ function easeOutQuad ( x , t , b , c , d ) {
6063 return - c * ( t /= d ) * ( t - 2 ) + b ;
6164}
0 commit comments