|
1 | | -# @rc-component/virtual-list |
2 | | - |
3 | | -React Virtual List Component which works with animation. |
4 | | - |
5 | | -[![NPM version][npm-image]][npm-url] |
6 | | -[![npm download][download-image]][download-url] |
7 | | -[![build status][github-actions-image]][github-actions-url] |
8 | | -[![Codecov][codecov-image]][codecov-url] |
9 | | -[![bundle size][bundlephobia-image]][bundlephobia-url] |
10 | | -[![dumi][dumi-image]][dumi-url] |
11 | | - |
12 | | -[npm-image]: https://img.shields.io/npm/v/@rc-component/virtual-list.svg?style=flat-square |
13 | | -[npm-url]: https://npmjs.org/package/@rc-component/virtual-list |
14 | | -[travis-image]: https://img.shields.io/travis/react-component/virtual-list/master?style=flat-square |
15 | | -[travis-url]: https://travis-ci.com/react-component/virtual-list |
16 | | -[github-actions-image]: https://github.com/react-component/virtual-list/actions/workflows/main.yml/badge.svg |
17 | | -[github-actions-url]: https://github.com/react-component/virtual-list/actions/workflows/main.yml |
18 | | -[codecov-image]: https://img.shields.io/codecov/c/github/react-component/virtual-list/master.svg?style=flat-square |
19 | | -[codecov-url]: https://app.codecov.io/gh/react-component/virtual-list |
20 | | -[david-url]: https://david-dm.org/react-component/virtual-list |
21 | | -[david-image]: https://david-dm.org/react-component/virtual-list/status.svg?style=flat-square |
22 | | -[david-dev-url]: https://david-dm.org/react-component/virtual-list?type=dev |
23 | | -[david-dev-image]: https://david-dm.org/react-component/virtual-list/dev-status.svg?style=flat-square |
24 | | -[download-image]: https://img.shields.io/npm/dm/@rc-component/virtual-list.svg?style=flat-square |
25 | | -[download-url]: https://npmjs.org/package/@rc-component/virtual-list |
26 | | -[bundlephobia-url]: https://bundlephobia.com/package/@rc-component/virtual-list |
27 | | -[bundlephobia-image]: https://badgen.net/bundlephobia/minzip/@rc-component/virtual-list |
28 | | -[dumi-url]: https://github.com/umijs/dumi |
29 | | -[dumi-image]: https://img.shields.io/badge/docs%20by-dumi-blue?style=flat-square |
30 | | - |
31 | | -## Online Preview |
32 | | - |
33 | | -https://virtual-list-react-component.vercel.app/ |
| 1 | +<div align="center"> |
| 2 | + <h1>@rc-component/virtual-list</h1> |
| 3 | + <p>📜 Virtual scrolling list component for React.</p> |
| 4 | + <p> |
| 5 | + <a href="https://ant.design"> |
| 6 | + <img width="32" height="32" src="https://gw.alipayobjects.com/zos/bmw-prod/ae669a89-0c24-40ff-a91d-2b83497170f6.svg" alt="Ant Design" /> |
| 7 | + </a> |
| 8 | + </p> |
| 9 | + <p>Part of the <a href="https://ant.design">Ant Design</a> ecosystem.</p> |
| 10 | + <p> |
| 11 | + <a href="https://www.npmjs.com/package/@rc-component/virtual-list"><img src="https://img.shields.io/npm/v/@rc-component/virtual-list.svg?style=flat-square" alt="npm version" /></a> |
| 12 | + <a href="https://www.npmjs.com/package/@rc-component/virtual-list"><img src="https://img.shields.io/npm/dm/@rc-component/virtual-list.svg?style=flat-square" alt="npm downloads" /></a> |
| 13 | + <a href="https://github.com/react-component/virtual-list/actions/workflows/react-component-ci.yml"><img src="https://github.com/react-component/virtual-list/actions/workflows/react-component-ci.yml/badge.svg" alt="CI" /></a> |
| 14 | + <a href="https://app.codecov.io/gh/react-component/virtual-list"><img src="https://img.shields.io/codecov/c/github/react-component/virtual-list/master.svg?style=flat-square" alt="Codecov" /></a> |
| 15 | + <a href="https://bundlephobia.com/package/@rc-component/virtual-list"><img src="https://badgen.net/bundlephobia/minzip/@rc-component/virtual-list" alt="bundle size" /></a> |
| 16 | + <a href="https://github.com/umijs/dumi"><img src="https://img.shields.io/badge/docs%20by-dumi-blue?style=flat-square" alt="dumi" /></a> |
| 17 | + </p> |
| 18 | +</div> |
| 19 | + |
| 20 | +## Highlights |
| 21 | + |
| 22 | +- Built for React and maintained by the rc-component team. |
| 23 | +- Used by Ant Design and other React component libraries. |
| 24 | +- Ships TypeScript declarations with both ES module and CommonJS outputs. |
| 25 | +- Keeps examples, tests, and preview builds aligned with the package source. |
34 | 26 |
|
35 | | -## Development |
| 27 | +## Install |
36 | 28 |
|
37 | 29 | ```bash |
38 | | -npm install |
39 | | -npm start |
40 | | -open http://localhost:8000/ |
| 30 | +npm install @rc-component/virtual-list |
41 | 31 | ``` |
42 | 32 |
|
43 | | -## Feature |
| 33 | +## Usage |
| 34 | + |
| 35 | +```tsx |
| 36 | +import List from '@rc-component/virtual-list'; |
44 | 37 |
|
45 | | -- Support react.js |
46 | | -- Support animation |
47 | | -- Support IE11+ |
| 38 | +const data = Array.from({ length: 1000 }).map((_, index) => ({ |
| 39 | + id: index, |
| 40 | + label: `Item ${index}`, |
| 41 | +})); |
48 | 42 |
|
49 | | -## Install |
| 43 | +export default () => ( |
| 44 | + <List data={data} height={240} itemHeight={32} itemKey="id"> |
| 45 | + {(item) => <div>{item.label}</div>} |
| 46 | + </List> |
| 47 | +); |
| 48 | +``` |
50 | 49 |
|
51 | | -[](https://npmjs.org/package/@rc-component/virtual-list) |
| 50 | +## Examples |
52 | 51 |
|
53 | | -## Usage |
| 52 | +Run the local dumi site to explore the examples: |
54 | 53 |
|
55 | | -```tsx |
56 | | -import List from '@rc-component/virtual-list'; |
| 54 | +```bash |
| 55 | +npm install |
| 56 | +npm start |
| 57 | +``` |
| 58 | + |
| 59 | +## API |
| 60 | + |
| 61 | +### List |
| 62 | + |
| 63 | +| Prop | Description | Type | Default | |
| 64 | +| ---------- | ---------------------------------------------------------------------------------------------------------------------- | -------------------------------------- | ------- | |
| 65 | +| children | Render function for each item. The third argument contains measuring props used by legacy browser compatibility paths. | `(item, index, props) => ReactElement` | - | |
| 66 | +| component | Custom list container element. | `string` \| `ComponentType` | `div` | |
| 67 | +| data | Items rendered by the virtual list. | `T[]` | - | |
| 68 | +| disabled | Disable scroll position checks, usually while coordinating animation. | `boolean` | `false` | |
| 69 | +| fullHeight | Whether the holder should keep full height. | `boolean` | `true` | |
| 70 | +| height | Visible list height. | `number` | - | |
| 71 | +| itemHeight | Minimum item height used to calculate the virtual range. | `number` | - | |
| 72 | +| itemKey | Key field or key getter for items. | `string` \| `(item) => React.Key` | - | |
| 73 | +| onScroll | Called when the list scrolls. | `React.UIEventHandler<HTMLElement>` | - | |
| 74 | +| styles | Custom scrollbar part styles. | `object` | - | |
| 75 | +| virtual | Enable virtual rendering. | `boolean` | `true` | |
| 76 | + |
| 77 | +## Development |
57 | 78 |
|
58 | | -<List data={[0, 1, 2]} height={200} itemHeight={30} itemKey="id"> |
59 | | - {(index) => <div>{index}</div>} |
60 | | -</List>; |
| 79 | +```bash |
| 80 | +npm install |
| 81 | +npm start |
| 82 | +npm test |
| 83 | +npm run tsc |
| 84 | +npm run compile |
| 85 | +npm run build |
61 | 86 | ``` |
62 | 87 |
|
63 | | -# API |
| 88 | +## Release |
64 | 89 |
|
65 | | -## List |
| 90 | +The release flow is handled by `@rc-component/np` from the `prepublishOnly` script: |
| 91 | + |
| 92 | +```bash |
| 93 | +npm publish |
| 94 | +``` |
66 | 95 |
|
67 | | -| Prop | Description | Type | Default | |
68 | | -| ---------- | ------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | |
69 | | -| children | Render props of item | (item, index, props) => ReactElement | - | |
70 | | -| component | Customize List dom element | string \| Component | div | |
71 | | -| data | Data list | Array | - | |
72 | | -| disabled | Disable scroll check. Usually used on animation control | boolean | false | |
73 | | -| height | List height | number | - | |
74 | | -| itemHeight | Item minimum height | number | - | |
75 | | -| itemKey | Match key with item | string | - | |
76 | | -| styles | style | { horizontalScrollBar?: React.CSSProperties; horizontalScrollBarThumb?: React.CSSProperties; verticalScrollBar?: React.CSSProperties; verticalScrollBarThumb?: React.CSSProperties; } | - | |
| 96 | +## License |
77 | 97 |
|
78 | | -`children` provides additional `props` argument to support IE 11 scroll shaking. |
79 | | -It will set `style` to `visibility: hidden` when measuring. You can ignore this if no requirement on IE. |
| 98 | +@rc-component/virtual-list is released under the MIT license. |
0 commit comments