npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

reactjs-infinite-scroll-loop

v1.0.2

Published

React component that supports infinite scrolling of finite number of elements.

Downloads

125

Readme

react-infinite-scroll-loop

demo3

Usage

<InfiniteScrollLoop {/* props here */}>
    <ContentWrapper {/* props here */}>
        {/* Content element 1 */}
    </ContentWrapper>
    <ContentWrapper {/* props here */}>
        {/* Content element 2 */}
    </ContentWrapper>
    ...
</InfiniteScrollLoop>

Animation

Custom animation when a content element is selected can be implemented by adding the custom pseudo class <className>__selected. The animation transition duration can be added to the target <className>.

Example

demo2

The following code snippets reproduce the above gif:

React JS:

const Example = () => {
    return (
        <div style={{ height:"150px", width:"200px" }}>
            <InfiniteScrollLoop>
                {
                    Array(6).fill(0).map((v, i) => {
                        return <Content key={i} id={`${i+1}`} number={i+1}/>
                    })
                }
            </InfiniteScrollLoop>
        </div>
    );
};

interface ContentProps {
    id: string;
    number: number;
}

const Content = ({ id, number }: ContentProps) => {
    return (
        <ContentWrapper height="30%" width="100%">
            <div id={id} className="container" >
                <h4 className="number">{number}</h4>
            </div>
        </ContentWrapper>
    );
};

CSS:

.container {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.number {
    margin: 0;
    opacity: 0.2;
    font-size: 18px;
    transition: 0.2s;
}

.number__selected {
    opacity: 1;
    font-size: 25px;
}

Docs

InfiniteScrollLoop Props

| Name | Type | Default | Description | |----------------|-----------------------------|-----------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | children | React.ReactNode | None (required) | The content of the scroll container.[^1] | | onSelect | (selected: Element) => void | undefined | Executes a given JavaScript code on the selected element. | | verticalScroll | boolean | true | The direction of scroll. true for vertical and false for horizontal.[^2] | | backup | number | 50 | The number of backup content sets on the top and bottom. Increasing this number will increase the amount of scroll required to the end of the scroll container, but decreases performance as more content needs to be rendered. |

ContentWrapper Props

| Name | Type | Default | Description | |--------|---------------------------------------|---------|-------------------------------------| | height | string (accept any CSS height values) | ‘auto’ | The height of each content element. | | width | string (accept any CSS width values) | ‘auto’ | The width of each content element. |

[^1]: Each content element must be contained in a ContentWrapper, or a custom parent wrapper class that consists of the scroll-snap-align property. [^2]: If scrollDirection is vertical, the height of scroll container must be larger than the height of each content element. If scrollDirection is horizontal, the width of scroll container must be larger than the width of each content element.