GithubHelp home page GithubHelp logo

andrewthehan / peripheral-view Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 1.3 MB

React component for rendering a sliding window view of elements.

Home Page: https://andrewthehan.github.io/peripheral-view/

License: MIT License

JavaScript 90.60% HTML 9.05% CSS 0.36%

peripheral-view's Introduction

peripheral-view npm

React component for rendering a sliding window view of elements.

Live demo

Installation

npm install peripheral-view --save

Usage

import PeripheralView from "peripheral-view";

<PeripheralView
  ref={r => (this.view = r)}
  length={1000}
  radius={100}
  renderMap={i => <div key={i}>{i}</div>}
  handleChange={i => console.log(i)}
/>;

this.view.scrollTo(250);

Props

length

type: number

The maximum number of elements. To create a view with an infinite number of elements, use Infinity.

radius

type: number

The number of elements to render adjacent to both sides of the current element. This value must be large enough such that when the current view is rendered, there exists elements rendered outside of the scrolling viewport.

renderMap

type: number => React element

A mapping function from element index to React element. The React element returned must have the key prop and its value must be a nonnegative value (usually the value will be the parameter of renderMap). The value must be nonnegative because PeripheralView internally has components with negative keys.

handleChange

type: number => void

A callback that is called when the index used as the "center" is changed.

Methods

scrollTo

type: number => void

Make the input index the current element. This brings the corresponding element to view by changing the scroll location of the nearest scrollable ancestor.

peripheral-view's People

Contributors

andrewthehan avatar dependabot[bot] avatar

Stargazers

Jonathan avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.