UNPKG

react-scroll-into-view

Version:

Simple React element that when clicked scrolls to any element on page

2 lines (1 loc) 16.5 kB
"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var React=require("react"),React__default=_interopDefault(React),commonjsGlobal="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function unwrapExports(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function createCommonjsModule(e,t){return e(t={exports:{}},t.exports),t.exports}function makeEmptyFunction(e){return function(){return e}}var emptyFunction=function(){};emptyFunction.thatReturns=makeEmptyFunction,emptyFunction.thatReturnsFalse=makeEmptyFunction(!1),emptyFunction.thatReturnsTrue=makeEmptyFunction(!0),emptyFunction.thatReturnsNull=makeEmptyFunction(null),emptyFunction.thatReturnsThis=function(){return this},emptyFunction.thatReturnsArgument=function(e){return e};var emptyFunction_1=emptyFunction,validateFormat=function(e){};function invariant(e,t,n,r,o,a,i,c){if(validateFormat(t),!e){var u;if(void 0===t)u=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var s=[n,r,o,a,i,c],p=0;(u=new Error(t.replace(/%s/g,function(){return s[p++]}))).name="Invariant Violation"}throw u.framesToPop=1,u}}"production"!==process.env.NODE_ENV&&(validateFormat=function(e){if(void 0===e)throw new Error("invariant requires an error message argument")});var invariant_1=invariant,warning=emptyFunction_1;if("production"!==process.env.NODE_ENV){var printWarning=function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];var o=0,a="Warning: "+e.replace(/%s/g,function(){return n[o++]});"undefined"!=typeof console&&console.error(a);try{throw new Error(a)}catch(e){}};warning=function(e,t){if(void 0===t)throw new Error("`warning(condition, format, ...args)` requires a warning message argument");if(0!==t.indexOf("Failed Composite propType: ")&&!e){for(var n=arguments.length,r=Array(n>2?n-2:0),o=2;o<n;o++)r[o-2]=arguments[o];printWarning.apply(void 0,[t].concat(r))}}}var warning_1=warning,getOwnPropertySymbols=Object.getOwnPropertySymbols,hasOwnProperty=Object.prototype.hasOwnProperty,propIsEnumerable=Object.prototype.propertyIsEnumerable;function toObject(e){if(null===e||void 0===e)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(e)}function shouldUseNative(){try{if(!Object.assign)return!1;var e=new String("abc");if(e[5]="de","5"===Object.getOwnPropertyNames(e)[0])return!1;for(var t={},n=0;n<10;n++)t["_"+String.fromCharCode(n)]=n;if("0123456789"!==Object.getOwnPropertyNames(t).map(function(e){return t[e]}).join(""))return!1;var r={};return"abcdefghijklmnopqrst".split("").forEach(function(e){r[e]=e}),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},r)).join("")}catch(e){return!1}}var objectAssign=shouldUseNative()?Object.assign:function(e,t){for(var n,r,o=toObject(e),a=1;a<arguments.length;a++){for(var i in n=Object(arguments[a]))hasOwnProperty.call(n,i)&&(o[i]=n[i]);if(getOwnPropertySymbols){r=getOwnPropertySymbols(n);for(var c=0;c<r.length;c++)propIsEnumerable.call(n,r[c])&&(o[r[c]]=n[r[c]])}}return o},ReactPropTypesSecret="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED",ReactPropTypesSecret_1=ReactPropTypesSecret;if("production"!==process.env.NODE_ENV)var invariant$1=invariant_1,warning$1=warning_1,ReactPropTypesSecret$1=ReactPropTypesSecret_1,loggedTypeFailures={};function checkPropTypes(e,t,n,r,o){if("production"!==process.env.NODE_ENV)for(var a in e)if(e.hasOwnProperty(a)){var i;try{invariant$1("function"==typeof e[a],"%s: %s type `%s` is invalid; it must be a function, usually from the `prop-types` package, but received `%s`.",r||"React class",n,a,typeof e[a]),i=e[a](t,a,r,n,null,ReactPropTypesSecret$1)}catch(e){i=e}if(warning$1(!i||i instanceof Error,"%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",r||"React class",n,a,typeof i),i instanceof Error&&!(i.message in loggedTypeFailures)){loggedTypeFailures[i.message]=!0;var c=o?o():"";warning$1(!1,"Failed %s type: %s%s",n,i.message,null!=c?c:"")}}}var checkPropTypes_1=checkPropTypes,factoryWithTypeCheckers=function(e,t){var n="function"==typeof Symbol&&Symbol.iterator,r="@@iterator";var o="<<anonymous>>",a={array:s("array"),bool:s("boolean"),func:s("function"),number:s("number"),object:s("object"),string:s("string"),symbol:s("symbol"),any:u(emptyFunction_1.thatReturnsNull),arrayOf:function(e){return u(function(t,n,r,o,a){if("function"!=typeof e)return new c("Property `"+a+"` of component `"+r+"` has invalid PropType notation inside arrayOf.");var i=t[n];if(!Array.isArray(i)){var u=l(i);return new c("Invalid "+o+" `"+a+"` of type `"+u+"` supplied to `"+r+"`, expected an array.")}for(var s=0;s<i.length;s++){var p=e(i,s,r,o,a+"["+s+"]",ReactPropTypesSecret_1);if(p instanceof Error)return p}return null})},element:function(){return u(function(t,n,r,o,a){var i=t[n];if(!e(i)){var u=l(i);return new c("Invalid "+o+" `"+a+"` of type `"+u+"` supplied to `"+r+"`, expected a single ReactElement.")}return null})}(),instanceOf:function(e){return u(function(t,n,r,a,i){if(!(t[n]instanceof e)){var u=e.name||o,s=function(e){if(!e.constructor||!e.constructor.name)return o;return e.constructor.name}(t[n]);return new c("Invalid "+a+" `"+i+"` of type `"+s+"` supplied to `"+r+"`, expected instance of `"+u+"`.")}return null})},node:function(){return u(function(e,t,n,r,o){if(!p(e[t]))return new c("Invalid "+r+" `"+o+"` supplied to `"+n+"`, expected a ReactNode.");return null})}(),objectOf:function(e){return u(function(t,n,r,o,a){if("function"!=typeof e)return new c("Property `"+a+"` of component `"+r+"` has invalid PropType notation inside objectOf.");var i=t[n],u=l(i);if("object"!==u)return new c("Invalid "+o+" `"+a+"` of type `"+u+"` supplied to `"+r+"`, expected an object.");for(var s in i)if(i.hasOwnProperty(s)){var p=e(i,s,r,o,a+"."+s,ReactPropTypesSecret_1);if(p instanceof Error)return p}return null})},oneOf:function(e){if(!Array.isArray(e))return"production"!==process.env.NODE_ENV&&warning_1(!1,"Invalid argument supplied to oneOf, expected an instance of array."),emptyFunction_1.thatReturnsNull;return u(function(t,n,r,o,a){for(var u=t[n],s=0;s<e.length;s++)if(i(u,e[s]))return null;var p=JSON.stringify(e);return new c("Invalid "+o+" `"+a+"` of value `"+u+"` supplied to `"+r+"`, expected one of "+p+".")})},oneOfType:function(e){if(!Array.isArray(e))return"production"!==process.env.NODE_ENV&&warning_1(!1,"Invalid argument supplied to oneOfType, expected an instance of array."),emptyFunction_1.thatReturnsNull;for(var t=0;t<e.length;t++){var n=e[t];if("function"!=typeof n)return warning_1(!1,"Invalid argument supplied to oneOfType. Expected an array of check functions, but received %s at index %s.",y(n),t),emptyFunction_1.thatReturnsNull}return u(function(t,n,r,o,a){for(var i=0;i<e.length;i++){var u=e[i];if(null==u(t,n,r,o,a,ReactPropTypesSecret_1))return null}return new c("Invalid "+o+" `"+a+"` supplied to `"+r+"`.")})},shape:function(e){return u(function(t,n,r,o,a){var i=t[n],u=l(i);if("object"!==u)return new c("Invalid "+o+" `"+a+"` of type `"+u+"` supplied to `"+r+"`, expected `object`.");for(var s in e){var p=e[s];if(p){var f=p(i,s,r,o,a+"."+s,ReactPropTypesSecret_1);if(f)return f}}return null})},exact:function(e){return u(function(t,n,r,o,a){var i=t[n],u=l(i);if("object"!==u)return new c("Invalid "+o+" `"+a+"` of type `"+u+"` supplied to `"+r+"`, expected `object`.");var s=objectAssign({},t[n],e);for(var p in s){var f=e[p];if(!f)return new c("Invalid "+o+" `"+a+"` key `"+p+"` supplied to `"+r+"`.\nBad object: "+JSON.stringify(t[n],null," ")+"\nValid keys: "+JSON.stringify(Object.keys(e),null," "));var y=f(i,p,r,o,a+"."+p,ReactPropTypesSecret_1);if(y)return y}return null})}};function i(e,t){return e===t?0!==e||1/e==1/t:e!=e&&t!=t}function c(e){this.message=e,this.stack=""}function u(e){if("production"!==process.env.NODE_ENV)var n={},r=0;function a(a,i,u,s,p,l,f){if(s=s||o,l=l||u,f!==ReactPropTypesSecret_1)if(t)invariant_1(!1,"Calling PropTypes validators directly is not supported by the `prop-types` package. Use `PropTypes.checkPropTypes()` to call them. Read more at http://fb.me/use-check-prop-types");else if("production"!==process.env.NODE_ENV&&"undefined"!=typeof console){var y=s+":"+u;!n[y]&&r<3&&(warning_1(!1,"You are manually calling a React.PropTypes validation function for the `%s` prop on `%s`. This is deprecated and will throw in the standalone `prop-types` package. You may be seeing this warning due to a third-party PropTypes library. See https://fb.me/react-warning-dont-call-proptypes for details.",l,s),n[y]=!0,r++)}return null==i[u]?a?null===i[u]?new c("The "+p+" `"+l+"` is marked as required in `"+s+"`, but its value is `null`."):new c("The "+p+" `"+l+"` is marked as required in `"+s+"`, but its value is `undefined`."):null:e(i,u,s,p,l)}var i=a.bind(null,!1);return i.isRequired=a.bind(null,!0),i}function s(e){return u(function(t,n,r,o,a,i){var u=t[n];return l(u)!==e?new c("Invalid "+o+" `"+a+"` of type `"+f(u)+"` supplied to `"+r+"`, expected `"+e+"`."):null})}function p(t){switch(typeof t){case"number":case"string":case"undefined":return!0;case"boolean":return!t;case"object":if(Array.isArray(t))return t.every(p);if(null===t||e(t))return!0;var o=function(e){var t=e&&(n&&e[n]||e[r]);if("function"==typeof t)return t}(t);if(!o)return!1;var a,i=o.call(t);if(o!==t.entries){for(;!(a=i.next()).done;)if(!p(a.value))return!1}else for(;!(a=i.next()).done;){var c=a.value;if(c&&!p(c[1]))return!1}return!0;default:return!1}}function l(e){var t=typeof e;return Array.isArray(e)?"array":e instanceof RegExp?"object":function(e,t){return"symbol"===e||"Symbol"===t["@@toStringTag"]||"function"==typeof Symbol&&t instanceof Symbol}(t,e)?"symbol":t}function f(e){if(void 0===e||null===e)return""+e;var t=l(e);if("object"===t){if(e instanceof Date)return"date";if(e instanceof RegExp)return"regexp"}return t}function y(e){var t=f(e);switch(t){case"array":case"object":return"an "+t;case"boolean":case"date":case"regexp":return"a "+t;default:return t}}return c.prototype=Error.prototype,a.checkPropTypes=checkPropTypes_1,a.PropTypes=a,a},factoryWithThrowingShims=function(){function e(e,t,n,r,o,a){a!==ReactPropTypesSecret_1&&invariant_1(!1,"Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types")}function t(){return e}e.isRequired=e;var n={array:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t};return n.checkPropTypes=emptyFunction_1,n.PropTypes=n,n},propTypes=createCommonjsModule(function(e){if("production"!==process.env.NODE_ENV){var t="function"==typeof Symbol&&Symbol.for&&Symbol.for("react.element")||60103;e.exports=factoryWithTypeCheckers(function(e){return"object"==typeof e&&null!==e&&e.$$typeof===t},!0)}else e.exports=factoryWithThrowingShims()}),hoistNonReactStatics=createCommonjsModule(function(e,t){var n,r,o,a,i,c,u,s;e.exports=(n={childContextTypes:!0,contextTypes:!0,defaultProps:!0,displayName:!0,getDefaultProps:!0,getDerivedStateFromProps:!0,mixins:!0,propTypes:!0,type:!0},r={name:!0,length:!0,prototype:!0,caller:!0,callee:!0,arguments:!0,arity:!0},o=Object.defineProperty,a=Object.getOwnPropertyNames,i=Object.getOwnPropertySymbols,c=Object.getOwnPropertyDescriptor,u=Object.getPrototypeOf,s=u&&u(Object),function e(t,p,l){if("string"!=typeof p){if(s){var f=u(p);f&&f!==s&&e(t,f,l)}var y=a(p);i&&(y=y.concat(i(p)));for(var d=0;d<y.length;++d){var v=y[d];if(!(n[v]||r[v]||l&&l[v])){var h=c(p,v);try{o(t,v,h)}catch(e){}}}return t}return t})}),lib=createCommonjsModule(function(e,t){Object.defineProperty(t,"__esModule",{value:!0});t.createChangeEmitter=function(){var e=[],t=e;function n(){t===e&&(t=e.slice())}return{listen:function(e){if("function"!=typeof e)throw new Error("Expected listener to be a function.");var r=!0;return n(),t.push(e),function(){if(r){r=!1,n();var o=t.indexOf(e);t.splice(o,1)}}},emit:function(){for(var n=e=t,r=0;r<n.length;r++)n[r].apply(n,arguments)}}}});unwrapExports(lib);var root,lib_1=lib.createChangeEmitter;function symbolObservablePonyfill(e){var t,n=e.Symbol;return"function"==typeof n?n.observable?t=n.observable:(t=n("observable"),n.observable=t):t="@@observable",t}var result=symbolObservablePonyfill(root="undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof module?module:Function("return this")()),setStatic=function(e,t){return function(n){return n[e]=t,n}},setDisplayName=function(e){return setStatic("displayName",e)},getDisplayName=function(e){return"string"==typeof e?e:e?e.displayName||e.name||"Component":void 0},wrapDisplayName=function(e,t){return t+"("+getDisplayName(e)+")"},classCallCheck=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},_extends=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},inherits=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)},possibleConstructorReturn=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t},mapValues=function(e,t){var n={};for(var r in e)e.hasOwnProperty(r)&&(n[r]=t(e[r],r));return n},withHandlers=function(e){return function(t){var n=React.createFactory(t),r=function(e){function t(){var n,r;classCallCheck(this,t);for(var a=arguments.length,i=Array(a),c=0;c<a;c++)i[c]=arguments[c];return n=r=possibleConstructorReturn(this,e.call.apply(e,[this].concat(i))),o.call(r),possibleConstructorReturn(r,n)}return inherits(t,e),t.prototype.componentWillReceiveProps=function(){this.cachedHandlers={}},t.prototype.render=function(){return n(_extends({},this.props,this.handlers))},t}(React.Component),o=function(){var t=this;this.cachedHandlers={},this.handlers=mapValues("function"==typeof e?e(this.props):e,function(e,n){return function(){var r=t.cachedHandlers[n];if(r)return r.apply(void 0,arguments);var o=e(t.props);return t.cachedHandlers[n]=o,"production"!==process.env.NODE_ENV&&"function"!=typeof o&&console.error("withHandlers(): Expected a map of higher-order functions. Refer to the docs for more info."),o.apply(void 0,arguments)}})};return"production"!==process.env.NODE_ENV?setDisplayName(wrapDisplayName(t,"withHandlers"))(r):r}},defaultProps=function(e){return function(t){var n=React.createFactory(t),r=function(e){return n(e)};return r.defaultProps=e,"production"!==process.env.NODE_ENV?setDisplayName(wrapDisplayName(t,"defaultProps"))(r):r}},Nothing=function(e){function t(){return classCallCheck(this,t),possibleConstructorReturn(this,e.apply(this,arguments))}return inherits(t,e),t.prototype.render=function(){return null},t}(React.Component);function compose(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];return 0===t.length?function(e){return e}:1===t.length?t[0]:t.reduce(function(e,t){return function(){return e(t.apply(void 0,arguments))}})}var _extends$1=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},defaultStyle={display:"inline"},ScrollInto=function(e){var t=e.children,n=e.scrollIntoView,r=e.style;return React__default.createElement("div",{style:_extends$1({},defaultStyle,r),onClick:n},t)};ScrollInto.propTypes={selector:propTypes.string.isRequired,smooth:propTypes.bool,style:propTypes.object,alignToTop:propTypes.bool};var index$1=compose(defaultProps({smooth:!0,style:{},alignToTop:!1}),withHandlers({scrollIntoView:function(e){var t=e.selector,n=e.smooth,r=e.alignToTop;return function(e){var o={behavior:n?"smooth":"instant"};r&&(o.block="start",o.inline="nearest"),document.querySelector(t).scrollIntoView(o)}}}))(ScrollInto);module.exports=index$1;