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

@mrtujiawei/react-components

v0.0.11

Published

react 组件库

Downloads

47

Readme

@mrtujiawei/react-components

npm version install size npm downloads js delivr downloads license

安装

使用 npm:

$ npm install @mrtujiawei/react-components

使用 yarn:

$ yarn add @mrtujiawei/react-components

使用 unpkg CDN:

注意: 使用 CDN 时,需要将React暴露到全局中

<!-- 开发环境 -->
<script src="https://unpkg.com/@mrtujiawei/react-components/dist/umd/index.js"></script>

<!-- 生产环境 -->
<script src="https://unpkg.com/@mrtujiawei/react-components/dist/umd/index.min.js"></script>

使用 jsdelivr CDN:

注意: 使用 CDN 时,需要将React暴露到全局中

<!-- 开发环境 -->
<script src="https://cdn.jsdelivr.net/npm/@mrtujiawei/react-components/dist/umd/index.js"></script>

<!-- 生产环境 -->
<script src="https://cdn.jsdelivr.net/npm/@mrtujiawei/react-components/dist/umd/index.min.js"></script>

使用

List

虚拟滚动列表

基本使用

import { List } from '@mrtujiawei/react-components';
import type { ListProps } from '@mrtujiawei/react-components';

const BasicList = () => {
  const itemCount = 1000;
  const dataList: number[] = Array.from(
    { length: itemCount },
    (_, index) => index + Math.random()
  );
  const height = 500;

  const Item: ListProps<number>['children'] = (props) => (
    <div style={props.style}>
      {props.index == itemCount ? '加载中...' : dataList[props.index]}
    </div>
  );

  return (
    <List itemCount={itemCount} itemSize={50} height={height}>
      {Item}
    </List>
  );
};

上拉加载

import { useState } from 'react';
import { List } from '@mrtujiawei/react-components';
import type { ListProps } from '@mrtujiawei/react-components';

const ListDemo = () => {
  const [hasMore, _setHasMore] = useState(true);
  const [itemCount, setItemCount] = useState(0);
  const [winHeight] = useState(() => {
    return document.documentElement.clientHeight;
  });

  const loadMore = async (_start: number, _end: number) => {
    setItemCount((itemCount) => itemCount + 20);
  };

  const Item: ListProps<unknown>['children'] = (props) => (
    <div style={props.style}>
      {props.index == itemCount ? '加载中...' : props.index}
    </div>
  );

  return (
    <List
      itemCount={itemCount}
      itemSize={50}
      height={winHeight}
      hasMore={hasMore}
      loadMore={loadMore}
    >
      {Item}
    </List>
  );
};

Props

height: number

容器高度

width: string | number = 100%

容器宽度

itemSize: number

单个列表项的高度

itemCount: number

数据总数

overscanCount: number = 1

屏幕外显示的列表项数量;数量越大,性能消耗越大; 适当增加可以减少页面空白

children: ComponentType<ListChildComponentProps>

子节点

useIsScrolling: boolean = false

开启滚动监听

itemKey: (index: number, data: T) => string | number

元素的key: 默认使用 index 作为下标

itemData: T = null

传递给children的数据

initialScrollOffset: number = 0

初始滚动高度

loadMore: (startIndex: number, endIndex: number) => void | Promise = null

触发上拉记载的参数, startIndex 开始加载数据的下标
startIndex == endIndextrue

hasMore: boolean = false

是否能够继续加载

threshold: number = 15

滚动到最后15个的时候, 开始加载新的数据

触发条件:

  1. 滚动
  2. 初始列表项不能填满容器高度

限制:
如果loadMore执行结束时,列表已停止滚动 那么即使剩余的列表项少于 threshold 也不会再次触发下一次加载