{"id":23773391,"url":"https://github.com/beenotung/stencil-virtual-scroll","last_synced_at":"2025-09-05T18:31:14.057Z","repository":{"id":57370750,"uuid":"210747052","full_name":"beenotung/stencil-virtual-scroll","owner":"beenotung","description":"virtual-scroll typed web component that only render visible items on the DOM","archived":false,"fork":false,"pushed_at":"2021-10-21T11:11:14.000Z","size":41,"stargazers_count":11,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-19T14:16:32.809Z","etag":null,"topics":["custom-elements","stencil-components","typescript","webcomponents"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/stencil-virtual-scroll","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/beenotung.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-09-25T03:24:21.000Z","updated_at":"2024-05-20T11:10:39.000Z","dependencies_parsed_at":"2022-09-18T10:41:17.380Z","dependency_job_id":null,"html_url":"https://github.com/beenotung/stencil-virtual-scroll","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beenotung%2Fstencil-virtual-scroll","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beenotung%2Fstencil-virtual-scroll/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beenotung%2Fstencil-virtual-scroll/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beenotung%2Fstencil-virtual-scroll/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/beenotung","download_url":"https://codeload.github.com/beenotung/stencil-virtual-scroll/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232052261,"owners_count":18465722,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["custom-elements","stencil-components","typescript","webcomponents"],"created_at":"2025-01-01T05:39:36.963Z","updated_at":"2025-01-01T05:39:37.548Z","avatar_url":"https://github.com/beenotung.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# stencil-virtual-scroll\n\nvirtual-scroll typed web component that only render visible items on the DOM\n\nDemo: https://virtual-scroll-demo.surge.sh\n\n[![npm Package Version](https://img.shields.io/npm/v/stencil-virtual-scroll.svg?maxAge=2592000)](https://www.npmjs.com/package/stencil-virtual-scroll)\n![Built With Stencil](https://img.shields.io/badge/-Built%20With%20Stencil-16161d.svg?logo=data%3Aimage%2Fsvg%2Bxml%3Bbase64%2CPD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPCEtLSBHZW5lcmF0b3I6IEFkb2JlIElsbHVzdHJhdG9yIDE5LjIuMSwgU1ZHIEV4cG9ydCBQbHVnLUluIC4gU1ZHIFZlcnNpb246IDYuMDAgQnVpbGQgMCkgIC0tPgo8c3ZnIHZlcnNpb249IjEuMSIgaWQ9IkxheWVyXzEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4IgoJIHZpZXdCb3g9IjAgMCA1MTIgNTEyIiBzdHlsZT0iZW5hYmxlLWJhY2tncm91bmQ6bmV3IDAgMCA1MTIgNTEyOyIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI%2BCjxzdHlsZSB0eXBlPSJ0ZXh0L2NzcyI%2BCgkuc3Qwe2ZpbGw6I0ZGRkZGRjt9Cjwvc3R5bGU%2BCjxwYXRoIGNsYXNzPSJzdDAiIGQ9Ik00MjQuNywzNzMuOWMwLDM3LjYtNTUuMSw2OC42LTkyLjcsNjguNkgxODAuNGMtMzcuOSwwLTkyLjctMzAuNy05Mi43LTY4LjZ2LTMuNmgzMzYuOVYzNzMuOXoiLz4KPHBhdGggY2xhc3M9InN0MCIgZD0iTTQyNC43LDI5Mi4xSDE4MC40Yy0zNy42LDAtOTIuNy0zMS05Mi43LTY4LjZ2LTMuNkgzMzJjMzcuNiwwLDkyLjcsMzEsOTIuNyw2OC42VjI5Mi4xeiIvPgo8cGF0aCBjbGFzcz0ic3QwIiBkPSJNNDI0LjcsMTQxLjdIODcuN3YtMy42YzAtMzcuNiw1NC44LTY4LjYsOTIuNy02OC42SDMzMmMzNy45LDAsOTIuNywzMC43LDkyLjcsNjguNlYxNDEuN3oiLz4KPC9zdmc%2BCg%3D%3D\u0026colorA=16161d\u0026style=flat-square)\n\n## Why yet another virtual-scroll component?\n1. The `ion-virtual-scroll` is only documented for Angular;\n   not supported for react;\n   undocumented and untyped for Javascript/Typescript (without framework)\n2. The `ion-virtual-scroll` for Javascript doesn't allow content before / after it.\n   i.e. It will occupy the entire page.\n   (Workaround exist when providing `renderHeader` and `renderFooter` but still limiting the comsumer component structure)\n3. The `ion-virtual-scroll` scroll height is not correct.\n   The content height grow as you scroll, resulting 'endless list' feeling.\n\n##### But why naming it stencil-virtual-scroll?\n~~Because virtual-scroll is already occupied on npm.~~\n\nUsing this name for now in case people search for stencil style (typed) web component library.\n\nMight rename it when better idea comes in. Welcome suggestions.\n\n## Features\n- [x] Auto places items based on their size.\n- [x] Support multiple columns in a row if the item width is smaller than the half of container width\n- [x] Allow parent to instruct the container to re-render when updated\n- [x] Allow lazy loading items instead of constructing a huge array\n- [x] Written in Typescript\n\n## Components Properties\n- [virtual-scroll](./src/components/virtual-scroll/readme.md)\n- [virtual-scroll-list](./src/components/virtual-scroll-list/readme.md)\n\n## Examples with typed hints on Props\nBelow shows some usage examples of \u003cvirtual-scroll\u003e and \u003cvirtual-scroll-list\u003e.\n\nDetails refer to:\n- [stencil-virtual-scroll-demo](./src/components/stencil-virtual-scroll-demo)\n\n### Using \u003cvirtual-scroll\u003e for fixed-size cells in grid view:\n\n```typescript jsx\nimport 'stencil-virtual-scroll'; // still need to import the library (js)\n\n@Component({\n  tag: 'virtual-scroll-demo',\n  styleUrl: 'virtual-scroll-demo.css',\n  scoped: true,\n})\nexport class VirtualScrollDemo {\n\n  render() {\n    return (\n      \u003cdiv\u003e\n        before\n        \u003cvirtual-scroll\n          itemCount={100000}\n          renderItem={i =\u003e \u003cimg src={`https://via.placeholder.com/600/${i}`}/\u003e}\n          itemWidth={48}\n          itemHeight={48}\n          style={{\n            display: 'block',\n            width: '100%',\n            height: '450px',\n            maxHeight: '80vh',\n            outline: 'blue solid 1px',\n          }}\n        /\u003e\n        after\n      \u003c/div\u003e\n    );\n  }\n\n}\n```\n\nDetails refer to:\n- [virtual-scroll-demo](./src/components/virtual-scroll-demo)\n\n### Using \u003cvirtual-scroll-list\u003e for vary-height items in list view:\n\n```typescript jsx\nimport { Component, h, Host } from '@stencil/core';\n\nconst N = 100;\nconst width = 450;\nconst height = 50;\nconst heights = Array(N).fill(height)\n  .map(height =\u003e Math.floor(height * (1 + Math.random() * 2)));\n\n@Component({\n  tag: 'virtual-scroll-list-demo',\n  styleUrl: 'virtual-scroll-list-demo.css',\n  scoped: true,\n})\nexport class VirtualScrollListDemo {\n\n  renderItem(i: number) {\n    let height = heights[i];\n    return \u003cdiv style={{\n      width: '450px',\n      height: height + 'px',\n      outline: '1px solid purple',\n      position: 'relative',\n    }}\u003e\n      {i}\n    \u003c/div\u003e;\n  }\n\n  render() {\n    return (\n      \u003cHost\u003e\n        before\n        \u003cvirtual-scroll-list\n          itemCount={N}\n          renderItem={i =\u003e this.renderItem(i)}\n          itemWidth={width}\n          itemHeights={heights}\n          estimatedItemHeight={height}\n          style={{\n            display: 'block',\n            width: '100%',\n            height: '450px',\n            maxHeight: '80vh',\n            outline: 'blue solid 1px',\n          }}\n        /\u003e\n        after\n      \u003c/Host\u003e\n    );\n  }\n\n}\n\n```\n\nDetails refer to:\n- [virtual-scroll-list-demo](./src/components/virtual-scroll-list-demo)\n\n## About Stencil\n\nStencil is a compiler for building fast web apps using Web Components.\n\nStencil combines the best concepts of the most popular frontend frameworks into a compile-time rather than run-time tool.  Stencil takes TypeScript, JSX, a tiny virtual DOM layer, efficient one-way data binding, an asynchronous rendering pipeline (similar to React Fiber), and lazy-loading out of the box, and generates 100% standards-based Web Components that run in any browser supporting the Custom Elements v1 spec.\n\nStencil components are just Web Components, so they work in any major framework or with no framework at all.\n\n## Getting Started\n\nTo develop this web component using Stencil, clone this repo to a new directory:\n\n```bash\ngit clone https://github.com/beenotung/stencil-virtual-scroll.git\ncd stencil-virtual-scroll\n```\n\nand run:\n\n```bash\nnpm install\nnpm start\n```\n\nTo build the component for production, run:\n\n```bash\nnpm run build\n```\n\nTo run the unit tests for the components, run:\n\n```bash\nnpm test\n```\n\nNeed help? Check out our docs [here](https://stenciljs.com/docs/my-first-component).\n\n\n## Naming Components\n\nWhen creating new component tags, we recommend _not_ using `stencil` in the component name (ex: `\u003cstencil-datepicker\u003e`). This is because the generated component has little to nothing to do with Stencil; it's just a web component!\n\nInstead, use a prefix that fits your company or any name for a group of related components. For example, all of the Ionic generated web components use the prefix `ion`.\n\n\n## Using this component\n\nThe web component is published on npm as https://www.npmjs.com/package/stencil-virtual-scroll.\n\nThere are three options to use web components built with Stencil.\n\n### In a stencil-starter app (recommended)\n- Run `npm install stencil-virtual-scroll --save`\n- Add an import to the npm packages `import 'stencil-virtual-scroll';`\n- Then you can use the element anywhere in your template, JSX, html etc\n\n### Node Modules (need backend support)\n- Run `npm install stencil-virtual-scroll --save`\n- Put a script tag similar to this `\u003cscript src='node_modules/stencil-virtual-scroll/dist/stencil-virtual-scroll.esm.js'\u003e\u003c/script\u003e` in the head of your index.html\n- Then you can use the element anywhere in your template, JSX, html etc\n\n### Script tag (easiest but depends on 3rd-party service)\n\n- Put a script tag similar to this `\u003cscript src='https://unpkg.com/stencil-virtual-scroll@0.0.5/dist/stencil-virtual-scroll.esm.js'\u003e\u003c/script\u003e` in the head of your index.html\n- Then you can use the element anywhere in your template, JSX, html etc\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeenotung%2Fstencil-virtual-scroll","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbeenotung%2Fstencil-virtual-scroll","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeenotung%2Fstencil-virtual-scroll/lists"}