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

react-rowboat

v0.1.1

Published

构建原始、简单、可扩展的react slide组件

Downloads

5

Readme

NPM JavaScript Style Guide

使用场景

如果您需要在网页中构建slide | carousel组件,并且希望它灵活且简单。您可以尝试使用它

实现原理

react-rowboat使用了React Render Props模式最大程度的减少API,为您自定义组件提供了最大的灵活性。因为所有的组件内容和样式都是您自己负责渲染。

安装

npm install --save react-rowboat

使用

建议保持getContainerPropsgetWrapperProps行div所在的层级关系,因为它们有一些基本的样式依赖,除此之外您可以渲染任意的内容。

import React from 'react'
import ReactDOM from 'react-dom'
import RowBoat from "react-rowbot";

const items = [
  "img src1",
  "img src2",
  "img src3"
];
ReactDOM.render(
  <RowBoat
    length={items.length}
    loop
  >
    {({
      index,
      setIndex,
      getContainerProps,
      getWrapperProps,
      getItemProps
    }) => {
      return (
        <div className="slide" {...getContainerProps()}>
          <div className="prev" onClick={() => setIndex(index - 1)}>
            prev
          </div>
          <div className="next" onClick={() => setIndex(index + 1)}>
            next
          </div>
          <div {...getWrapperProps()}>
            {items.map((v, vIndex) => {
              return (
                <div
                  key={vIndex}
                  className={`slide-item ${
                    index - 1 === vIndex ? "actives" : ""
                  }`}
                  {...getItemProps()}
                >
                  <img src={v} alt="" />
                </div>
              );
            })}
          </div>
        </div>
      );
    }}
  </RowBoat>,
  document.getElementById("root")
)

基础属性

下面列举出了所有RowBoat组件所能使用的属性

children

function({}) | required

接收一个函数类型,它应该返回您所需要的组件。

length

number | required

length用于边界判断,一般使用items.length的属性即可

defaultIndex

number/null | 默认为1

用于设置默认的index索引

speed

number/null | 默认为300, 单位为ms

用于控制播放的时间间隔,单位为ms

loop

bool/null | 默认为false

用于设置当index到达末尾时是否重新设置为1

direction

string/null | 默认为horizontal

有两种模式可以选择,您可以通过下面的方式引入

import RowBoat, { HORIZONTAL, VERTICAL } from "rect-rowboat";

HORIZONTAL为水平动画模式,VERTICAL为垂直动画模式

drag

bool/null | 默认为false

如果给定drag参数则可以使用鼠标拖动切换

autoplay

bool/null | 默认为false

如果传递此属性,react-rowboat将会自动播放

delay

number/null | 默认为3000,单位为ms

用于控制自动播放的时间间隔,单位为ms

Children Function

您可以像下面这样去使用Render Props, 强烈推荐保持如下的页面结构

<RowBoat
  length={items.length}
>
  {({
    index,
    setIndex,
    getContainerProps,
    getWrapperProps,
    getItemProps
  }) => {
    return (
      <div {...getContainerProps()}>
        <div {...getWrapperProps()}>
          {items.map((v, vIndex) => <div>{/* 你的jsx组件代码 */}</div>)}
        </div>
      </div>
    );
  }}
</RowBoat>

在这里对React Render Props模式所能使用的参数进行说明

| 属性 | 类型 | 描述 | |------------------------|-------------|----------------------------| | index | number | 当前正在显示中的索引 | | setIndex | func | 设置index的值 | | getContainerProps | func | 返回容器元素必须的属性 | | getWrapperProps | func | 返回包装元素必须的属性 | | getItemProps | func | 返回项目元素必须的属性 |

License

MIT © https://github.com/monsterooo