Skip to content

Commit

Permalink
Update readme and tag
Browse files Browse the repository at this point in the history
  • Loading branch information
fkhadra committed Oct 30, 2018
1 parent e06fd2d commit 8212433
Show file tree
Hide file tree
Showing 7 changed files with 240 additions and 188 deletions.
79 changes: 30 additions & 49 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@

![react-on-screen-demo](https://user-images.githubusercontent.com/5574267/32147681-74918d80-bceb-11e7-98d4-1cbc04b29eb4.gif)

* [Demo](#demo)
* [Installation](#installation)
* [Usage](#usage)
+ [Simple](#simple)
+ [Using a render props](#using-a-render-props)
+ [Track the visibility only once](#track-the-visibility-only-once)
+ [Defining offset](#defining-offset)
+ [Partial visibility](#partial-visibility)
* [Api](#api)
* [Contributions](#contributions)
* [Release Notes](#release-notes)
* [License](#license)
- [React on screen ![npm]() ![npm]() ![license]() ![Coverage Status](https://coveralls.io/github/fkhadra/react-on-screen?branch=master)](#react-on-screen-npm-npm-license-coverage-statushttpscoverallsiogithubfkhadrareact-on-screenbranchmaster)
- [Demo](#demo)
- [Installation](#installation)
- [Usage](#usage)
- [Simple](#simple)
- [Using a render props](#using-a-render-props)
- [Track the visibility only once](#track-the-visibility-only-once)
- [Defining offset](#defining-offset)
- [Partial visibility](#partial-visibility)
- [Use the html tag of your choice](#use-the-html-tag-of-your-choice)
- [Api](#api)
- [Contributions](#contributions)
- [License](#license)

## Demo

Expand Down Expand Up @@ -116,6 +117,18 @@ const YourApp = () => {
}
```

### Use the html tag of your choice

```js
const YourApp = () => {
return (
<TrackVisibility partialVisibility tag="h1">
{({ isVisible }) => <ComponentToTrack />}
</TrackVisibility>
);
}
```

## Api

|props |type |default|description|
Expand All @@ -127,48 +140,16 @@ const YourApp = () => {
|className |string | - |Css classes|
|offset |number | 0 |Allows you to specify how far left or above of the viewport you want to set isVisible to `true`|
|partialVisibility|bool |false|Set isVisible to true on element as soon as any part is in the viewport|
|tag |React Components|div |Allows specifying custom wrapper|
|tag |string|div |Allows specifying html tag of your choice|

## Contributions

Any contributions is welcome !

- Lint : ``` $ npm run lint ```
- Test : ``` $ npm run test ```
- Build : ``` $ npm run build // will lint and run test before ```

## Release Notes

### v2.0.4

- Recalculate on props change.

### v2.0.2

- Add check for component bottom up to stop whole page being visible
- Push componentDidMount `isComponentVisible` call into next tick

### v2.0.1

- Fix issue #9. The component was not updated on prop changes

### v2.0.0

- Added support for partial visibility. Thanks to [audiolion](https://github.com/audiolion)
- Internal rewrite
- CI intregration
- Better Test suite
- Typescript definition !

### v1.1.4

- React and react-dom are now peer dependencies

### v1.1.1

- switched to webpack2
- Upgraded to stand alone prop-types

- Develop: ``` $ yarn start ```
- Lint : ``` $ yarn lint ```
- Test : ``` $ yarn test ```
- Build : ``` $ yarn build // will lint and run test before ```

## License

Expand Down
2 changes: 1 addition & 1 deletion dist/ReactOnScreen.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/ReactOnScreen.js.map

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ interface TrackVisibilityProps {
* Update the visibility state as soon as a part of the tracked component is visible
*/
partialVisibility?: boolean;

/**
* Define a custom html tag
*/
tag?: string;
}

export default class TrackVisibility extends React.Component<TrackVisibilityProps> {}
19 changes: 11 additions & 8 deletions src/TrackVisibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default class TrackVisibility extends PureComponent {
}
return null;
},

/**
* Pass one or more children to track
*/
Expand All @@ -32,6 +33,7 @@ export default class TrackVisibility extends PureComponent {
PropTypes.element,
PropTypes.arrayOf(PropTypes.element)
]),

/**
* Additional style to apply
*/
Expand All @@ -57,10 +59,11 @@ export default class TrackVisibility extends PureComponent {
* for visibility
*/
nodeRef: PropTypes.object,

/**
* Define a custom tag
*/
tag: PropTypes.oneOfType([PropTypes.func, PropTypes.string])
tag: PropTypes.string
};

static defaultProps = {
Expand Down Expand Up @@ -143,13 +146,13 @@ export default class TrackVisibility extends PureComponent {

return partialVisibility
? top + height >= topThreshold &&
left + width >= leftThreshold &&
bottom - height <= heightCheck &&
right - width <= widthCheck
left + width >= leftThreshold &&
bottom - height <= heightCheck &&
right - width <= widthCheck
: top >= topThreshold &&
left >= leftThreshold &&
bottom <= heightCheck &&
right <= widthCheck;
left >= leftThreshold &&
bottom <= heightCheck &&
right <= widthCheck;
};

isComponentVisible = () => {
Expand All @@ -174,7 +177,7 @@ export default class TrackVisibility extends PureComponent {
}

this.setState({ isVisible });
}, 0)
}, 0);
};

setNodeRef = ref => (this.nodeRef = ref);
Expand Down
10 changes: 8 additions & 2 deletions src/__playground__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@ import { render } from 'react-dom';
import TrackVisibility from '../index';
import './index.css';


const Settings = ({ once, partialVisibility, offset, throttleInterval, handleCheckbox, handleInput }) => (
const Settings = ({
once,
partialVisibility,
offset,
throttleInterval,
handleCheckbox,
handleInput
}) => (
<ul className="settings">
<li>
<label htmlFor="once">Once</label>
Expand Down
Loading

0 comments on commit 8212433

Please sign in to comment.