react-scroll-into-view
Advanced tools
Comparing version 1.2.0 to 1.3.0
{ | ||
"name": "react-scroll-into-view", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "Simple React element that when clicked scrolls to any element on page", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -46,3 +46,3 @@ # React scroll-into-view | ||
## Changelog | ||
See [releases](/dominikbulaj/react-scroll-into-view/releases) tab | ||
See [releases](https://github.com/dominikbulaj/react-scroll-into-view/releases) tab | ||
@@ -49,0 +49,0 @@ ## TODO |
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import { compose, withHandlers } from 'recompose' | ||
import { compose, defaultProps, withHandlers } from 'recompose' | ||
const defaultStyle = { | ||
display:'inline', | ||
display: 'inline', | ||
} | ||
const ScrollInto = ({ children, scrollIntoView, style }) => ( | ||
<div style={{...defaultStyle, style}} onClick={scrollIntoView}> | ||
<div style={{ ...defaultStyle, style }} onClick={scrollIntoView}> | ||
{children} | ||
@@ -19,17 +19,25 @@ </div> | ||
style: PropTypes.object, | ||
alignToTop: PropTypes.bool, | ||
} | ||
ScrollInto.defaultProps = { | ||
smooth: true, | ||
style: {} | ||
} | ||
export default compose( | ||
defaultProps({ | ||
smooth: true, | ||
style: {}, | ||
alignToTop: false | ||
}), | ||
withHandlers({ | ||
scrollIntoView: ({ selector, smooth = true }) => e => { | ||
scrollIntoView: ({ selector, smooth, alignToTop }) => _ => { | ||
const behavior = smooth ? 'smooth' : 'instant' | ||
const options = { behavior } | ||
// scroll to top | ||
if (alignToTop) { | ||
options.block = 'start' | ||
options.inline = 'nearest' | ||
} | ||
const el = document.querySelector(selector) | ||
el.scrollIntoView({ behavior }) | ||
el.scrollIntoView(options) | ||
} | ||
}) | ||
)(ScrollInto) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
21765
3743
119
1