|
| 1 | +<img src="https://user-images.githubusercontent.com/13347/101237112-ec4c6000-36de-11eb-936d-4b6b7ec94976.png" width="229" /> |
| 2 | + |
| 3 | +[](//badge.fury.io/js/react-virtuoso) |
| 4 | + |
| 5 | +**React Virtuoso** - the most complete React virtualization rendering list/table/grid family of components. |
| 6 | + |
| 7 | +- Variable sized items out of the box; no manual measurements or hard-coding item heights is necessary; |
| 8 | +- [Chat message list UI](https://virtuoso.dev/virtuoso-message-list/) **NEW**; |
| 9 | +- [Grouped mode with sticky headers](https://virtuoso.dev/grouped-by-first-letter/); |
| 10 | +- [Responsive grid layout](https://virtuoso.dev/grid-responsive-columns/); |
| 11 | +- [Table Support](https://virtuoso.dev/hello-table/); |
| 12 | +- [Automatic handling of content resize](https://virtuoso.dev/auto-resizing/); |
| 13 | +- [Custom Header, Footer, and empty list components](https://virtuoso.dev/customize-structure/); |
| 14 | +- [Pinned top items](https://virtuoso.dev/top-items/); |
| 15 | +- [Endless scrolling](https://virtuoso.dev/endless-scrolling/), [press to load more](https://virtuoso.dev/press-to-load-more/); |
| 16 | +- [Initial top most item index](https://virtuoso.dev/initial-index/); |
| 17 | +- [Scroll to index method](https://virtuoso.dev/scroll-to-index/). |
| 18 | + |
| 19 | +For live examples and documentation, check the [documentation website](https://virtuoso.dev). |
| 20 | + |
| 21 | +## Sponsors |
| 22 | + |
| 23 | +If you are using Virtuoso for work, [sponsor it](https://github.com/sponsors/petyosi). Any donation helps a lot with the project development and maintenance. |
| 24 | + |
| 25 | +## Get Started |
| 26 | + |
| 27 | +```sh |
| 28 | +npm install react-virtuoso |
| 29 | +``` |
| 30 | + |
| 31 | +```jsx |
| 32 | +import * as React from 'react' |
| 33 | +import * as ReactDOM from 'react-dom' |
| 34 | +import { Virtuoso } from 'react-virtuoso' |
| 35 | + |
| 36 | +const App = () => { |
| 37 | + return <Virtuoso style={{ height: '400px' }} totalCount={200} itemContent={index => <div>Item {index}</div>} /> |
| 38 | +} |
| 39 | + |
| 40 | +ReactDOM.render(<App />, document.getElementById('root')) |
| 41 | +``` |
| 42 | + |
| 43 | +## [Message List](https://virtuoso.dev/virtuoso-message-list/) |
| 44 | + |
| 45 | +The Virtuoso message list component is built specifically for human/chatbot conversations. In addition to the virtualized rendering, the component exposes an imperative data management |
| 46 | +API that gives you the necessary control over the scroll position when older messages are loaded, new messages arrive, and when the user submits a message. The scroll position can update instantly or with a smooth scroll animation. |
| 47 | + |
| 48 | +## [Grouped Mode](https://virtuoso.dev/grouped-by-first-letter/) |
| 49 | + |
| 50 | +The `GroupedVirtuoso` component is a variant of the "flat" `Virtuoso`, with the following differences: |
| 51 | + |
| 52 | +- Instead of `totalCount`, the component exposes `groupCounts: number[]` property, which specifies the amount of items in each group. |
| 53 | + For example, passing `[20, 30]` will render two groups with 20 and 30 items each; |
| 54 | +- In addition the `itemContent` property, the component requires an additional `groupContent` property, |
| 55 | + which renders the **group header**. The `groupContent` callback receives the zero-based group index as a parameter. |
| 56 | + |
| 57 | +## [Grid](https://virtuoso.dev/grid-responsive-columns/) |
| 58 | + |
| 59 | +The `VirtuosoGrid` component displays **same sized items** in multiple columns. |
| 60 | +The layout and item sizing is controlled through CSS class properties, which allows you to use media queries, min-width, percentage, etc. |
| 61 | + |
| 62 | +## [Table](https://virtuoso.dev/hello-table/) |
| 63 | + |
| 64 | +The `TableVirtuoso` component works just like `Virtuoso`, but with HTML tables. |
| 65 | +It supports window scrolling, sticky headers, sticky columns, and works with React Table and MUI Table. |
| 66 | + |
| 67 | +## Works With Your UI Library of Choice |
| 68 | + |
| 69 | +You can customize the markup up to your requirements - check [the Material UI list demo](https://virtuoso.dev/material-ui-endless-scrolling/). |
| 70 | +If you need to support reordering, [check the React Sortable HOC example](https://virtuoso.dev/react-sortable-hoc/). |
| 71 | + |
| 72 | +## Documentation and Demos |
| 73 | + |
| 74 | +For in-depth documentation and live examples of the supported features and live demos, check the [documentation website](https://virtuoso.dev). |
| 75 | + |
| 76 | +## Browser support |
| 77 | + |
| 78 | +To support [legacy browsers](https://caniuse.com/resizeobserver), you might have to load a [ResizeObserver Polyfill](https://www.npmjs.com/package/resize-observer-polyfill) before using `react-virtuoso`: |
| 79 | + |
| 80 | +``` |
| 81 | +import ResizeObserver from 'resize-observer-polyfill' |
| 82 | +if (!window.ResizeObserver) |
| 83 | + window.ResizeObserver = ResizeObserver |
| 84 | +``` |
| 85 | + |
| 86 | +## Author |
| 87 | + |
| 88 | +Petyo Ivanov [@petyosi](//twitter.com/petyosi). |
| 89 | + |
| 90 | +## Contributing |
| 91 | + |
| 92 | +### Fixes and new Features |
| 93 | + |
| 94 | +To run the tests, use `npm run test`. |
| 95 | +An end-to-end browser-based test suite is runnable with `npm run e2e`, with the pages being `e2e/*.tsx` and the tests `e2e/*.test.ts`. |
| 96 | + |
| 97 | +A convenient way to debug something is to preview the test cases in the browser. |
| 98 | +To do that, run `npm run dev` - it will launch a Ladle server that lets you browse the components in the `examples` folder. |
| 99 | + |
| 100 | +## License |
| 101 | + |
| 102 | +MIT License. |
0 commit comments