-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b8e02e9
commit 5b937a1
Showing
4 changed files
with
70 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,27 @@ | ||
import resolve from 'rollup-plugin-node-resolve' | ||
import babel from 'rollup-plugin-babel' | ||
import commonjs from 'rollup-plugin-commonjs' | ||
import uglify from 'rollup-plugin-uglify' | ||
import resolve from "rollup-plugin-node-resolve"; | ||
import babel from "rollup-plugin-babel"; | ||
import commonjs from "rollup-plugin-commonjs"; | ||
import uglify from "rollup-plugin-uglify"; | ||
|
||
export default { | ||
input: 'src/index.js', | ||
input: "src/index.js", | ||
output: { | ||
file: 'dist/index.js', | ||
format: 'cjs' | ||
file: "dist/index.js", | ||
format: "cjs" | ||
}, | ||
plugins: [ | ||
commonjs({ | ||
include: 'node_modules/**' | ||
include: "node_modules/**" | ||
}), | ||
resolve(), | ||
babel({ | ||
babelrc: false, | ||
presets: ['es2015-rollup'], | ||
exclude: 'node_modules/**', | ||
plugins: ['transform-react-jsx', 'transform-object-rest-spread'], | ||
presets: ["es2015-rollup"], | ||
exclude: "node_modules/**", | ||
plugins: ["transform-react-jsx", "transform-object-rest-spread"] | ||
}), | ||
|
||
uglify() | ||
], | ||
external: ['react'] | ||
} | ||
external: ["react"] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,40 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import { compose, defaultProps, withHandlers } from 'recompose' | ||
import React from "react"; | ||
import PropTypes from "prop-types"; | ||
import { compose, defaultProps, withHandlers } from "recompose"; | ||
|
||
const ScrollInto = ({children, scrollIntoView, style, className}) => ( | ||
const ScrollInto = ({ children, scrollIntoView, style, className }) => ( | ||
<div style={style} className={className} onClick={scrollIntoView}> | ||
{children} | ||
</div> | ||
) | ||
); | ||
|
||
ScrollInto.propTypes = { | ||
selector: PropTypes.string.isRequired, | ||
smooth: PropTypes.bool, | ||
style: PropTypes.object, | ||
alignToTop: PropTypes.bool, | ||
className: PropTypes.string, | ||
} | ||
className: PropTypes.string | ||
}; | ||
|
||
export default compose( | ||
defaultProps({ | ||
smooth: true, | ||
style: {}, | ||
alignToTop: false, | ||
className: '' | ||
className: "" | ||
}), | ||
withHandlers({ | ||
scrollIntoView: ({selector, smooth, alignToTop}) => _ => { | ||
const behavior = smooth ? 'smooth' : 'instant' | ||
const options = {behavior} | ||
scrollIntoView: ({ selector, smooth, alignToTop }) => _ => { | ||
const behavior = smooth ? "smooth" : "instant"; | ||
const options = { behavior }; | ||
// scroll to top | ||
if (alignToTop) { | ||
options.block = 'start' | ||
options.inline = 'nearest' | ||
options.block = "start"; | ||
options.inline = "nearest"; | ||
} | ||
|
||
const el = document.querySelector(selector) | ||
el.scrollIntoView(options) | ||
const el = document.querySelector(selector); | ||
el.scrollIntoView(options); | ||
} | ||
}) | ||
)(ScrollInto) | ||
)(ScrollInto); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,51 @@ | ||
import React from 'react' | ||
import ScrollInto from './index' | ||
import renderer from 'react-test-renderer' | ||
import React from "react"; | ||
import ScrollInto from "./index"; | ||
import renderer from "react-test-renderer"; | ||
|
||
test('ScrollInto renders with children', () => { | ||
test("ScrollInto renders with children", () => { | ||
const component = renderer.create( | ||
<ScrollInto selector="test"> | ||
<div> | ||
Some child content | ||
</div> | ||
</ScrollInto>, | ||
) | ||
<div>Some child content</div> | ||
</ScrollInto> | ||
); | ||
|
||
let tree = component.toJSON() | ||
expect(tree).toMatchSnapshot() | ||
}) | ||
let tree = component.toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
|
||
test('ScrollInto renders with custom className', () => { | ||
test("ScrollInto renders with custom className", () => { | ||
const component = renderer.create( | ||
<ScrollInto selector="test" className="custom-class"> | ||
<div> | ||
Some child content | ||
</div> | ||
</ScrollInto>, | ||
) | ||
<div>Some child content</div> | ||
</ScrollInto> | ||
); | ||
|
||
let tree = component.toJSON() | ||
expect(tree).toMatchSnapshot() | ||
}) | ||
let tree = component.toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
|
||
test('ScrollInto renders with custom styles', () => { | ||
test("ScrollInto renders with custom styles", () => { | ||
const component = renderer.create( | ||
<ScrollInto selector="test" style={{display: 'inline'}}> | ||
<div> | ||
Some child content | ||
</div> | ||
</ScrollInto>, | ||
) | ||
|
||
let tree = component.toJSON() | ||
expect(tree).toMatchSnapshot() | ||
}) | ||
|
||
test('ScrollInto renders with custom styles and className', () => { | ||
<ScrollInto selector="test" style={{ display: "inline" }}> | ||
<div>Some child content</div> | ||
</ScrollInto> | ||
); | ||
|
||
let tree = component.toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
|
||
test("ScrollInto renders with custom styles and className", () => { | ||
const component = renderer.create( | ||
<ScrollInto selector="test" style={{display: 'inline', color: 'red'}} className="pinky"> | ||
<div> | ||
Some child content | ||
</div> | ||
</ScrollInto>, | ||
) | ||
|
||
let tree = component.toJSON() | ||
expect(tree).toMatchSnapshot() | ||
}) | ||
<ScrollInto | ||
selector="test" | ||
style={{ display: "inline", color: "red" }} | ||
className="pinky" | ||
> | ||
<div>Some child content</div> | ||
</ScrollInto> | ||
); | ||
|
||
let tree = component.toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
}); |