Skip to content

Commit

Permalink
Reformatted code with Prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikbulaj committed Oct 5, 2018
1 parent b8e02e9 commit 5b937a1
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 73 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# React scroll-into-view
[![Build Status](https://travis-ci.org/dominikbulaj/react-scroll-into-view.svg?branch=master)](https://travis-ci.org/dominikbulaj/react-scroll-into-view)
[![npm](https://img.shields.io/npm/v/react-scroll-into-view.svg)](https://www.npmjs.com/package/react-scroll-into-view)
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)

Declarative way for scrolling into view any page element

Expand Down
26 changes: 13 additions & 13 deletions rollup.config.js
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"]
};
32 changes: 16 additions & 16 deletions src/index.js
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);
84 changes: 40 additions & 44 deletions src/index.test.js
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();
});

0 comments on commit 5b937a1

Please sign in to comment.