Skip to content

Commit 837aa44

Browse files
committed
docs: README
1 parent 50f8dd2 commit 837aa44

File tree

2 files changed

+4
-269
lines changed

2 files changed

+4
-269
lines changed

README.md

Lines changed: 4 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -1,137 +1,9 @@
1-
# @phphe/react-base-virtual-list ![GitHub License](https://img.shields.io/github/license/phphe/react-base-virtual-list) ![NPM Version](https://img.shields.io/npm/v/@phphe/react-base-virtual-list) ![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/phphe/react-base-virtual-list/build.yml) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/%40phphe%2Freact-base-virtual-list)
1+
# he-tree-react ![GitHub License](https://img.shields.io/github/license/phphe/he-tree-react) ![NPM Version](https://img.shields.io/npm/v/he-tree-react)
22

3-
[中文](README_CN.md)
3+
React draggable sortable tree component. [Document](https://he-tree-react.phphe.com).
44

5-
React Basic Virtual List. [Online Demo](https://phphe.github.io/react-base-virtual-list/)
6-
7-
## Features
8-
9-
- Supports lists with different item heights.
10-
- Simple and easy to extend, only contains common features.
11-
- High performance. For lists with different item heights, it does not retrieve the height of each item.
12-
- Exported files include TypeScript definition files, CJS files, ES files, IIFE files, and IIFE source maps. The IIFE file can be use by `script` tag in browser, see [IIFE](#iife).
13-
14-
## Installation
15-
16-
```sh
17-
npm install @phphe/react-base-virtual-list --save
18-
```
19-
20-
## Usage
21-
22-
```tsx
23-
import { VirtualList } from "@phphe/react-base-virtual-list";
24-
25-
export default function BaseExample() {
26-
const exampleData = [
27-
{
28-
headline: "in magna bibendum imperdiet",
29-
content: "Praesent blandit. Nam nulla.",
30-
},
31-
{
32-
headline: "non velit donec diam",
33-
content: "Aenean fermentum.",
34-
},
35-
];
36-
return (
37-
<>
38-
<VirtualList
39-
items={exampleData}
40-
style={{ height: "600px", border: "1px solid #ccc", padding: "10px" }}
41-
renderItem={(item, index) => (
42-
<div key={index} style={{ marginBottom: "10px" }}>
43-
<h3>
44-
{index}. {item.headline}
45-
</h3>
46-
<div>
47-
<div
48-
style={{
49-
float: "left",
50-
width: "100px",
51-
height: "100px",
52-
background: "#f0f0f0",
53-
borderRadius: "5px",
54-
marginRight: "10px",
55-
}}
56-
></div>
57-
{item.content}
58-
</div>
59-
</div>
60-
)}
61-
></VirtualList>
62-
</>
63-
);
64-
}
65-
```
66-
67-
## props (required)
68-
69-
- `items`: `Array`. List data.
70-
- `renderItem`: `(item, index: number) => ReactNode`. Rendering function for each item in the list. Index is the index of the list item in the whole list.
71-
72-
## props (optional)
73-
74-
- `itemSize`: `number`. Estimated height of a single item in the list.
75-
- `buffer`: `number`. Additional space outside the visible area of the virtual list to render.
76-
- `persistentIndices`: `number[]`. Array of indices of items to be persistently rendered. This keeps the corresponding items rendered continuously without being removed due to being outside the rendering area. You can make them sticky by using CSS `position:sticky`.
77-
- `listSize`: `number`, default: 1000. Height of the visible area of the list. Only used before DOM creation, suitable for SSR.
78-
- `triggerDistance`: `number`. The min distance to trigger re-rendering when scrolling.
79-
- `onScroll`: `typeof document.onscroll`. Listen for the list's scroll event. Type is same with HTML native onscroll handle.
80-
- `className`: `string`. Add a CSS class to the list root element.
81-
- `style`: `React.CSSProperties`. Add CSS styles to the list root element.
82-
83-
## Exposed Methods
84-
85-
First, use `ref` to obtain the exposed object.
86-
87-
```tsx
88-
import { useRef } from "react";
89-
import { VirtualList, VirtualListHandle } from "@phphe/react-base-virtual-list";
90-
91-
export default function BaseExample() {
92-
const ref = useRef<VirtualListHandle>(null);
93-
return (
94-
<>
95-
<VirtualList ref={ref}></VirtualList>
96-
</>
97-
);
98-
}
99-
```
100-
101-
Irrelevant parts are omitted in the above code. `VirtualListHandle` is a `typescript` type, please ignore it if you are using pure JS.
102-
103-
`VirtualListHandle` type code.
104-
105-
```ts
106-
interface VirtualListHandle {
107-
scrollToIndex(
108-
index: number,
109-
block?: "start" | "end" | "center" | "nearest"
110-
): void;
111-
forceUpdate(): void;
112-
}
113-
```
114-
115-
Then use the `ref` object to access the exposed methods.
116-
117-
- `scrollToIndex`: `(index:number, block = 'start'):void`. Scroll to the specified index position. `block` is equal to the `block` option of the HTML native method `scrollIntoView`.
118-
- `forceUpdate`: Forcefully re-render the list. This can be called after the visible area of the list changes.
119-
120-
## Note
121-
122-
- Remember to set the height of the list. Class, style, px, em, percentage, etc. are all acceptable.
123-
- Delayed loading, loading when scrolling to the bottom, etc. can be implemented using the exposed `onScroll`.
124-
125-
## IIFE
126-
127-
The `dist/index.iife.js` file can be run in the browser.
128-
You can host it on your server and then use the `script` tag to include it. Before including it, you also need to include `react`, `react-dom`. The global variable exposed by this file is `reactBaseVirtualList`, you can access all the exports of this file through `window.reactBaseVirtualList`, and get the main component exported through `window.reactBaseVirtualList.VirtualList`.
129-
130-
You can also use the following third-party CDN url to include it.
131-
132-
- unpkg: https://unpkg.com/@phphe/react-base-virtual-list
133-
- jsdelivr: https://cdn.jsdelivr.net/npm/@phphe/react-base-virtual-list
5+
React 可拖拽树组件. [文档](https://he-tree-react.phphe.com/zh).
1346

1357
## Changelog
1368

137-
https://github.com/phphe/react-base-virtual-list/releases
9+
https://github.com/phphe/he-tree-react/releases

README_CN.md

Lines changed: 0 additions & 137 deletions
This file was deleted.

0 commit comments

Comments
 (0)