react-router-hash-link
Version:
Hash link scroll functionality for React Router v4/5
3 lines (2 loc) • 2.46 kB
JavaScript
Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react"),e=require("react-router-dom");function n(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var r=n(t),o=function(){return(o=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};var l="",i=null,u=null,a=null;function c(){l="",null!==i&&i.disconnect(),null!==u&&(window.clearTimeout(u),u=null)}function s(t){return["BUTTON","INPUT","SELECT","TEXTAREA"].includes(t.tagName)&&!t.hasAttribute("disabled")||["A","AREA"].includes(t.tagName)&&t.hasAttribute("href")}function f(){var t=null;if("#"===l)t=document.body;else{var e=l.replace("#","");null===(t=document.getElementById(e))&&"#top"===l&&(t=document.body)}if(null!==t){a(t);var n=t.getAttribute("tabindex");return null!==n||s(t)||t.setAttribute("tabindex",-1),t.focus({preventScroll:!0}),null!==n||s(t)||(t.blur(),t.removeAttribute("tabindex")),c(),!0}return!1}function d(t){return r.default.forwardRef((function(n,s){var d="";"string"==typeof n.to&&n.to.includes("#")?d="#"+n.to.split("#").slice(1).join("#"):"object"==typeof n.to&&"string"==typeof n.to.hash&&(d=n.to.hash);var b={};t===e.NavLink&&(b.isActive=function(t,e){return t&&t.isExact&&e.hash===d});var p=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n}(n,["scroll","smooth","timeout","elementId"]);return r.default.createElement(t,o({},b,p,{onClick:function(t){var e;c(),l=n.elementId?"#"+n.elementId:d,n.onClick&&n.onClick(t),""===l||t.defaultPrevented||0!==t.button||n.target&&"_self"!==n.target||t.metaKey||t.altKey||t.ctrlKey||t.shiftKey||(a=n.scroll||function(t){return n.smooth?t.scrollIntoView({behavior:"smooth"}):t.scrollIntoView()},e=n.timeout,window.setTimeout((function(){!1===f()&&(null===i&&(i=new MutationObserver(f)),i.observe(document,{attributes:!0,childList:!0,subtree:!0}),u=window.setTimeout((function(){c()}),e||1e4))}),0))},ref:s}),n.children)}))}var b=d(e.Link),p=d(e.NavLink);exports.HashLink=b,exports.NavHashLink=p,exports.genericHashLink=d;
//# sourceMappingURL=react-router-hash-link.cjs.production.js.map
;