Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ stats-hydration.json
stats.json
stats.html
.vscode/settings.json
.idea

*.log
.DS_Store
Expand Down
36 changes: 36 additions & 0 deletions docs/framework/lit/lit-virtual.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
title: Lit Virtual
---

The `@tanstack/lit-virtual` adapter is a wrapper around the core virtual logic.

## `createVirtualizer`

```tsx

private virtualizerController = new VirtualizerController<TScrollElement, TItemElement = unknown>(
options: PartialKeys< VirtualizerOptions<TScrollElement, TItemElement>,
'observeElementRect' | 'observeElementOffset' | 'scrollToFn'
)
```

This class stands for a standard `Virtualizer` instance configured to work with an HTML element as the scrollElement.
This will create a Lit Controller which can be accessed in the element render method.

```tsx
render() {
const virtualizer = this.virtualizerController.getVirtualizer();
const virtualItems = virtualizer.getVirtualItems();
}
)
```

## `createWindowVirtualizer`

```tsx
private windowVirtualizerController = new WindowVirtualizerController<TItemElement = unknown>(
options: PartialKeys< VirtualizerOptions<TItemElement>,
'getScrollElement' | 'observeElementRect' | 'observeElementOffset' | 'scrollToFn'
```

This class stands of window-based `Virtualizer` instance configured to work with an HTML element as the scrollElement.
5 changes: 5 additions & 0 deletions examples/lit/dynamic/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
.DS_Store
dist
dist-ssr
*.local
6 changes: 6 additions & 0 deletions examples/lit/dynamic/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Example

To run this example:

- `npm install` or `npm`
- `npm run start` or `npm run start`
12 changes: 12 additions & 0 deletions examples/lit/dynamic/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.ts"></script>
<my-app></my-app>
</body>
</html>
21 changes: 21 additions & 0 deletions examples/lit/dynamic/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "tanstack-lit-virtual-example-dynamic",
"private": true,
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"serve": "vite preview"
},
"dependencies": {
"@faker-js/faker": "^7.6.0",
"@tanstack/lit-virtual": "workspace:*",
"@tanstack/virtual-core": "workspace:*",
"lit": "^3.1.3"
},
"devDependencies": {
"@rollup/plugin-replace": "^5.0.2",
"@types/node": "^18.19.3",
"typescript": "5.2.2",
"vite": "^5.1.3"
}
}
8 changes: 8 additions & 0 deletions examples/lit/dynamic/src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
html {
font-family: sans-serif;
font-size: 14px;
}

body {
padding: 1rem;
}
Loading