Socket
Socket
Sign inDemoInstall

rc-horizontal-scroll

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    rc-horizontal-scroll

React Horizontal Scroll


Version published
Maintainers
1
Install size
16.5 kB
Created

Readme

Source

rc-horizontal-scroll

Simple lightweight and customizable horizontal scroll.

Install

rc-horizontal-scroll

Features

  • Draggable on desktop
  • Lazyloading
  • Control space between items and desktop manage drag speed

Usage

import { HorizontalScrollView } from "rc-horizontal-scroll";

function App() {
  const [items, setItems] = useState(generateItems());
  return (
    <HorizontalScrollView
      uniqueProp='id'
      items={items}
      ItemComponent={Item}
      itemComponentProps={{ example: "example" }}
      onLastItemReached={page => {
        console.log(page);
        setItems([...items, ...generateItems()]);
      }}
      defaultSpace='120px'
      spaceBetweenItems='40px'
      moveSpeed={3}
    />
  );
}

/**
 * item -> The item data
 * parentProps -> the props passed in "itemComponentProps"
 * index -> the index of the item
 */
function Item({ item, parentProps, index }) {
  return (
    <div className='item'>
      <div className='image' style={{ backgroundImage: `url(${item.image})` }}></div>
      <div className='content'>
        <h4>{item.title + (index + 1)}</h4>
      </div>
    </div>
  );
}

const generateItems = () => [
  {
    id: "1_" + Date.now(),
    image: "https://picsum.photos/200/300",
    title: "Title"
  },
  {
    id: "2_" + Date.now(),
    image: "https://picsum.photos/200/300",
    title: "Title"
  },
  {
    id: "3_" + Date.now(),
    image: "https://picsum.photos/200/300",
    title: "Title"
  },
  {
    id: "4_" + Date.now(),
    image: "https://picsum.photos/200/300",
    title: "Title"
  },
  {
    id: "5_" + Date.now(),
    image: "https://picsum.photos/200/300",
    title: "Title"
  },
  {
    id: "6_" + Date.now(),
    image: "https://picsum.photos/200/300",
    title: "Title"
  }
];

API

Properties

NameTypeDefaultRequiredDescription
itemsarrayNotrueArray if items (objects)
uniquePropstringNofalseA unique prop used for key. If not found index will be used instead
ItemComponentfunctionNotrueThe component that renders each slide
itemComponentPropsobject{}trueThe props that are going to be passed to the ItemComponent as parentProps
onLastItemReachedfunction() => {}falseUsed for lazy loading
defaultSpacestring20pxfalseThe left and right space
spaceBetweenItemsstring20pxfalseThe space between each item
moveSpeednumber1.5falseMove speed (only for desktop)

ItemComponent Props

NameTypeDescription
indexnumberThe index of the item
parentPropsobjectThe data passed in itemComponentProps
itemobjectThe item data

License

rc-horizontal-slider is released under the MIT license.

Keywords

FAQs

Last updated on 08 Apr 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc